コード例 #1
0
    //event data layout:
    //it must be a object array.
    //and always the first element is the turn of execution.
    private void CommandCallback(EventData photonEvent)
    {
        //null check is important

        object[] eventData     = (object[])photonEvent.CustomData;
        int      turnToExecute = (int)eventData[0];


        object[]      serializedMoveCommands = (object[])eventData[1];
        MoveCommand[] moveCommands;
        if (serializedMoveCommands != null)
        {
            moveCommands = new MoveCommand[serializedMoveCommands.Length];
            for (int i = 0; i < serializedMoveCommands.Length; i++)
            {
                moveCommands[i] = CommandUtils.DeserializeMoveCommand((object[])serializedMoveCommands[i]);
            }
        }
        else
        {
            moveCommands = null;
        }



        object[] serializedChangeBehaviourCommand = (object[])eventData[2];
        ChangeBehaviourCommand[] changeBehaviourCommands;
        if (serializedChangeBehaviourCommand != null)
        {
            changeBehaviourCommands = new ChangeBehaviourCommand[serializedChangeBehaviourCommand.Length];
            for (int i = 0; i < changeBehaviourCommands.Length; i++)
            {
                changeBehaviourCommands[i] = CommandUtils.DeserializeChangeBehaviourCommand((object[])serializedChangeBehaviourCommand[i]);
            }
        }
        else
        {
            changeBehaviourCommands = null;
        }


        object[]        serializedGatherCommand = (object[])eventData[3];
        GatherCommand[] gatherCommands;
        if (serializedGatherCommand != null)
        {
            gatherCommands = new GatherCommand[serializedGatherCommand.Length];
            for (int i = 0; i < gatherCommands.Length; i++)
            {
                gatherCommands[i] = CommandUtils.DeserializeGatherCommand((object[])serializedGatherCommand[i]);
            }
        }
        else
        {
            gatherCommands = null;
        }

        //otros commandos
        CommandStorageSystem.QueueNetworkedCommands(turnToExecute, moveCommands, changeBehaviourCommands, gatherCommands);

        CreateCommandLockstepCheck(turnToExecute);
        SendCommandConfirmationEvent(turnToExecute);
    }