Beispiel #1
0
 public ValueControl(ControlConfig config, bool autoLayout = false)
 {
     if (config.filter == null && config.type != null)
     {
         config.filter = new FilterAttribute(config.type);
     }
     this.config = config;
     EnableInClassList("Layout", autoLayout);
 }
Beispiel #2
0
        public MemberControl InstantiateControl(bool autoLayout = false)
        {
            ControlConfig config = new ControlConfig()
            {
                owner          = owner,
                value          = GetPortValue(),
                type           = GetPortType(),
                filter         = GetFilter(),
                onValueChanged = onValueChanged,
            };

            return(new MemberControl(config, autoLayout));
        }
Beispiel #3
0
        public static ValueControl CreateControl(Type controlType, ControlConfig config, bool autoLayout = false)
        {
            var controlAtts = FindControlsField();

            for (int i = 0; i < controlAtts.Count; i++)
            {
                if (controlAtts[i].type == controlType || controlType.IsSubclassOf(controlAtts[i].type))
                {
                    return(Activator.CreateInstance(controlAtts[i].classType, new object[] { config, autoLayout }) as ValueControl);
                }
            }
            return(new DefaultControl(config, autoLayout));
        }
 public Vector2IntControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }
Beispiel #5
0
 public QuaternionControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }
Beispiel #6
0
 public AnimationCurveControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }
Beispiel #7
0
 public FloatControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }
Beispiel #8
0
 public DefaultControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init(autoLayout);
 }
