mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
update
This commit is contained in:
parent
d6190b455b
commit
b782851697
@ -65,10 +65,27 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region Editor
|
||||
#if UNITY_EDITOR
|
||||
[ContextMenu("Autoset")]
|
||||
internal void Autoset_Editor()
|
||||
{
|
||||
_connect = GetComponentInChildren<EcsEntityConnect>();
|
||||
AutoResolveWorldProviderDependensy();
|
||||
foreach (var connect in GetComponentsInChildren<EcsEntityConnect>())
|
||||
{
|
||||
if (connect.GetComponentInParent<AutoEntityCreator>() == this)
|
||||
{
|
||||
_connect = connect;
|
||||
AutoResolveWorldProviderDependensy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
[ContextMenu("Autoset Cascade")]
|
||||
internal void AutosetCascade_Editor()
|
||||
{
|
||||
foreach (var target in GetComponentsInChildren<AutoEntityCreator>())
|
||||
{
|
||||
target.Autoset_Editor();
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -105,10 +107,57 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Editor
|
||||
internal void SetTemplates_Editor(MonoEntityTemplate[] tempaltes)
|
||||
#if UNITY_EDITOR
|
||||
[ContextMenu("Autoset")]
|
||||
internal void Autoset_Editor()
|
||||
{
|
||||
_monoTemplates = tempaltes;
|
||||
Autoset(this);
|
||||
}
|
||||
[ContextMenu("Autoset Cascade")]
|
||||
internal void AutosetCascade_Editor()
|
||||
{
|
||||
foreach (var item in GetComponentsInChildren<EcsEntityConnect>())
|
||||
{
|
||||
Autoset(item);
|
||||
}
|
||||
}
|
||||
[ContextMenu("Unlink Entity")]
|
||||
internal void UnlinkEntity_Editor()
|
||||
{
|
||||
ConnectWith(entlong.NULL);
|
||||
}
|
||||
[ContextMenu("Delete Entity")]
|
||||
internal void DeleteEntity_Editor()
|
||||
{
|
||||
if (_entity.TryUnpack(out int id, out EcsWorld world))
|
||||
{
|
||||
world.DelEntity(id);
|
||||
}
|
||||
UnlinkEntity_Editor();
|
||||
}
|
||||
|
||||
private static void Autoset(EcsEntityConnect target)
|
||||
{
|
||||
var result = target.MonoTemplates.Where(o => o != null).Union(GetTemplatesFor(target.transform));
|
||||
|
||||
target._monoTemplates = result.ToArray();
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
private static IEnumerable<MonoEntityTemplate> GetTemplatesFor(Transform parent)
|
||||
{
|
||||
IEnumerable<MonoEntityTemplate> result = parent.GetComponents<MonoEntityTemplate>();
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
if (child.TryGetComponent<EcsEntityConnect>(out _))
|
||||
{
|
||||
return Enumerable.Empty<MonoEntityTemplate>();
|
||||
}
|
||||
result = result.Concat(GetTemplatesFor(child));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -8,6 +9,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
[CanEditMultipleObjects]
|
||||
public class AutoEntityCreatorEditor : Editor
|
||||
{
|
||||
private AutoEntityCreator Target => (AutoEntityCreator)target;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
@ -21,15 +24,32 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
DrawControlButtons();
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button("Autoset"))
|
||||
private void DrawControlButtons()
|
||||
{
|
||||
float height = EcsGUI.EntityBarHeight;
|
||||
Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, height);
|
||||
EditorGUI.DrawRect(rect, new Color(0f, 0f, 0f, 0.1f));
|
||||
rect = RectUtility.AddPadding(rect, 2f, 0f);
|
||||
var (left, autosetCascadeRect) = RectUtility.HorizontalSliceRight(rect, height);
|
||||
var (_, autosetRect) = RectUtility.HorizontalSliceRight(left, height);
|
||||
|
||||
if (EcsGUI.AutosetCascadeButton(autosetCascadeRect))
|
||||
{
|
||||
foreach (var tr in targets)
|
||||
foreach (AutoEntityCreator target in targets)
|
||||
{
|
||||
AutoEntityCreator creator = (AutoEntityCreator)tr;
|
||||
creator.Autoset_Editor();
|
||||
EditorUtility.SetDirty(creator);
|
||||
target.AutosetCascade_Editor();
|
||||
}
|
||||
}
|
||||
|
||||
if (EcsGUI.AutosetButton(autosetRect))
|
||||
{
|
||||
foreach (AutoEntityCreator target in targets)
|
||||
{
|
||||
target.Autoset_Editor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#if UNITY_EDITOR
|
||||
using Codice.CM.Client.Differences;
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -36,7 +35,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
DrawTemplates();
|
||||
|
||||
DrawButtons();
|
||||
DrawControlButtons(targets);
|
||||
DrawComponents(targets);
|
||||
}
|
||||
|
||||
@ -44,27 +43,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
bool isConnected = Target.Entity.TryUnpack(out int id, out short gen, out EcsWorld world);
|
||||
EcsGUI.EntityStatus status = IsMultipleTargets ? EcsGUI.EntityStatus.Undefined : isConnected ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive;
|
||||
|
||||
float width = EditorGUIUtility.currentViewWidth;
|
||||
float height = EditorGUIUtility.singleLineHeight;
|
||||
Rect rect = GUILayoutUtility.GetRect(width, height + 3f);
|
||||
var (left, delEntityButtonRect) = RectUtility.HorizontalSliceRight(rect, height + 3);
|
||||
var (entityRect, unlinkButtonRect) = RectUtility.HorizontalSliceRight(left, height + 3);
|
||||
|
||||
using (new EditorGUI.DisabledScope(status != EcsGUI.EntityStatus.Alive))
|
||||
{
|
||||
if (EcsGUI.UnlinkButton(unlinkButtonRect))
|
||||
{
|
||||
Target.ConnectWith(entlong.NULL);
|
||||
}
|
||||
if (EcsGUI.DelEntityButton(delEntityButtonRect))
|
||||
{
|
||||
world.DelEntity(id);
|
||||
Target.ConnectWith(entlong.NULL);
|
||||
}
|
||||
}
|
||||
|
||||
EcsGUI.DrawEntity(entityRect, status, id, gen, world.id);
|
||||
EcsGUI.Layout.EntityBar(status, id, gen, world.id);
|
||||
}
|
||||
|
||||
private void DrawTemplates()
|
||||
@ -82,43 +61,47 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
}
|
||||
|
||||
private void Autoset(EcsEntityConnect target)
|
||||
private void DrawControlButtons(EcsEntityConnect[] targets)
|
||||
{
|
||||
var result = target.MonoTemplates.Where(o => o != null).Union(GetTemplatesFor(target.transform));
|
||||
|
||||
target.SetTemplates_Editor(result.ToArray());
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
private IEnumerable<MonoEntityTemplate> GetTemplatesFor(Transform parent)
|
||||
{
|
||||
IEnumerable<MonoEntityTemplate> result = parent.GetComponents<MonoEntityTemplate>();
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
float height = EcsGUI.EntityBarHeight;
|
||||
Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, height);
|
||||
EditorGUI.DrawRect(rect, new Color(0f, 0f, 0f, 0.1f));
|
||||
rect = RectUtility.AddPadding(rect, 2f, 0f);
|
||||
var (_, buttonRect) = RectUtility.HorizontalSliceRight(rect, height);
|
||||
if (EcsGUI.AutosetCascadeButton(buttonRect))
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
if (child.TryGetComponent<EcsEntityConnect>(out _))
|
||||
foreach (var target in targets)
|
||||
{
|
||||
return Enumerable.Empty<MonoEntityTemplate>();
|
||||
}
|
||||
result = result.Concat(GetTemplatesFor(child));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DrawButtons()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Autoset"))
|
||||
{
|
||||
Autoset(Target);
|
||||
}
|
||||
if (GUILayout.Button("Autoset Cascade"))
|
||||
{
|
||||
foreach (var item in Target.GetComponentsInChildren<EcsEntityConnect>())
|
||||
{
|
||||
Autoset(item);
|
||||
target.AutosetCascade_Editor();
|
||||
}
|
||||
}
|
||||
buttonRect = RectUtility.Move(buttonRect , - height, 0);
|
||||
if (EcsGUI.AutosetButton(buttonRect))
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
target.Autoset_Editor();
|
||||
}
|
||||
}
|
||||
using (new EditorGUI.DisabledScope(!Application.isPlaying))
|
||||
{
|
||||
buttonRect = RectUtility.Move(buttonRect, -height, 0);
|
||||
if (EcsGUI.DelEntityButton(buttonRect))
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
target.DeleteEntity_Editor();
|
||||
}
|
||||
}
|
||||
buttonRect = RectUtility.Move(buttonRect, -height, 0);
|
||||
if (EcsGUI.UnlinkButton(buttonRect))
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
target.UnlinkEntity_Editor();
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawComponents(EcsEntityConnect[] targets)
|
||||
|
@ -30,6 +30,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 19f, 19f);
|
||||
private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 19f, 19f);
|
||||
|
||||
public static float EntityBarHeight => EditorGUIUtility.singleLineHeight + 3f;
|
||||
|
||||
private static bool IsShowHidden
|
||||
{
|
||||
get { return DebugMonitorPrefs.instance.IsShowHidden; }
|
||||
@ -111,7 +113,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
//
|
||||
// return result;
|
||||
//}
|
||||
public static (bool, bool) IconButton(Rect position)
|
||||
public static (bool, bool) IconButtonGeneric(Rect position)
|
||||
{
|
||||
Color dc = GUI.color;
|
||||
GUI.color = Color.clear; //Хак чтобы сделать реакцию от курсора мыши без лага
|
||||
@ -121,42 +123,46 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
var current = Event.current;
|
||||
return (GUI.enabled && HitTest(position, current), result);
|
||||
}
|
||||
public static bool SingleIconButton(Rect position, Texture icon)
|
||||
public static bool IconButton(Rect position, Texture icon, float iconPadding, string description)
|
||||
{
|
||||
var (hover, click) = IconButton(position);
|
||||
Color color = GUI.color;
|
||||
float enableMultiplier = GUI.enabled ? 1f : 0.72f;
|
||||
//var (hover, click) = IconButton(position);
|
||||
//Color color = GUI.color;
|
||||
//float enableMultiplier = GUI.enabled ? 1f : 0.72f;
|
||||
//
|
||||
//if (hover)
|
||||
//{
|
||||
// if (Event.current.type == EventType.Repaint)
|
||||
// {
|
||||
// GUI.color = Color.white * 2.2f * enableMultiplier;
|
||||
// EditorStyles.helpBox.Draw(position, hover, false, false, false);
|
||||
// }
|
||||
//
|
||||
// Rect rect = RectUtility.AddPadding(position, -1f);
|
||||
// GUI.color = Color.white * enableMultiplier;
|
||||
// GUI.DrawTexture(rect, icon);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (Event.current.type == EventType.Repaint)
|
||||
// {
|
||||
// GUI.color = Color.white * 1.7f * enableMultiplier;
|
||||
// EditorStyles.helpBox.Draw(position, hover, false, false, false);
|
||||
// }
|
||||
// GUI.color = Color.white * enableMultiplier;
|
||||
// GUI.DrawTexture(position, icon);
|
||||
//}
|
||||
//GUI.color = color;
|
||||
//return click;
|
||||
|
||||
if (hover)
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
GUI.color = Color.white * 2.2f * enableMultiplier;
|
||||
EditorStyles.helpBox.Draw(position, hover, false, false, false);
|
||||
}
|
||||
|
||||
Rect rect = RectUtility.AddPadding(position, -1f);
|
||||
GUI.color = Color.white * enableMultiplier;
|
||||
GUI.DrawTexture(rect, icon);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
GUI.color = Color.white * 1.7f * enableMultiplier;
|
||||
EditorStyles.helpBox.Draw(position, hover, false, false, false);
|
||||
}
|
||||
GUI.color = Color.white * enableMultiplier;
|
||||
GUI.DrawTexture(position, icon);
|
||||
}
|
||||
GUI.color = color;
|
||||
return click;
|
||||
bool result = GUI.Button(position, UnityEditorUtility.GetLabel(string.Empty));
|
||||
GUI.Label(RectUtility.AddPadding(position, iconPadding), UnityEditorUtility.GetLabel(icon, description));
|
||||
return result;
|
||||
}
|
||||
public static void DescriptionIcon(Rect position, string description)
|
||||
{
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, 0.8f)))
|
||||
{
|
||||
GUIContent descriptionLabel = UnityEditorUtility.GetLabel(EditorGUIUtility.IconContent("d__Help@2x").image, description);
|
||||
GUIContent descriptionLabel = UnityEditorUtility.GetLabel(EditorGUIUtility.IconContent("d__Help").image, description);
|
||||
GUI.Label(position, descriptionLabel, EditorStyles.boldLabel);
|
||||
}
|
||||
}
|
||||
@ -164,7 +170,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, 0.8f)))
|
||||
{
|
||||
var (hover, click) = IconButton(position);
|
||||
var (hover, click) = IconButtonGeneric(position);
|
||||
if (hover)
|
||||
{
|
||||
Rect rect = RectUtility.AddPadding(position, -4f);
|
||||
@ -172,20 +178,30 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.DrawTexture(position, EditorGUIUtility.IconContent("d_winbtn_win_close@2x").image);
|
||||
GUI.DrawTexture(position, EditorGUIUtility.IconContent("d_winbtn_win_close").image);
|
||||
}
|
||||
return click;
|
||||
}
|
||||
}
|
||||
public static bool AutosetCascadeButton(Rect position)
|
||||
{
|
||||
return IconButton(position, EditorGUIUtility.IconContent("d_winbtn_win_max@2x").image, 1f, "Autoset Cascade");
|
||||
}
|
||||
public static bool AutosetButton(Rect position)
|
||||
{
|
||||
return IconButton(position, EditorGUIUtility.IconContent("d_winbtn_win_restore@2x").image, 1f, "Autoset");
|
||||
}
|
||||
public static bool UnlinkButton(Rect position)
|
||||
{
|
||||
return SingleIconButton(position, EditorGUIUtility.IconContent("d_Unlinked@2x").image);
|
||||
bool result = GUI.Button(position, UnityEditorUtility.GetLabel(string.Empty));
|
||||
GUI.Label(RectUtility.Move(position, 0, -1f), UnityEditorUtility.GetLabel(EditorGUIUtility.IconContent("d_Unlinked").image, "Unlink Entity"));
|
||||
return result;
|
||||
}
|
||||
public static bool DelEntityButton(Rect position)
|
||||
{
|
||||
return SingleIconButton(position, EditorGUIUtility.IconContent("d_winbtn_win_close@2x").image);
|
||||
return IconButton(position, EditorGUIUtility.IconContent("d_winbtn_win_close").image, 0f, "Delete Entity");
|
||||
}
|
||||
public static void DrawEntity(Rect position, EntityStatus status, int id, short gen, short world)
|
||||
public static void EntityBar(Rect position, EntityStatus status, int id, short gen, short world)
|
||||
{
|
||||
var (entityInfoRect, statusRect) = RectUtility.VerticalSliceBottom(position, 3f);
|
||||
|
||||
@ -258,11 +274,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
public static class Layout
|
||||
{
|
||||
public static void DrawEntity(EntityStatus status, int id, short gen, short world)
|
||||
public static void EntityBar(EntityStatus status, int id, short gen, short world)
|
||||
{
|
||||
float width = EditorGUIUtility.currentViewWidth;
|
||||
float height = EditorGUIUtility.singleLineHeight;
|
||||
EcsGUI.DrawEntity(GUILayoutUtility.GetRect(width, height + 3f), status, id, gen, world);
|
||||
float height = EntityBarHeight;
|
||||
EcsGUI.EntityBar(GUILayoutUtility.GetRect(width, height), status, id, gen, world);
|
||||
}
|
||||
public static bool AddComponentButtons()
|
||||
{
|
||||
|
@ -50,9 +50,9 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
return AddPadding(rect, verticalHorizontal, verticalHorizontal, verticalHorizontal, verticalHorizontal);
|
||||
}
|
||||
public static Rect AddPadding(Rect rect, float vertical, float horizontal)
|
||||
public static Rect AddPadding(Rect rect, float horizontal, float vertical)
|
||||
{
|
||||
return AddPadding(rect, vertical, vertical, horizontal, horizontal);
|
||||
return AddPadding(rect, horizontal, horizontal, vertical, vertical);
|
||||
}
|
||||
public static Rect AddPadding(Rect rect, float left, float right, float top, float bottom)
|
||||
{
|
||||
@ -62,5 +62,14 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
rect.yMax -= bottom;
|
||||
return rect;
|
||||
}
|
||||
public static Rect Move(Rect rect, Vector2 addVector)
|
||||
{
|
||||
rect.center += addVector;
|
||||
return rect;
|
||||
}
|
||||
public static Rect Move(Rect rect, float addX, float addY)
|
||||
{
|
||||
return Move(rect, new Vector2(addX, addY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user