Ejemplo n.º 1
0
    /// <summary>
    /// 最もenemyControllerから近いEnemyTargetControllerを返す
    /// </summary>
    /// <param name="enemyController"></param>
    /// <returns></returns>
    public EnemyTargetController GetMostNearEnemyTaget(EnemyController enemyController)
    {
        if (enemyController == null)
        {
            return(null);
        }

        EnemyTargetController result = null;
        float tempDistance           = float.MaxValue;

        foreach (EnemyTargetController etc in NrcGameManager.NrcGameStageObserver.GetNowStageController().StageEnemyTargetObserver.EnemyTargetControllerList)
        {
            if (etc == null)
            {
                continue;
            }



            float distance = (etc.transform.position - enemyController.transform.position).sqrMagnitude;
            if (tempDistance > distance)
            {
                tempDistance = distance;
                result       = etc;
            }
        }

        return(result);
    }
Ejemplo n.º 2
0
    public StageEnemyTargetObserver(StageController stageController)
    {
        _stageController = stageController;
        _stageController = NrcGameManager.NrcGameStageObserver.GetNowStageController();

        foreach (EnemyTargetPointController enemyTargetPointController in _stageController.EnemyTargetPointControllerList)
        {
            EnemyTargetModel enemyTargetModel = NrcGameManager.NrcGameDatabaseService.GetEnemyTargetModelById(enemyTargetPointController.Id);

            GameObject enemyTarget = GameObject.Instantiate(enemyTargetModel.Prefab,
                                                            NrcGameManager.NrcGameStageObserver.GetNowStageController().transform);

            EnemyTargetController enemyTargetController = enemyTarget.GetComponent <EnemyTargetController>();
            enemyTargetController.transform.position = enemyTargetPointController.transform.position;
            enemyTargetController.Init(enemyTargetModel);
            enemyTargetController.EnemyTargetDeadBeforeEvent += (etc) =>
            {
                _enemyTargetControllerList.Remove(etc);
                if (_enemyTargetControllerList.Count < 1)
                {
                    NrcGameManager.NrcGameEnemyTargetService.EnemyTargetAllDeadEvent();
                }
            };

            _enemyTargetControllerList.Add(enemyTargetController);
        }
    }
Ejemplo n.º 3
0
    public void Init(EnemyTargetController enemyTargetController)
    {
        _enemyTargetController = enemyTargetController;
        _explosion             = NrcResourceManager.GetGameObject(ResourceDefine.PREFAB_EXPLOSION) as GameObject;
        _bullet = NrcResourceManager.GetGameObject(ResourceDefine.PREFAB_BULLET) as GameObject;

        _enemyTargetController.EnemyTargetDeadBeforeEvent += (etc) =>
        {
            Observable.FromCoroutine(observe => Explodison(_enemyTargetController.transform.position)).Subscribe();
        };
    }
