Esempio n. 1
0
        // ReSharper disable once MemberCanBePrivate.Global
        public static bool DrawAvatarFoldout(SerializedProperty avatar, BoneWrapper[] bones, ref bool showBodyPicker, bool forceDrawing = false)
        {
            if (!forceDrawing)
            {
                if (avatar.objectReferenceValue == null)
                {
                    return(false);
                }
                if (!((Avatar)avatar.objectReferenceValue).isHuman)
                {
                    return(false);
                }
            }

            EditorGUIUtils.DrawSplitter();
            if (EditorGUIUtils.DrawHeaderWithFoldout(bodyLabel, showBodyPicker))
            {
                showBodyPicker = !showBodyPicker;
            }
            if (showBodyPicker)
            {
                using (new EditorGUILayout.VerticalScope("TE NodeBackground"))
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();
                        Rect rect = GUILayoutUtility.GetRect(Silhouettes[bodyView], GUIStyle.none, GUILayout.MaxWidth(Silhouettes[bodyView].image.width));
                        DrawBodyParts(rect, bodyView);
                        bool hasHover = false;
                        if (bones != null)
                        {
                            for (int i = 0; i < bones.Length; i++)
                            {
                                hasHover |= DrawBone(bodyView, i, rect, bones[i], hasHover);
                            }
                        }

                        GUILayout.FlexibleSpace();
                    }

                    Rect lastRect = GUILayoutUtility.GetLastRect();
                    lastRect.x     += 5f;
                    lastRect.width  = 80f;
                    lastRect.yMin   = lastRect.yMax - 69f;
                    lastRect.height = 16f;
                    for (int j = 0; j < toggleStrings.Length; j++)
                    {
                        if (GUI.Toggle(lastRect, bodyView == j, toggleStrings[j], EditorStyles.miniButton))
                        {
                            bodyView = j;
                        }
                        lastRect.y += 16f;
                    }
                }
            }

            EditorGUIUtils.DrawSplitter();
            return(true);
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();

            if (type == null)
            {
                EditorGUILayout.HelpBox("The type associated with this Asset List could not be found.", MessageType.Error);
                EditorGUILayout.PropertyField(typeString);
                serializedObject.ApplyModifiedProperties();
                return;
            }

            using (new EditorGUI.DisabledScope(typeIsAsset))
            {
                //Force assets to only display as InAssets.
                if (typeIsAsset && assetType.intValue != 0)
                {
                    assetType.intValue = 0;
                }
                EditorGUILayout.PropertyField(assetType);
            }

            using (var cCS = new EditorGUI.ChangeCheckScope())
            {
                referenceObject = EditorGUILayout.ObjectField(referenceObjectLabel, referenceObject, type, true, singleHeight);
                if (cCS.changed)
                {
                    if (referenceObject != null)
                    {
                        CreatePropertyDropdown();
                    }
                }
            }

            if (EditorGUIUtils.DrawHeaderWithFoldout(preferencesLabel, missingPropertyDisplay.isExpanded, headerXOffset: -16f))
            {
                missingPropertyDisplay.isExpanded = !missingPropertyDisplay.isExpanded;
            }
            if (missingPropertyDisplay.isExpanded)
            {
                EditorGUILayout.PropertyField(missingPropertyDisplay);
                EditorGUILayout.PropertyField(additionalColumns);
            }
            EditorGUIUtils.DrawSplitter();

            GUILayout.Space(8);

            using (new EditorGUIUtils.ContainerScope(columnsLabel, -2))
                using (new EditorGUIUtils.OutlineScope(false, false))
                {
                    //Icon Header
                    GUILayout.Label(iconLabel, EditorGUIUtils.CenteredMiniLabel);

                    if (typeIsTextureOrSprite)
                    {
                        EditorGUILayout.HelpBox("Type inherits from Texture or Sprite. Icon is automated.", MessageType.Info);
                    }
                    else
                    {
                        //Icon property path
                        if (!string.IsNullOrEmpty(iconPropertyPath.stringValue))
                        {
                            EditorGUILayout.PropertyField(iconPropertyPath, GUIContent.none);
                        }
                        if (ValidateReferenceObjectWithHelpWarning(referenceObject))
                        {
                            //Icon property button.
                            Rect rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                            rect.height = EditorGUIUtility.singleLineHeight;                     //this is required to fix issues with the Layout stage
                            rect.xMin  += EditorGUI.indentLevel * 15;
                            if (GUI.Button(rect, findIconLabel))
                            {
                                CreateIconPropertyDropdown();
                                iconPropertyDropdown?.Show(rect);
                            }

                            bool isArray = iconIsArray.boolValue;
                            if (isArray)
                            {
                                float yBefore = rect.yMax;
                                ArrayDataDrawer.OnGUI(ref rect, iconPropertyPath, iconArrayPropertyInformation, referenceObject, typeStrings, rect.x - 2);
                                GUILayoutUtility.GetRect(0, rect.yMax - yBefore);
                            }
                        }
                    }

                    GUILayout.Space(6);
                    EditorGUIUtils.DrawSplitter(alignXMinToZero: false);
                    GUILayout.Space(4);
                    GUILayout.Label(propertyLabel, EditorGUIUtils.CenteredMiniLabel);
                    using (new EditorGUI.DisabledScope(true))
                        EditorGUILayout.TextField(titleLabel, "Name");

                    EditorGUILayout.PropertyField(nameDisplay);
                }

            reorderableList.DoLayoutList();

            using (new EditorGUIUtils.OutlineScope())
            {
                GUILayout.Label(searchlabel, EditorStyles.boldLabel);
                if (ValidateReferenceObjectWithHelpWarning(referenceObject))
                {
                    Rect rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                    if (GUI.Button(rect, addLabel))
                    {
                        if (propertyDropdown == null)
                        {
                            CreatePropertyDropdown();
                        }
                        propertyDropdown.Show(rect);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!Initialise(property))
            {
                return;
            }

            Rect originalPosition = position;

            position.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.PropertyScope(position, GUIContent.none, property))
            {
                if (EditorGUIUtils.DrawHeaderWithFoldout(position, label, property.isExpanded, noBoldOrIndent: true))
                {
                    property.isExpanded = !property.isExpanded;
                }
            }

            if (!property.isExpanded)
            {
                return;
            }

            originalPosition.yMin  = position.yMax;
            originalPosition.xMin += 10;
            EditorGUIUtils.DrawOutline(originalPosition, 1);

            position.xMin += 15;             //Indent
            position.xMax -= 4;
            position.y     = position.yMax + EditorGUIUtility.standardVerticalSpacing * 2;

            SerializedProperty values = property.FindPropertyRelative("values");

            values.arraySize = enumNames.Length;
            float contentX     = position.x + EditorGUIUtility.labelWidth;
            float contentWidth = position.width - EditorGUIUtility.labelWidth;

            for (int i = hidesFirstEnum ? 1 : 0; i < enumNames.Length; i++)
            {
                SerializedProperty value = values.GetArrayElementAtIndex(i);
                Rect labelRect           = new Rect(position.x, position.y, EditorGUIUtility.labelWidth - 4, position.height);
                Rect contentRect         = new Rect(contentX, position.y, contentWidth, position.height);
                if (multiLine)
                {
                    Rect r = new Rect(position.x - 5, contentRect.y - 2, position.width + 8, contentRect.height + 2);
                    EditorGUI.DrawRect(r, EditorGUIUtils.HeaderColor);

                    labelRect.xMin += 12;

                    using (new EditorGUI.PropertyScope(r, GUIContent.none, value))
                    {
                        GUI.enabled = false;
                        EditorGUI.Popup(labelRect, i, enumNames);
                        GUI.enabled = true;
                    }

                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    //Foldout
                    value.isExpanded = EditorGUI.Foldout(new Rect(r.x + 15, r.y, r.width, r.height), value.isExpanded, GUIContent.none, true);

                    contentRect.y = labelRect.yMax + EditorGUIUtility.standardVerticalSpacing;
                    if (!value.isExpanded)
                    {
                        EditorGUI.DrawRect(new Rect(r.x, labelRect.yMax, r.width, 1), EditorGUIUtils.SplitterColor);
                        position.y = contentRect.y;
                        continue;
                    }

                    SerializedProperty end = value.GetEndProperty();
                    int  index             = 0;
                    bool enterChildren     = true;
                    while (value.NextVisible(enterChildren) && !SerializedProperty.EqualContents(value, end))
                    {
                        float height = propertyHeights[index++];
                        contentRect.height = height;
                        using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        {
                            float labelRectX = labelRect.x + 15;
                            GUI.Label(new Rect(labelRectX, contentRect.y, contentRect.x - labelRectX - 2, contentRect.height), value.displayName);
                            EditorGUI.PropertyField(contentRect, value, GUIContent.none, false);
                        }

                        contentRect.y += height + EditorGUIUtility.standardVerticalSpacing;
                        enterChildren  = false;
                    }
                }
                else
                {
                    GUI.enabled = false;
                    EditorGUI.Popup(labelRect, i, enumNames);
                    GUI.enabled = true;
                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    Color lastColor = GUI.color;
                    if (value.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        if (value.objectReferenceValue == null)
                        {
                            GUI.color *= new Color(1f, 0.46f, 0.51f);
                        }
                    }

                    using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        EditorGUI.PropertyField(contentRect, value, GUIContent.none);
                    contentRect.y += propertyHeights[0] + EditorGUIUtility.standardVerticalSpacing;
                    GUI.color      = lastColor;
                }

                position.y = contentRect.yMin;
            }
        }
