示例#1
0
        // Display Mesh
        protected override void OnUpdate()
        {
            Material   marineMaterial     = ECS_RTSControls.instance.marineMaterial;
            Quaternion quaternionIdentity = Quaternion.identity;

            EntityQuery skeletonQuery = GetEntityQuery(ComponentType.ReadOnly <Translation>(), ComponentType.ReadOnly <Skeleton_Data>());
            NativeArray <Translation>   translationArray  = skeletonQuery.ToComponentDataArray <Translation>(Allocator.TempJob);
            NativeArray <Skeleton_Data> skeletonDataArray = skeletonQuery.ToComponentDataArray <Skeleton_Data>(Allocator.TempJob);

            float3 skeletonOffset = new float3(0, 5f, 0);

            //*
            for (int i = 0; i < translationArray.Length; i++)
            {
                Vector3 position = translationArray[i].Value + skeletonOffset;
                position.z = position.y * .05f;
                Skeleton_Data skeletonData = skeletonDataArray[i];
                // #### TODO: Performance issue when grabbing mesh list
                List <Mesh> meshList = ECS_UnitAnim.GetMeshList(skeletonData.activeUnitAnimTypeEnum, skeletonData.activeAnimDir);
                Mesh        mesh     = meshList[skeletonData.currentFrame];
                Material    material = marineMaterial;
                Graphics.DrawMesh(mesh, position, quaternionIdentity, material, 0);

                Graphics.DrawMesh(ECS_RTSControls.instance.shadowMesh, (float3)position + new float3(0, -8f, -.01f), quaternionIdentity, ECS_RTSControls.instance.shadowMaterial, 0);
            }
            //*/

            translationArray.Dispose();
            skeletonDataArray.Dispose();
        }
 public static void PlayAnim(Entity entity, Skeleton_Data skeletonData, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir, Skeleton_Anim_OnComplete onComplete)
 {
     if (IsAnimDifferentFromActive(skeletonData, ecsUnitAnimTypeEnum, animDir))
     {
         PlayAnimForced(entity, ecsUnitAnimTypeEnum, animDir, onComplete);
     }
 }
        public static void PlayAnimForcedJobs(Entity entity, int index, EntityCommandBuffer.Concurrent entityCommandBuffer, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir, Skeleton_Anim_OnComplete onComplete)
        {
            Skeleton_Data skeletonData = GetSkeletonData(ecsUnitAnimTypeEnum, animDir, onComplete);

            entityCommandBuffer.SetComponent(index, entity, skeletonData);

            if (skeletonData.frameRate <= 0)
            {
                Debug.LogError("#################### FRAMERATE ZERO!");
            }
        }
        public static void PlayAnimForced(Entity entity, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir, Skeleton_Anim_OnComplete onComplete)
        {
            Skeleton_Data skeletonData = GetSkeletonData(ecsUnitAnimTypeEnum, animDir, onComplete);

            World.Active.EntityManager.SetComponentData(entity, skeletonData);

            if (skeletonData.frameRate <= 0)
            {
                Debug.LogError("#################### FRAMERATE ZERO!");
            }
        }
        public static bool IsAnimDifferentFromActive(Skeleton_Data skeletonData, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir)
        {
            // Ignores if same animType, same angle and same frameRateMod

            // 8 angles
            if (ecsUnitAnimTypeEnum == skeletonData.activeUnitAnimTypeEnum && animDir == skeletonData.activeAnimDir)
            {
                // Same anim, same angle
                return(false);
            }
            else
            {
                if (ecsUnitAnimTypeEnum != skeletonData.activeUnitAnimTypeEnum)
                {
                    // Different anim, same angle
                    return(true);
                }
                else
                {
                    // Different angle, same anim
                    return(true);
                }
            }
        }
        public static void PlayAnim(Entity entity, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, Vector3 dir, Skeleton_Anim_OnComplete onComplete)
        {
            Skeleton_Data skeletonData = World.Active.EntityManager.GetComponentData <Skeleton_Data>(entity);

            PlayAnim(entity, skeletonData, ecsUnitAnimTypeEnum, GetAnimDir(dir), onComplete);
        }
 public static void PlayAnimJobs(Entity entity, int index, EntityCommandBuffer.Concurrent entityCommandBuffer, Skeleton_Data skeletonData, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, UnitAnim.AnimDir animDir, Skeleton_Anim_OnComplete onComplete)
 {
     if (IsAnimDifferentFromActive(skeletonData, ecsUnitAnimTypeEnum, animDir))
     {
         // Different from current, play anim
         PlayAnimForcedJobs(entity, index, entityCommandBuffer, ecsUnitAnimTypeEnum, animDir, onComplete);
     }
 }
 public static void PlayAnimJobs(Entity entity, int index, EntityCommandBuffer.Concurrent entityCommandBuffer, Skeleton_Data skeletonData, ECS_UnitAnimType.TypeEnum ecsUnitAnimTypeEnum, Vector3 dir, Skeleton_Anim_OnComplete onComplete)
 {
     PlayAnimJobs(entity, index, entityCommandBuffer, skeletonData, ecsUnitAnimTypeEnum, GetAnimDir(dir), onComplete);
 }