示例#1
0
        public static UnitState Read(this UnitStateInfo info)
        {
            UnitState newState = new UnitState();

            newState.Frame    = info.Frame;
            newState.Position = new Vector3(info.PosX, info.PosY, info.PosZ);
            newState.Rotate   = info.Rotate;
            newState.Velocity = info.Velocity;

            return(newState);
        }
示例#2
0
        public static UnitStateInfo Pack(this UnitState state, long id, uint frame)
        {
            UnitStateInfo info = new UnitStateInfo();

            info.UnitId   = id;
            info.Frame    = frame;
            info.PosX     = state.Position.x;
            info.PosY     = state.Position.y;
            info.PosZ     = state.Position.z;
            info.Rotate   = state.Rotate;
            info.Velocity = state.Velocity;

            return(info);
        }
        private static void OnSimulateAfter(this UnitSimulateComponent self)
        {
            ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
            UnitGateComponent           unitGateComponent            = self.Entity.GetComponent <UnitGateComponent>();
            ActorMessageSender          actorMessageSender           = actorLocationSenderComponent.Get(unitGateComponent.GateSessionActorId);

            if (unitGateComponent.IsDisconnect)
            {
                return;
            }

            if (self.ExecuteQueue.Count > 0)
            {
                Actor_ServerCommond serverCommond = new Actor_ServerCommond();
                while (self.ExecuteQueue.Count > 0)
                {
                    StateCommand stateCommand = self.ExecuteQueue.Dequeue();
                    serverCommond.Result.Add(stateCommand.ToCommand());
                }

                actorMessageSender.Send(serverCommond);
            }

            if (self.Frame % UnitStateComponent.SyncFrame == 1)
            {
                Actor_StateSync stateSync = new Actor_StateSync();

                Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
                foreach (Unit unit in units)
                {
                    UnitStateComponent unitStateComponent = unit.GetComponent <UnitStateComponent>();
                    UnitState          state = unitStateComponent.State;
                    UnitStateInfo      info  = state.Pack(unit.Id, state.Frame);
                    stateSync.States.Add(info);
                }

                actorMessageSender.Send(stateSync);
            }
        }