public IEnumerator PortConnectorAndCapHavePortColor()
        {
            var nodeModel = new SingleOutputNodeModel();

            nodeModel.DefineNode();
            var node = new CollapsibleInOutNode();

            node.SetupBuildAndUpdate(nodeModel, m_CommandDispatcher, m_GraphView);
            m_GraphView.AddElement(node);
            yield return(null);

            var portModel = nodeModel.Ports.First();
            var port      = portModel.GetUI <Port>(m_GraphView);

            Assert.IsNotNull(port);
            var connector    = port.SafeQ(PortConnectorPart.connectorUssName);
            var connectorCap = port.SafeQ(PortConnectorPart.connectorCapUssName);

            CustomStyleProperty <Color> portColorProperty = new CustomStyleProperty <Color>("--port-color");
            Color portColor;

            Assert.IsTrue(port.customStyle.TryGetValue(portColorProperty, out portColor));

            Assert.AreEqual(portColor, connector.resolvedStyle.borderBottomColor);
            Assert.AreEqual(portColor, connectorCap.resolvedStyle.backgroundColor);
        }
예제 #2
0
        public bool TryGetValue(CustomStyleProperty <string> property, out string value)
        {
            CustomPropertyHandle propertyHandle;

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out propertyHandle))
            {
                value = propertyHandle.data.ReadAsString(propertyHandle.handles[0]);
                return(true);
            }

            value = string.Empty;
            return(false);
        }
예제 #3
0
        public bool TryGetValue(CustomStyleProperty <bool> property, out bool value)
        {
            CustomPropertyHandle propertyHandle;

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out propertyHandle))
            {
                value = propertyHandle.data.ReadKeyword(propertyHandle.handles[0]) == StyleValueKeyword.True;
                return(true);
            }

            value = false;
            return(false);
        }
예제 #4
0
        public bool TryGetValue(CustomStyleProperty <VectorImage> property, out VectorImage value)
        {
            CustomPropertyHandle propertyHandle;
            var tmp = new StyleBackground();

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out propertyHandle))
            {
                s_StyleSheetApplicator.ApplyImage(propertyHandle.data, propertyHandle.handles, propertyHandle.specificity, ref tmp);
                value = tmp.value.vectorImage;
                return(true);
            }

            value = null;
            return(false);
        }
예제 #5
0
        public bool TryGetValue(CustomStyleProperty <Color> property, out Color value)
        {
            CustomPropertyHandle propertyHandle;
            var tmp = new StyleColor();

            if (TryGetValue(property.name, StyleValueType.Color, out propertyHandle))
            {
                s_StyleSheetApplicator.ApplyColor(propertyHandle.data, propertyHandle.handles, propertyHandle.specificity, ref tmp);
                value = tmp.value;
                return(true);
            }

            value = Color.clear;
            return(false);
        }
예제 #6
0
        public bool TryGetValue(CustomStyleProperty <int> property, out int value)
        {
            CustomPropertyHandle propertyHandle;
            var tmp = new StyleInt();

            if (TryGetValue(property.name, StyleValueType.Float, out propertyHandle))
            {
                s_StyleSheetApplicator.ApplyInt(propertyHandle.data, propertyHandle.handles, propertyHandle.specificity, ref tmp);
                value = tmp.value;
                return(true);
            }

            value = 0;
            return(false);
        }
        public bool TryGetValue(CustomStyleProperty <Color> property, out Color value)
        {
            CustomPropertyHandle propertyHandle;

            if (TryGetValue(property.name, StyleValueType.Color, out propertyHandle))
            {
                var propValue = propertyHandle.value;
                if (propValue.sheet.TryReadColor(propValue.handle, out value))
                {
                    return(true);
                }
            }

            value = Color.clear;
            return(false);
        }
        public bool TryGetValue(CustomStyleProperty <float> property, out float value)
        {
            CustomPropertyHandle propertyHandle;

            if (TryGetValue(property.name, StyleValueType.Float, out propertyHandle))
            {
                var propValue = propertyHandle.value;
                if (propValue.sheet.TryReadFloat(propValue.handle, out value))
                {
                    return(true);
                }
            }

            value = 0f;
            return(false);
        }
        public bool TryGetValue(CustomStyleProperty <VectorImage> property, out VectorImage value)
        {
            CustomPropertyHandle propertyHandle;

            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out propertyHandle))
            {
                var source    = new ImageSource();
                var propValue = propertyHandle.value;
                if (StylePropertyReader.TryGetImageSourceFromValue(propValue, out source) && source.vectorImage != null)
                {
                    value = source.vectorImage;
                    return(true);
                }
            }

            value = null;
            return(false);
        }
