Example #1
0
    void Update()
    {
        if (GetComponent <ObservableView>())
        {
            ObservableView  observableView = GetComponent <ObservableView>();
            NetworkedPlayer owner          = EdgeManager.GetPlayer(observableView.ownerId);
            Material        playerMat      = owner.GetComponent <MeshRenderer>().material;
            GetComponent <MeshRenderer>().material = playerMat;
            if (owner.isLocalPlayer)
            {
                float h = Input.GetAxis("Horizontal") * 100 * Time.deltaTime;
                float v = Input.GetAxis("Vertical") * Time.deltaTime;
                transform.Translate(0, 0, v);
                transform.Rotate(0, h, 0);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    Observable      observable = owner.observer.observables[observableView.observableIndex];
                    NetworkedPlayer otherPlayer;

                    //Switch ownership to the other player in the room
                    if (owner.playerIndex == 0)
                    {
                        otherPlayer = EdgeManager.GetPlayer(1);
                    }
                    else
                    {
                        otherPlayer = EdgeManager.GetPlayer(0);
                    }
                    observable.ChangeOwnership(otherPlayer.playerId);
                }
            }
        }
    }
Example #2
0
 void OnEnable()
 {
     targetObject = (NetworkedPlayer)target;
     netTransform = targetObject.GetComponent <NetworkTransform> ();
 }
    void ActivateElement()
    {
        // ASSUMING NOTHING HAS BEEN SELECTED...
        // Check to see if there's a piece above the selected tile
        //      If there is, activate this tile and open that piece's context menu
        //      If that piece wants to move, it should call what this used to do but is now in a public function
        //          This should use the Unit script's numMoves as a parameter for showing movement
        //      If there is not, do nothing
        if (activeGO == null)
        {
            NetworkedGridElement selectedGE = selectedGO.GetComponent <NetworkedGridElement>();
            activeGO = selectedGO;
            if (selectedGE.piece && selectedGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedUnit)
            {
                if (selectedGE.piece.GetComponent <NetworkedUnit>().owner.GetComponent <NetworkedPlayer>() != activePlayer)
                {
                    activeGO = null;
                    return;
                }
                selectedPiece = selectedGE.piece;
                selectedPiece.GetComponent <NetworkedUnit>().DisplayMoveGrid();
                //canPressButtons = false;
            }
            else if (!(selectedGE.piece && selectedGE.piece.GetComponent <NetworkedGamePiece>() is NetworkedTrap) &&
                     ((selectedGE.spawnable && selectedGE.owner == activePlayer.GetComponent <NetworkedPlayer>().identity) ||
                      (selectedGE.portal && selectedGE.portalOwner == activePlayer.GetComponent <NetworkedPlayer>().identity)))
            {
                // Display a ContextMenu with all the pieces that can be spawned
                contextMenu.ShowContextMenu(this);
                // Move the canvas to SelectedGO's location
                contextMenu.menuCanvas.transform.position = selectedGO.transform.position + contextMenu.menuCanvas.transform.position.z * Vector3.forward;
                canPressButtons = false;
                // Long term, this must be dynamic, but we can settle for short term for now
            }
            else
            {
                activeGO = null;
            }
        }

        // ASSUMING SOMETHING *HAS* BEEN SELECTED (that is, we're already displaying a movement grid
        // Check to see if this element is a valid movement target for the piece
        //      If it is, turn off the movement grid and move the piece here
        //      If it isn't, cancel the move action? Do nothing? Do nothing for now
        else
        {
            // don't do anything if we reselect the active game object
            if (selectedGO == activeGO)
            {
                return;
            }
            else if (selectedPiece != null)
            {
                if (selectedGO.GetComponent <NetworkedGridElement>().isHighlighted)
                {
                    selectedPiece.GetComponent <NetworkedUnit>().PerformAction(selectedGO);
                    SetElementColor(selectedGO, selectedColor, defaultColor);
                    activeGO      = null;
                    selectedPiece = null;
                }
            }
        }
    }