-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
529 additions
and
234 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
#if UNITY_EDITOR | ||
using System; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Aya.DataBinding | ||
{ | ||
public static class EditorIcon | ||
{ | ||
#region Icon Method | ||
|
||
public static Texture2D CreateIcon(Type type, int size = 24) | ||
{ | ||
var srcIcon = GetIcon(type); | ||
if (srcIcon == null) return default; | ||
var icon = CreateIconWithSrc(srcIcon, size); | ||
return icon; | ||
} | ||
|
||
public static Texture2D CreateIcon(string name, int size = 24) | ||
{ | ||
var srcIcon = GetIcon(name); | ||
if (srcIcon == null) return default; | ||
var icon = CreateIconWithSrc(srcIcon, size); | ||
return icon; | ||
} | ||
|
||
public static Texture2D GetIcon(Type type) | ||
{ | ||
if (type != null) return EditorGUIUtility.ObjectContent(null, type).image as Texture2D; | ||
return default; | ||
} | ||
|
||
public static Texture2D GetIcon(string name) | ||
{ | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
var icon = EditorGUIUtility.FindTexture(name); | ||
if (icon == null) icon = AssetDatabase.GetCachedIcon(name) as Texture2D; | ||
if (icon == null) icon = EditorGUIUtility.IconContent(name).image as Texture2D; | ||
return icon; | ||
} | ||
|
||
return default; | ||
} | ||
|
||
public static Texture2D CreateIconWithSrc(Texture2D srcIcon, int size = 24) | ||
{ | ||
// Copy Built-in texture with RenderTexture | ||
var tempRenderTexture = RenderTexture.GetTemporary(size, size, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); | ||
Graphics.Blit(srcIcon, tempRenderTexture); | ||
var previousRenderTexture = RenderTexture.active; | ||
RenderTexture.active = tempRenderTexture; | ||
var icon = new Texture2D(size, size); | ||
icon.ReadPixels(new Rect(0, 0, tempRenderTexture.width, tempRenderTexture.height), 0, 0); | ||
icon.Apply(); | ||
RenderTexture.ReleaseTemporary(tempRenderTexture); | ||
RenderTexture.active = previousRenderTexture; | ||
return icon; | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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,68 @@ | ||
#if UNITY_EDITOR | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Aya.DataBinding | ||
{ | ||
public static partial class GUIMenu | ||
{ | ||
public static void DrawSearchableDropdownMenu(string propertyName, | ||
SearchableDropdown menu, | ||
Func<bool> checkNullFunc, | ||
Func<string> currentDisplayNameGetter) | ||
{ | ||
var isNull = checkNullFunc(); | ||
using (GUIErrorColorArea.Create(isNull)) | ||
{ | ||
GUILayout.BeginHorizontal(); | ||
GUILayout.Label(propertyName, GUILayout.Width(EditorGUIUtility.labelWidth)); | ||
|
||
var displayName = currentDisplayNameGetter(); | ||
var currentPropertyDisplayName = isNull ? EditorStyle.NoneStr : displayName; | ||
var btnRect = GUILayoutUtility.GetRect(new GUIContent(currentPropertyDisplayName), EditorStyles.toolbarButton); | ||
var btnType = GUI.Button(btnRect, currentPropertyDisplayName, EditorStyles.popup); | ||
if (btnType) | ||
{ | ||
btnRect.width = EditorGUIUtility.currentViewWidth; | ||
menu.Show(btnRect, 500f); | ||
} | ||
|
||
GUILayout.EndHorizontal(); | ||
} | ||
} | ||
|
||
public static SearchableDropdown CreateSearchableDropdownMenu<T>(string menuTitle, | ||
IEnumerable<T> valueSource, | ||
Func<T, string> pathGetter, | ||
Func<T, Texture2D> iconGetter, | ||
Action<T> onClick = null) | ||
{ | ||
var root = new SearchableDropdownItem(menuTitle); | ||
var menu = new SearchableDropdown(root, item => | ||
{ | ||
var value = (T)item.Value; | ||
onClick?.Invoke(value); | ||
}); | ||
|
||
root.AddChild(new SearchableDropdownItem(EditorStyle.NoneStr, null)); | ||
root.AddSeparator(); | ||
|
||
foreach (var value in valueSource) | ||
{ | ||
var path = pathGetter(value); | ||
var icon = iconGetter(value); | ||
var item = new SearchableDropdownItem(path, value) | ||
{ | ||
icon = icon | ||
}; | ||
|
||
root.AddChild(item); | ||
} | ||
|
||
return menu; | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
Oops, something went wrong.