示例#1
0
    void Start()
    {
        m_EnemyManager = FindObjectOfType <EnemyManager>();
        DebugUtility.HandleErrorIfNullFindObject <EnemyManager, EnemyController>(m_EnemyManager, this);

        m_ActorsManager = FindObjectOfType <ActorsManager>();
        DebugUtility.HandleErrorIfNullFindObject <ActorsManager, EnemyController>(m_ActorsManager, this);

        m_EnemyManager.RegisterEnemy(this);

        m_Health = GetComponent <Health>();
        DebugUtility.HandleErrorIfNullGetComponent <Health, EnemyController>(m_Health, this, gameObject);

        m_Actor = GetComponent <Actor>();
        DebugUtility.HandleErrorIfNullGetComponent <Actor, EnemyController>(m_Actor, this, gameObject);

        m_NavMeshAgent  = GetComponent <NavMeshAgent>();
        m_SelfColliders = GetComponentsInChildren <Collider>();

        m_GameFlowManager = FindObjectOfType <GameFlowManager>();
        DebugUtility.HandleErrorIfNullFindObject <GameFlowManager, EnemyController>(m_GameFlowManager, this);

        // Subscribe to damage & death actions
        m_Health.onDie     += OnDie;
        m_Health.onDamaged += OnDamaged;

        weapon.owner = gameObject;

        foreach (var renderer in GetComponentsInChildren <Renderer>(true))
        {
            for (int i = 0; i < renderer.sharedMaterials.Length; i++)
            {
                if (renderer.sharedMaterials[i] == eyeColorMaterial)
                {
                    m_EyeRendererData = new RendererIndexData(renderer, i);
                }

                if (renderer.sharedMaterials[i] == bodyMaterial)
                {
                    m_BodyRenderers.Add(new RendererIndexData(renderer, i));
                }
            }
        }

        m_EyeColorMaterialPropertyBlock  = new MaterialPropertyBlock();
        m_BodyFlashMaterialPropertyBlock = new MaterialPropertyBlock();

        m_EyeColorMaterialPropertyBlock.SetColor("_EmissionColor", defaultEyeColor);
        m_EyeRendererData.renderer.SetPropertyBlock(m_EyeColorMaterialPropertyBlock, m_EyeRendererData.materialIndex);
    }
示例#2
0
    void Start()
    {
        m_EnemyManager = FindObjectOfType <EnemyManager>();
        DebugUtility.HandleErrorIfNullFindObject <EnemyManager, EnemyController>(m_EnemyManager, this);

        m_ActorsManager = FindObjectOfType <ActorsManager>();
        DebugUtility.HandleErrorIfNullFindObject <ActorsManager, EnemyController>(m_ActorsManager, this);

        m_EnemyManager.RegisterEnemy(this);

        m_Health = GetComponent <Health>();
        DebugUtility.HandleErrorIfNullGetComponent <Health, EnemyController>(m_Health, this, gameObject);

        m_Actor = GetComponent <Actor>();
        DebugUtility.HandleErrorIfNullGetComponent <Actor, EnemyController>(m_Actor, this, gameObject);

        m_NavMeshAgent  = GetComponent <NavMeshAgent>();
        m_SelfColliders = GetComponentsInChildren <Collider>();

        m_GameFlowManager = FindObjectOfType <GameFlowManager>();
        DebugUtility.HandleErrorIfNullFindObject <GameFlowManager, EnemyController>(m_GameFlowManager, this);

        // Subscribe to damage & death actions
        m_Health.onDie     += OnDie;
        m_Health.onDamaged += OnDamaged;

        // Find and initialize all weapons
        FindAndInitializeAllWeapons();
        var weapon = GetCurrentWeapon();

        weapon.ShowWeapon(true);

        var detectionModules = GetComponentsInChildren <DetectionModule>();

        DebugUtility.HandleErrorIfNoComponentFound <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        DebugUtility.HandleWarningIfDuplicateObjects <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        // Initialize detection module
        m_DetectionModule = detectionModules[0];
        m_DetectionModule.onDetectedTarget += OnDetectedTarget;
        m_DetectionModule.onLostTarget     += OnLostTarget;
        onAttack += m_DetectionModule.OnAttack;

        var navigationModules = GetComponentsInChildren <NavigationModule>();

        DebugUtility.HandleWarningIfDuplicateObjects <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        // Override navmesh agent data
        if (navigationModules.Length > 0)
        {
            m_NavigationModule          = navigationModules[0];
            m_NavMeshAgent.speed        = m_NavigationModule.moveSpeed;
            m_NavMeshAgent.angularSpeed = m_NavigationModule.angularSpeed;
            m_NavMeshAgent.acceleration = m_NavigationModule.acceleration;
        }

        foreach (var renderer in GetComponentsInChildren <Renderer>(true))
        {
            for (int i = 0; i < renderer.sharedMaterials.Length; i++)
            {
                if (renderer.sharedMaterials[i] == eyeColorMaterial)
                {
                    m_EyeRendererData = new RendererIndexData(renderer, i);
                }

                if (renderer.sharedMaterials[i] == bodyMaterial)
                {
                    m_BodyRenderers.Add(new RendererIndexData(renderer, i));
                }
            }
        }

        m_BodyFlashMaterialPropertyBlock = new MaterialPropertyBlock();

        // Check if we have an eye renderer for this enemy
        if (m_EyeRendererData.renderer != null)
        {
            m_EyeColorMaterialPropertyBlock = new MaterialPropertyBlock();
            m_EyeColorMaterialPropertyBlock.SetColor("_EmissionColor", defaultEyeColor);
            m_EyeRendererData.renderer.SetPropertyBlock(m_EyeColorMaterialPropertyBlock, m_EyeRendererData.materialIndex);
        }
    }
