예제 #1
0
        private void Activate(Unit_AI unitBase)
        {
            this.unitBase       = unitBase;
            enemySpineTransform = unitBase.BodyTransform.Spine;

            mainCamera.transform.SetParent(null);
        }
예제 #2
0
        private void Deactivate()
        {
            unitBase            = null;
            enemySpineTransform = null;

            mainCamera.transform.SetParent(cameraLookTransform);
        }
예제 #3
0
        private void SphereCastEnemy()
        {
            if (UnitEnemy != null)
            {
                UnitEnemy.Status.HP.OnCurrentHealthUpdated.RemoveListener(OnEnemyDead);

                UnitEnemy = null;
                OnCatchedEnemyReleased.Invoke();
                return;
            }

            var radius = 10.0f;
            var layer  = LayerMask.GetMask(LayerManager.LAYER_AI);

            var colliders = Physics.OverlapSphere(transform.position, radius, layer);

            if (colliders.Length == 0)
            {
                OnCatchedNothing.Invoke();
                return;
            }

            var mainCamera = GameManager.MainCamera;

            UnitEnemy = null;
            var distance = float.MaxValue;
            var myPos    = transform.position;

            foreach (var c in colliders)
            {
                if (c.transform.IsInsideCameraFrustum(mainCamera) == false)
                {
                    continue;
                }

                var unitEnemy = c.GetComponent <Unit_AI>();
                if (unitEnemy.Status.IsDead == true || unitEnemy.Behaviour == AIBehaviour.Neutral)
                {
                    continue;
                }

                var dist = Vector3.Distance(myPos, c.transform.position);
                if (dist < distance)
                {
                    distance  = dist;
                    UnitEnemy = unitEnemy;
                }
            }

            if (UnitEnemy == null)
            {
                Debug.Log("Unable to catch any enemy!!", Debug.LogType.Error);
                OnCatchedNothing.Invoke();
                return;
            }

            UnitEnemy.Status.HP.OnCurrentHealthUpdated.AddListener(OnEnemyDead);
            OnEnemyCatched.Invoke(UnitEnemy);
        }
예제 #4
0
        public void Deactivate()
        {
            ResetCameraPosition(out Quaternion rot);
            CameraHandler.CameraMovement.SetRotation(rot);
            GameManager.MainCameraTransform.SetParent(CameraHandler.CameraLookPoint);

            ai = null;
        }
예제 #5
0
 private void OnEnemyDead(float enemyCurrentHealthRate)
 {
     if (UnitEnemy.Status.IsDead == true)
     {
         UnitEnemy = null;
         OnCatchedEnemyReleased.Invoke();
     }
 }
예제 #6
0
 private void SetActiveCameraCombatHandler(Unit_AI enemy)
 {
     CameraLookPlayer.enabled       = false;
     CameraMovement.enabled         = false;
     CameraCollisionHandler.enabled = false;
     // -----------------------------------------------------
     CameraCombatHandler.enabled          = true;
     CameraCombatCollisionHandler.enabled = true;
 }
예제 #7
0
        public void ActivateTarget(Unit_AI ai)
        {
            this.ai = ai;

            GameManager.MainCameraTransform.SetParent(null);

            GameManager.MainCameraTransform.position = GetCameraPosition(150, out Vector3 dir);
            GameManager.MainCameraTransform.rotation = Quaternion.LookRotation(dir, Vector3.up);
        }
예제 #8
0
        public void Deactivate()
        {
            ai            = null;
            headTransform = null;
            aiTransform   = null;

            Image.enabled = false;
            gameObject.SetActive(false);

            InputEvent.Instance.Event_Chat.RemoveListener(StartChat);
        }
예제 #9
0
        public async void Activate(Unit_AI ai)
        {
            if (this.ai == ai)
            {
                return;
            }

            this.ai       = ai;
            headTransform = ai.BodyTransform.Head;
            aiTransform   = ai.transform;
            gameObject.SetActive(true);

            await AsyncManager.WaitForFrame(1);

            Image.enabled = true;
            InputEvent.Instance.Event_Chat.AddListener(StartChat);
        }
