Skip to content

Commit

Permalink
✨ EditorWindow support PreferBinarySerialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jun 25, 2024
1 parent d1295a2 commit 9c05fe3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ namespace AIO.UEditor
/// <summary>
/// 自定义窗口基类
/// </summary>
[PreferBinarySerialization]
public abstract partial class EmptyGraphWindow : EditorWindow
{
/// <summary>
/// 当前窗口中心点
/// </summary>
/// <param name="w">宽</param>
/// <param name="h">高</param>
protected EmptyGraphWindow(float w = 800, float h = 600)
{
minSize = new Vector2(w, h);
}
protected EmptyGraphWindow(float w = 800, float h = 600) { minSize = new Vector2(w, h); }

/// <summary>
/// 当前窗口宽度
Expand All @@ -48,24 +46,14 @@ protected EmptyGraphWindow(float w = 800, float h = 600)
/// </summary>
public Rect ReliablePosition { get; private set; }

private void ModifierKeysChanged()
{
OnModifierKeysChanged();
}
private void ModifierKeysChanged() { OnModifierKeysChanged(); }

private void ShowButton(Rect rect)
{
OnShowButton(rect);
}
private void ShowButton(Rect rect) { OnShowButton(rect); }

/// <summary>
/// 转化为信息字符串
/// </summary>
public sealed override string ToString()
{
return base.ToString();
}

public sealed override string ToString() { return base.ToString(); }

/// <summary>
/// 标记目标已改变
Expand All @@ -86,4 +74,4 @@ protected static void HasChanged(Object target)
EditorSceneManager.MarkSceneDirty(component.gameObject.scene);
}
}
}
}
3 changes: 2 additions & 1 deletion Editor.GUI.CLI/External/AIO.Plugins/PluginData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace AIO
/// 插件信息
/// </summary>
[CreateAssetMenu(menuName = "Plugins/AIO Data", fileName = nameof(PluginData))]
[PreferBinarySerialization]
internal class PluginData : ScriptableObject
{
/// <summary>
Expand Down Expand Up @@ -40,4 +41,4 @@ internal class PluginData : ScriptableObject
}

internal partial class Plugins { }
}
}
36 changes: 20 additions & 16 deletions Editor.GUI.CLI/Window/CustomExecute/CustomExecute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ namespace AIO.UEditor
)]
public class CustomExecute : GraphicWindow
{
public enum ExecuterMode
public enum ExecutedMode
{
Dynamic,
Static
}

private static string _projectPath;
private ExecuterMode _mode = ExecuterMode.Dynamic;
private static string _projectPath;

private ExecutedMode _mode = ExecutedMode.Dynamic;

/// <summary>
/// 项目路径(也即是 Application.dataPath 路径的末尾去掉了 Assets)
Expand Down Expand Up @@ -100,13 +101,13 @@ protected override void OnActivation()
protected override void OnDraw()
{
GUILayout.BeginHorizontal();
if (GUILayout.Toggle(_mode == ExecuterMode.Dynamic, "Dynamic", GEStyle.LargeButtonLeft)) _mode = ExecuterMode.Dynamic;
if (GUILayout.Toggle(_mode == ExecutedMode.Dynamic, "Dynamic", GEStyle.LargeButtonLeft)) _mode = ExecutedMode.Dynamic;

if (GUILayout.Toggle(_mode == ExecuterMode.Static, "Static", GEStyle.LargeButtonRight)) _mode = ExecuterMode.Static;
if (GUILayout.Toggle(_mode == ExecutedMode.Static, "Static", GEStyle.LargeButtonRight)) _mode = ExecutedMode.Static;

GUILayout.EndHorizontal();

if (_mode == ExecuterMode.Dynamic)
if (_mode == ExecutedMode.Dynamic)
DynamicGUI();
else
StaticGUI();
Expand Down Expand Up @@ -233,22 +234,25 @@ private void StaticGUI()
Entity = EditorGUILayout.ObjectField(Entity, typeof(GameObject), true) as GameObject;
GUILayout.EndHorizontal();

using (new EditorGUI.DisabledScope(Entity))
using (new EditorGUI.DisabledScope(!Entity))
{
GUILayout.BeginHorizontal();
GUILayout.Label("Target:", GUILayout.Width(60));
var content = Target ? EditorGUIUtility.ObjectContent(Target, Target.GetType()) : new GUIContent("<None>");
if (GUILayout.Button(content, GEStyle.MiniPopup))
{
var gm = new GenericMenu();
var components = Entity.GetComponents<Component>();
var gm = new GenericMenu();
gm.AddItem(new GUIContent("<None>"), !Target, () => { Target = null; });
foreach (var component in components)
if (Entity)
{
var component1 = component;
gm.AddItem(new GUIContent(component.GetType().FullName), Target == component, () => { Target = component1; });
foreach (var component in Entity.GetComponents<Component>())
{
var component1 = component;
gm.AddItem(EditorGUIUtility.TrTempContent(component.GetType().FullName), Target == component, () => { Target = component1; });
}
}


gm.ShowAsContext();
}

Expand Down Expand Up @@ -302,13 +306,13 @@ private void StaticGUI()
case "Boolean":
_parameters[i].BoolValue = EditorGUILayout.Toggle(_parameters[i].BoolValue);
break;
case "Vector2":
case nameof(Vector2):
_parameters[i].Vector2Value = EditorGUILayout.Vector2Field("", _parameters[i].Vector2Value);
break;
case "Vector3":
case nameof(Vector3):
_parameters[i].Vector3Value = EditorGUILayout.Vector3Field("", _parameters[i].Vector3Value);
break;
case "Color":
case nameof(Color):
_parameters[i].ColorValue = EditorGUILayout.ColorField(_parameters[i].ColorValue);
break;
default:
Expand Down Expand Up @@ -570,4 +574,4 @@ private MethodInfo Method

#endregion
}
}
}

0 comments on commit 9c05fe3

Please sign in to comment.