2023-05-07 00:50:44 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
[DebugColor(255 / 3, 255, 0)]
|
2023-06-29 14:26:01 +08:00
|
|
|
|
public readonly 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-29 14:26:01 +08:00
|
|
|
|
public readonly T obj;
|
|
|
|
|
public UnityComponent(T obj) => this.obj = obj;
|
2023-05-07 00:50:44 +08:00
|
|
|
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-28 15:08:09 +08:00
|
|
|
|
|
|
|
|
|
public class UnityComponentInitializer<T> : TemplateComponentInitializer<UnityComponent<T>> where T : Component
|
|
|
|
|
{
|
|
|
|
|
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)
|
2023-06-29 14:26:01 +08:00
|
|
|
|
component = new UnityComponent<T>(gameObject.GetComponent<T>());
|
2023-06-28 15:08:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-05-07 00:50:44 +08:00
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentRigitBodyInitializer : UnityComponentInitializer<Rigidbody>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentAnimatorInitializer : UnityComponentInitializer<Animator>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentCharacterControllerInitializer : UnityComponentInitializer<CharacterController>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Colliders
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentColliderInitializer : UnityComponentInitializer<Collider>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Collider/" + nameof(Collider);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentBoxColliderInitializer : UnityComponentInitializer<BoxCollider>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Collider/" + nameof(BoxCollider);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentSphereColliderInitializer : UnityComponentInitializer<SphereCollider>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Collider/" + nameof(SphereCollider);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentCapsuleColliderInitializer : UnityComponentInitializer<CapsuleCollider>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Collider/" + nameof(CapsuleCollider);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentMeshColliderInitializer : UnityComponentInitializer<MeshCollider>
|
2023-05-07 00:50:44 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Collider/" + nameof(MeshCollider);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2023-05-23 01:48:54 +08:00
|
|
|
|
#region Joints
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentJointInitializer : UnityComponentInitializer<Joint>
|
2023-05-23 01:48:54 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Joint/" + nameof(Joint);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentFixedJointInitializer : UnityComponentInitializer<FixedJoint>
|
2023-05-23 01:48:54 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Joint/" + nameof(FixedJoint);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentCharacterJointInitializer : UnityComponentInitializer<CharacterJoint>
|
2023-05-23 01:48:54 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Joint/" + nameof(CharacterJoint);
|
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
2023-06-28 15:08:09 +08:00
|
|
|
|
public sealed class UnityComponentConfigurableJointInitializer : UnityComponentInitializer<ConfigurableJoint>
|
2023-05-23 01:48:54 +08:00
|
|
|
|
{
|
|
|
|
|
public override string Name => "UnityComponent/Joint/" + nameof(ConfigurableJoint);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2023-05-07 00:50:44 +08:00
|
|
|
|
}
|