Example #1
0
        private void SaveCharactersInInitalState(GameCharacter[] characters)
        {
            GameCharacter[] storedCharacters = new GameCharacter[characters.Length];
            for (int i = 0; i < characters.Length; ++i)
            {
                GameCharacter character = characters[i];
                bool          isActive  = character.gameObject.activeSelf;
                character.gameObject.SetActive(false);

                GameCharacter stored = Instantiate(character, character.transform.position, character.transform.rotation);
                stored.name = character.name;
                character.gameObject.SetActive(isActive);

                ExposeToEditor[] exposeToEditor = stored.GetComponentsInChildren <ExposeToEditor>();
                foreach (ExposeToEditor obj in exposeToEditor)
                {
                    obj.MarkAsDestroyed = true;
                }

                stored.transform.SetParent(transform);
                storedCharacters[i] = stored;
            }

            m_storedCharacters = storedCharacters;
        }
Example #2
0
        private void InitializeGame(GameCharacter[] characters, int activeCharacterIndex)
        {
            m_gameOver = false;
            if (m_cameraFollow)
            {
                m_playerCamera = FindObjectOfType <GameCameraFollow>();
                if (m_playerCamera == null)
                {
                    if (Camera.main != null)
                    {
                        m_playerCamera = Camera.main.gameObject.AddComponent <GameCameraFollow>();
                    }
                }

                if (m_playerCamera != null)
                {
                    Canvas canvas = GetComponentInChildren <Canvas>();
                    canvas.renderMode = RenderMode.ScreenSpaceCamera;
                    Camera cam = m_playerCamera.GetComponent <Camera>();
                    canvas.worldCamera   = cam;
                    canvas.planeDistance = cam.nearClipPlane + 0.05f;
                }
            }


            m_activeCharacters = new List <GameCharacter>();
            for (int i = 0; i < characters.Length; ++i)
            {
                GameCharacter character = characters[i];
                character.transform.SetParent(null);
                character.gameObject.SetActive(true);
                character.HandleInput = false;

                ExposeToEditor exposeToEditor = character.GetComponent <ExposeToEditor>();
                if (!exposeToEditor)
                {
                    character.gameObject.AddComponent <ExposeToEditor>();
                }
                else
                {
                    ExposeToEditor[] children = character.GetComponentsInChildren <ExposeToEditor>(true);
                    for (int j = 0; j < children.Length; ++j)
                    {
                        ExposeToEditor child = children[j];
                        child.MarkAsDestroyed = false;
                    }
                }
                m_activeCharacters.Add(character);
            }

            m_total = m_activeCharacters.Count;
            m_score = 0;

            if (m_total == 0)
            {
                TxtCompleted.gameObject.SetActive(true);
                TxtScore.gameObject.SetActive(false);
                TxtTip.gameObject.SetActive(false);

                TxtCompleted.text = "Game Over!";
                m_gameOver        = true;
            }
            else
            {
                TxtCompleted.gameObject.SetActive(false);
                TxtScore.gameObject.SetActive(true);
                TxtTip.gameObject.SetActive(true);
                UpdateScore();

                if (activeCharacterIndex >= 0)
                {
                    m_current = m_activeCharacters[activeCharacterIndex];
                    if (m_current != null)
                    {
                        ActivatePlayer();
                    }
                    else
                    {
                        SwitchPlayer(null, 0.0f, true);
                    }
                }
                else
                {
                    SwitchPlayer(null, 0.0f, true);
                }
            }
        }