/*
 *Copyright(C) 2020 by Chief All rights reserved.
 *Unity版本：2020.2.20b8
 *作者:程一峰  
 *创建日期: 2022-07-21 
 *模块说明：ECS 通用的组件
 *版本: 0.1
*/

using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;

namespace Aster.ECS
{

    public struct ATransform : IComponentData
    {
        public float3 Position;
        public quaternion Rotation;
        public float3 Scale;

        public ATransform(float3 position, quaternion rotation, float3 scale)
        {
            Position = position;
            Rotation = rotation;
            Scale = scale;
        }
    }

    /// <summary>
    /// 本地Transform；
    /// 如果有父对象用这个；
    /// </summary>
    public struct ALocalTransform : IComponentData
    {
        public float3 Position;
        public quaternion Rotation;
        public float3 Scale;

        public ALocalTransform(float3 position, quaternion rotation, float3 scale)
        {
            Position = position;
            Rotation = rotation;
            Scale = scale;
        }

        public ALocalTransform(ATransform transform)
        {
            Position = transform.Position;
            Rotation = transform.Rotation;
            Scale = transform.Scale;
        }

        public ATransform UpdateByParent(ATransform parentTransform)
        {
            float3 nPos = parentTransform.Position + parentTransform.Scale * math.mul(parentTransform.Rotation, Position);
            float3 nScale = parentTransform.Scale * Scale;
            quaternion nRot = math.mul(parentTransform.Rotation, Rotation);
            return new ATransform(nPos, nRot, nScale);
        }

    }

    /// <summary>
    /// 父对象；
    /// 这个是在Job里可以用的；
    /// </summary>
    public struct AParent : IComponentData
    {
        public Entity Parent;

        public AParent(ASharedParent shareP) { Parent = shareP.Parent; }
    }

    /// <summary>
    /// 共享的 ComponentData ；辅助Chunk分组。
    /// </summary>
    public struct ASharedParent : ISharedComponentData
    {
        public Entity Parent;

        public ASharedParent(AParent p) { Parent = p.Parent; }
    }

    internal struct AEnable : IComponentData
    {
        public bool ParentEnable;

        public bool EnableSelf;

        public bool Enable => EnableSelf && ParentEnable;

        public AEnable(bool enable)
        {
            ParentEnable = true;
            EnableSelf = enable;
        }

    }

    public struct ABounds : IComponentData
    {
        public float3 Center;
        public float3 Size;

        public ABounds(Bounds bound)
        {
            Center = bound.center;
            Size = bound.extents;
        }

    }

}