Exemple #1
0
 // Use this for initialization
 void Awake()
 {
     Assert.IsTrue(spawnPositions.Length != 0);
     sfx = GetComponent <AudioSource>();
     Callback.FireForUpdate(() => puckFX = GameObject.FindGameObjectWithTag(Tags.puck).GetComponent <PuckFX>(), this);
     //TODO: maybe move to start instead of using callback?
 }
 // Use this for initialization
 void Awake()
 {
     Assert.IsTrue(spawnPositions.Length != 0);
     sfx = GetComponent<AudioSource>();
     Callback.FireForUpdate(() => puckFX = GameObject.FindGameObjectWithTag(Tags.puck).GetComponent<PuckFX>(), this);
     //TODO: maybe move to start instead of using callback?
 }
    // 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;
                }
            }
        }
    }
 void Start()
 {
     Callback.FireForUpdate(() => puckFX = GameObject.FindGameObjectWithTag(Tags.puck).GetComponent<PuckFX>(), this);
 }