// Start is called before the first frame update
        void Start()
        {
            if (mySettings)
            {
                alignment  = mySettings.GetBehavior <AlignmentBehavior>();
                cohesion   = mySettings.GetBehavior <CohesionBehavior>();
                separation = mySettings.GetBehavior <SeparationBehavior>();

                if (alignment && alignmentSlider)
                {
                    alignmentSlider.value = (alignment.weight / maxWeight);
                }
                if (cohesion && cohesionSlider)
                {
                    cohesionSlider.value = (cohesion.weight / maxWeight);
                }
                if (separation && separationSlider)
                {
                    separationSlider.value = (separation.weight / maxWeight);
                }
            }
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            if (_containment.objectReferenceValue == null)
            {
                if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target)))
                {
                    _containment.objectReferenceValue = CreateBehavior(typeof(ContainmentBehavior));
                }
            }

            EditorGUILayout.PropertyField(_maxSpeed);
            EditorGUILayout.PropertyField(_maxForce);

            DrawBehaviorBox(targetSettings.Containment, _containment, -1, false);

            for (int i = 0; i < _behaviors.arraySize; i++)
            {
                DrawBehaviorBox(targetSettings.GetBehavior(i), _behaviors.GetArrayElementAtIndex(i), i, true);
            }

            if (toRemove >= 0)
            {
                AssetDatabase.RemoveObjectFromAsset(_behaviors.GetArrayElementAtIndex(toRemove).objectReferenceValue);
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                _behaviors.DeleteArrayElementAtIndex(toRemove);
                _behaviors.DeleteArrayElementAtIndex(toRemove);
                toRemove = -1;
            }


            GUILayout.BeginVertical("BOX");
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add Behavior", GUILayout.Width(130)))
            {
                GenericMenu             menu      = new GenericMenu();
                List <SteeringBehavior> behaviors = targetSettings.Behaviors.ToList();
                foreach (Type type in System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(SteeringBehavior)))
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }
                    if (behaviors.Any(x => x.GetType() == type) || type == typeof(ContainmentBehavior))
                    {
                        menu.AddDisabledItem(new GUIContent(type.Name));
                    }
                    else
                    {
                        menu.AddItem(new GUIContent(type.Name), false, AddBehavior, type);
                    }
                }
                menu.ShowAsContext();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            GUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }