generated from kurone-kito/vpm-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added the utility functions for the editor extensions
- Loading branch information
1 parent
3f76f3e
commit 83c85fa
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace black.kit.toybox.Editor | ||
{ | ||
/// <summary>The utility class for the editor.</summary> | ||
public static class EditorUtils | ||
{ | ||
/// <summary>Draw the banner to the inspector.</summary> | ||
/// <param name="banner">The texture of the banner.</param> | ||
public static void DrawBanner(Texture banner, float aspectRatio) | ||
{ | ||
if (!banner) | ||
{ | ||
return; | ||
} | ||
const float PADDING = 20f; | ||
var width = EditorGUIUtility.currentViewWidth - PADDING * 2f; | ||
var height = BannerInit.GetHeight(width, aspectRatio); | ||
var rect = new Rect() { width = width, height = height }; | ||
var rect2 = GUILayoutUtility.GetRect(rect.width, rect.height); | ||
rect.x = PADDING - 4f; | ||
rect.y = rect2.y; | ||
GUI.DrawTexture(rect, banner, ScaleMode.StretchToFill); | ||
EditorGUILayout.Space(); | ||
} | ||
|
||
/// <summary>Draw the detail of the inspector.</summary> | ||
/// <typeparam name="T">The type of the target.</typeparam> | ||
/// <param name="detail">The detail to draw.</param> | ||
/// <param name="style">The style of the detail.</param> | ||
public static void DrawDetail<T>(string detail, GUIStyle style) | ||
where T : MonoBehaviour | ||
{ | ||
EditorGUILayout.BeginVertical(GUI.skin.box); | ||
var className = typeof(T).FullName; | ||
EditorGUILayout.LabelField($"<b>{className}</b>", style); | ||
EditorGUILayout.LabelField(detail, style); | ||
EditorGUILayout.EndVertical(); | ||
EditorGUILayout.Space(); | ||
} | ||
|
||
/// <summary>Draw the list of the inspector.</summary> | ||
/// <param name="list">The list to draw.</param> | ||
/// <param name="style">The style of the list.</param> | ||
/// <param name="selectable">The list is selectable.</param> | ||
public static void DrawList( | ||
IEnumerable<string> list, | ||
GUIStyle style, | ||
ListOptions options = new ()) | ||
{ | ||
var putItem = options.CreatePutItem(style); | ||
foreach ( | ||
var (item, index) | ||
in list.Select((item, index) => (item, index))) | ||
{ | ||
putItem(item, index); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Draw the Udon event of the inspector. | ||
/// </summary> | ||
/// <param name="argument">The argument of the Udon event.</param> | ||
/// <param name="style">The style of the list.</param> | ||
public static void DrawUdonEvent(string argument, GUIStyle style) | ||
{ | ||
var list = new[] | ||
{ | ||
T.USAGE_RUNTIME_ONLY, | ||
T.USAGE_THIS_COMPONENT, | ||
T.USAGE_SEND_CUSTOM_EVENT, | ||
argument, | ||
}; | ||
EditorGUI.indentLevel++; | ||
DrawList(list, style, new() { Selectable = true }); | ||
EditorGUI.indentLevel--; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.