public static GradientColorKey[] ToGradientColorKeys(SerializableGradientColorKey[] incoming)
 {
     GradientColorKey[] keys = new GradientColorKey[incoming.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = incoming[i].ToGradientColorKey();
     return keys;
 }
 public static SerializableGradientColorKey[] FromGradientColorKeys(GradientColorKey[] ks)
 {
     SerializableGradientColorKey[] keys = new SerializableGradientColorKey[ks.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = new SerializableGradientColorKey(ks[i]);
     return keys;
 }
Пример #3
0
        private void ColorGUI()
        {
            // color type selection
            colorNode.type = (ColorNode.COLORTYPE)EditorGUILayout.EnumPopup(colorNode.type);
            if (colorNode.type != colorNode.lastType)
            {
                colorNode.SetInputs();
                UpdatePreview();
                colorNode.lastType = colorNode.type;
                node.title         = colorNode.type.ToString();
            }
            node.rect.height += controlHeight * 1.5f;

            switch (colorNode.type)
            {
            case ColorNode.COLORTYPE.GRADIENT:
                gradient = GUIGradientField.GradientField(gradient);

                //colorNode.gradient = (Gradient)gradient.GradientData;
                colorNode.gradientColorKeys = SerializableGradientColorKey.FromGradientColorKeys(colorNode.gradient.colorKeys);
                colorNode.gradientAlphaKeys = SerializableGradientAlphaKey.FromGradientColorKeys(colorNode.gradient.alphaKeys);

                node.rect.height += controlHeight * 1.5f;
                break;

            case ColorNode.COLORTYPE.COLOR:
                colorNode.color.FromColor(EditorGUILayout.ColorField(colorNode.color.ToColor()));
                break;
            }
        }
Пример #4
0
 public static SerializableGradientColorKey[] FromGradientColorKeys(GradientColorKey[] ks)
 {
     SerializableGradientColorKey[] keys = new SerializableGradientColorKey[ks.Length];
     for (int i = 0; i < keys.Length; i++)
     {
         keys[i] = new SerializableGradientColorKey(ks[i]);
     }
     return(keys);
 }
Пример #5
0
        public ColorNode(int x, int y) : base("Color Node", new SerializableRect(x, y, 200, 150))
        {
            type = lastType = ColorNode.COLORTYPE.COLOR;

            gradient = new Gradient();
            if (gradientColorKeys != null && gradientAlphaKeys != null)
            {
                gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys);
                gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys);
            }

            color = new SerializableColor(Color.black);

            SetInputs();
        }
Пример #6
0
        override public ModuleBase GetModule()
        {
            // check that has inputs
            if (type != COLORTYPE.COLOR)
            {
                for (int i = 0; i < inputs.Length; i++)
                {
                    if (inputs[i] == null)
                    {
                        return(null);
                    }
                }
            }

            // get module
            switch (type)
            {
            case COLORTYPE.GRADIENT:
                if (gradient == null)
                {
                    gradient = new Gradient();
                    if (gradientColorKeys != null)
                    {
                        gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(gradientColorKeys);
                    }
                    if (gradientAlphaKeys != null)
                    {
                        gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(gradientAlphaKeys);
                    }
                }
                if (gradientColorKeys == null)
                {
                    gradientColorKeys = SerializableGradientColorKey.FromGradientColorKeys(gradient.colorKeys);
                }
                if (gradientAlphaKeys == null)
                {
                    gradientAlphaKeys = SerializableGradientAlphaKey.FromGradientColorKeys(gradient.alphaKeys);
                }

                module = new GradientModule(inputs[0].GetModule(), gradient);
                break;

            case COLORTYPE.ADD:
                module = new AddColorModule(inputs[0].GetModule(), inputs[1].GetModule());
                break;

            case COLORTYPE.MULTIPLY:
                module = new MultiplyColorModule(inputs[0].GetModule(), inputs[1].GetModule());
                break;

            case COLORTYPE.BLEND:
                module = new BlendColorModule(inputs[0].GetModule(), inputs[1].GetModule(), inputs[2].GetModule());
                break;

            case COLORTYPE.COLOR:
                module = new ColorSource(color.ToColor());
                break;

            case COLORTYPE.OVERLAY:
                module = new OverlayColorModule(inputs[0].GetModule(), inputs[1].GetModule());
                break;
            }

            SetOutputOptions();

            return(this.module);
        }
Пример #7
0
        public NodeWindow(Node node)
        {
            this.windowIndex = indexCount;
            indexCount++;

            // cast to specific type
            if (node is GeneratorNode)
            {
                generatorNode = (GeneratorNode)node;
                type          = WINDOWTYPE.GENERATOR;
                node.title    = generatorNode.type.ToString();
            }
            if (node is OperatorNode)
            {
                operatorNode = (OperatorNode)node;
                type         = WINDOWTYPE.OPERATOR;
                node.title   = operatorNode.type.ToString();
            }
            if (node is OutputNode)
            {
                outputNode  = (OutputNode)node;
                type        = WINDOWTYPE.OUTPUT;
                previewSize = PreviewSize.x2;
            }
            if (node is MacroNode)
            {
                macroNode = (MacroNode)node;
                type      = WINDOWTYPE.MACRO;
            }
            if (node is TextureNode)
            {
                textureNode = (TextureNode)node;
                type        = WINDOWTYPE.TEXTURE;
            }
            if (node is ColorNode)
            {
                colorNode = (ColorNode)node;

                if (colorNode.gradient == null)
                {
                    colorNode.gradient = new Gradient();
                    if (colorNode.gradientColorKeys != null)
                    {
                        colorNode.gradient.colorKeys = SerializableGradientColorKey.ToGradientColorKeys(colorNode.gradientColorKeys);
                        colorNode.gradient.alphaKeys = SerializableGradientAlphaKey.ToGradientColorKeys(colorNode.gradientAlphaKeys);
                    }
                    gradient = new GradientWrapper();
                    gradient.GradientData = colorNode.gradient;
                }

                type = WINDOWTYPE.COLOR;
            }

            // also save general reference
            this.node = node;

            // random connection color
            connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

            UpdatePreview();
            node.rect.height = controlHeight + (int)previewSize;
            node.rect.width  = (int)previewSize + 20;
            if (node.rect.width < 200)
            {
                node.rect.width = 200;
            }
        }