using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace DCFApixels.DragonECS { internal static class UnityComponentConsts { private const string UNITY_COMPONENT_NAME = "UnityComponent"; public static readonly MetaGroup BaseGroup = new MetaGroup(UNITY_COMPONENT_NAME); public static readonly MetaGroup ColliderGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Collider/"); public static readonly MetaGroup JointGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Joint/"); } [Serializable] [MetaColor(255 / 3, 255, 0)] public struct UnityComponent : IEcsComponent, IEnumerable//IntelliSense hack where T : Component { public T obj; public UnityComponent(T obj) { this.obj = obj; } IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack { throw new NotImplementedException(); } IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack { throw new NotImplementedException(); } } #region Unity Component Templates public class UnityComponentTemplate : ComponentTemplateBase> where T : Component { public override string Name { get { return typeof(T).Name; } } public override MetaGroup Group { get { return UnityComponentConsts.BaseGroup; } } public sealed override void Apply(short worldID, int entityID) { EcsWorld.GetPoolInstance>>(worldID).TryAddOrGet(entityID) = component; } public override void OnValidate(UnityEngine.Object obj) { if (component.obj == null) { if (obj is GameObject go) { component.obj = go.GetComponent(); } } } } [Serializable] public sealed class UnityComponentRigitBodyInitializer : UnityComponentTemplate { } [Serializable] public sealed class UnityComponentAnimatorInitializer : UnityComponentTemplate { } [Serializable] public sealed class UnityComponentCharacterControllerInitializer : UnityComponentTemplate { } #endregion #region Collider Templates [Serializable] public sealed class UnityComponentColliderTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } } } [Serializable] public sealed class UnityComponentBoxColliderTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } } } [Serializable] public sealed class UnityComponentSphereColliderTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } } } [Serializable] public sealed class UnityComponentCapsuleColliderTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } } } [Serializable] public sealed class UnityComponentMeshColliderTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } } } #endregion #region Joint Templates [Serializable] public sealed class UnityComponentJointTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } } } [Serializable] public sealed class UnityComponentFixedJointTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } } } [Serializable] public sealed class UnityComponentCharacterJointTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } } } [Serializable] public sealed class UnityComponentConfigurableJointTemplate : UnityComponentTemplate { public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } } } #endregion }