Exemple #1
0
        public static void DrawPropertyDrawer(Rect rect, GUIContent label, Type type, SerializedProperty property, GUIContent errorLabel)
        {
            if (SOArchitecture_EditorUtility.HasPropertyDrawer(type) || typeof(Object).IsAssignableFrom(type) || type.IsEnum)
            {
                //Unity doesn't like it when you have scene objects on assets,
                //so we do some magic to display it anyway
                if (typeof(Object).IsAssignableFrom(type) &&
                    !EditorUtility.IsPersistent(property.objectReferenceValue) &&
                    property.objectReferenceValue != null)
                {
                    using (new EditorGUI.DisabledGroupScope(true))
                    {
                        EditorGUI.ObjectField(rect, label, property.objectReferenceValue, type, false);
                    }
                }
                else if (type.IsAssignableFrom(typeof(Quaternion)))
                {
                    Vector4 displayValue = property.quaternionValue.ToVector4();

                    property.quaternionValue = EditorGUI.Vector4Field(rect, label, displayValue).ToQuaternion();
                }
                else if (type.IsAssignableFrom(typeof(Vector4)))
                {
                    property.vector4Value = EditorGUI.Vector4Field(rect, label, property.vector4Value);
                }
                else
                {
                    EditorGUI.PropertyField(rect, property, label);
                }
            }
            else
            {
                EditorGUI.LabelField(rect, errorLabel);
            }
        }
        public static void DrawPropertyDrawerLayout(SerializedProperty property, Type type, bool drawLabel = true)
        {
            if (property == null)
            {
                Debug.LogError(NullPropertyText);
                return;
            }

            using (var scope = new EditorGUI.ChangeCheckScope())
            {
                if (SOArchitecture_EditorUtility.HasPropertyDrawer(type))
                {
                    if (drawLabel)
                    {
                        EditorGUILayout.PropertyField(property);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(property, GUIContent.none);
                    }
                }
                else
                {
                    PropertyDrawIteratorLayout iter = new PropertyDrawIteratorLayout(property.Copy(), drawLabel);

                    DrawPropertyDrawerInternal(iter);
                }

                if (scope.changed)
                {
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }
            }
        }
        public static float GetHeight(SerializedProperty property, Type type)
        {
            if (SOArchitecture_EditorUtility.HasPropertyDrawer(type))
            {
                return(EditorGUI.GetPropertyHeight(property));
            }
            else
            {
                property = property.Copy();

                int elements = 0;

                PropertyIterator iter = new PropertyIterator(property);
                do
                {
                    ++elements;
                }while (iter.Next());

                iter.End();

                float spacing        = (elements - 1) * EditorGUIUtility.standardVerticalSpacing;
                float elementHeights = elements * EditorGUIUtility.singleLineHeight;

                return(spacing + elementHeights);
            }
        }
Exemple #4
0
        public static void DrawPropertyDrawerLayout(SerializedProperty property, Type type, bool drawLabel = true)
        {
            if (property == null)
            {
                Debug.LogError(NullPropertyText);
                return;
            }

            if (SOArchitecture_EditorUtility.HasPropertyDrawer(type))
            {
                if (drawLabel)
                {
                    EditorGUILayout.PropertyField(property);
                }
                else
                {
                    EditorGUILayout.PropertyField(property, GUIContent.none);
                }
            }
            else
            {
                PropertyDrawIteratorLayout iter = new PropertyDrawIteratorLayout(property.Copy(), drawLabel);

                DrawPropertyDrawerInternal(iter);
            }
        }