Exemple #1
0
        public static void FixCamera()
        {
            GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera");

            CameraBehavior cameraBehavior = mainCamera.GetComponent <CameraBehavior>();
            float          cameraSpeed    = cameraBehavior.MovementRate;

            // Destroy the camera in preparation for adding the new one.
            GameObject.DestroyImmediate(mainCamera);

            // Retrieve the MainCamera prefab from the asset database.
            GameObject newCamera = (GameObject)GameObject.Instantiate(AssetDatabase.LoadAssetAtPath(
                                                                          "Assets/Prefabs/Main Camera.prefab", typeof(GameObject)));

            newCamera.transform.name = "Main Camera";

            cameraBehavior = newCamera.GetComponent <CameraBehavior>();
            cameraBehavior.MovementRate = cameraSpeed;

            // Update the main camera property of the combat camera.
            CombatSystemBehavior combatSystem = (CombatSystemBehavior)GameObject.Find("Combat Camera").GetComponent <CombatSystemBehavior>();

            combatSystem.mainCamera = newCamera.camera;

            EditorUtility.SetDirty(combatSystem);

            // Disable all text renderers on the camera.
            MeshRenderer[] renderers = newCamera.GetComponentsInChildren <MeshRenderer>();
            foreach (MeshRenderer renderer in renderers)
            {
                if (renderer.gameObject.name == "MiniMapBG")
                {
                    continue;
                }

                renderer.enabled = false;
            }

            // Update the grid for the minimap.
            GridBehavior         grid        = GameObject.FindGameObjectWithTag("Grid").GetComponent <GridBehavior>();
            MiniMapGridBehaviour minimapGrid = newCamera.GetComponentInChildren <MiniMapGridBehaviour>();

            minimapGrid.theGrid        = grid;
            minimapGrid.gameController = grid.GetComponent <GameControllerBehaviour>();

            EditorUtility.SetDirty(newCamera);

            Selection.activeGameObject = newCamera;

            Debug.Log("Camera fixed.");
        }
    /// <summary>
    /// Completes the combat,
    /// </summary>
    /// <param name="losingSquad">
    /// Reference to the squad that lost the combat.
    /// </param>
    private void endCombat(CombatSquadBehavior losingSquad)
    {
        MonoBehaviour[] objects = GetComponentsInChildren <MonoBehaviour>();
        for (int _i = (objects.Count() - 1); _i >= 0; _i--)
        {
            if (objects[_i].name == "__UNITBASE__")
            {
                DestroyImmediate(objects[_i].gameObject);
            }
        }

        if (losingSquad != null)
        {
            ActorBehavior actor = losingSquad.GetComponent <ActorBehavior>();
            if (actor != null && grid.ignoreList.Contains(actor.currentMovePoint))
            {
                grid.ignoreList.Remove(actor.currentMovePoint);
            }

            // Retrieve the game controller to determine which side the losing team was on.
            GameControllerBehaviour gameController = grid.GetComponent <GameControllerBehaviour>();
            if (actor.theSide == GameControllerBehaviour.UnitSide.player)
            {
                gameController.playerTeamTotal--;
            }
            else
            {
                gameController.enemyTeamTotal--;
            }

            Destroy(losingSquad.gameObject);
        }

        foreach (NodeSkeletonBehavior node in unitPrefabs)
        {
            DestroyImmediate(node.gameObject);
        }

        this.offensiveSquad = null;
        this.defensiveSquad = null;

        GridBehavior.preCombat       = false;
        HonorSystemBehavior.inCombat = true;
        GridBehavior.inCombat        = false;
        AudioBehavior.inCombat       = false;
    }