コード例 #1
0
		public static async Task<KS.KSObject> ProcessBuffer(byte[] buffer)
		{
#if !UNITY_WEBGL || UNITY_EDITOR
			await new WaitForBackgroundThread();

			return await Task.Run<KS.KSObject>(() =>
			{
#endif
				Message message = new Message();
				message.Deserialize(buffer);

				var baseMessageType = Helper.Assembly.GetType("KS.Messages." + message.Type);
				KS.KSObject baseMessage = Activator.CreateInstance(baseMessageType) as KS.KSObject;
				baseMessage.Deserialize(message.Payload.ISOGetBytes());

				if (baseMessage.Name() == SceneActions.NameStatic)
				{
					var sceneActions = (SceneActions)baseMessage;
					sceneActions.ParsedActions = new List<KS.KSObject>(sceneActions.ActionTypes.Count);

					for (int i = 0; i < sceneActions.ActionTypes.Count; i++)
					{
						var action = KS.KSObject.GetAction(sceneActions.ActionTypes[i], sceneActions.ActionPayloads[i]);
						sceneActions.ParsedActions.Add(action);
					}
				}

				return baseMessage;
#if !UNITY_WEBGL || UNITY_EDITOR
			});
#endif
		}
コード例 #2
0
        public void Action(KS.KSObject action)
        {
            Type actionType        = null;
            Type occurrenceType    = null;
            bool onlySuddenChanges = _onlySuddenChanges[action.Name()];

            switch (action.Name())
            {
            case CreateEmptyGameObject.NameStatic:
            case InstantiateBundleAsset.NameStatic:
            case CreateBasicObject.NameStatic:
            case CreateUIElement.NameStatic:
                occurrenceType = Helper.Assembly.GetType("Koala.InstantiateOccurrence");
                break;

            case EndCycle.NameStatic:
                Helper.MaxCycle += 1;
                return;
            }

            // Defaults
            actionType     = actionType ?? Helper.Assembly.GetType("KS.SceneActions." + action.Name());
            occurrenceType = occurrenceType ?? Helper.Assembly.GetType("Koala." + action.Name() + "Occurrence");

            // Call method
            var doActionMethod = Helper.MakeGenericMethod(_doActionMethodInfo, occurrenceType, actionType);

            doActionMethod.Invoke(this, new object[] { Helper.DynamicCast(action, actionType), onlySuddenChanges });
        }
コード例 #3
0
        private void ParseMessage(KS.KSObject message)
        {
            if (message == null)
            {
                return;
            }

            switch (message.Name())
            {
            case GameInfo.NameStatic:
                var gameInfo = (GameInfo)message;
                Helper.CycleDuration = gameInfo.GuiCycleDuration.Value;
                Helper.GameName      = gameInfo.GameName;
                m_playersBoard.Init(gameInfo.Sides, gameInfo.GuiSideColors);
                break;

            case AgentJoined.NameStatic:
                var agentJoined = (AgentJoined)message;
                Director.Action(new KS.SceneActions.AgentJoined
                {
                    Cycle     = 0,
                    Team      = agentJoined.TeamNickname,
                    Side      = agentJoined.SideName,
                    AgentName = agentJoined.AgentName,
                });
                if (!Helper.GameStarted)
                {
                    Helper.MaxCycle += 1;
                }
                break;

            case AgentLeft.NameStatic:
                var agentLeft = (AgentLeft)message;
                Director.Action(new KS.SceneActions.AgentLeft
                {
                    Cycle     = 0,
                    Side      = agentLeft.SideName,
                    AgentName = agentLeft.AgentName,
                    IsLeft    = true,
                });
                break;

            case StartGame.NameStatic:
                var startGame = (StartGame)message;
                StartCoroutine(StartGameCounter((int)startGame.StartTime.Value));
                if (!Helper.ReplayMode)
                {
                    StartCoroutine(CheckNetworkTimeout());
                }
                break;

            case EndGame.NameStatic:
                var endGame = (EndGame)message;

                FillEndGamePanel(endGame.WinnerSidename, endGame.Details);
                Director.Action(new KS.SceneActions.EndGame
                {
                    Cycle        = 0.001f,
                    EndGamePanel = m_endGamePanel,
                });

                Helper.MaxCycle += 0.002f;
                Helper.MaxCycle  = Timeline.Instance.GetFirstEmptyCycle(Helper.MaxCycle);

                GameEnded = true;
                break;

            case SceneActions.NameStatic:
                var sceneActions = (SceneActions)message;
                foreach (var action in sceneActions.ParsedActions)
                {
                    Director.Action(action);
                }
                break;
            }
        }