Ejemplo n.º 4
0
    public void Init(EnemyController enemyController)
    {
        _enemyController                 = enemyController;
        _navMeshAgent                    = _enemyController.GetComponent <NavMeshAgent>();
        _navMeshAgent.speed              = 1.5f;
        _explosion                       = NrcResourceManager.GetGameObject(ResourceDefine.PREFAB_EXPLOSION) as GameObject;
        _enemyController.EnemyDeadEvent += (e) =>
        {
            Observable.FromCoroutine(observe => Explodison(_enemyController.transform.position)).Subscribe();
            if (_iDisposable != null)
            {
                _iDisposable.Dispose();
            }
        };

        NrcEventForwarder nrcEventForwarder = enemyController.GetComponent <NrcEventForwarder>();

        nrcEventForwarder.OnTriggerStayEvent += (col) =>
        {
            if (col.gameObject.tag == TagDefine.TAG_ENEMY_TARGET && _iDisposable != null)
            {
                EnemyTargetController enemyTargetController = col.gameObject.GetComponent <EnemyTargetController>();
                enemyTargetController.Damage(1);
            }
        };

        EnemyTargetController etc = NrcGameManager.NrcGameEnemyTargetService.GetMostNearEnemyTaget(_enemyController);

        if (etc != null)
        {
            etc.EnemyTargetDeadAfterEvent += () =>
            {
                if (_enemyController != null)
                {
                    etc = NrcGameManager.NrcGameEnemyTargetService.GetMostNearEnemyTaget(_enemyController);

                    if (etc != null)
                    {
                        _navMeshAgent.SetDestination(etc.transform.position);
                    }
                }
            };

            _navMeshAgent.enabled = true;
            _navMeshAgent.SetDestination(etc.transform.position);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// enemyTargetから一番近いEnemyを返す
    /// </summary>
    /// <param name="enemyTargetController"></param>
    /// <returns></returns>
    public EnemyController GetMostNearEnemy(EnemyTargetController enemyTargetController)
    {
        EnemyController result       = null;
        float           tempDistance = float.MaxValue;

        List <StageEnemySpawnController> stageEnemySpawnControllerList =
            _nrcGameStageService.GetNowStageController().StageEnemySpawnControllerList;

        foreach (StageEnemySpawnController stageEnemySpawnController in stageEnemySpawnControllerList)
        {
            List <EnemyController> enemyControllerList =
                stageEnemySpawnController.StageEnemySpawnObserver.EnemyList;

            foreach (EnemyController enemyController in enemyControllerList)
            {
                //Vector3 initForward = enemyController.transform.position - enemyTargetController.transform.position;
                ////enemyTargetController.transform.LookAt(enemyController.transform);
                //Ray ray = new Ray(enemyTargetController.transform.position, initForward.normalized);
                //RaycastHit hit;
                //Debug.DrawRay(ray.origin, ray.direction * 30.0f, Color.red, 0.0f);
                //if (Physics.Raycast(ray, out hit, 1000.0f))
                //{
                //    //enemyTargetController.transform.LookAt(initForward);
                //    if (hit.collider.tag == "Stage")
                //    {
                //        continue;
                //    }
                //}
                //else
                //{
                //    enemyTargetController.transform.LookAt(initForward);
                //    continue;
                //}


                float distance = (enemyController.transform.position - enemyTargetController.transform.position).sqrMagnitude;
                if (tempDistance > distance)
                {
                    tempDistance = distance;
                    result       = enemyController;
                }
            }
        }

        return(result);
    }
Ejemplo n.º 6
0
    public EnemyTargetHpGaugeObserver(EnemyTargetController enemyTargetController)
    {
        _enemyTargetController = enemyTargetController;
        _hpGaugePrefab         = NrcResourceManager.GetGameObject(ResourceDefine.PREFAB_ENEMY_TARGET_HP_GAUGE) as GameObject;

        _hpGauge = GameObject.Instantiate(_hpGaugePrefab,
                                          NrcGameManager.NrcGameStageObserver.GetNowStageController().transform);

        Slider slider = _hpGauge.transform.Find("HpSlider").GetComponent <Slider>();

        slider.value = (float)_enemyTargetController.Hp / (float)_enemyTargetController.MaxHp;

        _enemyTargetController.EnemyTargetDamageService.EnemyTargetHpChangeEvent += (hp) =>
        {
            slider.value = (float)hp / (float)_enemyTargetController.MaxHp;
            if (hp == 0)
            {
                GameObject.Destroy(_hpGauge);
                _iDisposable.Dispose();
            }
        };
    }
Ejemplo n.º 7
0
 public EnemyTargetDamageService(EnemyTargetController enemyTargetController)
 {
     _enemyTargetController = enemyTargetController;
 }
Ejemplo n.º 8
0
 public EnemyTargetActionObserver(EnemyTargetController enemyTargetController)
 {
     _enemyTargetController      = enemyTargetController;
     _iEnemyTargetActionObserver = EnemyTargetActionCreator.GetInstance(enemyTargetController.EnemyTargetModel.ActionId);
     _iEnemyTargetActionObserver.Init(enemyTargetController);
 }