예제 #1
0
 private void SetupReorder(ListAttribute listAttribute, ListField field, SerializedProperty property, Type declaringType)
 {
     if (field.AllowReorder)
     {
         if (!string.IsNullOrEmpty(listAttribute.ReorderCallback))
         {
             var reorderCallback = ReflectionHelper.CreateActionCallback(listAttribute.ReorderCallback, declaringType, property);
             if (reorderCallback != null)
             {
                 field.RegisterCallback <ListField.ItemReorderedEvent>(evt => reorderCallback.Invoke());
             }
             else
             {
                 var reorderCallbackFromTo = ReflectionHelper.CreateActionCallback <int, int>(listAttribute.ReorderCallback, declaringType, property);
                 if (reorderCallbackFromTo != null)
                 {
                     field.RegisterCallback <ListField.ItemReorderedEvent>(evt => reorderCallbackFromTo.Invoke(evt.FromIndex, evt.ToIndex));
                 }
                 else
                 {
                     Debug.LogWarningFormat(_invalidReorderCallbackWarning, property.propertyPath);
                 }
             }
         }
     }
 }
예제 #2
0
        private void SetupAdd(ListAttribute listAttribute, PropertyListProxy proxy, ListField field, SerializedProperty property, Type declaringType, bool isReference)
        {
            if (field.AllowAdd)
            {
                if (!string.IsNullOrEmpty(listAttribute.AllowAdd))
                {
                    proxy.CanAddCallback = ReflectionHelper.CreateValueSourceFunction(listAttribute.AllowAdd, property, field, declaringType, true);
                }

                if (!string.IsNullOrEmpty(listAttribute.AddCallback))
                {
                    if (!isReference)
                    {
                        var addCallback = ReflectionHelper.CreateActionCallback(listAttribute.AddCallback, declaringType, property);
                        if (addCallback != null)
                        {
                            field.RegisterCallback <ListField.ItemAddedEvent>(evt => addCallback.Invoke());
                        }
                        else
                        {
                            var addCallbackIndex = ReflectionHelper.CreateActionCallback <int>(listAttribute.AddCallback, declaringType, property);
                            if (addCallbackIndex != null)
                            {
                                field.RegisterCallback <ListField.ItemAddedEvent>(evt => addCallbackIndex.Invoke(evt.Index));
                            }
                            else
                            {
                                Debug.LogWarningFormat(_invalidAddCallbackWarning, property.propertyPath);
                            }
                        }
                    }
                    else
                    {
                        var addCallback = ReflectionHelper.CreateActionCallback(listAttribute.AddCallback, declaringType, property);
                        if (addCallback != null)
                        {
                            field.RegisterCallback <ListField.ItemAddedEvent>(evt => addCallback.Invoke());
                        }
                        else
                        {
                            var addCallbackIndex = ReflectionHelper.CreateActionCallback <int>(listAttribute.AddCallback, declaringType, property);
                            if (addCallbackIndex != null)
                            {
                                field.RegisterCallback <ListField.ItemAddedEvent>(evt => addCallbackIndex.Invoke(evt.Index));
                            }
                            else
                            {
                                Debug.LogWarningFormat(_invalidAddReferenceCallbackWarning, property.propertyPath);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        private void SetupRemove(ListAttribute listAttribute, PropertyListProxy proxy, ListField field, SerializedProperty property, Type declaringType)
        {
            if (field.AllowRemove)
            {
                if (!string.IsNullOrEmpty(listAttribute.AllowRemove))
                {
                    proxy.CanRemoveCallback = ReflectionHelper.CreateFunctionCallback <int, bool>(listAttribute.AllowRemove, declaringType, property);

                    if (proxy.CanRemoveCallback == null)
                    {
                        var canRemove = ReflectionHelper.CreateValueSourceFunction(listAttribute.AllowRemove, property, field, declaringType, true);
                        proxy.CanRemoveCallback = index => canRemove();
                    }
                }

                if (!string.IsNullOrEmpty(listAttribute.RemoveCallback))
                {
                    var removeCallback = ReflectionHelper.CreateActionCallback(listAttribute.RemoveCallback, declaringType, property);
                    if (removeCallback != null)
                    {
                        field.RegisterCallback <ListField.ItemRemovedEvent>(evt => removeCallback.Invoke());
                    }
                    else
                    {
                        var removeCallbackIndex = ReflectionHelper.CreateActionCallback <int>(listAttribute.RemoveCallback, declaringType, property);
                        if (removeCallbackIndex != null)
                        {
                            field.RegisterCallback <ListField.ItemRemovedEvent>(evt => removeCallbackIndex.Invoke(evt.Index));
                        }
                        else
                        {
                            Debug.LogWarningFormat(_invalidRemoveCallbackWarning, property.propertyPath);
                        }
                    }
                }
            }
        }
예제 #4
0
 private void SetupChange(ListAttribute listAttribute, ListField field, SerializedProperty property, Type declaringType)
 {
     if (!string.IsNullOrEmpty(listAttribute.ChangeCallback))
     {
         var changeCallback = ReflectionHelper.CreateActionCallback(listAttribute.ChangeCallback, declaringType, property);
         if (changeCallback != null)
         {
             field.RegisterCallback <ListField.ItemsChangedEvent>(evt => changeCallback.Invoke());
         }
         else
         {
             Debug.LogWarningFormat(_invalidChangeCallbackWarning, property.propertyPath);
         }
     }
 }