Beispiel #9
0
        public void UpdateControl()
        {
            if (control != null)
            {
                control.RemoveFromHierarchy();
                control      = null;
                showInstance = false;
            }
            Type targetType = member.type;

            if (member.isTargeted)
            {
                tooltip = member.Tooltip;
            }
            if (member.targetType == MemberData.TargetType.Values && targetType != null)
            {
                Type portType = targetType;
                // var mVal = member.Get();
                // if(mVal != null && !mVal.GetType().IsCastableTo(portType)) {
                //  portType = mVal.GetType();
                // }
                var           controlAtts = UIElementUtility.FindControlsField();
                ControlConfig config      = new ControlConfig()
                {
                    owner          = this.config.owner,
                    value          = member.Get(),
                    filter         = this.config.filter,
                    type           = portType,
                    onValueChanged = (val) => {
                        this.config.OnValueChanged(MemberData.CreateFromValue(val, member.type));
                        MarkDirtyRepaint();
                    },
                };
                if (config.value == null && config.type.IsValueType)
                {
                    //Ensure to initialize value for value type since value type cannot be null
                    config.value = ReflectionUtils.CreateInstance(config.type);
                    member.CopyFrom(MemberData.CreateFromValue(config.value));
                }
                control = UIElementUtility.CreateControl(portType, config, ClassListContains("Layout"));
                if (control is ObjectControl && config.value as uNodeRoot == config.owner.targetNode.owner)
                {
                    control = new DefaultControl(config, ClassListContains("Layout"));
                }
                if (control is StringControl && ClassListContains("multiline"))
                {
                    (control as StringControl).field.multiline = true;
                }
                if (popupElement != null && popupElement.visible)
                {
                    popupElement.visible = false;
                    popupElement.RemoveFromHierarchy();
                }
            }
            else if (!member.IsTargetingUNode && !member.isStatic && !hideInstance && member.startType != null)
            {
                if (config.filter == null)
                {
                    config.filter = new FilterAttribute();
                }
                FilterAttribute filter = config.filter;
                if (filter.UnityReference && !filter.OnlyGetType && !member.targetType.HasFlags(
                        MemberData.TargetType.Values |
                        MemberData.TargetType.Type |
                        MemberData.TargetType.Null |
                        MemberData.TargetType.uNodeGenericParameter) && member.instance as UnityEngine.Object != config.owner.targetNode.owner)
                {
                    Type portType = member.startType;
                    if (member.instance is MemberData)
                    {
                        portType = typeof(MemberData);
                    }
                    var           controlAtts = UIElementUtility.FindControlsField();
                    ControlConfig config      = new ControlConfig()
                    {
                        owner          = this.config.owner,
                        value          = member.instance,
                        filter         = new FilterAttribute(member.startType),
                        type           = member.startType,
                        onValueChanged = (val) => {
                            bool flag3 = false;
                            if (member.instance != null && !member.instance.GetType().IsCastableTo(portType))
                            {
                                flag3 = true;
                            }
                            member.instance = val;
                            this.config.OnValueChanged(member);
                            MarkDirtyRepaint();
                            if (flag3)
                            {
                                UpdateControl();
                            }
                        },
                    };
                    control = UIElementUtility.CreateControl(portType, config, ClassListContains("Layout"));
                    if (control is ObjectControl)
                    {
                        var objectControl = control as ObjectControl;
                        if (config.value != null && !config.value.GetType().IsCastableTo(portType))
                        {
                            objectControl.style.backgroundColor = Color.red;
                        }
                        objectControl.AddManipulator(new ContextualMenuManipulator(evt => {
                            object instance = member.instance;
                            if (instance != null)
                            {
                                if (instance as GameObject)
                                {
                                    var go            = instance as GameObject;
                                    Component[] comps = go.GetComponents <Component>();
                                    evt.menu.AppendAction("0-" + typeof(GameObject).Name, (act) => {
                                        objectControl.config.OnValueChanged(go);
                                        UpdateControl();
                                    }, DropdownMenuAction.AlwaysEnabled);
                                    for (int x = 0; x < comps.Length; x++)
                                    {
                                        Component com = comps[x];
                                        evt.menu.AppendAction((x + 1) + "-" + com.GetType().Name, (act) => {
                                            objectControl.config.OnValueChanged(com);
                                            UpdateControl();
                                        }, DropdownMenuAction.AlwaysEnabled);
                                    }
                                }
                                else if (instance as Component)
                                {
                                    var component     = instance as Component;
                                    Component[] comps = component.GetComponents <Component>();
                                    evt.menu.AppendAction("0-" + typeof(GameObject).Name, (act) => {
                                        objectControl.config.OnValueChanged(new MemberData(component.gameObject));
                                        UpdateControl();
                                    }, DropdownMenuAction.AlwaysEnabled);
                                    for (int x = 0; x < comps.Length; x++)
                                    {
                                        Component com = comps[x];
                                        evt.menu.AppendAction((x + 1) + "-" + com.GetType().Name, (act) => {
                                            objectControl.config.OnValueChanged(com);
                                            UpdateControl();
                                        }, DropdownMenuAction.AlwaysEnabled);
                                    }
                                }
                            }
                            evt.menu.AppendSeparator("");
                            if (config.owner.targetNode != null)
                            {
                                uNodeRoot UNR = config.owner.targetNode.owner;
                                if (UNR != null)
                                {
                                    GameObject go     = UNR.gameObject;
                                    Component[] comps = go.GetComponents <Component>();
                                    evt.menu.AppendAction("this uNode/0-" + typeof(GameObject).Name, (act) => {
                                        objectControl.config.OnValueChanged(go);
                                        UpdateControl();
                                    }, DropdownMenuAction.AlwaysEnabled);
                                    for (int x = 0; x < comps.Length; x++)
                                    {
                                        Component com = comps[x];
                                        evt.menu.AppendAction("this uNode/" + x + "-" + com.GetType().Name, (act) => {
                                            objectControl.config.OnValueChanged(com);
                                            UpdateControl();
                                        }, DropdownMenuAction.AlwaysEnabled);
                                    }
                                }
                            }
                            evt.menu.AppendAction("Reset", (act) => {
                                objectControl.config.OnValueChanged(null);
                                UpdateControl();
                            }, DropdownMenuAction.AlwaysEnabled);
                        }));
                    }
                    showInstance = true;
                }
            }
            if (popupElement != null)
            {
                if (!popupElement.visible && (control == null || showInstance || config.filter == null || config.filter.ValidTargetType != MemberData.TargetType.Values))
                {
                    UpdatePopupLabel();
                    popupElement.visible = true;
                    Add(popupElement);
                }
                popupElement.MarkDirtyRepaint();
            }
            if (control != null)
            {
                control.RemoveFromHierarchy();
                Insert(0, control);
            }
        }
Beispiel #10
0
 public IntegerControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }
