mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54: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);
|
||||
|
||||
#region Draw Component Block
|
||||
Rect optionButton = position;
|
||||
optionButton.center -= new Vector2(0, optionButton.height);
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.xMin = optionButton.xMax - 64;
|
||||
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)
|
||||
{
|
||||
@ -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
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
|
@ -4,6 +4,7 @@ using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -176,17 +177,39 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA;
|
||||
|
||||
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();
|
||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor));
|
||||
|
||||
#region Draw Component Block
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
//Close button
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.center += Vector2.up * padding * 2f;
|
||||
|
||||
bool isRemoveComponent = EcsGUI.CloseButton(optionButton);
|
||||
if (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)
|
||||
{
|
||||
@ -205,21 +228,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
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
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
@ -223,7 +223,34 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
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;
|
||||
|
||||
@ -238,13 +265,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
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)
|
||||
{
|
||||
AssetDatabase.OpenAsset(script);
|
||||
//AssetDatabase.OpenAsset(script);
|
||||
return new ScriptAssetButtonCommand(ScriptAssetButtonCommand.Command.DoubleClick);
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
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);
|
||||
|
||||
Type componentType = pool.ComponentType;
|
||||
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
|
||||
|
||||
float padding = EditorGUIUtility.standardVerticalSpacing;
|
||||
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));
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
bool isRemoveComponent = false;
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
//Close button
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.center += Vector2.up * padding * 2f;
|
||||
if (CloseButton(optionButton))
|
||||
{
|
||||
isRemoveComponent = true;
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
pool.SetRaw(entityID, resultData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Edit script button
|
||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||
{
|
||||
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)
|
||||
{
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
DescriptionIcon(optionButton, meta.Description.Text);
|
||||
}
|
||||
|
||||
|
||||
if (DrawRuntimeData(componentType, UnityEditorUtility.GetLabel(meta.Name), expandMatrix, data, out object resultData))
|
||||
{
|
||||
pool.SetRaw(entityID, resultData);
|
||||
}
|
||||
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
_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()
|
||||
{
|
||||
_ptr++;
|
||||
|
Loading…
Reference in New Issue
Block a user