protected override void OnUpdate()
        {
            if (CheckTime(ref querySet.inter) == false)
            {
                return;
            }

            Entities.With(querySet.group).ForEach((Entity entity,
                                                   ref BaseUnitStatus.Component status,
                                                   ref BoneAnimation.Component anim) =>
            {
                if (UnitUtils.IsBuilding(status.Type))
                {
                    return;
                }

                var container = EntityManager.GetComponentObject <PostureBoneContainer>(entity);
                if (container == null)
                {
                    return;
                }

                var boneMap = anim.BoneMap;

                bool changed = false;
                foreach (var bone in container.Bones)
                {
                    bool localChanged = false;
                    if (boneMap.ContainsKey(bone.hash) == false)
                    {
                        localChanged = true;
                    }
                    else
                    {
                        var trans = boneMap[bone.hash];

                        localChanged |= bone.transform.position != trans.Position.ToWorkerPosition(this.Origin);
                        localChanged |= bone.transform.rotation != trans.Rotation.ToUnityQuaternion();
                        localChanged |= bone.transform.localScale != trans.Scale.ToUnityVector();
                    }

                    if (localChanged)
                    {
                        boneMap[bone.hash] = PostureUtils.ConvertTransform(bone.transform);
                    }

                    changed |= localChanged;
                }

                if (changed)
                {
                    anim.BoneMap = boneMap;
                }
            });
        }
        void FactoryQuery(Unity.Entities.Entity entity,
                          ref UnitFactory.Component factory,
                          ref BaseUnitStatus.Component status,
                          ref StrongholdSight.Component sight,
                          ref HexFacility.Component hex)
        {
            if (status.State != UnitState.Alive)
            {
                return;
            }

            if (UnitUtils.IsBuilding(status.Type) == false)
            {
                return;
            }

            if (status.Side == UnitSide.None)
            {
                return;
            }

            UnityEngine.Profiling.Profiler.BeginSample("HandleFactoryRequests:CheckAlive");
            var trans = EntityManager.GetComponentObject <Transform>(entity);

            CheckAlive(trans.position, status.Side, uint.MaxValue, HexDictionary.HexEdgeLength * 2, teamsDic);
            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("HandleFactoryRequests:MakeOrders");
            // number check
            if (factory.TeamOrders.Count == 0 && sight.StrategyVector.Side != UnitSide.None)
            {
                var teamOrders = factory.TeamOrders;
                makeOrders(status.Side, status.Rank, PostureUtils.RotFoward(sight.StrategyVector.Vector.ToUnityVector()), status.Order, hex.HexIndex,
                           sight.FrontLineCorners, sight.TargetHexes, teamsDic, teamOrders);

                factory.TeamOrders = teamOrders;
            }
            UnityEngine.Profiling.Profiler.EndSample();

#if false
            if (factory.TurretOrders.Count == 0)
            {
                var turretOrders = factory.TurretOrders;
                makeOrders(trans.position, status.Side, status.Rank, turretOrders);
                factory.TurretOrders = turretOrders;
            }
#endif
        }
Esempio n. 3
0
        public static EntityTemplate CreateObjectEntityTemplate(ObjectType type, Coordinates coords, CompressedQuaternion?rotation = null, FixedPointVector3?scale = null)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(metaDic[type]), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PostureRoot.Snapshot()
            {
                RootTrans = PostureUtils.ConvertTransform(coords, rotation, scale)
            }, WorkerUtils.UnityGameLogic);

            SwitchType(template, type, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(GetReadAttributes(type));
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Esempio n. 4
0
        private void Query(Rigidbody rigid,
                           ref BaseUnitStatus.Component status,
                           ref PostureRoot.Component posture)
        {
            if (UnitUtils.IsBuilding(status.Type))
            {
                return;
            }

            var trans     = rigid.transform;
            var rootTrans = posture.RootTrans;

            bool changed = false;

            changed |= (trans.rotation.eulerAngles - rootTrans.Rotation.ToUnityQuaternion().eulerAngles).sqrMagnitude > rotDiff * rotDiff;
            changed |= (trans.localScale - rootTrans.Scale.ToUnityVector()).sqrMagnitude > scaleDiff * scaleDiff;

            if (changed)
            {
                posture.RootTrans = PostureUtils.ConvertTransform(trans);
            }
        }
Esempio n. 5
0
        public static EntityTemplate CreateBaseUnitEntityTemplate(UnitSide side, UnitType type, Coordinates coords, CompressedQuaternion?rotation = null, FixedPointVector3?scale = null, OrderType?order = null, uint?rank = null)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(metaDic[type]), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PostureRoot.Snapshot()
            {
                RootTrans = PostureUtils.ConvertTransform(coords, rotation, scale)
            }, WorkerUtils.UnityGameLogic);

            template.AddComponent(new BaseUnitSight.Snapshot(), WorkerUtils.UnityGameLogic);
            //template.AddComponent(new BaseUnitAction.Snapshot { EnemyPositions = new List<FixedPointVector3>() }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitStatus.Snapshot(side, type, UnitState.Alive, order == null ? orderDic[type] : order.Value, GetRank(rank, type)), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitTarget.Snapshot().DefaultSnapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitHealth.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GunComponent.Snapshot {
                GunsDic = new Dictionary <int, GunInfo>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new FuelComponent.Snapshot(), WorkerUtils.UnityGameLogic);

            if (type.BaseType() == UnitBaseType.Moving)
            {
                template.AddComponent(new BaseUnitMovement.Snapshot(), WorkerUtils.UnityGameLogic);
                template.AddComponent(new BaseUnitReviveTimer.Snapshot {
                    IsStart = false, RestTime = 0.0f
                }, WorkerUtils.UnityGameLogic);
            }

            SwitchType(template, type, WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(GetReadAttributes(type));
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }