Beispiel #1
0
        private static void DrawProperties()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(5);
            GUILayout.Label("Base Options", UEditorStyles.SectionHeaderLabel);
            GUILayout.Space(5);
            if (properties != null)
            {
                properties.SetAIType((AIProperties.AIType)EditorGUILayout.EnumPopup(ContentProperties.Type, properties.GetAIType()));
                properties.SetName(EditorGUILayout.DelayedTextField(ContentProperties.Name, properties.GetName()));
                if (properties.GetName() == "")
                {
                    properties.SetDefaultName();
                }
                properties.SetModel((GameObject)EditorGUILayout.ObjectField(ContentProperties.Model, properties.GetModel(), typeof(GameObject), true));
                if (properties.GetModel() == null)
                {
                    UEditorHelpBoxMessages.Error("AI model cannot be empty!", "Add AI model.");
                }
                properties.SetController((AnimatorController)EditorGUILayout.ObjectField(ContentProperties.Controller, properties.GetController(), typeof(AnimatorController), true));
                properties.DefaultPreset(EditorGUILayout.Toggle(ContentProperties.DefaultPreset, properties.DefaultPreset()));

                if (properties.DefaultPreset())
                {
                    properties.SetDefaultPreset();
                }

                EditorGUI.BeginDisabledGroup(properties.DefaultPreset());
                LayerMask targetMask = EditorGUILayout.MaskField(ContentProperties.Tagrets, InternalEditorUtility.LayerMaskToConcatenatedLayersMask(properties.GetTargets()), InternalEditorUtility.layers);
                properties.SetTargets(InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(targetMask));
                LayerMask obstacleMask = EditorGUILayout.MaskField(ContentProperties.Obstacles, InternalEditorUtility.LayerMaskToConcatenatedLayersMask(properties.GetObstacles()), InternalEditorUtility.layers);
                properties.SetObstacles(InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(obstacleMask));
                EditorGUI.EndDisabledGroup();

                GUILayout.Space(5);
                UEditor.HorizontalLine();
                GUILayout.Space(5);
                EditorGUI.BeginDisabledGroup(!properties.GetModel());
                if (UEditor.Button("Create", "Right", GUILayout.Width(70)))
                {
                    _AI = CreateAI(properties);
                }
                if (_AI != null && delay.WaitForSeconds())
                {
                    if (UDisplayDialogs.Message("Create Successful", "AI was created on scene!\nSetup AI components before start play.", "Select", "Ok"))
                    {
                        Selection.activeGameObject = _AI;
                    }
                    _AI = null;
                }
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                UEditorHelpBoxMessages.Error("Properties not loaded...", "Try to reload UProject Manager window.", true);
            }
            GUILayout.Space(5);
            GUILayout.EndVertical();
        }
Beispiel #2
0
        private static GameObject CreateAI(AIProperties properties)
        {
            // Instantiate AI object
            GameObject ai = GameObject.Instantiate(properties.GetModel(), Vector3.zero, Quaternion.identity);

            // Set tag and layer
            ai.name = properties.GetName();
            ai.tag  = TNC.AI;
            switch (properties.GetAIType())
            {
            case AIProperties.AIType.AgainstAll:
                ai.layer = LayerMask.NameToLayer(LNC.AI);
                break;

            case AIProperties.AIType.Friendly:
                ai.layer = LayerMask.NameToLayer(LNC.AI_FRIENDLY);
                break;

            case AIProperties.AIType.Enemy:
                ai.layer = LayerMask.NameToLayer(LNC.AI_ENEMY);
                break;
            }

            // Set components
            Animator animator = ai.GetComponent <Animator>();

            if (animator == null)
            {
                animator = ai.AddComponent <Animator>();
            }
            if (properties.GetController() != null)
            {
                animator.runtimeAnimatorController = properties.GetController();
            }

            AIController controller = ai.GetComponent <AIController>();

            if (controller == null)
            {
                controller = ai.AddComponent <AIController>();
            }

            AIHealth health = ai.GetComponent <AIHealth>();

            if (health == null)
            {
                health = ai.AddComponent <AIHealth>();
            }

            AIFieldOfView fieldOfView = ai.GetComponent <AIFieldOfView>();

            if (fieldOfView == null)
            {
                fieldOfView = ai.AddComponent <AIFieldOfView>();
            }

            AIAttackSystem attackSystem = ai.GetComponent <AIAttackSystem>();

            if (attackSystem == null)
            {
                attackSystem = ai.AddComponent <AIAttackSystem>();
            }

            AIReloadSystem reloadSystem = ai.GetComponent <AIReloadSystem>();

            if (reloadSystem == null)
            {
                reloadSystem = ai.AddComponent <AIReloadSystem>();
            }

            AIAnimatorHandler animatorHandler = ai.GetComponent <AIAnimatorHandler>();

            if (animatorHandler == null)
            {
                animatorHandler = ai.AddComponent <AIAnimatorHandler>();
            }

            CharacterRagdollSystem ragdollSystem = ai.GetComponent <CharacterRagdollSystem>();

            if (ragdollSystem == null)
            {
                ragdollSystem = ai.AddComponent <CharacterRagdollSystem>();
            }

            NavMeshAgent navMeshAgent = ai.GetComponent <NavMeshAgent>();

            if (navMeshAgent == null)
            {
                navMeshAgent = ai.AddComponent <NavMeshAgent>();
            }

            CapsuleCollider capsuleCollider = ai.GetComponent <CapsuleCollider>();

            if (capsuleCollider == null)
            {
                capsuleCollider = ai.AddComponent <CapsuleCollider>();
            }

            AudioSource audioSource = ai.GetComponent <AudioSource>();

            if (audioSource == null)
            {
                audioSource = ai.AddComponent <AudioSource>();
            }

            // Set component positions
            UEditorInternal.MoveComponentBottom <Animator>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIController>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIHealth>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIFieldOfView>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAttackSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIReloadSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <AIAnimatorHandler>(ai.transform);
            UEditorInternal.MoveComponentBottom <CharacterRagdollSystem>(ai.transform);
            UEditorInternal.MoveComponentBottom <NavMeshAgent>(ai.transform);
            UEditorInternal.MoveComponentBottom <CapsuleCollider>(ai.transform);
            UEditorInternal.MoveComponentBottom <AudioSource>(ai.transform);

            // Set properties settings
            fieldOfView.SetTargetMask(properties.GetTargets());
            fieldOfView.SetObstacleMask(properties.GetObstacles());

            return(ai);
        }