Beispiel #11
0
        void InitializeView()
        {
            if (data.block == null)
            {
                return;
            }
            if (data.block is Events.HLAction || data.block is Events.HLCondition)
            {
                InitializeHLBlock(data.block);
                return;
            }
            var fields = EditorReflectionUtility.GetFields(data.block.GetType());

            if (fields != null && fields.Length > 0)
            {
                for (int idx = 0; idx < fields.Length; idx++)
                {
                    FieldInfo field = fields[idx];
                    if (uNodeGUIUtility.IsHide(field, data.block))
                    {
                        continue;
                    }
                    Type type = field.FieldType;
                    if (type == typeof(MemberData))
                    {
                        MemberData member         = field.GetValueOptimized(data.block) as MemberData;
                        object[]   fieldAttribute = field.GetCustomAttributes(true);
                        if (!ReflectionUtils.TryCorrectingAttribute(data.block, ref fieldAttribute))
                        {
                            continue;
                        }
                        var filter = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttribute);
                        if (member == null)
                        {
                            if (filter != null && !filter.SetMember && !filter.OnlyGetType && ReflectionUtils.CanCreateInstance(filter.GetActualType()))
                            {
                                member = new MemberData(ReflectionUtils.CreateInstance(filter.GetActualType()));
                            }
                            else if (filter != null && !filter.SetMember && !filter.OnlyGetType)
                            {
                                member = MemberData.none;
                            }
                            field.SetValueOptimized(data.block, member);
                            Repaint();
                        }
                        bool hasDependencies = EditorReflectionUtility.HasFieldDependencies(new string[] { field.Name }, fields);
                        var  port            = AddPort(new PortData()
                        {
                            getPortName    = () => ObjectNames.NicifyVariableName(field.Name),
                            getPortType    = () => filter?.GetActualType() ?? typeof(object),
                            getPortValue   = () => field.GetValueOptimized(data.block),
                            filter         = filter,
                            onValueChanged = (obj) => {
                                RegisterUndo();
                                member = obj as MemberData;
                                field.SetValueOptimized(data.block, member);
                                Repaint();
                                if (hasDependencies)
                                {
                                    owner.nodeView.MarkRepaint();
                                }
                            },
                        });
                        port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                    }
                    else if (type == typeof(MultipurposeMember))
                    {
                        InitMultipurposeMember(field);
                    }
                    else
                    {
                        object   fieldVal       = field.GetValueOptimized(data.block);
                        object[] fieldAttribute = field.GetCustomAttributes(true);
                        if (!ReflectionUtils.TryCorrectingAttribute(data.block, ref fieldAttribute))
                        {
                            continue;
                        }
                        bool          hasDependencies = EditorReflectionUtility.HasFieldDependencies(new string[] { field.Name }, fields);
                        var           filter          = ReflectionUtils.GetAttribute <FilterAttribute>(fieldAttribute);
                        ControlConfig config          = new ControlConfig()
                        {
                            owner          = owner.nodeView,
                            value          = fieldVal,
                            type           = type,
                            filter         = filter,
                            onValueChanged = (obj) => {
                                RegisterUndo();
                                field.SetValueOptimized(data.block, obj);
                                Repaint();
                                if (hasDependencies)
                                {
                                    owner.nodeView.MarkRepaint();
                                }
                            },
                        };
                        var valueControl = UIElementUtility.CreateControl(type, config, true);
                        AddControl(field.Name, new ControlView(valueControl, true));
                        if (fieldVal is IList <MemberData> )
                        {
                            IList <MemberData> members = fieldVal as IList <MemberData>;
                            if (members != null)
                            {
                                for (int i = 0; i < members.Count; i++)
                                {
                                    int index  = i;
                                    var member = members[i];
                                    if (member == null)
                                    {
                                        if (filter != null && !filter.SetMember && !filter.OnlyGetType &&
                                            ReflectionUtils.CanCreateInstance(filter.GetActualType()))
                                        {
                                            member = new MemberData(ReflectionUtils.CreateInstance(filter.GetActualType()));
                                        }
                                        else
                                        {
                                            member = MemberData.none;
                                        }
                                        members[index] = member;
                                        field.SetValueOptimized(data.block, members);
                                        Repaint();
                                    }
                                    var port = AddPort(new PortData()
                                    {
                                        getPortName    = () => "Element " + index.ToString(),
                                        getPortType    = () => filter?.GetActualType() ?? typeof(object),
                                        getPortValue   = () => (field.GetValueOptimized(data.block) as IList <MemberData>)[index],
                                        filter         = filter,
                                        onValueChanged = (obj) => {
                                            RegisterUndo();
                                            member         = obj as MemberData;
                                            members[index] = member;
                                            field.SetValueOptimized(data.block, members);
                                            Repaint();
                                        },
                                    });
                                    port.Add(new ControlView(port.portData.InstantiateControl(true), true));
                                }
                            }
                        }
                        else if (fieldVal is IList)
                        {
                            IList list = fieldVal as IList;
                            if (list != null)
                            {
                                for (int i = 0; i < list.Count; i++)
                                {
                                    int           index   = i;
                                    var           element = list[i];
                                    ControlConfig cfg     = new ControlConfig()
                                    {
                                        owner          = owner.nodeView,
                                        value          = fieldVal,
                                        type           = type,
                                        filter         = filter,
                                        onValueChanged = (obj) => {
                                            RegisterUndo();
                                            field.SetValueOptimized(data.block, obj);
                                            Repaint();
                                        },
                                    };
                                    var elementControl = UIElementUtility.CreateControl(type, cfg, true);
                                    AddControl("Element " + index, new ControlView(elementControl, true));
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #12
0
 public LayerMaskControl(ControlConfig config, bool autoLayout = false) : base(config, autoLayout)
 {
     Init();
 }