protected virtual void Start()
    {
        if (transform.parent != null)
        {
            visuals = transform.parent.Find("SuperUI").gameObject;
            AbstractPlayerInput input = transform.root.GetComponent <AbstractPlayerInput>();
            if (input != null)
            {
                switch (transform.root.GetComponent <AbstractPlayerInput>().bindings.inputMode)
                {
                case InputConfiguration.PlayerInputType.MOUSE:
                    tooltip = transform.parent.Find("SuperUI/Tooltips/Mouse Tooltip").gameObject;
                    break;

                case InputConfiguration.PlayerInputType.JOYSTICK:
                    tooltip = transform.parent.Find("SuperUI/Tooltips/Joystick Tooltip").gameObject;
                    break;
                }
            }
            else
            {
                Destroy(tooltip);
            }
        }
    }
    IEnumerator SelectCharacterVisuals()
    {
        yield return(null);

        AbstractPlayerInput input = registration.playgroundAvatar.GetComponent <AbstractPlayerInput>();

        if (input != null)
        {
            while (true)
            {
                Vector2 deltaVisuals = input.deltaVisuals();

                //Debug.Log(deltaVisuals);

                if (deltaVisuals != Vector2.zero)
                {
                    characterVisualsVector += Time.deltaTime * visualsSelectSensitivity * deltaVisuals;

                    //limit to [0,1] range
                    characterVisualsVector.x = (characterVisualsVector.x + 1) % 1;
                    characterVisualsVector.y = (characterVisualsVector.y + 1) % 1;
                    UpdateCharacterVisuals(characterVisualsVector);
                }
                yield return(null);
            }
        }
    }
