コード例 #1
0
        private void Update()
        {
            if (SceneManager.GetActiveScene().buildIndex == 0)
            {
                Destroy(gameObject);
            }

            if (SceneManager.GetActiveScene().buildIndex != SceneManager.sceneCount - 1)
            {
                // Destroy on main menu to clear data
                if (SceneManager.GetActiveScene().buildIndex == 0)
                {
                    Destroy(gameObject);
                }

                if (inDialogue)
                {
                    var mouse = Mouse.current;
                    if (mouse.leftButton.wasPressedThisFrame)
                    {
                        if (dialog.finishedTyping)
                        {
                            if (_currentMsg < _currentDialogue.dialogue.Count - 1)
                            {
                                _currentMsg++;
                                RunMessage(_currentDialogue.dialogue[_currentMsg]);
                            }
                            else
                            {
                                FinishDialogue();
                                PlayerController.Instance.PostDialogeHotfix();
                            }
                        }
                        else
                        {
                            dialog.QuickFinish();
                        }
                    }
                }

                hud.companionCounter.text = FindObjectsOfType <CompanionAI>().Length.ToString();

                UpdateObjectiveCount();

                // Iterate over enemies and find closest
                var state = PlayerState.Instance;
                int kills = state.killedOverall.Count + state.killedThisLife.Count;

                if (kills < _enemyCount || bossBattle)
                {
                    var enemies = FindObjectsOfType <EnemyAI>();
                    var plr     = PlayerController.Instance;
                    if (enemies.Length > 0)
                    {
                        var     smallestDistance = Single.MaxValue;
                        EnemyAI closest          = null;
                        foreach (var enemy in enemies)
                        {
                            var dist = enemy.transform.position - plr.transform.position;
                            if (dist.magnitude < smallestDistance)
                            {
                                smallestDistance = dist.magnitude;
                                closest          = enemy;
                            }
                        }

                        if (closest != null)
                        {
                            var viewportPos = Camera.main.WorldToViewportPoint(closest.transform.position);
                            if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1)
                            {
                                var dir = closest.transform.position - plr.transform.position;

                                var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
                                indicatorArrow.rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                                indicatorArrow.rectTransform.position =
                                    uiCenter.position + dir.normalized * indicatorRadius;
                                indicatorArrow.gameObject.SetActive(true);
                                indicatorArrow.color = enemyIndicator;
                            }
                            else
                            {
                                indicatorArrow.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            indicatorArrow.gameObject.SetActive(false);
                        }
                    }
                    else
                    {
                        var boss        = FindObjectOfType <BossManager>();
                        var viewportPos = Camera.main.WorldToViewportPoint(boss.transform.position);
                        if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1)
                        {
                            var dir = boss.transform.position - plr.transform.position;

                            var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
                            indicatorArrow.rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                            indicatorArrow.rectTransform.position =
                                uiCenter.position + dir.normalized * indicatorRadius;
                            indicatorArrow.gameObject.SetActive(true);
                            indicatorArrow.color = enemyIndicator;
                        }
                        else
                        {
                            indicatorArrow.gameObject.SetActive(false);
                        }
                    }
                }
                else
                {
                    var plr        = PlayerController.Instance;
                    var companions = FindObjectsOfType <Rescue>();
                    var boss       = FindObjectOfType <BossManager>();
                    if (boss == null)
                    {
                        return;
                    }

                    if (companions.Length > 0 && boss.exitDoor.locked)
                    {
                        var    smallestDistance = Single.MaxValue;
                        Rescue closest          = null;
                        foreach (var companion in companions)
                        {
                            var dist = companion.transform.position - plr.transform.position;
                            if (dist.magnitude < smallestDistance)
                            {
                                smallestDistance = dist.magnitude;
                                closest          = companion;
                            }
                        }

                        if (closest != null)
                        {
                            var viewportPos = Camera.main.WorldToViewportPoint(closest.transform.position);
                            if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1)
                            {
                                var dir = closest.transform.position - plr.transform.position;

                                var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
                                indicatorArrow.rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                                indicatorArrow.rectTransform.position =
                                    uiCenter.position + dir.normalized * indicatorRadius;
                                indicatorArrow.gameObject.SetActive(true);
                                indicatorArrow.color = companionIndicator;
                            }
                            else
                            {
                                indicatorArrow.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            indicatorArrow.gameObject.SetActive(false);
                        }
                    }
                    else
                    {
                        if (boss.exitDoor.locked)
                        {
                            var viewportPos = Camera.main.WorldToViewportPoint(boss.entryDoor.transform.position);
                            if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1)
                            {
                                var dir = boss.entryDoor.transform.position - plr.transform.position;

                                var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
                                indicatorArrow.rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                                indicatorArrow.rectTransform.position =
                                    uiCenter.position + dir.normalized * indicatorRadius;
                                indicatorArrow.gameObject.SetActive(true);
                                indicatorArrow.color = enemyIndicator;
                            }
                            else
                            {
                                indicatorArrow.gameObject.SetActive(false);
                            }
                        }
                        else
                        {
                            var viewportPos = Camera.main.WorldToViewportPoint(boss.exitDoor.transform.position);
                            if (viewportPos.x < 0 || viewportPos.x > 1 || viewportPos.y < 0 || viewportPos.y > 1)
                            {
                                var dir = boss.exitDoor.transform.position - plr.transform.position;

                                var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90;
                                indicatorArrow.rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
                                indicatorArrow.rectTransform.position =
                                    uiCenter.position + dir.normalized * indicatorRadius;
                                indicatorArrow.gameObject.SetActive(true);
                                indicatorArrow.color = enemyIndicator;
                            }
                            else
                            {
                                indicatorArrow.gameObject.SetActive(false);
                            }
                        }
                    }
                }
            }
        }