2024-12-10 20:34:15 +08:00
|
|
|
|
#if UNITY_EDITOR
|
2025-04-16 09:36:51 +08:00
|
|
|
|
using DCFApixels.DragonECS.Unity.Editors.X;
|
2024-12-10 20:34:15 +08:00
|
|
|
|
using DCFApixels.DragonECS.Unity.Internal;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using Color = UnityEngine.Color;
|
|
|
|
|
|
using UnityObject = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS.Unity.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static partial class EcsGUI
|
|
|
|
|
|
{
|
|
|
|
|
|
public static partial class Layout
|
|
|
|
|
|
{
|
2025-03-24 21:24:30 +08:00
|
|
|
|
public static void ManuallySerializeButton(IEnumerable<UnityObject> objects)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GUILayout.Button(UnityEditorUtility.GetLabel("Manually serialize")))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var obj in objects)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.SetDirty(obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-20 11:05:29 +08:00
|
|
|
|
public static void ManuallySerializeButton(UnityObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GUILayout.Button(UnityEditorUtility.GetLabel("Manually serialize")))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorUtility.SetDirty(obj);
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-10 20:34:15 +08:00
|
|
|
|
public static void ScriptAssetButton(MonoScript script, params GUILayoutOption[] options)
|
|
|
|
|
|
{
|
|
|
|
|
|
EcsGUI.ScriptAssetButton(GUILayoutUtility.GetRect(UnityEditorUtility.GetLabelTemp(), EditorStyles.miniButton, options), script);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void CopyMetaIDButton(string metaID, params GUILayoutOption[] options)
|
|
|
|
|
|
{
|
|
|
|
|
|
Rect r = GUILayoutUtility.GetRect(UnityEditorUtility.GetLabelTemp(), EditorStyles.miniButton, options);
|
|
|
|
|
|
var current = Event.current;
|
|
|
|
|
|
var hover = IconHoverScan(r, current);
|
|
|
|
|
|
using (new ColorScope(new Color(1f, 1f, 1f, hover ? 1f : 0.8f)))
|
|
|
|
|
|
{
|
|
|
|
|
|
DrawIcon(r, Icons.Instance.MetaIDIcon, hover ? 1f : 2f, metaID);
|
|
|
|
|
|
if (hover && current.type == EventType.MouseUp)
|
|
|
|
|
|
{
|
|
|
|
|
|
GUIUtility.systemCopyBuffer = metaID;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IconButton(Texture icon, params GUILayoutOption[] options)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool result = GUILayout.Button(UnityEditorUtility.GetLabel(string.Empty), options);
|
|
|
|
|
|
DrawIcon(GUILayoutUtility.GetLastRect(), icon, 0, null);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IconButton(Texture icon, float iconPadding = 0, string description = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool result = GUILayout.Button(UnityEditorUtility.GetLabel(string.Empty));
|
|
|
|
|
|
DrawIcon(GUILayoutUtility.GetLastRect(), icon, iconPadding, description);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IconButton(Texture icon, float iconPadding = 0, string description = null, GUIStyle style = null, params GUILayoutOption[] options)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool result;
|
|
|
|
|
|
if (style == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result = GUILayout.Button(UnityEditorUtility.GetLabel(string.Empty), options);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
result = GUILayout.Button(UnityEditorUtility.GetLabel(string.Empty), style, options);
|
|
|
|
|
|
}
|
|
|
|
|
|
DrawIcon(GUILayoutUtility.GetLastRect(), icon, iconPadding, description);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void DrawEmptyComponentProperty(SerializedProperty property, string name, bool isDisplayEmpty)
|
|
|
|
|
|
{
|
|
|
|
|
|
EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(UnityEditorUtility.GetLabel(name), EditorStyles.label), property, name, isDisplayEmpty);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void DrawEmptyComponentProperty(SerializedProperty property, GUIContent label, bool isDisplayEmpty)
|
|
|
|
|
|
{
|
|
|
|
|
|
EcsGUI.DrawEmptyComponentProperty(GUILayoutUtility.GetRect(label, EditorStyles.label), property, label, isDisplayEmpty);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void DrawWorldBaseInfo(EcsWorld world)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool isNull = world == null || world.IsDestroyed || world.ID == 0;
|
|
|
|
|
|
int entitesCount = isNull ? 0 : world.Count;
|
|
|
|
|
|
int capacity = isNull ? 0 : world.Capacity;
|
|
|
|
|
|
long Version = isNull ? 0 : world.Version;
|
|
|
|
|
|
int leakedEntitesCount = isNull ? 0 : world.CountLeakedEntitesDebug();
|
|
|
|
|
|
EditorGUILayout.IntField("Entities", entitesCount, EditorStyles.boldLabel);
|
|
|
|
|
|
EditorGUILayout.IntField("Capacity", capacity, EditorStyles.boldLabel);
|
|
|
|
|
|
EditorGUILayout.LongField("Version", Version, EditorStyles.boldLabel);
|
|
|
|
|
|
Color color = leakedEntitesCount > 0 ? Color.yellow : GUI.contentColor;
|
|
|
|
|
|
using (new ContentColorScope(color))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.IntField("Leaked Entites", leakedEntitesCount, EditorStyles.boldLabel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void DrawWorldComponents(EcsWorld world)
|
|
|
|
|
|
{
|
2025-04-16 09:36:51 +08:00
|
|
|
|
RuntimeComponentsDrawer.DrawWorldComponents(world);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region entity bar
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static void EntityField(entlong entity)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
2025-04-16 09:36:51 +08:00
|
|
|
|
EntityField(default(GUIContent), entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void EntityField(string label, entlong entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityField(UnityEditorUtility.GetLabel(label), entity);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static unsafe void EntityField(GUIContent label, entlong entity)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
float width = EditorGUIUtility.currentViewWidth;
|
|
|
|
|
|
float height = EntityBarHeight;
|
2025-04-16 09:36:51 +08:00
|
|
|
|
EcsGUI.EntityField(GUILayoutUtility.GetRect(width, height), label, entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void EntityField(EntitySlotInfo entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityField(default(GUIContent), entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void EntityField(string label, EntitySlotInfo entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityField(UnityEditorUtility.GetLabel(label), entity);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static void EntityField(GUIContent label, EntitySlotInfo entity)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
float width = EditorGUIUtility.currentViewWidth;
|
|
|
|
|
|
float height = EntityBarHeight;
|
2025-04-16 09:36:51 +08:00
|
|
|
|
EcsGUI.EntityField(GUILayoutUtility.GetRect(width, height), label, entity);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static void EntityField(SerializedProperty property)
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityField(property, default(GUIContent));
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void EntityField(SerializedProperty property, string label)
|
|
|
|
|
|
{
|
|
|
|
|
|
EntityField(property, UnityEditorUtility.GetLabel(label));
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void EntityField(SerializedProperty property, GUIContent label)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
float width = EditorGUIUtility.currentViewWidth;
|
|
|
|
|
|
float height = EntityBarHeight;
|
2025-04-16 09:36:51 +08:00
|
|
|
|
EcsGUI.EntityField(GUILayoutUtility.GetRect(width, height), property, label);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public static bool AddComponentButtons(out Rect dropDownRect)
|
|
|
|
|
|
{
|
|
|
|
|
|
return EcsGUI.AddComponentButton(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 24f), out dropDownRect);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static AddClearButton AddClearComponentButtons(out Rect dropDownRect)
|
|
|
|
|
|
{
|
|
|
|
|
|
return EcsGUI.AddClearComponentButtons(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 24f), out dropDownRect);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static AddClearButton AddClearSystemButtons(out Rect dropDownRect)
|
|
|
|
|
|
{
|
|
|
|
|
|
return EcsGUI.AddClearSystemButtons(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 24f), out dropDownRect);
|
|
|
|
|
|
}
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static void DrawRuntimeComponents(entlong entity, bool isWithFoldout, bool isRoot = true)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (entity.TryUnpackForUnityEditor(out int entityID, out _, out _, out EcsWorld world))
|
|
|
|
|
|
{
|
2025-04-16 09:36:51 +08:00
|
|
|
|
DrawRuntimeComponents(entityID, world, isWithFoldout, isRoot);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-16 09:36:51 +08:00
|
|
|
|
public static void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout, bool isRoot)
|
2024-12-10 20:34:15 +08:00
|
|
|
|
{
|
2025-04-16 09:36:51 +08:00
|
|
|
|
RuntimeComponentsDrawer.DrawRuntimeComponents(entityID, world, isWithFoldout, isRoot);
|
2024-12-10 20:34:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|