コード例 #1
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        if (!property.isExpanded)
        {
            return(EditorGUIUtility.singleLineHeight);
        }
        SerializedProperty  values = property.FindPropertyRelative("_values");
        ProbabilityListBase list   = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ProbabilityListBase;

        System.Type listType = list.GetTemplateType();
        return((values.arraySize + 2 + (listType.IsSubclassOf(typeof(Object)) ? 2 : 0)) * _lineHeight);
    }
コード例 #2
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        var height = EditorGUI.GetPropertyHeight(property, label, true);

        if (property.hasVisibleChildren && property.isExpanded)
        {
            var targetObject = SerializedPropertyUtil.GetTargetObject(property);
            if (targetObject != null)
            {
                height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            }
        }
        return(height);
    }
コード例 #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var typeSelector = attribute as ReferenceTypeSelectorAttribute;
        var targetObject = SerializedPropertyUtil.GetTargetObject(property);

        typeSelector.GetSubTypes(property);

        if (targetObject != null && property.hasVisibleChildren)
        {
            ShowFoldout(position, property, label, typeSelector, targetObject);
        }
        else
        {
            ShowInline(position, property, label, typeSelector, targetObject);
        }
    }
コード例 #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ProbabilityListBase list = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ProbabilityListBase;

        System.Type listType = list.GetTemplateType();

        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty values        = property.FindPropertyRelative("_values");
        SerializedProperty priorities    = property.FindPropertyRelative("_priorities");
        SerializedProperty totalPriority = property.FindPropertyRelative("_totalPriority");

        Rect elementRect = new Rect(position);

        elementRect.height = EditorGUIUtility.singleLineHeight;

        property.isExpanded = EditorGUI.Foldout(elementRect, property.isExpanded, new GUIContent(label.text + " (" + values.arraySize + ")", label.image, label.tooltip), true);
        elementRect.y      += _lineHeight;

        if (property.isExpanded)
        {
            int origIndent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 1;
            elementRect           = EditorGUI.IndentedRect(elementRect);
            EditorGUI.indentLevel = origIndent;

            if (listType.IsSubclassOf(typeof(Object)))
            {
                Rect dragDropRect = elementRect;
                dragDropRect.height *= 2.0f;
                EditorGUI.HelpBox(dragDropRect, "Drag & drop here to add items!", MessageType.Info);
                elementRect.y += 2.0f * _lineHeight;

                if (dragDropRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.DragUpdated)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                    }
                    else if (Event.current.type == EventType.DragPerform)
                    {
                        for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
                        {
                            Object obj         = DragAndDrop.objectReferences[i];
                            bool   validInsert = false;
                            if (obj is GameObject)
                            {
                                GameObject go = obj as GameObject;
                                if (listType == typeof(GameObject) || (listType.IsSubclassOf(typeof(Component)) && go.GetComponent(listType) != null))
                                {
                                    validInsert = true;
                                }
                            }
                            else if (obj.GetType().IsAssignableFrom(listType))
                            {
                                validInsert = true;
                            }
                            if (validInsert)
                            {
                                int insert_index = values.arraySize;
                                values.InsertArrayElementAtIndex(insert_index);
                                priorities.InsertArrayElementAtIndex(insert_index);
                                values.GetArrayElementAtIndex(insert_index).objectReferenceValue = obj;
                                priorities.GetArrayElementAtIndex(insert_index).intValue         = 1;
                            }
                        }
                        Event.current.Use();
                    }
                }
            }


            int total = 0;
            for (int i = 0; i < values.arraySize; i++)
            {
                SerializedProperty value    = values.GetArrayElementAtIndex(i);
                SerializedProperty priority = priorities.GetArrayElementAtIndex(i);
                total += priority.intValue;

                Rect objectRect = elementRect;
                objectRect.width = Mathf.Floor(elementRect.width * 0.5f);
                if (listType.IsSubclassOf(typeof(Object)))
                {
                    value.objectReferenceValue = EditorGUI.ObjectField(objectRect, value.objectReferenceValue, listType, true);
                }
                else
                {
                    EditorGUI.PropertyField(objectRect, value, new GUIContent());
                }

                Rect priorityRect = elementRect;
                priorityRect.width = 60.0f;
                priorityRect.x    += objectRect.width;
                priority.intValue  = EditorGUI.IntField(priorityRect, priority.intValue);

                float percentage = totalPriority.intValue > 0 ? (float)priority.intValue / totalPriority.intValue : 0.0f;

                Rect percentageRect = elementRect;
                percentageRect.x    += priorityRect.width + objectRect.width;
                percentageRect.width = 60.0f;
                EditorGUI.LabelField(percentageRect, string.Format("{0:P}", percentage));

                Rect deleteRect = elementRect;
                deleteRect.width = 60.0f;
                deleteRect.x    += elementRect.width - deleteRect.width;
                if (GUI.Button(deleteRect, "Delete"))
                {
                    if (values.GetArrayElementAtIndex(i).propertyType == SerializedPropertyType.ObjectReference)
                    {
                        values.GetArrayElementAtIndex(i).objectReferenceValue = null;
                    }
                    values.DeleteArrayElementAtIndex(i);
                    priorities.DeleteArrayElementAtIndex(i);
                }

                elementRect.y += _lineHeight;
            }

            totalPriority.intValue = total;

            Rect addRect = elementRect;
            addRect.width = 60.0f;
            addRect.x    += elementRect.width - addRect.width;
            if (GUI.Button(addRect, "Add"))
            {
                int insert_index = values.arraySize;
                values.InsertArrayElementAtIndex(insert_index);
                priorities.InsertArrayElementAtIndex(insert_index);
                priorities.GetArrayElementAtIndex(insert_index).intValue = 1;
            }
            elementRect.y += _lineHeight;
        }

        EditorGUI.EndProperty();
    }
