private void AddNewProperty(Rect rect, ReorderableList r)
        {
            // Get the property list being drawn
            uaiAgent           agent        = target as uaiAgent;
            List <uaiProperty> propertyList = agent.properties;

            if (propertyList != null)
            {
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Bool"), false,
                             () =>
                {
                    propertyList.Add(new uaiProperty(true));
                }
                             );

                menu.AddItem(new GUIContent("Int"), false,
                             () =>
                {
                    propertyList.Add(new uaiProperty(1));
                }
                             );

                menu.AddItem(new GUIContent("Float"), false,
                             () =>
                {
                    propertyList.Add(new uaiProperty(0.0f));
                }
                             );

                menu.ShowAsContext();
            }
        }
        private void OnEnable()
        {
            // Create a new reorderable list for properties in the inspector
            properties = new ReorderableList(serializedObject,
                                             serializedObject.FindProperty("_properties"),
                                             true, true, true, true);

            singleLineHeight        = EditorGUIUtility.singleLineHeight;
            singleLineHeightDoubled = singleLineHeight + singleLineHeight;

            // Lambda function for drawing header. This simply uses a label field to write Considerations as the list header
            properties.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Properties"); };

            // Allow each element enough space for five lines, plus some padding
            properties.elementHeight = singleLineHeightDoubled + singleLineHeightDoubled + singleLineHeightDoubled + 18;

            properties.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                SerializedProperty element = properties.serializedProperty.GetArrayElementAtIndex(index);
                uaiAgent           agent   = target as uaiAgent;

                lineOneY   = rect.y + singleLineHeight + 3;
                lineTwoY   = lineOneY + singleLineHeight + 3;
                lineThreeY = lineTwoY + singleLineHeight + 3;
                lineFourY  = lineThreeY + singleLineHeight + 3;

                if (agent != null)
                {
                    uaiProperty currentProperty = agent.properties[index];

                    if (currentProperty.isBool)
                    {
                        DrawBoolProperty(rect, element);
                    }
                    else if (currentProperty.isFloat)
                    {
                        DrawFloatProperty(rect, element);
                    }
                    else if (currentProperty.isInt)
                    {
                        DrawIntProperty(rect, element);
                    }
                }
            };

            // Add delegate for the drop-down 'add element' button
            properties.onAddDropdownCallback += AddNewProperty;

            properties.onRemoveCallback = (ReorderableList list) =>
            {
                if (EditorUtility.DisplayDialog("Warning!",
                                                "Are you sure you want to delete this property from the agent?", "Yes", "No"))
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };
        }
示例#3
0
        void Start()
        {
            // Get a reference to the agent component
            _agent = GetComponentInParent <uaiAgent>();

            // Remove this behaviour if there is no agent tied to the gameobject
            if (!_agent)
            {
                Debug.LogError("No Agent script was found on this object or any parent objects. The behaviour script will be deleted.");
                Destroy(this);
            }

            // Add this behaviour to the agent
            _agent.AddBehaviour(this);

            // Link all considerations to their correct properties
            LinkConsiderations();
        }