mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 10:04:36 +08:00
update
This commit is contained in:
parent
5b3bce5476
commit
2a4978c907
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: a20b387d9272da846b2a1206bfb6d53a
|
guid: 2b32116c3998f6742a35e492a88176be
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
19
src/Connectors/EcsDefaultWorldProvider.cs
Normal file
19
src/Connectors/EcsDefaultWorldProvider.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = nameof(EcsDefaultWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/WorldProviders/" + nameof(EcsDefaultWorldProvider), order = 1)]
|
||||||
|
public class EcsDefaultWorldProvider : EcsWorldProvider<EcsDefaultWorld>
|
||||||
|
{
|
||||||
|
private static EcsDefaultWorldProvider _single;
|
||||||
|
public static EcsDefaultWorldProvider Single
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_single == null)
|
||||||
|
_single = FindOrCreateSingle<EcsDefaultWorldProvider>();
|
||||||
|
return _single;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d0af8ddc3edb89242a26c1d308a18c87
|
guid: 15b6f990a7e05b34a937a9a850d7c68c
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@ -93,8 +93,6 @@ namespace DCFApixels.DragonECS.Editors
|
|||||||
public class EcsEntityEditor : Editor
|
public class EcsEntityEditor : Editor
|
||||||
{
|
{
|
||||||
private EcsEntityConnect Target => (EcsEntityConnect)target;
|
private EcsEntityConnect Target => (EcsEntityConnect)target;
|
||||||
private GUIStyle _greenStyle;
|
|
||||||
private GUIStyle _redStyle;
|
|
||||||
|
|
||||||
private bool _isInit = false;
|
private bool _isInit = false;
|
||||||
|
|
||||||
@ -103,19 +101,13 @@ namespace DCFApixels.DragonECS.Editors
|
|||||||
if (_isInit)
|
if (_isInit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_greenStyle = EcsEditor.GetStyle(new Color32(75, 255, 0, 100));
|
|
||||||
_redStyle = EcsEditor.GetStyle(new Color32(255, 0, 75, 100));
|
|
||||||
|
|
||||||
_isInit = true;
|
_isInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
if (Target.IsAlive)
|
EcsGUI.Layout.DrawConnectStatus(Target.IsAlive);
|
||||||
GUILayout.Box("Connected", _greenStyle, GUILayout.ExpandWidth(true));
|
|
||||||
else
|
|
||||||
GUILayout.Box("Not connected", _redStyle, GUILayout.ExpandWidth(true));
|
|
||||||
|
|
||||||
if (Target.Entity.TryGetID(out int id))
|
if (Target.Entity.TryGetID(out int id))
|
||||||
EditorGUILayout.IntField(id);
|
EditorGUILayout.IntField(id);
|
66
src/Connectors/EcsWorldProvider.cs
Normal file
66
src/Connectors/EcsWorldProvider.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEditor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public abstract class EcsWorldProviderBase : ScriptableObject
|
||||||
|
{
|
||||||
|
public abstract EcsWorld WorldRaw { get; }
|
||||||
|
public abstract EcsWorld GetRaw(Func<EcsWorld> builder = null);
|
||||||
|
}
|
||||||
|
[Serializable]
|
||||||
|
public abstract class EcsWorldProvider<TWorld> : EcsWorldProviderBase where TWorld : EcsWorld
|
||||||
|
{
|
||||||
|
private static TWorld _world;
|
||||||
|
public sealed override EcsWorld WorldRaw => _world;
|
||||||
|
public override EcsWorld GetRaw(Func<EcsWorld> builder = null)
|
||||||
|
{
|
||||||
|
if (_world == null || _world.IsDestroyed)
|
||||||
|
{
|
||||||
|
if (builder != null)
|
||||||
|
_world = (TWorld)builder();
|
||||||
|
else
|
||||||
|
_world = (TWorld)Activator.CreateInstance(typeof(TWorld));
|
||||||
|
OnWorldCreated(_world);
|
||||||
|
}
|
||||||
|
return _world;
|
||||||
|
}
|
||||||
|
public TWorld Get(Func<TWorld> builder = null)
|
||||||
|
{
|
||||||
|
if (_world == null || _world.IsDestroyed)
|
||||||
|
{
|
||||||
|
if(builder != null)
|
||||||
|
_world = builder();
|
||||||
|
else
|
||||||
|
_world = (TWorld)Activator.CreateInstance(typeof(TWorld));
|
||||||
|
OnWorldCreated(_world);
|
||||||
|
}
|
||||||
|
return _world;
|
||||||
|
}
|
||||||
|
protected virtual void OnWorldCreated(TWorld world) { }
|
||||||
|
|
||||||
|
protected static TProvider FindOrCreateSingle<TProvider>() where TProvider : EcsWorldProvider<TWorld>
|
||||||
|
{
|
||||||
|
string name = typeof(TProvider).Name + "Single";
|
||||||
|
TProvider instance = Resources.Load<TProvider>(name);
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = CreateInstance<TProvider>();
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
if (AssetDatabase.IsValidFolder("Assets/Resources/") == false)
|
||||||
|
{
|
||||||
|
System.IO.Directory.CreateDirectory(Application.dataPath + "/Resources/");
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
AssetDatabase.CreateAsset(instance, "Assets/Resources/" + name + ".asset");
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
src/Connectors/EcsWorldProvider.cs.meta
Normal file
11
src/Connectors/EcsWorldProvider.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b041a062a2a5b2643bec37be4fad79f1
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -6,6 +6,44 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS.Editors
|
namespace DCFApixels.DragonECS.Editors
|
||||||
{
|
{
|
||||||
|
public static class EcsGUI
|
||||||
|
{
|
||||||
|
private static GUIStyle _greenStyle;
|
||||||
|
private static GUIStyle _redStyle;
|
||||||
|
|
||||||
|
private static bool _isInit = false;
|
||||||
|
private static void Init()
|
||||||
|
{
|
||||||
|
if (_isInit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_greenStyle = EcsEditor.GetStyle(new Color32(75, 255, 0, 100));
|
||||||
|
_redStyle = EcsEditor.GetStyle(new Color32(255, 0, 75, 100));
|
||||||
|
_isInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DrawConnectStatus(Rect position, bool status)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
if (status)
|
||||||
|
GUI.Box(position, "Connected", _greenStyle);
|
||||||
|
else
|
||||||
|
GUI.Box(position, "Not connected", _redStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Layout
|
||||||
|
{
|
||||||
|
public static void DrawConnectStatus(bool status, params GUILayoutOption[] options)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
if (status)
|
||||||
|
GUILayout.Box("Connected", _greenStyle, GUILayout.ExpandWidth(true));
|
||||||
|
else
|
||||||
|
GUILayout.Box("Not connected", _redStyle, GUILayout.ExpandWidth(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public static class EcsEditor
|
public static class EcsEditor
|
||||||
{
|
{
|
||||||
@ -40,10 +78,11 @@ namespace DCFApixels.DragonECS.Editors
|
|||||||
{
|
{
|
||||||
GUIStyle result = new GUIStyle(GUI.skin.box);
|
GUIStyle result = new GUIStyle(GUI.skin.box);
|
||||||
Color componentColor = color32;
|
Color componentColor = color32;
|
||||||
result.normal.background = CreateTexture(2, 2, componentColor);
|
Texture2D texture2D = CreateTexture(2, 2, componentColor);
|
||||||
result.active.background = CreateTexture(2, 2, componentColor);
|
result.hover.background = texture2D;
|
||||||
result.hover.background = CreateTexture(2, 2, componentColor);
|
result.focused.background = texture2D;
|
||||||
result.focused.background = CreateTexture(2, 2, componentColor);
|
result.active.background = texture2D;
|
||||||
|
result.normal.background = texture2D;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private static Texture2D CreateTexture(int width, int height, Color color)
|
private static Texture2D CreateTexture(int width, int height, Color color)
|
||||||
@ -58,7 +97,6 @@ namespace DCFApixels.DragonECS.Editors
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static string GetGenericName(Type type) => EcsDebugUtility.GetGenericTypeName(type);
|
public static string GetGenericName(Type type) => EcsDebugUtility.GetGenericTypeName(type);
|
||||||
|
|
||||||
public static string GetName<T>() => GetName(typeof(T));
|
public static string GetName<T>() => GetName(typeof(T));
|
||||||
|
@ -7,10 +7,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[DebugColor(255 / 3, 255, 0)]
|
[DebugColor(255 / 3, 255, 0)]
|
||||||
public struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
|
public readonly struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
|
||||||
where T : Component
|
where T : Component
|
||||||
{
|
{
|
||||||
public T obj;
|
public readonly T obj;
|
||||||
|
public UnityComponent(T obj) => this.obj = obj;
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
||||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
||||||
}
|
}
|
||||||
@ -23,7 +24,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public override void OnValidate(GameObject gameObject)
|
public override void OnValidate(GameObject gameObject)
|
||||||
{
|
{
|
||||||
if (component.obj == null)
|
if (component.obj == null)
|
||||||
component.obj = gameObject.GetComponent<T>();
|
component = new UnityComponent<T>(gameObject.GetComponent<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@ using UnityEditor;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
[DebugColor(DebugColor.Cyan)]
|
[DebugColor(DebugColor.Cyan)]
|
||||||
public struct UnityGameObject : IEcsComponent
|
public readonly struct UnityGameObject : IEcsComponent
|
||||||
{
|
{
|
||||||
public GameObject gameObject;
|
public readonly GameObject gameObject;
|
||||||
public Transform transform;
|
public readonly Transform transform;
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public static class UnityWorldProvider<TWorld>
|
|
||||||
{
|
|
||||||
private static TWorld _world;
|
|
||||||
|
|
||||||
public static TWorld Get(Func<TWorld> builder)
|
|
||||||
{
|
|
||||||
if (builder == null)
|
|
||||||
throw new ArgumentNullException();
|
|
||||||
|
|
||||||
if (_world == null)
|
|
||||||
_world = builder();
|
|
||||||
|
|
||||||
return _world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TWorld Get()
|
|
||||||
{
|
|
||||||
if (_world == null)
|
|
||||||
_world = (TWorld)Activator.CreateInstance(typeof(TWorld));
|
|
||||||
return _world;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user