예제 #10
0
    private void OnEnable()
    {
        // uxml 読み込み
        string path  = "Assets/Editor/Samples/004/CustomPropertySample.uxml";
        var    asset =
            AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(path);

        // 読み込んだUXMLをEditorWindowに配置
        asset.CloneTree(this.rootVisualElement);

        // UXML側にStyleへのリンクがあるので明示的に呼ばなくても良いのですが…
        string ussPath    = "Assets/Editor/Samples/004/CustomPropertySample.uss";
        var    stylesheet =
            AssetDatabase.LoadAssetAtPath <StyleSheet>(ussPath);

        // CustomStylePropertyを読むところ
        rootVisualElement.Query <Label>(null, "mycustom").ForEach((label) =>
        {
            // CustomStyleResolvedEventに処理する
            // このイベントが飛ぶ前だとCustomStylePropertyが読めない
            label.RegisterCallback <CustomStyleResolvedEvent>(
                (evt) =>
            {
                // CustomStylePropertyを読むところ
                int val;
                var customProperty = new CustomStyleProperty <int>("--data-origin");
                bool res           = label.customStyle.TryGetValue(customProperty, out val);
                if (res)
                {
                    label.text = "--data-origin:" + val;
                }
                else
                {
                    label.text = "not found customProperty";
                }
            });
        });
    }
예제 #11
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);
            curveNode = nodeTarget as CurveNode;

            controlsContainer.styleSheets.Add(Resources.Load <StyleSheet>("MixtureCurveColors"));

            var modeField = new EnumField("Mode", curveNode.mode);

            controlsContainer.Add(modeField as VisualElement);

            var rCurve = CreateCurveField(() => curveNode.redCurve, c => curveNode.redCurve = c);
            var gCurve = CreateCurveField(() => curveNode.greenCurve, c => curveNode.greenCurve = c);
            var bCurve = CreateCurveField(() => curveNode.blueCurve, c => curveNode.blueCurve = c);
            var aCurve = CreateCurveField(() => curveNode.alphaCurve, c => curveNode.alphaCurve = c);

            rCurve.AddToClassList("red");
            gCurve.AddToClassList("green");
            bCurve.AddToClassList("blue");
            aCurve.AddToClassList("white");

            controlsContainer.Add(rCurve);
            controlsContainer.Add(gCurve);
            controlsContainer.Add(bCurve);
            controlsContainer.Add(aCurve);

            if (fromInspector)
            {
                controlsContainer.Add(AddControlField(nameof(CurveNode.evaluationRange), "Evaluation Range", false, () => {
                    curveNode.UpdateTexture();
                    NotifyNodeChanged();
                }));
            }

            modeField.RegisterValueChangedCallback(e => {
                curveNode.mode = (CurveNode.CurveOutputMode)e.newValue;
                owner.RegisterCompleteObjectUndo("Change Curve Mode");
                UpdateVisibleCurves();
                curveNode.UpdateTexture();
                NotifyNodeChanged();
            });
            UpdateVisibleCurves();

            var p = new CustomStyleProperty <Color>("--unity-curve-color");

            void UpdateVisibleCurves()
            {
                rCurve.style.display = DisplayStyle.None;
                gCurve.style.display = DisplayStyle.None;
                bCurve.style.display = DisplayStyle.None;
                aCurve.style.display = DisplayStyle.None;

                switch (curveNode.mode)
                {
                case CurveNode.CurveOutputMode.RRRR:
                case CurveNode.CurveOutputMode.R:
                    rCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RG:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RGB:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    bCurve.style.display = DisplayStyle.Flex;
                    break;

                case CurveNode.CurveOutputMode.RGBA:
                    rCurve.style.display = DisplayStyle.Flex;
                    gCurve.style.display = DisplayStyle.Flex;
                    bCurve.style.display = DisplayStyle.Flex;
                    aCurve.style.display = DisplayStyle.Flex;
                    break;
                }
            }
        }