Exemplo n.º 3
0
    void SpawnEndScreen()
    {
        Debug.Log(Time.timeScale);

        if (leftScore < rightScore)
        {
            audioSource.clip = witchWinClip;
        }
        else
        {
            audioSource.clip = alienWinClip;
        }

        audioSource.Play();

        int maxScore = Mathf.Max(leftScore, rightScore, 1);

        foreach (KeyValuePair <Transform, int> player in playerScores)
        {
            Side      side = player.Key.GetComponent <Stats>().side;
            Transform instantiatedEntry = Instantiate(playerEntryPrefab).transform;
            instantiatedEntry.SetParent(side == Side.LEFT ? witchesStats : aliensStats, false);
            GameEndPlayerEntry gameEndEntry = instantiatedEntry.GetComponentInChildren <GameEndPlayerEntry>();
            gameEndEntry.Init(player.Value, maxScore, player.Key.GetComponentInChildren <AbstractPlayerVisuals>());

            AbstractPlayerInput playerInput = player.Key.GetComponent <AbstractPlayerInput>();
            if (playerInput != null)
            {
                inputs.Add(playerInput);
            }
        }

        highlightGradient.color = Color.white;
        if (leftScore < rightScore)
        {
            title.text = "Witches Win!";
        }
        else if (leftScore > rightScore)
        {
            title.text = "Aliens Win!";
        }

        title.color = title.color.setAlphaFloat(1);

        Callback.FireAndForget(() => Callback.DoLerp((float l) => continueTooltip.alpha = l, gameEndTime, this), gameEndTime, this);
        if (NetworkNode.node == null || NetworkNode.node is Server)
        {
            StartCoroutine(CheckSceneTransition());
        }
    }
    // Use this for initialization
    void Awake()
    {
        Assert.IsTrue(Time.timeScale == 1);
        Assert.IsTrue(MenuMusic.singleton == null);
        if (Time.timeScale != 1)
        {
            Pause.unPause();
        }

        if (SetupData.self != null) //workaround for unity level-loading method order
        {
            data = SetupData.self;
        }
        else
        {
            Debug.Log("Setup data not linked");
        }

        Observers.Subscribe(this, GoalScoredMessage.classMessageType, GameEndMessage.classMessageType, OvertimeMessage.classMessageType);

        leftPoints = new Vector2[leftRespawnPointsParent.childCount];
        int index = 0;

        foreach (Transform child in leftRespawnPointsParent)
        {
            leftPoints[index] = child.position;
            index++;
        }

        index       = 0;
        rightPoints = new Vector2[rightRespawnPointsParent.childCount];
        foreach (Transform child in rightRespawnPointsParent)
        {
            rightPoints[index] = child.position;
            index++;
        }

        puck = ((GameObject)(Instantiate(PuckPrefab, puckRespawnPoint.position, Quaternion.identity))).GetComponent <PuckFX>();
        puck.gameObject.AddComponent <OutOfBoundsCheck>().Init(new Vector2(-horizontalBounds - 1, -verticalBounds), new Vector2(horizontalBounds + 1, verticalBounds));

        players = new Transform[data.playerComponentPrefabs.Length];
        for (int i = 0; i < data.playerComponentPrefabs.Length; i++)
        {
            GameObject spawnedPlayer = (GameObject)Instantiate(data.playerComponentPrefabs[i].character.basePlayer, new Vector2((i + 1) * 200, 0), Quaternion.identity); //the positions are temporary
            Stats      spawnedStats  = spawnedPlayer.AddComponent <Stats>();
            spawnedStats.side        = data.playerComponentPrefabs[i].character.side;
            spawnedStats.playerID    = data.playerComponentPrefabs[i].playerID;
            spawnedStats.networkMode = data.playerComponentPrefabs[i].bindings.networkMode;

            switch (data.playerComponentPrefabs[i].bindings.inputMode)
            {
            case InputConfiguration.PlayerInputType.MOUSE:
                switch (data.playerComponentPrefabs[i].bindings.networkMode)
                {
                case NetworkMode.LOCALCLIENT:
                case NetworkMode.LOCALSERVER:
                case NetworkMode.UNKNOWN:
                    spawnedPlayer.AddComponent <MousePlayerInput>().bindings = data.playerComponentPrefabs[i].bindings;
                    break;
                }
                break;

            case InputConfiguration.PlayerInputType.JOYSTICK:
                switch (data.playerComponentPrefabs[i].bindings.networkMode)
                {
                case NetworkMode.LOCALCLIENT:
                case NetworkMode.LOCALSERVER:
                case NetworkMode.UNKNOWN:
                    spawnedPlayer.AddComponent <JoystickCustomDeadZoneInput>().bindings = data.playerComponentPrefabs[i].bindings;
                    break;
                }
                break;

            case InputConfiguration.PlayerInputType.CRAPAI:
                spawnedPlayer.AddComponent <CrappyAIInput>().bindings = data.playerComponentPrefabs[i].bindings;    //don't really need the bindings; it's an AI
                break;

            case InputConfiguration.PlayerInputType.INTERPOSEAI:
                spawnedPlayer.AddComponent <InterposeAI>().bindings = data.playerComponentPrefabs[i].bindings;    //don't really need the bindings; it's an AI
                break;

            case InputConfiguration.PlayerInputType.DEFENSIVEAI:
                spawnedPlayer.AddComponent <DefensiveAI>().bindings = data.playerComponentPrefabs[i].bindings;    //don't really need the bindings; it's an AI
                break;
            }
            GameObject.Instantiate(data.playerComponentPrefabs[i].character.movementAbility).transform.SetParent(spawnedPlayer.transform, false);
            GameObject.Instantiate(data.playerComponentPrefabs[i].character.genericAbility).transform.SetParent(spawnedPlayer.transform, false);
            GameObject.Instantiate(data.playerComponentPrefabs[i].character.superAbility).transform.SetParent(spawnedPlayer.transform, false);
            GameObject visuals = GameObject.Instantiate(data.playerComponentPrefabs[i].character.visuals);
            visuals.transform.SetParent(spawnedPlayer.transform, false);
            IHueShiftableVisuals huedVisuals = visuals.GetComponent <IHueShiftableVisuals>();
            if (huedVisuals != null)
            {
                huedVisuals.shift = data.playerComponentPrefabs[i].characterVisualsVector;
            }
            players[i] = spawnedPlayer.transform;
            switch (data.playerComponentPrefabs[i].character.side)
            {
            case Side.LEFT:
                leftPlayers.Add(players[i]);
                break;

            case Side.RIGHT:
                rightPlayers.Add(players[i]);
                break;
            }
        }
        //set up AI/Ability data
        Goal[] goals = GameObject.FindObjectsOfType <Goal>();
        switch (goals[0].side)
        {
        case Side.LEFT:
            leftGoal  = goals[0].transform;
            rightGoal = goals[1].transform;
            break;

        case Side.RIGHT:
            rightGoal = goals[0].transform;
            leftGoal  = goals[1].transform;
            break;
        }
        for (int i = 0; i < players.Length; i++)
        {
            AbstractPlayerInput input = players[i].GetComponent <AbstractPlayerInput>();
            if (input is IInterferenceAI)
            {
                switch (data.playerComponentPrefabs[i].character.side)
                {
                case Side.LEFT:
                    (input as IInterferenceAI).myOpponents = rightPlayers;
                    break;

                case Side.RIGHT:
                    (input as IInterferenceAI).myOpponents = leftPlayers;
                    break;
                }
            }

            if (input is IGoalAI)
            {
                switch (data.playerComponentPrefabs[i].character.side)
                {
                case Side.LEFT:
                    (input as IGoalAI).myGoal       = leftGoal;
                    (input as IGoalAI).opponentGoal = rightGoal;
                    break;

                case Side.RIGHT:
                    (input as IGoalAI).myGoal       = rightGoal;
                    (input as IGoalAI).opponentGoal = leftGoal;
                    break;
                }
            }

            //now abilities

            foreach (AbstractAbility ability in players[i].GetComponentsInChildren <AbstractAbility>())
            {
                if (ability is IOpponentsAbility)
                {
                    switch (data.playerComponentPrefabs[i].character.side)
                    {
                    case Side.LEFT:
                        (ability as IOpponentsAbility).opponents = rightPlayers;
                        break;

                    case Side.RIGHT:
                        (ability as IOpponentsAbility).opponents = leftPlayers;
                        break;
                    }
                }
                if (ability is IAlliesAbility)
                {
                    switch (data.playerComponentPrefabs[i].character.side)
                    {
                    case Side.LEFT:
                        (ability as IAlliesAbility).allies = leftPlayers;
                        break;

                    case Side.RIGHT:
                        (ability as IAlliesAbility).allies = rightPlayers;
                        break;
                    }
                }
                if (ability is IGoalAbility)
                {
                    switch (data.playerComponentPrefabs[i].character.side)
                    {
                    case Side.LEFT:
                        (ability as IGoalAbility).myGoal       = leftGoal;
                        (ability as IGoalAbility).opponentGoal = rightGoal;
                        break;

                    case Side.RIGHT:
                        (ability as IGoalAbility).myGoal       = rightGoal;
                        (ability as IGoalAbility).opponentGoal = leftGoal;
                        break;
                    }
                }
                if (ability is IPuckAbility)
                {
                    (ability as IPuckAbility).puck = puck.transform;
                }
            }
        }
    }