mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 18:14:35 +08:00
update
This commit is contained in:
parent
cadf7abbd3
commit
5b3bce5476
@ -13,7 +13,16 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var item in _components)
|
foreach (var item in _components)
|
||||||
item.Add(world, entityID);
|
item.Add(world, entityID);
|
||||||
}
|
}
|
||||||
|
private void OnValidate()
|
||||||
|
{
|
||||||
|
if (_components == null) return;
|
||||||
|
foreach (var item in _components)
|
||||||
|
{
|
||||||
|
if (item is ITemplateComponentOnValidate g)
|
||||||
|
g.OnValidate(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private void OnDrawGizmos()
|
private void OnDrawGizmos()
|
||||||
{
|
{
|
||||||
if (_components == null) return;
|
if (_components == null) return;
|
||||||
|
@ -23,6 +23,10 @@ namespace DCFApixels.DragonECS
|
|||||||
Selected
|
Selected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public interface ITemplateComponentOnValidate
|
||||||
|
{
|
||||||
|
public void OnValidate(GameObject gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class TemplateComponentInitializerBase
|
public abstract class TemplateComponentInitializerBase
|
||||||
@ -73,7 +77,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class TemplateComponentInitializer<T> : TemplateComponentInitializerBase, ITemplateComponentName, ITemplateComponentGizmos
|
public abstract class TemplateComponentInitializer<T> : TemplateComponentInitializerBase, ITemplateComponentName, ITemplateComponentGizmos, ITemplateComponentOnValidate
|
||||||
{
|
{
|
||||||
private static string _autoname = GetName(typeof(T));
|
private static string _autoname = GetName(typeof(T));
|
||||||
private static Color _autoColor = GetColor(typeof(T));
|
private static Color _autoColor = GetColor(typeof(T));
|
||||||
@ -94,6 +98,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public abstract void Add(EcsWorld w, int e);
|
public abstract void Add(EcsWorld w, int e);
|
||||||
public virtual void OnGizmos(Transform transform, ITemplateComponentGizmos.Mode mode) { }
|
public virtual void OnGizmos(Transform transform, ITemplateComponentGizmos.Mode mode) { }
|
||||||
|
public virtual void OnValidate(GameObject gameObject) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class ITemplateBrowsableExt
|
internal static class ITemplateBrowsableExt
|
||||||
|
@ -78,11 +78,14 @@ namespace DCFApixels.DragonECS
|
|||||||
t.Apply(_world, entityID);
|
t.Apply(_world, entityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
namespace Editors
|
namespace DCFApixels.DragonECS.Editors
|
||||||
{
|
{
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
@ -93,7 +96,6 @@ namespace DCFApixels.DragonECS
|
|||||||
private GUIStyle _greenStyle;
|
private GUIStyle _greenStyle;
|
||||||
private GUIStyle _redStyle;
|
private GUIStyle _redStyle;
|
||||||
|
|
||||||
|
|
||||||
private bool _isInit = false;
|
private bool _isInit = false;
|
||||||
|
|
||||||
private void Init()
|
private void Init()
|
||||||
@ -104,7 +106,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_greenStyle = EcsEditor.GetStyle(new Color32(75, 255, 0, 100));
|
_greenStyle = EcsEditor.GetStyle(new Color32(75, 255, 0, 100));
|
||||||
_redStyle = EcsEditor.GetStyle(new Color32(255, 0, 75, 100));
|
_redStyle = EcsEditor.GetStyle(new Color32(255, 0, 75, 100));
|
||||||
|
|
||||||
|
|
||||||
_isInit = true;
|
_isInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +148,5 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: cdc92b01ccc1e684f955830aa7cea7d4
|
guid: 495156623a7b1e94087f916ba42745e6
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
|
@ -2,97 +2,94 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Scripting.APIUpdating;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
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 struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
|
||||||
where T : class
|
where T : Component
|
||||||
{
|
{
|
||||||
public T obj;
|
public T 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
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
[MovedFrom(false, "Client", null, "RefRigitBodyInitializer")]
|
public class UnityComponentInitializer<T> : TemplateComponentInitializer<UnityComponent<T>> where T : Component
|
||||||
public sealed class UnityComponentRigitBodyInitializer : TemplateComponentInitializer<UnityComponent<Rigidbody>>
|
{
|
||||||
|
public override string Name => "UnityComponent/" + typeof(T).Name;
|
||||||
|
public sealed override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<T>>().Add(e) = component;
|
||||||
|
public override void OnValidate(GameObject gameObject)
|
||||||
|
{
|
||||||
|
if (component.obj == null)
|
||||||
|
component.obj = gameObject.GetComponent<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public sealed class UnityComponentRigitBodyInitializer : UnityComponentInitializer<Rigidbody>
|
||||||
{
|
{
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<Rigidbody>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[MovedFrom(false, "Client", null, "RefAnimatorInitializer")]
|
public sealed class UnityComponentAnimatorInitializer : UnityComponentInitializer<Animator>
|
||||||
public sealed class UnityComponentAnimatorInitializer : TemplateComponentInitializer<UnityComponent<Animator>>
|
|
||||||
{
|
{
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<Animator>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentCharacterControllerInitializer : TemplateComponentInitializer<UnityComponent<CharacterController>>
|
public sealed class UnityComponentCharacterControllerInitializer : UnityComponentInitializer<CharacterController>
|
||||||
{
|
{
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<CharacterController>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Colliders
|
#region Colliders
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentColliderInitializer : TemplateComponentInitializer<UnityComponent<Collider>>
|
public sealed class UnityComponentColliderInitializer : UnityComponentInitializer<Collider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(Collider);
|
public override string Name => "UnityComponent/Collider/" + nameof(Collider);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<Collider>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentBoxColliderInitializer : TemplateComponentInitializer<UnityComponent<BoxCollider>>
|
public sealed class UnityComponentBoxColliderInitializer : UnityComponentInitializer<BoxCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(BoxCollider);
|
public override string Name => "UnityComponent/Collider/" + nameof(BoxCollider);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<BoxCollider>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentSphereColliderInitializer : TemplateComponentInitializer<UnityComponent<SphereCollider>>
|
public sealed class UnityComponentSphereColliderInitializer : UnityComponentInitializer<SphereCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(SphereCollider);
|
public override string Name => "UnityComponent/Collider/" + nameof(SphereCollider);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<SphereCollider>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentCapsuleColliderInitializer : TemplateComponentInitializer<UnityComponent<CapsuleCollider>>
|
public sealed class UnityComponentCapsuleColliderInitializer : UnityComponentInitializer<CapsuleCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(CapsuleCollider);
|
public override string Name => "UnityComponent/Collider/" + nameof(CapsuleCollider);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<CapsuleCollider>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentMeshColliderInitializer : TemplateComponentInitializer<UnityComponent<MeshCollider>>
|
public sealed class UnityComponentMeshColliderInitializer : UnityComponentInitializer<MeshCollider>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Collider/" + nameof(MeshCollider);
|
public override string Name => "UnityComponent/Collider/" + nameof(MeshCollider);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<MeshCollider>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Joints
|
#region Joints
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentJointInitializer : TemplateComponentInitializer<UnityComponent<Joint>>
|
public sealed class UnityComponentJointInitializer : UnityComponentInitializer<Joint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(Joint);
|
public override string Name => "UnityComponent/Joint/" + nameof(Joint);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<Joint>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentFixedJointInitializer : TemplateComponentInitializer<UnityComponent<FixedJoint>>
|
public sealed class UnityComponentFixedJointInitializer : UnityComponentInitializer<FixedJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint);
|
public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<FixedJoint>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentCharacterJointInitializer : TemplateComponentInitializer<UnityComponent<CharacterJoint>>
|
public sealed class UnityComponentCharacterJointInitializer : UnityComponentInitializer<CharacterJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint);
|
public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<CharacterJoint>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class UnityComponentConfigurableJointInitializer : TemplateComponentInitializer<UnityComponent<ConfigurableJoint>>
|
public sealed class UnityComponentConfigurableJointInitializer : UnityComponentInitializer<ConfigurableJoint>
|
||||||
{
|
{
|
||||||
public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint);
|
public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint);
|
||||||
public override void Add(EcsWorld w, int e) => w.GetPool<UnityComponent<ConfigurableJoint>>().Add(e) = component;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user