public RuntimeSerializedProperty GetFixedBufferElementAtIndex(int index)
        {
            RuntimeSerializedProperty property = Copy();
            RuntimeSerializedProperty result   = null;

            if (index >= 0 && index < property.FixedBufferSize)
            {
                int i = 0;
                if (property.NextVisible(true))
                {
                    property.NextVisible(false);
                    do
                    {
                        if (i == index)
                        {
                            result = property;
                            break;
                        }
                        i++;
                    } while (property.NextVisible(false));
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
예제 #2
0
        private void DrawPropertySortableArray(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            // Try to get the sortable list this property belongs to
            RuntimeReorderableListData listData = null;

            if (listDataDict.Count > 0)
            {
                listData = listDataDict.Find(data => property.PropertyPath.StartsWith(data.Parent));
            }

            UnityEditor.Editor scriptableEditor;
            bool isScriptableEditor = editableDict.TryGetValue(property.PropertyPath, out scriptableEditor);

            // Has ReorderableList and Try to show the list
            if (listData != null && listData.DoProperty(position, property))
            {
            }
            // Else try to draw ScriptableObject editor
            else if (isScriptableEditor)
            {
                bool hasHeader = property.HasAttribute <HeaderAttribute>();
                bool hasSpace  = property.HasAttribute <SpaceAttribute>();

                hasSpace |= hasHeader;

                // Reference type is not supported!
            }
            else
            {
                RuntimeEasyGUI.PropertyField(position, property, label, property.IsExpanded, null);
            }
        }
예제 #3
0
        public static void RevertPrefabPropertyOverride(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;
            SerializedProperty        serializedProperty        = runtimeSerializedProperty.RuntimeSerializedObject.ParentProperty as SerializedProperty;

            if (serializedProperty == null)
            {
                Debug.LogError("Revert Value to Prefab is not supported on Nested Runtime Serialized Property!");
                return;
            }
            int index;
            var parentProperty = serializedProperty.GetBelongArrayAndIndex(out index);

            if (index >= 0)
            {
#if UNITY_2018_2_OR_NEWER
                Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(parentProperty.serializedObject.targetObject);
#else
                Object prefab = PrefabUtility.GetPrefabParent(parentProperty.serializedObject.targetObject);
#endif
                SerializedObject   serializedObject = new SerializedObject(prefab);
                SerializedProperty prop             = serializedObject.FindProperty(parentProperty.propertyPath);

                parentProperty.arraySize = prop.arraySize;
                for (int i = 0; i < parentProperty.arraySize; i++)
                {
                    var obj1 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(parentProperty.GetArrayElementAtIndex(i));
                    var obj2 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop.GetArrayElementAtIndex(i), RuntimeObject.FromJson(prop.GetArrayElementAtIndex(i).stringValue));
                    obj1.Target = obj2.Target;
                    obj1.ForceReloadProperties();
                }

                EditorUtilityHelper.ForceReloadInspectors();
            }
        }
        public static RuntimeSerializedObject GetRuntimeSerializedObject(RuntimeSerializedProperty runtimeSerializedProperty, object target)
        {
            var runtimeSerializedObject = GetRuntimeSerializedObject(runtimeSerializedProperty, target, GetHashCode(runtimeSerializedProperty, target));

            runtimeSerializedObject.SerializedObject = runtimeSerializedProperty.RuntimeSerializedObject.SerializedObject;
            return(runtimeSerializedObject);
        }
예제 #5
0
 private static void DoPropertyFieldKeyboardHandling(RuntimeSerializedProperty property)
 {
     // Delete & Duplicate commands
     if (Event.current.type == EventType.ExecuteCommand || Event.current.type == EventType.ValidateCommand)
     {
         if (GUIUtility.keyboardControl == EditorGUIUtilityHelper.s_LastControlID && (Event.current.commandName == EventCommandNamesHelper.Delete || Event.current.commandName == EventCommandNamesHelper.SoftDelete))
         {
             if (Event.current.type == EventType.ExecuteCommand)
             {
                 // Wait with deleting the property until the property stack is empty. See EndProperty.
                 s_PendingPropertyDelete = property.Copy();
             }
             Event.current.Use();
         }
         if (GUIUtility.keyboardControl == EditorGUIUtilityHelper.s_LastControlID && Event.current.commandName == EventCommandNamesHelper.Duplicate)
         {
             if (Event.current.type == EventType.ExecuteCommand)
             {
                 property.DuplicateCommand();
             }
             Event.current.Use();
         }
     }
     s_PendingPropertyKeyboardHandling = null;
 }
예제 #6
0
        public static void DeleteArrayElement(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;

            runtimeSerializedProperty.DeleteCommand();
            EditorUtilityHelper.ForceReloadInspectors();
        }
        public RuntimeSerializedProperty FindPropertyRelative(string relativePropertyPath)
        {
            RuntimeSerializedProperty property = null;

            if (!string.IsNullOrEmpty(relativePropertyPath))
            {
                string[] paths = relativePropertyPath.Split(StopChar);
                if (paths.Length > 0 && nativeProperty.Properties != null)
                {
                    foreach (var child in nativeProperty.Properties)
                    {
                        if (child.Name == paths[0])
                        {
                            property = new RuntimeSerializedProperty(child);
                            if (paths.Length == 1)
                            {
                                return(property);
                            }
                            else
                            {
                                int    startIndex = paths[0].Length + 1;
                                string path       = relativePropertyPath.Substring(startIndex, relativePropertyPath.Length - startIndex);
                                property = property.FindPropertyRelative(path);
                                if (property != null)
                                {
                                    return(property);
                                }
                            }
                        }
                    }
                }
            }
            return(property);
        }
 public RuntimePropertyGUIData(RuntimeSerializedProperty property, Rect totalPosition, bool wasBoldDefaultFont, bool wasEnabled, Color color)
 {
     Property           = property;
     TotalPosition      = totalPosition;
     WasBoldDefaultFont = wasBoldDefaultFont;
     WasEnabled         = wasEnabled;
     Color = color;
 }
예제 #9
0
        private string DoHeader(RuntimeSerializedProperty property, Rect position, string displayName)
        {
            displayName = string.IsNullOrEmpty(displayName) ? property.DisplayName : displayName;
            string headerName = string.Format(HeaderStr, displayName, property.ArraySize, property.HashCodeForPropertyPath());

            RuntimeEasyGUI.PropertyField(position, property, new GUIContent(headerName), false, null);
            return(headerName);
        }
예제 #10
0
        internal bool CanCacheInspectorGUISafe(RuntimeSerializedProperty property)
        {
            RuntimeScriptAttributeUtility.s_DrawerStack.Push(this);
            bool result = this.CanCacheInspectorGUI(property);

            RuntimeScriptAttributeUtility.s_DrawerStack.Pop();
            return(result);
        }
예제 #11
0
 public static bool ValidateObjectReferenceValue(RuntimeSerializedProperty property, Object obj, EasyGUI.ObjectFieldValidatorOptions options)
 {
     if ((options & EasyGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) == EasyGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation)
     {
         return(property.ValidateObjectReferenceValueExact(obj));
     }
     return(property.ValidateObjectReferenceValue(obj));
 }
예제 #12
0
 public static float GetSinglePropertyHeight(RuntimeSerializedProperty property, GUIContent label)
 {
     if (property == null)
     {
         return(kSingleLineHeight);
     }
     return(GetPropertyHeight(property.PropertyType, label));
 }
 public RuntimeReorderableList GetPropertyList(RuntimeSerializedProperty property)
 {
     if (runtimeReorderableListDict.ContainsKey(property.PropertyPath))
     {
         return(runtimeReorderableListDict[property.PropertyPath]);
     }
     return(null);
 }
예제 #14
0
        internal float GetPropertyHeightSafe(RuntimeSerializedProperty property, GUIContent label)
        {
            RuntimeScriptAttributeUtility.s_DrawerStack.Push(this);
            float propertyHeight = this.GetPropertyHeight(property, label);

            RuntimeScriptAttributeUtility.s_DrawerStack.Pop();
            return(propertyHeight);
        }
예제 #15
0
        public static void PasteComponentValues(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;

            runtimeSerializedProperty.RuntimeSerializedObject.Target = Clipboard[runtimeSerializedProperty.RuntimeSerializedObject.Type].Target;
            runtimeSerializedProperty.RuntimeSerializedObject.ForceReloadProperties();
            EditorUtilityHelper.ForceReloadInspectors();
        }
예제 #16
0
        public bool MoveNext()
        {
            uint num = (uint)position;

            position = -1;
            switch (num)
            {
            case 0:
                if (!target.IsArray)
                {
                    end = target.GetEndProperty();
                    if (target.NextVisible(true) && !RuntimeSerializedProperty.EqualContents(target, end))
                    {
                        current = target;
                        if (!disposing)
                        {
                            position = 2;
                        }
                        return(true);
                    }
                    position = -1;
                    return(false);
                }
                index = 0;
                break;

            case 1:
                index++;
                break;

            case 2:
                if (target.NextVisible(true) && !RuntimeSerializedProperty.EqualContents(target, end))
                {
                    current = target;
                    if (!disposing)
                    {
                        position = 2;
                    }
                    return(true);
                }
                position = -1;
                return(false);

            default:
                return(false);
            }
            if (index >= target.ArraySize)
            {
                position = -1;
                return(false);
            }
            current = target.GetArrayElementAtIndex(index);
            if (!disposing)
            {
                position = 1;
            }
            return(true);
        }
        public void AddProperty(RuntimeSerializedProperty property)
        {
            // Check if this property actually belongs to the same direct child
            if (!property.GetRootPath().Equals(Parent))
            {
                return;
            }

            if (runtimeReorderableListDict.ContainsKey(property.PropertyPath))
            {
                return;
            }

            RuntimeReorderableList propList = new RuntimeReorderableList(
                property.RuntimeSerializedObject.SerializedObject, property,
                draggable: true, displayHeader: false,
                displayAddButton: true, displayRemoveButton: true)
            {
                headerHeight = 5
            };

            propList.drawElementBackgroundCallback = (Rect position, int index, bool active, bool focused) =>
            {
                if (DrawBackgroundCallback != null)
                {
                    Rect backgroundRect = new Rect(position);
                    if (index <= 0)
                    {
                        backgroundRect.yMin -= 8;
                    }
                    if (index >= propList.count - 1)
                    {
                        backgroundRect.yMax += 3;
                    }
                    EditorGUI.DrawRect(backgroundRect, DrawBackgroundCallback(active, focused));
                }
                else
                {
                    propList.drawElementBackgroundCallback = null;
                }
            };

            propList.drawElementCallback = (Rect position, int index, bool active, bool focused) =>
            {
                var iterProp    = property.GetArrayElementAtIndex(index);
                var elementName = iterProp.DisplayName;
                if (ElementNameCallback != null)
                {
                    elementName = ElementNameCallback(index);
                }
                RuntimeEasyGUI.PropertyField(position, iterProp, new GUIContent(elementName), ElementAttributes);
            };

            propList.elementHeightCallback = index => ElementHeightCallback(property, index);

            runtimeReorderableListDict.Add(property.PropertyPath, propList);
        }
예제 #18
0
 public static bool HasAttribute <T>(this RuntimeSerializedProperty property)
 {
     object[] attrs = GetAttributes <T>(property);
     if (attrs != null)
     {
         return(attrs.Length > 0);
     }
     return(false);
 }
예제 #19
0
        private void Initialize(RuntimeSerializedProperty property)
        {
            if (isInitialized)
            {
                return;
            }

            FindTargetProperties(property.Copy());
        }
예제 #20
0
        private void Initialize(RuntimeSerializedProperty property, bool force)
        {
            if (force)
            {
                isInitialized = false;
            }

            Initialize(property);
        }
        public override void OnGUI(Rect position, RuntimeSerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginChangeCheck();
            var index = EditorGUI.MaskField(position, property.DisplayName, property.IntValue, property.EnumDisplayNames);

            if (EditorGUI.EndChangeCheck())
            {
                property.IntValue = index;
            }
        }
예제 #22
0
        public void ForceReloadProperties()
        {
            RuntimeSerializedProperty prop = GetIterator();

            while (prop.Next(true))
            {
                prop.Value = prop.Value;
            }
            UpdateIfRequiredOrScript();
        }
예제 #23
0
        public static GUIContent BeginProperty(Rect totalPosition, GUIContent label, RuntimeSerializedProperty property)
        {
            Highlighter.HighlightIdentifier(totalPosition, property.PropertyPath);

            if (s_PendingPropertyKeyboardHandling != null)
            {
                DoPropertyFieldKeyboardHandling(s_PendingPropertyKeyboardHandling);
            }

            // Properties can be nested, so A BeginProperty may not be followed by its corresponding EndProperty
            // before there have been one or more pairs of BeginProperty/EndProperty in between.
            // The keyboard handling for a property (that handles duplicate and delete commands for array items)
            // uses EditorGUI.lastControlID so it has to be executed for a property before any possible child
            // properties are handled. However, it can't be done in it's own BeginProperty, because the controlID
            // for the property is not yet known at that point. For that reason we mark the keyboard handling as
            // pending and handle it either the next BeginProperty call (for the first child property) or if there's
            // no child properties, then in the matching EndProperty call.
            s_PendingPropertyKeyboardHandling = property;

            if (property == null)
            {
                string error = ((label != null) ? (label.text + ": ") : EmptyStr) + "RuntimeSerializedProperty is null";
                EditorGUI.HelpBox(totalPosition, "null", MessageType.Error);
                throw new System.NullReferenceException(error);
            }

            s_PropertyFieldTempContent.text    = LocalizationDatabaseHelper.GetLocalizedString((label != null) ? label.text : property.DisplayName); // no necessary to be translated.
            s_PropertyFieldTempContent.tooltip = EasyGUI.IsCollectingTooltips ? ((label == null) ? property.Tooltip : label.tooltip) : null;
            string attributeTooltip = RuntimeScriptAttributeUtility.GetHandler(property, null).Tooltip;

            if (attributeTooltip != null)
            {
                s_PropertyFieldTempContent.tooltip = attributeTooltip;
            }
            s_PropertyFieldTempContent.image = label != null ? label.image : null;

            // In inspector debug mode & when holding down alt. Show the property path of the property.
            if (Event.current.alt && property.RuntimeSerializedObject.SerializedObject.InspectorMode() != InspectorMode.Normal)
            {
                s_PropertyFieldTempContent.tooltip = s_PropertyFieldTempContent.text = property.PropertyPath;
            }

            bool wasBoldDefaultFont = EditorGUIUtilityHelper.GetBoldDefaultFont();

            if (property.RuntimeSerializedObject.SerializedObject.targetObjects.Length == 1 && property.IsInstantiatedPrefab)
            {
                EditorGUIUtilityHelper.SetBoldDefaultFont(property.PrefabOverride);
            }

            s_PropertyStack.Push(new RuntimePropertyGUIData(property, totalPosition, wasBoldDefaultFont, GUI.enabled, GUI.backgroundColor));

            GUI.enabled &= property.Editable;

            return(s_PropertyFieldTempContent);
        }
        public RuntimePropertyHandler GetHandler(RuntimeSerializedProperty property, List <PropertyAttribute> attributes)
        {
            RuntimePropertyHandler handler;
            int key = GetPropertyHash(property, attributes);

            if (PropertyHandlers.TryGetValue(key, out handler))
            {
                return(handler);
            }
            return(null);
        }
 private void SetValue(RuntimeSerializedProperty property, float value)
 {
     if (property.PropertyType == RuntimeSerializedPropertyType.Integer)
     {
         property.IntValue = (int)value;
     }
     else if (property.PropertyType == RuntimeSerializedPropertyType.Float)
     {
         property.FloatValue = value;
     }
 }
예제 #26
0
        public static string GetRootPath(this RuntimeSerializedProperty property)
        {
            var rootPath = property.PropertyPath;
            var firstDot = property.PropertyPath.IndexOf(StopChar);

            if (firstDot > 0)
            {
                rootPath = property.PropertyPath.Substring(0, firstDot);
            }
            return(rootPath);
        }
예제 #27
0
        public static object GetRuntimeObject(RuntimeSerializedProperty property, string json)
        {
            var hashCode = property.HashCodeForPropertyPath();

            if (!RuntimeObjectDict.ContainsKey(hashCode))
            {
                RuntimeObjectDict.Add(hashCode, RuntimeObject.FromJson(json));
            }

            return(RuntimeObjectDict[hashCode]);
        }
        private static FieldInfo GetFieldInfoFromProperty(RuntimeSerializedProperty property, out Type type)
        {
            var classType = GetScriptTypeFromProperty(property);

            if (classType == null)
            {
                type = null;
                return(null);
            }

            return(GetFieldInfoFromPropertyPath(classType, property.PropertyPath, out type));
        }
 private float GetValue(RuntimeSerializedProperty property)
 {
     if (property.PropertyType == RuntimeSerializedPropertyType.Integer)
     {
         return(property.IntValue);
     }
     else if (property.PropertyType == RuntimeSerializedPropertyType.Float)
     {
         return(property.FloatValue);
     }
     return(0);
 }
예제 #30
0
        public static void DoPropertyContextMenu(RuntimeSerializedProperty property)
        {
            GenericMenu pm = FillPropertyContextMenu(property);

            if (pm == null || pm.GetItemCount() == 0)
            {
                return;
            }

            Event.current.Use();
            pm.ShowAsContext();
        }