コード例 #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            curve = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ResponseCurve ?? new ResponseCurve();
            GUIRect rect = new GUIRect(position);

            isCurveShown = curve.__editorOnlyFoldout__ = EditorGUI.Foldout(rect.GetFieldRect(), curve.__editorOnlyFoldout__, label.text);

            GUIStyle style = new GUIStyle(GUI.skin.box);

            if (!isCurveShown)
            {
                DrawGraph(64, 32);
                GUIContent content = new GUIContent();
                content.text    = curve.DisplayString;
                content.image   = graphTexture;
                style.alignment = TextAnchor.MiddleLeft;
                GUI.Box(rect.GetFieldRect(2), content, style);
                return;
            }

            GUIRect[] splits = rect.SplitHorizontal(0.5f);
            GUIRect   left   = splits[0];
            GUIRect   right  = splits[1];

            DrawGraph(right.GetRect().width, right.GetRect().height);

            GUIContent graphContent = new GUIContent();

            graphContent.image = graphTexture;
            GUI.Box(right.GetRect(), graphContent, style);
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            DrawerUtil.PushIndentLevel(1);
            EditorGUI.BeginChangeCheck();
            {
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("curveType"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("slope"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("exp"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("vShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("hShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("threshold"));
                GUIRect   lineRect      = new GUIRect(left.GetFieldRect());
                GUIRect[] lineRectParts = lineRect.SplitHorizontal(0.5f);
                EditorGUI.PropertyField(lineRectParts[0].GetRect(), property.FindPropertyRelative("invert"));


                if (GUI.Button(lineRectParts[1].GetRect(), "Reset Curve"))
                {
                    property.FindPropertyRelative("curveType").intValue   = (int)ResponseCurveType.Polynomial;
                    property.FindPropertyRelative("slope").floatValue     = 1f;
                    property.FindPropertyRelative("exp").floatValue       = 1f;
                    property.FindPropertyRelative("vShift").floatValue    = 0f;
                    property.FindPropertyRelative("hShift").floatValue    = 0f;
                    property.FindPropertyRelative("threshold").floatValue = 0f;
                    property.FindPropertyRelative("invert").boolValue     = false;
                }
            }
            DrawerUtil.PopIndentLevel();
            EditorGUIUtility.labelWidth = oldWidth;
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }