Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public override float GetPropertyHeight(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));
            }

            return(listData != null?listData.GetPropertyHeight(property) : RuntimeEasyGUI.GetPropertyHeight(property, label, property.IsExpanded, null));
        }
Exemplo n.º 3
0
        private void CreateListData(RuntimeSerializedProperty property)
        {
            var root = property.GetRootPath();
            // Try to find the grand parent in RuntimeReorderableListData
            var data = listDataDict.Find(listData => listData.Parent.Equals(root));

            if (data == null)
            {
                data = new RuntimeReorderableListData(root);
                listDataDict.Add(data);
            }

            data.AddProperty(property);
            data.EditableCallback = () =>
            {
                if (Application.isPlaying && property.HasAttribute <RuntimeObjectAttribute>())
                {
                    return(false);
                }
                return(true);
            };

            if (property.HasAttribute <ReorderableAttribute>())
            {
                var reorderableAttr = property.GetAttributes <ReorderableAttribute>()[0] as ReorderableAttribute;
                if (reorderableAttr != null)
                {
                    HandleReorderableOptions(reorderableAttr, property, data);
                }
            }

            if (property.HasAttribute <BackgroundColorAttribute>())
            {
                var bgColorAttr = property.GetAttributes <BackgroundColorAttribute>()[0] as BackgroundColorAttribute;
                if (bgColorAttr != null)
                {
                    HandleBackgroundColorOptions(bgColorAttr, property, data);
                }
            }

            if (property.HasAttribute <DropdownMenuAttribute>())
            {
                var dropDownAttr    = property.GetAttributes <DropdownMenuAttribute>()[0] as DropdownMenuAttribute;
                var reorderableList = data.GetPropertyList(property);

                reorderableTypeDict.Add(reorderableList, dropDownAttr.Type);
                reorderableList.onAddDropdownCallback += OnAddDropdownHandler;
                reorderableList.onRemoveCallback      += OnRemoveHandler;
            }

            if (property.HasAttribute <PropertyAttribute>())
            {
                foreach (var attr in property.GetAttributes <PropertyAttribute>())
                {
                    if (attr is ReorderableAttribute || attr is BackgroundColorAttribute || attr is DropdownMenuAttribute)
                    {
                    }
                    else
                    {
                        data.ElementAttributes.Add(attr as PropertyAttribute);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void HandleBackgroundColorOptions(BackgroundColorAttribute bgColorAttr, RuntimeSerializedProperty property, RuntimeReorderableListData data)
 {
     data.DrawBackgroundCallback = (active, focused) =>
     {
         if (focused)
         {
             return(1.35f * bgColorAttr.Color);
         }
         else if (active)
         {
             return(Color.Lerp(Color.white, bgColorAttr.Color, 0.75f));
         }
         else
         {
             return(bgColorAttr.Color);
         }
     };
 }
Exemplo n.º 5
0
        private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, RuntimeSerializedProperty property, RuntimeReorderableListData data)
        {
            data.HeaderCallback = rect =>
            {
                return(DoHeader(property, rect, reorderableAttr.DisplayName));
            };

            if (!string.IsNullOrEmpty(reorderableAttr.ElementName))
            {
                data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i);
            }
        }