예제 #10
0
        private void SetActiveCameraChat(Unit_AI ai)
        {
            CameraLookPlayer.enabled       = false;
            CameraMovement.enabled         = false;
            CameraCollisionHandler.enabled = false;
            // =====================================================

            CameraCombatHandler.enabled          = false;
            CameraCombatCollisionHandler.enabled = false;
            // =====================================================

            var type = ai.DialogueHolder.Dialogues.ElementAt(0).Type;

            if (type == ChatType.Player)
            {
                ChatCameraHandler.ActivatePlayer(ai);
            }
            else if (type == ChatType.Target)
            {
                ChatCameraHandler.ActivateTarget(ai);
            }
        }
예제 #11
0
        public void Initialize(Unit_AI enemy, UnityAction <int> deregisterOnDestroyAction)
        {
            if (isInitialized == true)
            {
                Debug.Log("This component was already initialized");
                return;
            }

            this.enemy = enemy;
            this.deregisterOnDestroyAction = deregisterOnDestroyAction;
            enemyInstanceID = enemy.GetInstanceID();
            mainCamera      = GameManager.MainCamera;
            enemyTransform  = enemy.BodyTransform.Head;
            rt           = GetComponent <RectTransform>();
            rt.sizeDelta = new Vector2(202, 18);
            enemy.Status.HP.OnCurrentHealthUpdated.AddListener(SetFillRate);

            frame = UI_Pool.Instance.GetImage(transform, 202, 18, nameof(frame));
            frame.rectTransform.sizeDelta     = rt.sizeDelta;
            frame.rectTransform.localPosition = Vector3.zero;
            frame.sprite  = UI_Battle.Instance.TargetHP.HPST_Sprite;
            frame.type    = Image.Type.Sliced;
            frame.enabled = true;

            fill        = UI_Pool.Instance.GetImage(transform, (int)width, 16, nameof(fill));
            fill.color  = Color.red;
            fill.sprite = UI_Battle.Instance.TargetHP.HPST_Sprite;
            fill.type   = Image.Type.Sliced;
            fill.rectTransform.pivot         = new Vector2(0.0f, 0.5f);
            fill.rectTransform.localPosition = Vector3.zero + new Vector3(1, 0, 0);
            fill.rectTransform.anchorMax     = new Vector2(0.0f, 0.5f);
            fill.rectTransform.anchorMin     = new Vector2(0.0f, 0.5f);
            fill.enabled = true;

            SetFillRate(enemy.Status.HP.CurrentHealthRate);
            isInitialized = true;
        }
예제 #12
0
        public void RegisterEnemy(Unit_AI enemy)
        {
            if (registeredEnemyDic == null)
            {
                registeredEnemyDic = new Dictionary <int, Unit_AI>();
            }

            var instanceID = enemy.GetInstanceID();

            if (registeredEnemyDic.ContainsKey(instanceID) == true)
            {
                return;
            }

            registeredEnemyDic.Add(instanceID, enemy);

            var targetHP = new GameObject($"{nameof(UI_Battle_TargetHP)}-{enemy.name}");

            targetHP.AddComponent <RectTransform>();
            targetHP.transform.SetParent(transform);
            var comp = targetHP.gameObject.AddComponent <UI_Battle_TargetHP_Child>();

            comp.Initialize(enemy, Deregister);
        }
예제 #13
0
 private void Activate(Unit_AI targetUnit)
 {
     TargetUnit       = targetUnit;
     DotImage.enabled = true;
     enabled          = true;
 }
예제 #14
0
 private void OnEnemyCatched(Unit_AI enemy)
 {
     this.enemy = enemy;
     enabled    = true;
 }
예제 #15
0
 private void OnCatchedEnemyReleased()
 {
     enemy   = null;
     enabled = false;
 }
예제 #16
0
 public void Chat(Unit_AI ai)
 {
 }
예제 #17
0
 private void SetMovementTypeToStrafe(Unit_AI enemy)
 {
     SetMovementType(MovementType.Strafe);
 }