Ejemplo n.º 1
0
        SteeringBehavior CreateBehavior(object behaviorType)
        {
            SteeringBehavior newBehavior = (SteeringBehavior)ScriptableObject.CreateInstance((Type)behaviorType);

            newBehavior.hideFlags = HideFlags.HideInHierarchy;

            AssetDatabase.AddObjectToAsset(newBehavior, AssetDatabase.GetAssetPath(target));
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newBehavior));

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            return(newBehavior);
        }
Ejemplo n.º 2
0
        void DrawBehaviorBox(SteeringBehavior behavior, SerializedProperty property, int i, bool canRemove)
        {
            if (!behavior)
            {
                return;
            }
            EditorGUILayout.BeginVertical("BOX");
            EditorGUILayout.BeginHorizontal(behavior.IsActive ? activeStyle : inactiveStyle);
            GUILayout.Space(20);

            SerializedObject   behaviorObject  = new SerializedObject(property.objectReferenceValue);
            SerializedProperty foldoutProperty = behaviorObject.FindProperty("foldout");

            bool foldout = foldoutProperty.boolValue;

#if UNITY_2018
            foldout = EditorGUILayout.Foldout(foldout, behavior.GetType().Name);
#else
            foldout = EditorGUILayout.BeginFoldoutHeaderGroup(foldout, behavior.GetType().Name);
            EditorGUILayout.EndFoldoutHeaderGroup();
#endif
            foldoutProperty.boolValue = foldout;

            behaviorObject.ApplyModifiedProperties();

            GUILayout.FlexibleSpace();
            if (canRemove)
            {
                if (GUILayout.Button("Remove", GUILayout.Width(60)))
                {
                    toRemove = i;
                }
            }

            EditorGUILayout.EndHorizontal();

            if (foldout)
            {
                GUILayout.Space(-20);

                EditorGUILayout.PropertyField(property);
            }


            GUILayout.Space(5);

            EditorGUILayout.EndVertical();
            GUILayout.Space(10);
        }
Ejemplo n.º 3
0
        public static HashSet <Agent> GetFilteredAgents(SurroundingsContainer surroundings, SteeringBehavior behavior)
        {
            if (!behavior.useTagFilter)
            {
                return(surroundings.allAgents);
            }

            _filterCache.Clear();

            foreach (Agent other in surroundings.allAgents)
            {
                for (int i = 0; i < behavior.filterTags.Length; i++)
                {
                    if (other.CompareTag(behavior.filterTags[i]))
                    {
                        _filterCache.Add(other);
                        break;
                    }
                }
            }
            return(_filterCache);
        }
Ejemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SteeringBehavior behavior = property.objectReferenceValue as SteeringBehavior;



            if (property.objectReferenceValue == null)
            {
                return;
            }
            Type concreteType = property.objectReferenceValue.GetType();

            UnityEngine.Object wrapped = property.objectReferenceValue;
            wrapped = (UnityEngine.Object)Convert.ChangeType(wrapped, concreteType);

            SerializedObject serializedObject = new SerializedObject(wrapped);

            SerializedProperty isActiveProp = serializedObject.FindProperty("isActive");

            if (behavior.CanToggleActive)
            {
                EditorGUILayout.PropertyField(isActiveProp);
            }

            if (isActiveProp.boolValue)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(20);
                EditorGUILayout.BeginVertical("BOX");

                EditorGUILayout.PropertyField(serializedObject.FindProperty("weight"));

                if (behavior.CanUseTagFilter)
                {
                    DrawTagFilters(serializedObject);
                }

                var editor = Editor.CreateEditor(behavior);
                editor.DrawDefaultInspectorWithoutScriptField();


                SerializedProperty drawDebugProp      = serializedObject.FindProperty("drawDebug");
                SerializedProperty drawVectorProp     = serializedObject.FindProperty("debugDrawSteering");
                SerializedProperty drawPerceptionProp = serializedObject.FindProperty("debugDrawProperties");

                EditorGUILayout.PropertyField(drawDebugProp);
                if (drawDebugProp.boolValue)
                {
                    EditorGUI.indentLevel++;
                    SerializedProperty color = serializedObject.FindProperty("debugColor");
                    color.colorValue = EditorGUILayout.ColorField(color.colorValue);

                    EditorGUILayout.PropertyField(drawVectorProp);
                    EditorGUILayout.PropertyField(drawPerceptionProp);
                    EditorGUI.indentLevel--;
                    //EditorGUILayout.EndHorizontal();
                }

                GUILayout.Space(5);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
            serializedObject.ApplyModifiedProperties();
        }