예제 #1
0
        /// <summary>
        /// Used internally to iterate through each consideration &
        /// link them to the correct properties.
        /// </summary>
        private void LinkConsiderations()
        {
            if (_agent)
            {
                // Iterate through each consideration
                for (int i = 0; i < _considerations.Count; i++)
                {
                    uaiConsideration c = _considerations[i];

                    // Find the correct property attached to the agent
                    uaiProperty property = _agent.FindProperty(c._propertyName);

                    if (property != null)
                    {
                        c.property = property;
                    }
                    else
                    {
                        // No property matching the consideration's name was found
                        Debug.LogWarning("No attached property with name '" + c._propertyName + "' was found. The consideration will be removed.");
                        _considerations.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
        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);
                }
            };
        }