// Works for any TextValueField types, needs to know fieldType and object type
        private EngineUI.VisualElement SetupField <TField, TType>(TField field)
            where TField : EngineUI.VisualElement, EngineUI.INotifyValueChanged <TType>
        {
            field.AddToClassList("portField");
            if (TryGetValueObject(out object result))
            {
                field.value = (TType)result;
            }

            field.OnValueChanged((e) => SetNewValue(e.newValue, ValueIndices.value));
            _inputField = field;
            return(_inputField);
        }
        // 0 = Value, 1 = name, 2 = public, 3 = synced, 4 = syncType
        public UdonParameterProperty(UdonGraph graphView, UdonNodeDefinition definition, UdonNodeData nodeData)
        {
            this.graph      = graphView;
            this.definition = definition;
            this.nodeData   = nodeData;

            // Make sure the incoming nodeData has the right number of nodeValues (super old graphs didn't have sync info)
            if (this.nodeData.nodeValues.Length != 5)
            {
                this.nodeData.nodeValues = GetDefaultNodeValues();
                for (int i = 0; i < nodeData.nodeValues.Length; i++)
                {
                    this.nodeData.nodeValues[i] = nodeData.nodeValues[i];
                }
            }

            // Public Toggle
            isPublic = new EngineUI.Toggle
            {
                text  = "public",
                value = (bool)GetValue(ValueIndices.isPublic)
            };
            isPublic.OnValueChanged(e => { SetNewValue(e.newValue, ValueIndices.isPublic); });
            Add(isPublic);

            // Is Synced Field
            isSynced = new EngineUI.Toggle
            {
                text  = "synced",
                value = (bool)GetValue(ValueIndices.isSynced),
            };

            isSynced.OnValueChanged(e =>
            {
                SetNewValue(e.newValue, ValueIndices.isSynced);
                syncField.visible = e.newValue;
            });
            Add(isSynced);

            // Sync Field, add to isSynced
            List <string> choices = new List <string>()
            {
                "none", "linear", "smooth"
            };

            syncField = new EditorUI.PopupField <string>(choices, 0)
            {
                visible = isSynced.value
            };
            syncField.OnValueChanged(e => { SetNewValue(e.newValue, ValueIndices.syncType); });
            isSynced.Add(syncField);

            // Container to show/edit Default Value
            var friendlyName = UdonGraphExtensions.FriendlyTypeName(definition.type).FriendlyNameify();

            defaultValueContainer = new EngineUI.VisualElement
            {
                new EngineUI.Label("default value")
                {
                    name = "default-value-label"
                }
            };

            // Generate Default Value Field
            var value = TryGetValueObject(out object result);

            _inputField = UdonFieldFactory.CreateField(
                definition.type,
                result,
                newValue => SetNewValue(newValue, ValueIndices.value)
                );
            if (_inputField != null)
            {
                defaultValueContainer.Add(_inputField);
                Add(defaultValueContainer);
            }
        }
 internal CreationContext(Dictionary <string, VisualElement> slotInsertionPoints, VisualTreeAsset vta, VisualElement target)
 {
     this.target = target;
     this.slotInsertionPoints = slotInsertionPoints;
     visualTreeAsset          = vta;
 }
        private VisualElement CloneSetupRecursively(VisualElementAsset root, Dictionary <int, List <VisualElementAsset> > idToChildren, CreationContext context)
        {
            VisualElement ve = root.Create(context);

            // context.target is the created templateContainer
            if (root.id == context.visualTreeAsset.contentContainerId)
            {
                if (context.target is TemplateContainer)
                {
                    ((TemplateContainer)context.target).SetContentContainer(ve);
                }
                else
                {
                    Debug.LogError("Trying to clone a VisualTreeAsset with a custom content container into a element which is not a template container");
                }
            }

            ve.name = root.name;

            // if the current element had a slot-name attribute, put it in the resulting slot mapping
            string slotName;

            if (context.slotInsertionPoints != null && TryGetSlotInsertionPoint(root.id, out slotName))
            {
                context.slotInsertionPoints.Add(slotName, ve);
            }

            if (root.classes != null)
            {
                for (int i = 0; i < root.classes.Length; i++)
                {
                    ve.AddToClassList(root.classes[i]);
                }
            }

            if (root.ruleIndex != -1)
            {
                if (inlineSheet == null)
                {
                    Debug.LogWarning("VisualElementAsset has a RuleIndex but no inlineStyleSheet");
                }
                else
                {
                    StyleRule r          = inlineSheet.rules[root.ruleIndex];
                    var       stylesData = new VisualElementStylesData(false);
                    ve.SetInlineStyles(stylesData);
                    stylesData.ApplyRule(inlineSheet, Int32.MaxValue, r,
                                         StyleSheetCache.GetPropertyIDs(inlineSheet, root.ruleIndex));
                }
            }

            var templateAsset = root as TemplateAsset;
            List <VisualElementAsset> children;

            if (idToChildren.TryGetValue(root.id, out children))
            {
                foreach (VisualElementAsset childVea in children)
                {
                    // this will fill the slotInsertionPoints mapping
                    VisualElement childVe = CloneSetupRecursively(childVea, idToChildren, context);
                    if (childVe == null)
                    {
                        continue;
                    }

                    // if the parent is not a template asset, just add the child to whatever hierarchy we currently have
                    // if ve is a scrollView (with contentViewport as contentContainer), this will go to the right place
                    if (templateAsset == null)
                    {
                        ve.Add(childVe);
                        continue;
                    }

                    int index = templateAsset.slotUsages == null ? -1 : templateAsset.slotUsages.FindIndex(u => u.assetId == childVea.id);
                    if (index != -1)
                    {
                        VisualElement parentSlot;
                        string        key = templateAsset.slotUsages[index].slotName;
                        Assert.IsFalse(String.IsNullOrEmpty(key), "a lost name should not be null or empty, this probably points to an importer or serialization bug");
                        if (context.slotInsertionPoints == null || !context.slotInsertionPoints.TryGetValue(key, out parentSlot))
                        {
                            Debug.LogErrorFormat("Slot '{0}' was not found. Existing slots: {1}", key, context.slotInsertionPoints == null
                                ? String.Empty
                                : String.Join(", ", System.Linq.Enumerable.ToArray(context.slotInsertionPoints.Keys)));
                            ve.Add(childVe);
                        }
                        else
                        {
                            parentSlot.Add(childVe);
                        }
                    }
                    else
                    {
                        ve.Add(childVe);
                    }
                }
            }

            if (templateAsset != null && context.slotInsertionPoints != null)
            {
                context.slotInsertionPoints.Clear();
            }

            return(ve);
        }
