コード例 #1
0
        /// <summary>
        /// restart current level
        /// </summary>
        private void _restartCurrentLevel()
        {
#if UNITY_5_3 || UNITY_5_4 || UNITY_5_5
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
#else
            Application.LoadLevel(Application.loadedLevel);
#endif
            ArrowPool.ClearArrows();
            restartLevel = false;
            restartTimer = 0.0f;
        }
コード例 #2
0
        /// <summary>
        /// create game controller object
        /// </summary>
        /// <param name="extended">default or extended</param>
        /// <returns>game controller object</returns>
        public static GameObject CreateGameControllerObject(bool extended)
        {
            GameObject gc = GameObject.FindGameObjectWithTag("GameController");

            if (!gc)
            {
                if (!extended)
                {
                    gc      = Resources.Load <GameObject>("GAMECONTROLLER_DEFAULT");
                    gc      = Object.Instantiate(gc);
                    gc.name = "GAMECONTROLLER_DEFAULT";
                }
                else
                {
                    gc      = Resources.Load <GameObject>("GAMECONTROLLER");
                    gc      = Object.Instantiate(gc);
                    gc.name = "GAMECONTROLLER";
                }
                Undo.RegisterCreatedObjectUndo(gc.gameObject, "Create GAMECONTROLLER");
            }
            else
            {
                if (extended)
                {
                    NPCManager npcMan = gc.GetComponent <NPCManager>();
                    if (!npcMan)
                    {
                        npcMan = Undo.AddComponent <NPCManager>(gc);
                    }

                    ArrowPool ap = gc.GetComponent <ArrowPool>();
                    if (!ap)
                    {
                        ap = Undo.AddComponent <ArrowPool>(gc);
                    }
                }
            }
            return(gc);
        }
コード例 #3
0
        /// <summary>
        /// shoot arrow
        /// </summary>
        protected override void _shootArrow()
        {
#if DEBUG_INFO
            if (!m_EquipmentScript)
            {
                Debug.LogError("object cannot be null"); return;
            }
            if (m_EquipmentScript.bones == null)
            {
                Debug.LogError("object cannot be null."); return;
            }
            if (m_TopDownPlayer.m_Camera == null)
            {
                Debug.LogError("object cannot be null"); return;
            }
            if (m_CurrentArrowInHand == null)
            {
                Debug.LogError("object cannot be null"); return;
            }
            if (!m_AudioMan)
            {
                Debug.LogError("object cannot be null"); return;
            }
#endif

            Vector3 arrow_pos      = m_EquipmentScript.bones.arrow_bone.position;
            Vector3 currentTarget  = m_BowShootPosition;
            Vector3 arrowDirection = (currentTarget - arrow_pos).normalized;
            float   curStrength    = Mathf.Clamp(m_BowShootPower * m_BowShootPower, 0.05f, 1.0f);
            float   arrowspeed     = m_EquipmentScript.currentBow.range * curStrength;
            ArrowPool.ShootArrow(m_CurrentArrowInHand, ref arrow_pos, ref arrowDirection, arrowspeed);
            m_CurrentArrowInHand = null;
            m_AudioMan.stopAudio();
            GameUtils.PlayRandomClip(m_AudioMan.audioSource,
                                     m_EquipmentScript.currentBow.weaponAudio.attackHitSounds);
        }
コード例 #4
0
        /// <summary>
        /// Unity Update method
        /// Update is called every frame, if the MonoBehaviour is enabled
        /// </summary>
        void Update()
        {
            if (fadeFunc != null)
            {
                fadeFunc();                   //fadeFunc run in update function。 actually we suggest run in croutine
            }
            if (restartLevel)
            {
                restartTimer += Time.deltaTime;
                if (restartTimer > restartTime)
                {
                    if (m_fade_black_image)
                    {
                        fadeFunc = _fade2BlackAndRestart;
                    }
                    else
                    {
                        _restartCurrentLevel();
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Z))
            {
                if (m_NpcManager)
                {
                    m_NpcManager.reviveAll();
                }
            }

            // lockand center cursor in webgl on left mouse down
#if UNITY_WEBGL
            if (Input.GetMouseButtonDown(0))
            {
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
#endif

            if (Input.GetKeyDown(KeyCode.T))
            {
                m_Player.enableJumpToTarget = !m_Player.enableJumpToTarget;
            }

            // quit
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }

            // restart
            if (Input.GetButtonDown("Submit"))
            {
                _restartCurrentLevel();
            }

            if (!m_Paused)
            {
                Time.timeScale = timeScale;
            }


            // pause / unpause
            if (Input.GetButtonDown("Pause"))
            {
                if (m_Paused)
                {
                    Time.timeScale = 1.0f;
                    m_Paused       = false;
                    if (pauseUI)
                    {
                        pauseUI.gameObject.SetActive(false);
                    }
                }
                else
                {
                    Time.timeScale = 0.0f;
                    m_Paused       = true;
                    if (pauseUI)
                    {
                        pauseUI.gameObject.SetActive(true);
                    }
                }
            }


            // toggle text info
            if (Input.GetKeyDown(KeyCode.F1))
            {
                m_ShowInfo = !m_ShowInfo;
            }

            if (InfoUI)
            {
                if (m_ShowInfo)
                {
                    InfoUI.text = InfoText;
                }
                else
                {
                    InfoUI.text = "Press F1 to show controls";
                }
            }

            ArrowPool.UpdateArrows();
        }