示例#3
0
    void Start()
    {
        m_EnemyManager = FindObjectOfType <EnemyManager>();
        DebugUtility.HandleErrorIfNullFindObject <EnemyManager, EnemyController>(m_EnemyManager, this);

        m_ActorsManager = FindObjectOfType <ActorsManager>();
        DebugUtility.HandleErrorIfNullFindObject <ActorsManager, EnemyController>(m_ActorsManager, this);

        m_EnemyManager.RegisterEnemy(this);

        m_Health = GetComponent <Health>();
        DebugUtility.HandleErrorIfNullGetComponent <Health, EnemyController>(m_Health, this, gameObject);

        m_Actor = GetComponent <Actor>();
        DebugUtility.HandleErrorIfNullGetComponent <Actor, EnemyController>(m_Actor, this, gameObject);

        m_NavMeshAgent  = GetComponent <NavMeshAgent>();
        m_SelfColliders = GetComponentsInChildren <Collider>();

        m_GameFlowManager = FindObjectOfType <GameFlowManager>();
        DebugUtility.HandleErrorIfNullFindObject <GameFlowManager, EnemyController>(m_GameFlowManager, this);

        //ダメージと死のアクションをサブスクライブします
        m_Health.onDie     += OnDie;
        m_Health.onDamaged += OnDamaged;

        //すべての武器を見つけて初期化します
        FindAndInitializeAllWeapons();
        var weapon = GetCurrentWeapon();

        weapon.ShowWeapon(true);

        var detectionModules = GetComponentsInChildren <DetectionModule>();

        DebugUtility.HandleErrorIfNoComponentFound <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        DebugUtility.HandleWarningIfDuplicateObjects <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        //検出モジュールを初期化します
        m_DetectionModule = detectionModules[0];
        m_DetectionModule.onDetectedTarget += OnDetectedTarget;
        m_DetectionModule.onLostTarget     += OnLostTarget;
        onAttack += m_DetectionModule.OnAttack;

        var navigationModules = GetComponentsInChildren <NavigationModule>();

        DebugUtility.HandleWarningIfDuplicateObjects <DetectionModule, EnemyController>(detectionModules.Length, this, gameObject);
        // navmeshエージェントのデータを上書きします
        if (navigationModules.Length > 0)
        {
            m_NavigationModule          = navigationModules[0];
            m_NavMeshAgent.speed        = m_NavigationModule.moveSpeed;
            m_NavMeshAgent.angularSpeed = m_NavigationModule.angularSpeed;
            m_NavMeshAgent.acceleration = m_NavigationModule.acceleration;
        }

        foreach (var renderer in GetComponentsInChildren <Renderer>(true))
        {
            for (int i = 0; i < renderer.sharedMaterials.Length; i++)
            {
                if (renderer.sharedMaterials[i] == eyeColorMaterial)
                {
                    m_EyeRendererData = new RendererIndexData(renderer, i);
                }

                if (renderer.sharedMaterials[i] == bodyMaterial)
                {
                    m_BodyRenderers.Add(new RendererIndexData(renderer, i));
                }
            }
        }

        m_BodyFlashMaterialPropertyBlock = new MaterialPropertyBlock();

        //この敵のアイレンダラーがあるかどうかを確認します
        if (m_EyeRendererData.renderer != null)
        {
            m_EyeColorMaterialPropertyBlock = new MaterialPropertyBlock();
            m_EyeColorMaterialPropertyBlock.SetColor("_EmissionColor", defaultEyeColor);
            m_EyeRendererData.renderer.SetPropertyBlock(m_EyeColorMaterialPropertyBlock, m_EyeRendererData.materialIndex);
        }
    }