Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Seantong committed Dec 3, 2019
1 parent e8fba28 commit bf27680
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 51 deletions.
33 changes: 33 additions & 0 deletions Editor/AssetDBHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using UnityEditor;
namespace EditorPlus
{
public static class AssetDBHelper
{
/// <summary>
/// Load Searched Asset
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="search"></param>
/// <returns></returns>
public static T LoadAsset<T>(string search) where T : UnityEngine.Object
{
var templatePath = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets(search)[0]);
var TemplateAsset = AssetDatabase.LoadAssetAtPath<T>(templatePath);
return TemplateAsset;
}
public static List<T> LoadAssets<T>(string search) where T : UnityEngine.Object
{
List<T> ts = new List<T>();
var assetPathes = AssetDatabase.FindAssets(search);
foreach (var item in assetPathes)
{
var path = AssetDatabase.GUIDToAssetPath(item);
var asset = AssetDatabase.LoadAssetAtPath<T>(path);
ts.Add(asset);
}
return ts;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Editor/AssetDBHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Editor/EditorMarkdown/EditorMarkDownWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override void OnEnable(SeanLibManager drawer)
Docs[docName] = doc;
}
}
public override void EnableUIElements()
public override void SetupUIElements()
{
if (!string.IsNullOrEmpty(UXML))
{
Expand Down
109 changes: 71 additions & 38 deletions Editor/InspectorPlus/Window/SelectWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SeanLib.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
Expand All @@ -9,36 +10,65 @@ namespace EditorPlus
{
public class SelectWindow<T> : PopupWindowContent
{
protected OnGUIUtility.Search searchField = new OnGUIUtility.Search();
public struct CallBack
{
public Action<T, int> OnSelected;
public Func<Vector2> WindowSize;
public Action<T, int> DrawSelection;
public void Merge(CallBack option)
{
OnSelected = option.OnSelected == null ? OnSelected : option.OnSelected;
WindowSize = option.WindowSize == null ? WindowSize : option.WindowSize;
DrawSelection = option.DrawSelection == null ? DrawSelection : option.DrawSelection;
}
}
#region Default
private static SelectWindow<T> defaultContent = new SelectWindow<T>();
private static CallBack defaultCallback = new CallBack() { WindowSize = defaultSize, DrawSelection=DrawSelection};
public static void DrawSelection(T item,int index)
{
if (item == null)
{
if (GUILayout.Button("null", Styles.Selection))
{
instance.Select(default(T), index);
instance.editorWindow.Close();
return;
}
}
else if (instance.searchField.GeneralValid(item.ToString()))
{
if (GUILayout.Button(item.ToString(), Styles.Selection))
{
instance.Select(item, index);
instance.editorWindow.Close();
return;
}
}
}
public static Vector2 defaultSize() { return new Vector2(200, 300); }
#endregion
#region API
public static SelectWindow<T> instance;
public static void Show(List<T> list, string controlId)
{
Show(list, controlId, new Vector2(0, 0));
Show(list, controlId,new CallBack());
}
public static void Show(List<T> list, string controlId,Vector2 size)
public static void Show(List<T> list, string controlId, CallBack callback)
{
instance = defaultContent;
instance.ControlId = controlId;
instance.List = list;
instance.size = size;
instance.OnEnable(list, controlId, callback);
try
{
PopupWindow.Show(new Rect(Event.current.mousePosition.DeltaX(-100),Vector2.zero), instance);
PopupWindow.Show(new Rect(Event.current.mousePosition.DeltaX(-100), Vector2.zero), instance);
}
catch
{
// EditorGUIUtility.ExitGUI();
}
}
public override Vector2 GetWindowSize()
{
if(size!=Vector2.zero)
{
return size;
}
return base.GetWindowSize();
}
#endregion
#region IMGUI
protected static bool canPick;
public static bool CanPick(string controlId)
{
Expand All @@ -59,12 +89,16 @@ public static int GetPickIndex()
canPick = false;
return i;
}
#endregion

protected OnGUIUtility.Search searchField = new OnGUIUtility.Search();
public string ControlId;
public List<T> List;

public T Selected;
public int SelectedIndex;
public Vector2 size;

protected CallBack callback;
protected Vector2 v;
protected static class Styles
{
Expand All @@ -74,6 +108,22 @@ static Styles()
Selection = new GUIStyle("OL Title");
}
}
protected virtual void OnEnable(List<T> list, string controlId, CallBack optional)
{
CallBack instanceCallBack = defaultCallback;
instanceCallBack.Merge(optional);
instance.ControlId = controlId;
instance.List = list;
instance.callback= instanceCallBack;
}
protected virtual void Select(T t, int index)
{
instance.Selected = t;
instance.SelectedIndex = index;
instance.callback.OnSelected?.Invoke(t, index);
instance.callback.OnSelected = null;
canPick = true;
}
public override void OnGUI(Rect rect)
{
var searching = searchField.OnToolbarGUI();
Expand All @@ -83,28 +133,7 @@ public override void OnGUI(Rect rect)
for (int i = 0; i < List.Count; i++)
{
var item = List[i];
if (item == null)
{
if (GUILayout.Button("null", Styles.Selection))
{
instance.Selected = default(T);
instance.SelectedIndex = i;
canPick = true;
this.editorWindow.Close();
return;
}
}
else if (searchField.GeneralValid(item.ToString()))
{
if (GUILayout.Button(item.ToString(), Styles.Selection))
{
instance.Selected = item;
instance.SelectedIndex = i;
canPick = true;
this.editorWindow.Close();
return;
}
}
callback.DrawSelection(item, i);
}
EditorGUILayout.EndScrollView();
}
Expand All @@ -118,5 +147,9 @@ public override void OnClose()
{
base.OnClose();
}
public override Vector2 GetWindowSize()
{
return callback.WindowSize();
}
}
}
8 changes: 4 additions & 4 deletions Editor/SeanLibManager/SeanLibIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ static styles()
public virtual void OnEnable(SeanLibManager drawer)
{
window = drawer;
if(UseIMGUI) EnableIMGUI();
else EnableUIElements();
if(UseIMGUI) SetupIMGUI();
else SetupUIElements();

}
public virtual void EnableUIElements()
public virtual void SetupUIElements()
{
if (!string.IsNullOrEmpty(UXML))
{
Expand All @@ -141,7 +141,7 @@ public virtual void EnableUIElements()
editorContent.CloneTree(window.EditorContent);
}
}
public virtual void EnableIMGUI()
public virtual void SetupIMGUI()
{
EditorContent_IMGUI = new IMGUIContainer(OnGUI);
EditorContent_IMGUI.name = "EditorContent_IMGUI";
Expand Down
10 changes: 10 additions & 0 deletions Editor/UIElements/ElementsFileAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

using System;

[Serializable]
public struct ElementsFileAsset
{
public string UXML;
public string USS;
public Type BaseType;
}
11 changes: 11 additions & 0 deletions Editor/UIElements/ElementsFileAsset.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions Editor/UIElements/TreeForm.meta

This file was deleted.

0 comments on commit bf27680

Please sign in to comment.