mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 18:14:35 +08:00
update component header button
This commit is contained in:
parent
2b265cb9ef
commit
7ffeac0fc8
@ -186,15 +186,37 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
Rect paddingPosition = RectUtility.AddPadding(position, Padding * 2f);
|
Rect paddingPosition = RectUtility.AddPadding(position, Padding * 2f);
|
||||||
|
|
||||||
#region Draw Component Block
|
|
||||||
Rect optionButton = position;
|
Rect optionButton = position;
|
||||||
optionButton.center -= new Vector2(0, optionButton.height);
|
optionButton.center -= new Vector2(0, optionButton.height);
|
||||||
optionButton.yMin = optionButton.yMax;
|
optionButton.yMin = optionButton.yMax;
|
||||||
optionButton.yMax += HeadIconsRect.height;
|
optionButton.yMax += HeadIconsRect.height;
|
||||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
optionButton.xMin = optionButton.xMax - 64;
|
||||||
optionButton.center += Vector2.up * Padding * 1f;
|
optionButton.center += Vector2.up * Padding * 1f;
|
||||||
|
//EditorGUI.DrawRect(optionButton, Color.black);
|
||||||
|
if (EcsGUI.HitTest(optionButton) && Event.current.type == EventType.MouseUp)
|
||||||
|
{
|
||||||
|
componentProperty.isExpanded = !componentProperty.isExpanded;
|
||||||
|
}
|
||||||
|
|
||||||
bool isRemoveComponent = EcsGUI.CloseButton(optionButton);
|
#region Draw Component Block
|
||||||
|
//Close button
|
||||||
|
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||||
|
if (EcsGUI.CloseButton(optionButton))
|
||||||
|
{
|
||||||
|
componentRefProp.managedReferenceValue = null;
|
||||||
|
}
|
||||||
|
//Edit script button
|
||||||
|
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||||
|
{
|
||||||
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
|
EcsGUI.ScriptAssetButton(optionButton).Execute(script);
|
||||||
|
}
|
||||||
|
//Description icon
|
||||||
|
if (string.IsNullOrEmpty(description) == false)
|
||||||
|
{
|
||||||
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
|
EcsGUI.DescriptionIcon(optionButton, description);
|
||||||
|
}
|
||||||
|
|
||||||
if (propCount <= 0)
|
if (propCount <= 0)
|
||||||
{
|
{
|
||||||
@ -224,21 +246,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isRemoveComponent)
|
|
||||||
{
|
|
||||||
componentRefProp.managedReferenceValue = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
|
||||||
{
|
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
|
||||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(description) == false)
|
|
||||||
{
|
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
|
||||||
EcsGUI.DescriptionIcon(optionButton, description);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
@ -4,6 +4,7 @@ using System;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Unity.Editors
|
namespace DCFApixels.DragonECS.Unity.Editors
|
||||||
{
|
{
|
||||||
@ -176,17 +177,39 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA;
|
alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA;
|
||||||
|
|
||||||
Rect optionButton = GUILayoutUtility.GetLastRect();
|
Rect optionButton = GUILayoutUtility.GetLastRect();
|
||||||
|
optionButton.yMin = optionButton.yMax;
|
||||||
|
optionButton.yMax += HeadIconsRect.height;
|
||||||
|
optionButton.xMin = optionButton.xMax - 64;
|
||||||
|
optionButton.center += Vector2.up * padding * 2f;
|
||||||
|
//EditorGUI.DrawRect(optionButton, Color.black);
|
||||||
|
if (EcsGUI.HitTest(optionButton) && Event.current.type == EventType.MouseUp)
|
||||||
|
{
|
||||||
|
componentProperty.isExpanded = !componentProperty.isExpanded;
|
||||||
|
}
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor));
|
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor));
|
||||||
|
|
||||||
#region Draw Component Block
|
#region Draw Component Block
|
||||||
optionButton.yMin = optionButton.yMax;
|
//Close button
|
||||||
optionButton.yMax += HeadIconsRect.height;
|
|
||||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||||
optionButton.center += Vector2.up * padding * 2f;
|
if (EcsGUI.CloseButton(optionButton))
|
||||||
|
{
|
||||||
bool isRemoveComponent = EcsGUI.CloseButton(optionButton);
|
OnRemoveComponentAt(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Edit script button
|
||||||
|
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||||
|
{
|
||||||
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
|
EcsGUI.ScriptAssetButton(optionButton).Execute(script);
|
||||||
|
}
|
||||||
|
//Description icon
|
||||||
|
if (string.IsNullOrEmpty(description) == false)
|
||||||
|
{
|
||||||
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
|
EcsGUI.DescriptionIcon(optionButton, description);
|
||||||
|
}
|
||||||
|
|
||||||
if (propCount <= 0)
|
if (propCount <= 0)
|
||||||
{
|
{
|
||||||
@ -205,21 +228,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
EditorGUI.PropertyField(r, componentProperty, label, true);
|
EditorGUI.PropertyField(r, componentProperty, label, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isRemoveComponent)
|
|
||||||
{
|
|
||||||
OnRemoveComponentAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
|
||||||
{
|
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
|
||||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(description) == false)
|
|
||||||
{
|
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
|
||||||
EcsGUI.DescriptionIcon(optionButton, description);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
@ -223,7 +223,34 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
DrawIcon(position, Icons.Instance.HelpIcon, 0, description);
|
DrawIcon(position, Icons.Instance.HelpIcon, 0, description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ScriptAssetButton(Rect position, MonoScript script)
|
|
||||||
|
public readonly ref struct ScriptAssetButtonCommand
|
||||||
|
{
|
||||||
|
public enum Command
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
OneClick = 1,
|
||||||
|
DoubleClick = 2,
|
||||||
|
}
|
||||||
|
public readonly Command command;
|
||||||
|
public ScriptAssetButtonCommand(Command command)
|
||||||
|
{
|
||||||
|
this.command = command;
|
||||||
|
}
|
||||||
|
public void Execute(MonoScript script)
|
||||||
|
{
|
||||||
|
switch (command)
|
||||||
|
{
|
||||||
|
case Command.OneClick:
|
||||||
|
EditorGUIUtility.PingObject(script);
|
||||||
|
break;
|
||||||
|
case Command.DoubleClick:
|
||||||
|
AssetDatabase.OpenAsset(script);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static ScriptAssetButtonCommand ScriptAssetButton(Rect position)
|
||||||
{
|
{
|
||||||
var current = Event.current;
|
var current = Event.current;
|
||||||
|
|
||||||
@ -238,13 +265,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
{
|
{
|
||||||
if (current.type == EventType.MouseUp)
|
if (current.type == EventType.MouseUp)
|
||||||
{
|
{
|
||||||
EditorGUIUtility.PingObject(script);
|
//EditorGUIUtility.PingObject(script);
|
||||||
|
return new ScriptAssetButtonCommand(ScriptAssetButtonCommand.Command.OneClick);
|
||||||
}
|
}
|
||||||
else if (current.type == EventType.MouseDown && current.clickCount >= 2)
|
else if (current.type == EventType.MouseDown && current.clickCount >= 2)
|
||||||
{
|
{
|
||||||
AssetDatabase.OpenAsset(script);
|
//AssetDatabase.OpenAsset(script);
|
||||||
|
return new ScriptAssetButtonCommand(ScriptAssetButtonCommand.Command.DoubleClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return default;
|
||||||
}
|
}
|
||||||
public static bool CloseButton(Rect position, string description = null)
|
public static bool CloseButton(Rect position, string description = null)
|
||||||
{
|
{
|
||||||
@ -588,49 +618,53 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
|
|
||||||
Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
||||||
|
|
||||||
|
Type componentType = pool.ComponentType;
|
||||||
|
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
|
||||||
|
|
||||||
float padding = EditorGUIUtility.standardVerticalSpacing;
|
float padding = EditorGUIUtility.standardVerticalSpacing;
|
||||||
Rect optionButton = GUILayoutUtility.GetLastRect();
|
Rect optionButton = GUILayoutUtility.GetLastRect();
|
||||||
|
optionButton.yMin = optionButton.yMax;
|
||||||
|
optionButton.yMax += HeadIconsRect.height;
|
||||||
|
optionButton.xMin = optionButton.xMax - 64;
|
||||||
|
optionButton.center += Vector2.up * padding * 2f;
|
||||||
|
//EditorGUI.DrawRect(optionButton, Color.black);
|
||||||
|
if (HitTest(optionButton) && Event.current.type == EventType.MouseUp)
|
||||||
|
{
|
||||||
|
ref bool isExpanded = ref expandMatrix.Down();
|
||||||
|
isExpanded = !isExpanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(panelColor, EscEditorConsts.COMPONENT_DRAWER_ALPHA));
|
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(panelColor, EscEditorConsts.COMPONENT_DRAWER_ALPHA));
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
bool isRemoveComponent = false;
|
//Close button
|
||||||
optionButton.yMin = optionButton.yMax;
|
|
||||||
optionButton.yMax += HeadIconsRect.height;
|
|
||||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||||
optionButton.center += Vector2.up * padding * 2f;
|
|
||||||
if (CloseButton(optionButton))
|
if (CloseButton(optionButton))
|
||||||
{
|
{
|
||||||
isRemoveComponent = true;
|
pool.Del(entityID);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
//Edit script button
|
||||||
Type componentType = pool.ComponentType;
|
|
||||||
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
|
|
||||||
bool changed = DrawRuntimeData(componentType, UnityEditorUtility.GetLabel(meta.Name), expandMatrix, data, out object resultData);
|
|
||||||
if (changed || isRemoveComponent)
|
|
||||||
{
|
|
||||||
if (isRemoveComponent)
|
|
||||||
{
|
|
||||||
pool.Del(entityID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pool.SetRaw(entityID, resultData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||||
{
|
{
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
ScriptAssetButton(optionButton).Execute(script);
|
||||||
}
|
}
|
||||||
|
//Description icon
|
||||||
if (string.IsNullOrEmpty(meta.Description.Text) == false)
|
if (string.IsNullOrEmpty(meta.Description.Text) == false)
|
||||||
{
|
{
|
||||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||||
DescriptionIcon(optionButton, meta.Description.Text);
|
DescriptionIcon(optionButton, meta.Description.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (DrawRuntimeData(componentType, UnityEditorUtility.GetLabel(meta.Name), expandMatrix, data, out object resultData))
|
||||||
|
{
|
||||||
|
pool.SetRaw(entityID, resultData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
|||||||
_ptr--;
|
_ptr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ref bool Peek()
|
||||||
|
{
|
||||||
|
int _ptr = this._ptr + 1;
|
||||||
|
if (_ptr >= _count)
|
||||||
|
{
|
||||||
|
if (_count >= _flags.Length)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _flags, _flags.Length << 1);
|
||||||
|
}
|
||||||
|
_flags[_count++] = _ptr <= 1 ? TOP_DEFAULT : DEFAULT;
|
||||||
|
}
|
||||||
|
return ref _flags[_ptr];
|
||||||
|
}
|
||||||
|
|
||||||
public ref bool Down()
|
public ref bool Down()
|
||||||
{
|
{
|
||||||
_ptr++;
|
_ptr++;
|
||||||
|
Loading…
Reference in New Issue
Block a user