Пример #5
0
 internal override void OnVersionChanged(VisualElement ve, VersionChangeType versionChangeType)
 {
     ++m_Version;
     m_VisualTreeUpdater.OnVersionChanged(ve, versionChangeType);
 }
Пример #6
0
        private VisualElement PerformPick(VisualElement root, Vector2 point, List <VisualElement> picked = null)
        {
            // do not pick invisible
            if (root.visible == false)
            {
                return(null);
            }

            if (root.pickingMode == PickingMode.Ignore && root.shadow.childCount == 0)
            {
                return(null);
            }

            Vector3 localPoint    = root.WorldToLocal(point);
            bool    containsPoint = root.ContainsPoint(localPoint);

            // we only skip children in the case we visually clip them
            if (!containsPoint && root.ShouldClip())
            {
                return(null);
            }

            VisualElement returnedChild = null;

            // Depth first in reverse order, do children
            for (int i = root.shadow.childCount - 1; i >= 0; i--)
            {
                var child  = root.shadow[i];
                var result = PerformPick(child, point, picked);
                if (returnedChild == null && result != null)
                {
                    returnedChild = result;
                }
            }

            if (picked != null && root.enabledInHierarchy && root.pickingMode == PickingMode.Position && containsPoint)
            {
                picked.Add(root);
            }

            if (returnedChild != null)
            {
                return(returnedChild);
            }

            switch (root.pickingMode)
            {
            case PickingMode.Position:
            {
                if (containsPoint && root.enabledInHierarchy)
                {
                    return(root);
                }
            }
            break;

            case PickingMode.Ignore:
                break;
            }
            return(null);
        }
Пример #7
0
 internal abstract void OnVersionChanged(VisualElement ele, VersionChangeType changeTypeFlag);