DragonECS-Unity/src/Buildin/UnityComponent.cs

249 lines
10 KiB
C#
Raw Normal View History

2024-06-13 18:04:47 +08:00
using DCFApixels.DragonECS.Unity;
using System;
2023-05-07 00:50:44 +08:00
using System.Collections;
using System.Collections.Generic;
2024-05-16 19:59:57 +08:00
using System.Runtime.CompilerServices;
2023-05-07 00:50:44 +08:00
using UnityEngine;
namespace DCFApixels.DragonECS
{
2024-10-12 14:37:21 +08:00
using static EcsConsts;
2024-03-06 23:29:54 +08:00
internal static class UnityComponentConsts
{
2024-05-16 19:59:57 +08:00
internal const string UNITY_COMPONENT_NAME = "UnityComponent";
2024-05-01 15:02:54 +08:00
public static readonly MetaGroup BaseGroup = new MetaGroup(UNITY_COMPONENT_NAME);
2024-09-16 19:30:49 +08:00
public static readonly MetaGroup RenderGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Render/");
2024-05-01 15:02:54 +08:00
public static readonly MetaGroup ColliderGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Collider/");
public static readonly MetaGroup JointGroup = new MetaGroup($"{UNITY_COMPONENT_NAME}/Joint/");
2024-03-06 23:29:54 +08:00
}
2023-05-07 00:50:44 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, COMPONENTS_GROUP)]
[MetaDescription(AUTHOR, "Component-reference to Unity object for EcsPool.")]
[MetaID("734F667C9201B80F1913388C2A8BB689")]
2024-10-11 23:29:48 +08:00
[MetaTags(MetaTags.ENGINE_MEMBER)]
2023-06-30 01:13:49 +08:00
public struct UnityComponent<T> : IEcsComponent, IEnumerable<T>//IntelliSense hack
2023-06-28 15:08:09 +08:00
where T : Component
2023-05-07 00:50:44 +08:00
{
2023-06-30 01:13:49 +08:00
public T obj;
2024-05-16 19:59:57 +08:00
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2024-03-03 03:51:49 +08:00
public UnityComponent(T obj)
{
this.obj = obj;
}
2024-03-09 03:35:01 +08:00
IEnumerator<T> IEnumerable<T>.GetEnumerator() //IntelliSense hack
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack
{
throw new NotImplementedException();
}
2024-05-16 19:59:57 +08:00
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator T(UnityComponent<T> a) { return a.obj; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator UnityComponent<T>(T a) { return new UnityComponent<T>(a); }
2023-05-07 00:50:44 +08:00
}
2024-03-03 03:51:49 +08:00
#region Unity Component Templates
2024-09-16 19:30:49 +08:00
[MetaID("13DAACF9910155DD27F822442987E0AE")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, OTHER_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "Template for UnityComponent<T>")]
2024-09-16 19:30:49 +08:00
public abstract class UnityComponentTemplate<T> : ComponentTemplateBase<UnityComponent<T>> where T : Component
2023-06-28 15:08:09 +08:00
{
2024-03-06 23:29:54 +08:00
public override string Name
{
get { return typeof(T).Name; }
}
public override MetaGroup Group
{
get { return UnityComponentConsts.BaseGroup; }
}
2024-04-22 17:20:10 +08:00
public sealed override void Apply(short worldID, int entityID)
2024-03-03 03:51:49 +08:00
{
2024-03-07 03:24:02 +08:00
EcsWorld.GetPoolInstance<EcsPool<UnityComponent<T>>>(worldID).TryAddOrGet(entityID) = component;
2024-03-03 03:51:49 +08:00
}
public override void OnValidate(UnityEngine.Object obj)
2023-06-28 15:08:09 +08:00
{
if (component.obj == null)
2024-03-03 03:51:49 +08:00
{
if (obj is GameObject go)
{
component.obj = go.GetComponent<T>();
}
}
2023-06-28 15:08:09 +08:00
}
}
2023-05-07 00:50:44 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("843B8EF991013F1BFD9133437E1AFE9C")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-09-16 19:30:49 +08:00
public sealed class UnityComponentTransformTemplate : UnityComponentTemplate<Transform> { }
[Serializable]
[MetaTags(MetaTags.HIDDEN)]
[MetaID("9A4B8EF99101396C44BF789C3215E9A9")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentRigitBodyInitializer : UnityComponentTemplate<Rigidbody> { }
2023-05-07 00:50:44 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("52598EF991016655335F234F20F44526")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentAnimatorInitializer : UnityComponentTemplate<Animator> { }
2023-05-07 00:50:44 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("AD658EF99101E8E38BB575D5353E7B1E")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentCharacterControllerInitializer : UnityComponentTemplate<CharacterController> { }
#endregion
2023-05-07 00:50:44 +08:00
2024-09-16 19:30:49 +08:00
#region Render Templates
[Serializable]
[MetaTags(MetaTags.HIDDEN)]
[MetaID("6C6CA0F99101E80E013BCCCB5DA78FA5")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-09-16 19:30:49 +08:00
public sealed class UnityComponentMeshRendererTemplate : UnityComponentTemplate<MeshRenderer>
{
public override MetaGroup Group { get { return UnityComponentConsts.RenderGroup; } }
}
[Serializable]
[MetaTags(MetaTags.HIDDEN)]
[MetaID("5475A1F9910109A138F609268B697A62")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-09-16 19:30:49 +08:00
public sealed class UnityComponentMeshFilterTemplate : UnityComponentTemplate<MeshFilter>
{
public override MetaGroup Group { get { return UnityComponentConsts.RenderGroup; } }
}
[Serializable]
[MetaTags(MetaTags.HIDDEN)]
[MetaID("2C13A2F99101FAA3EA21BD351BF3B169")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-09-16 19:30:49 +08:00
public sealed class UnityComponentSkinnedMeshRendererTemplate : UnityComponentTemplate<SkinnedMeshRenderer>
{
public override MetaGroup Group { get { return UnityComponentConsts.RenderGroup; } }
}
[Serializable]
[MetaTags(MetaTags.HIDDEN)]
[MetaID("8B57A1F991016B2E1FC57D16F2D20A64")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-09-16 19:30:49 +08:00
public sealed class UnityComponentSpriteRendererTemplate : UnityComponentTemplate<SpriteRenderer>
{
public override MetaGroup Group { get { return UnityComponentConsts.RenderGroup; } }
}
#endregion
2024-03-03 03:51:49 +08:00
#region Collider Templates
2023-05-07 00:50:44 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("557F8EF9910132FE990CF50CBF368412")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentColliderTemplate : UnityComponentTemplate<Collider>
2023-05-07 00:50:44 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
2023-05-07 00:50:44 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("43669CF99101E94AB9EC19DC8EA3878B")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentBoxColliderTemplate : UnityComponentTemplate<BoxCollider>
2023-05-07 00:50:44 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
2023-05-07 00:50:44 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("749F9CF991017792E288D4E3B5BFE340")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentSphereColliderTemplate : UnityComponentTemplate<SphereCollider>
2023-05-07 00:50:44 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
2023-05-07 00:50:44 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("72B09CF99101A33EBC4410B0FD8375E0")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentCapsuleColliderTemplate : UnityComponentTemplate<CapsuleCollider>
2023-05-07 00:50:44 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
2023-05-07 00:50:44 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("3BBC9CF99101F7C00989D2E55A40EF1B")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentMeshColliderTemplate : UnityComponentTemplate<MeshCollider>
2023-05-07 00:50:44 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.ColliderGroup; } }
2023-05-07 00:50:44 +08:00
}
#endregion
2024-03-03 03:51:49 +08:00
#region Joint Templates
2023-05-23 01:48:54 +08:00
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("1AC79CF99101C4279852BB6AE12DC61B")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentJointTemplate : UnityComponentTemplate<Joint>
2023-05-23 01:48:54 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
2023-05-23 01:48:54 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("E3D99CF991016428C6688672052C6F4E")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentFixedJointTemplate : UnityComponentTemplate<FixedJoint>
2023-05-23 01:48:54 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
2023-05-23 01:48:54 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("7BE59CF99101322AE307229E1466B225")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentCharacterJointTemplate : UnityComponentTemplate<CharacterJoint>
2023-05-23 01:48:54 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
2023-05-23 01:48:54 +08:00
}
[Serializable]
2024-09-16 19:30:49 +08:00
[MetaTags(MetaTags.HIDDEN)]
[MetaID("FBF29CF99101EE07543CFF460854B1F6")]
[MetaColor(MetaColor.DragonCyan)]
2024-10-12 14:37:21 +08:00
[MetaGroup(EcsUnityConsts.PACK_GROUP, TEMPLATES_GROUP)]
2024-10-19 00:05:07 +08:00
[MetaDescription(AUTHOR, "...")]
2024-03-03 03:51:49 +08:00
public sealed class UnityComponentConfigurableJointTemplate : UnityComponentTemplate<ConfigurableJoint>
2023-05-23 01:48:54 +08:00
{
2024-03-06 23:29:54 +08:00
public override MetaGroup Group { get { return UnityComponentConsts.JointGroup; } }
2023-05-23 01:48:54 +08:00
}
#endregion
2023-05-07 00:50:44 +08:00
}