Esempio n. 4
0
        public static void OnGUI(
            ref Rect rect,
            SerializedProperty propertyPath,
            SerializedProperty arrayProperty,
            Object referenceObject,
            HashSet <string> typeStrings,
            float backgroundXMin,
            float headerXOffset = 0
            )
        {
            rect.NextGUIRect();
            if (EditorGUIUtils.DrawHeaderWithFoldout(
                    rect,
                    new GUIContent("Array Property"),
                    propertyPath.isExpanded,
                    backgroundXMin: backgroundXMin,
                    headerXOffset: headerXOffset
                    ))
            {
                propertyPath.isExpanded = !propertyPath.isExpanded;
            }

            if (!propertyPath.isExpanded)
            {
                return;
            }

            SerializedProperty indexing = arrayProperty.FindPropertyRelative("ArrayIndexing");

            rect.NextGUIRect();
            EditorGUI.PropertyField(rect, indexing);

            if (!AssetListConfigurationInspector.ValidateReferenceObjectWithHelpWarningRect(referenceObject, ref rect))
            {
                return;
            }

            switch ((ArrayIndexing)indexing.intValue)
            {
            case ArrayIndexing.First:
                DrawDrawingProperty(ref rect);
                break;

            case ArrayIndexing.ByKey:
                //The property to look for as a key. This is associated with the query.
                SerializedProperty key = arrayProperty.FindPropertyRelative("ArrayPropertyKey");
                bool hasKey            = !string.IsNullOrEmpty(key.stringValue);
                rect.NextGUIRect();
                rect.y += EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.LabelField(rect, hasKey ? keyAndQueryLabel : keyLabel, EditorGUIUtils.CenteredBoldLabel);

                rect.NextGUIRect();
                using (new EditorGUI.DisabledScope(true))
                    EditorGUI.PropertyField(rect, key, GUIContent.none);
                rect.NextGUIRect();
                if (GUI.Button(rect.GetIndentedRect(), hasKey ? modifyArrayKeyLabel : addArrayKeyLabel))
                {
                    //retrieves properties under the first array index for the dropdown
                    DisplayArrayKeyPropertyDropdown(rect, $"{propertyPath.stringValue}.Array.data[0]", arrayProperty, referenceObject);
                }

                //The query into the array. This is associated with the array property key.
                if (!string.IsNullOrEmpty(key.stringValue))
                {
                    rect.NextGUIRect();
                    SerializedProperty arrayQuery = arrayProperty.FindPropertyRelative("ArrayQuery");
                    EditorGUI.PropertyField(rect, arrayQuery, queryLabel);

                    //The property to draw if the query has passed.
                    if (!string.IsNullOrEmpty(arrayQuery.stringValue))
                    {
                        DrawDrawingProperty(ref rect);
                    }
                }

                break;

            case ArrayIndexing.ByIndex:
                rect.NextGUIRect();
                EditorGUI.PropertyField(rect, arrayProperty.FindPropertyRelative("ArrayIndex"));
                DrawDrawingProperty(ref rect);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            void DrawDrawingProperty(ref Rect r)
            {
                r.NextGUIRect();
                r.y += EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.LabelField(r, "Property", EditorGUIUtils.CenteredBoldLabel);
                r.NextGUIRect();
                SerializedProperty arrayPropertyPath = arrayProperty.FindPropertyRelative("ArrayPropertyPath");

                using (new EditorGUI.DisabledScope(true))
                    EditorGUI.PropertyField(r, arrayPropertyPath);
                r.NextGUIRect();
                if (GUI.Button(r.GetIndentedRect(), string.IsNullOrEmpty(arrayPropertyPath.stringValue) ? addDrawingPropertyLabel : modifyDrawingPropertyLabel))
                {
                    DisplayArrayDrawingPropertyDropdown(r, $"{propertyPath.stringValue}.Array.data[0]", arrayProperty, referenceObject, typeStrings);
                }
            }
        }