Пример #1
0
    private void OnReceivedMessage()
    {
        if (this.firstRun == false)
        {
            this.player.SetClientID(ARNetworkHub.Instance.GetClientID());
            this.firstRun = true;
        }

        //process message here
        ARLocalMessage localMsg = ARMessageQueue.Instance.GetLatestMessage();

        //ConsoleManager.LogMessage (TAG + " received message with type of " + localMsg.GetActionType ());
        if (localMsg.GetActionType() == ARNetworkMessage.ActionType.SPAWN_OBJECT && !this.opponents.ContainsKey(localMsg.GetClientID()))
        {
            ConsoleManager.LogMessage(TAG + " Spawning opponent for " + localMsg.GetClientID());
            ARController opponent = GameObject.Instantiate <ARController>(this.opponentCopy, this.opponentCopy.transform.parent);
            opponent.gameObject.transform.position = this.player.transform.position;
            opponent.gameObject.SetActive(true);
            opponent.SetClientID(localMsg.GetClientID());
            this.opponents.Add(localMsg.GetClientID(), opponent);
        }
        else if (localMsg.GetActionType() == ARNetworkMessage.ActionType.MOVE)
        {
            this.opponents[localMsg.GetClientID()].MoveToDestination(localMsg.GetPosition());
            //this.opponent.MoveToDestination(localMsg.GetPosition());
        }
    }
Пример #2
0
    /// <summary>
    /// Enqueues a message. The ARMessage is translated to an ARLocalMessage instance to avoid referencing issues
    /// </summary>
    /// <param name="actionType">Action type.</param>
    /// <param name="position">Position.</param>
    public void EnqueueMessage(string clientID, ARNetworkMessage.ActionType actionType, Vector3 position)
    {
        ARLocalMessage arMsg = new ARLocalMessage(clientID, actionType, position);

        this.messageQueue.Enqueue(arMsg);

        ConsoleManager.LogMessage(TAG + " successfully enqueued message of type " + arMsg.GetActionType());
    }