Exemplo n.º 1
0
        protected void ShowTitle()
        {
            if ((this is SWNodeRoot) || !titleEditing)
            {
                GUI.Label(rectTop, data.name, SWEditorUI.Style_Get(SWCustomStyle.eNodeTitle));
                if (Event.current.type == EventType.MouseUp &&
                    rectTop.Contains(Event.current.mousePosition))
                {
                    titleEditing = true;
                    nameEditing  = data.name;
                }
            }
            else
            {
                if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return)
                {
                    titleEditing = false;

                    nameEditing = SWRegex.NameLegal(nameEditing);
                    if (NameUnique(nameEditing))
                    {
                        data.name = SWRegex.NameLegal(nameEditing);
                    }
                }
                nameEditing = EditorGUI.TextField(rectTop, nameEditing, SWEditorUI.Style_Get(SWCustomStyle.eNodeTitle));
            }
        }
Exemplo n.º 2
0
        public void EndTitleEditing()
        {
            titleEditing = false;

            nameEditing = SWRegex.NameLegal(nameEditing);
            if (NameUnique(nameEditing))
            {
                data.name = SWRegex.NameLegal(nameEditing);
            }
        }
Exemplo n.º 3
0
        public virtual string TextureShaderName()
        {
            if (SWWindowMain.Instance.nRoot.texture != null && texture == SWWindowMain.Instance.nRoot.texture)
            {
                return("MainTex");
            }

            string name = textureDuplicatedSuffix == 0 ? SWRegex.NameLegal(Texture.name) : SWRegex.NameLegal(Texture.name) + "_" + textureDuplicatedSuffix;

            return(name);
        }
Exemplo n.º 4
0
        protected void ShowTitle()
        {
            GUILayout.BeginHorizontal();
            if (!titleEditing)
            {
                GUILayout.Space(spacing);
                GUILayout.Label(nodeCode.dataCode.name, SWEditorUI.Style_Get(SWCustomStyle.eTxtLight));

                if (Event.current.type == EventType.MouseUp &&
                    GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    titleEditing = true;
                    nameEditing  = nodeCode.dataCode.name;
                }
            }
            else
            {
                GUILayout.Space(spacing + 2);
                if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Return)
                {
                    titleEditing = false;

                    nameEditing = SWRegex.NameLegal(nameEditing);
                    if (CodeNameUnique(nameEditing))
                    {
                        SWUndo.Record(this);
                        SWUndo.Record(nodeCode);
                        Code_SetName(nameEditing);
                    }
                }
                nameEditing = EditorGUILayout.TextField(nameEditing, SWEditorUI.Style_Get(SWCustomStyle.eTxtLight));
            }

            if (GUILayout.Button("D", GUILayout.Width(22)))
            {
                SWUndo.Record(this);
                SWUndo.Record(nodeCode);
                Code_Duplicate(nodeCode.dataCode);
            }
            Tooltip_Rec(SWTipsText.Code_Duplicate);


            if (GUILayout.Button("-", GUILayout.Width(22)))
            {
                SWUndo.Record(this);
                SWUndo.Record(nodeCode);
                Code_Remove();
            }
            Tooltip_Rec(SWTipsText.Code_Delete);
            GUILayout.EndHorizontal();
        }
Exemplo n.º 5
0
 public string TextureShaderName_NormalMap()
 {
     return(SWRegex.NameLegal(textureNormalMap.name));
 }
Exemplo n.º 6
0
        protected void Factor_CustomParamCreation()
        {
            paramNameLastDeleted = "";
            DrawModuleTitle("Custom Parameters");
            Rect lastRect = GUILayoutUtility.GetLastRect();
            Rect rect     = new Rect(lastRect.x, lastRect.y, lastRect.width + SWGlobalSettings.FieldWidth, lastRect.height + rightUpUnitHeight);

            Tooltip_Rec(SWTipsText.Right_CustomParam, rect);

            paramName = EditorGUILayout.TextField(paramName, GUILayout.Width(100));


            GUILayout.BeginHorizontal();
            if (GUILayout.Button("New Float", GUILayout.Width(80)))
            {
                paramName = SWRegex.NameLegal(paramName);
                if (ParamNameUnique(paramName))
                {
                    SWParam pa = new SWParam();
                    pa.type = SWParamType.FLOAT;
                    pa.name = paramName;
                    SWWindowMain.Instance.data.paramList.Add(pa);
                }
                paramName = "";
            }
            if (GUILayout.Button("New Range", GUILayout.Width(80)))
            {
                paramName = SWRegex.NameLegal(paramName);
                if (ParamNameUnique(paramName))
                {
                    SWParam pa = new SWParam();
                    pa.type = SWParamType.RANGE;
                    pa.name = paramName;
                    SWWindowMain.Instance.data.paramList.Add(pa);
                }
                paramName = "";
            }
            GUILayout.EndHorizontal();


            int toDeleteId = -1;

            for (int i = 0; i < SWWindowMain.Instance.data.paramList.Count; i++)
            {
                //GUILayout.Space (SWGlobalSettings.UIGap);
                var item = SWWindowMain.Instance.data.paramList[i];
                GUILayout.BeginHorizontal();
                float nameWidth = 64f;
                GUILayout.Label(item.name, SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(nameWidth));
                if (item.type == SWParamType.RANGE)
                {
                    var f = EditorGUILayout.FloatField(item.defaultValue, GUILayout.Width(30));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }

                    f = GUILayout.HorizontalSlider(item.defaultValue, item.min, item.max, GUILayout.Width(40));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }


                    GUILayout.Label("Min", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(22));
                    item.min = EditorGUILayout.FloatField("", item.min, GUILayout.Width(25));
                    GUILayout.Label("Max", SWEditorUI.Style_Get(SWCustomStyle.eTxtSmallLight), GUILayout.Width(26));
                    item.max = EditorGUILayout.FloatField("", item.max, GUILayout.Width(25));
                }
                if (item.type == SWParamType.FLOAT)
                {
                    var f = EditorGUILayout.FloatField(item.defaultValue, GUILayout.Width(rightupWidth - nameWidth - SWGlobalSettings.UIGap * 2 - 18 - 2));
                    if (f != item.defaultValue)
                    {
                        item.defaultValue = f;
                        SWProperties.SetFloat(item.name, item.defaultValue);
                    }
                }

                lastRect = GUILayoutUtility.GetLastRect();

                if (GUI.Button(new Rect(position.width - 33 - SWGlobalSettings.UIGap, lastRect.y, 18, 17), "X"))
                {
                    toDeleteId = i;
                }
                GUILayout.EndHorizontal();
            }
            if (toDeleteId >= 0)
            {
                paramNameLastDeleted = SWWindowMain.Instance.data.paramList[toDeleteId].name;
                SWWindowMain.Instance.data.paramList.RemoveAt(toDeleteId);
            }
        }
        public override SWOutput Process(SWNodeBase _node)
        {
            //1: init
            node = _node;
            Child_Process();
            CommentHead();

            //2: port belong
            PortBelong();
            SWOutputSub[] subs = new SWOutputSub[node.data.childPortNumber];
            foreach (var op in childOutputs)
            {
                foreach (var item in op.outputs)
                {
                    int port = portBelongs [item.node.data.id];
                    subs [port] = item;
                }
            }

            //3: param
            var dataCode = SWWindowMain.Instance.dataCode.CodeOfName(node.data.code);

            string param = string.Format("v{0}", node.data.iName);

            if (dataCode.output.GetType() == SWDataType._Color)
            {
                StringAddLine(string.Format("\t\t\t\tfloat4 {0} = float4(0,0,0,0);", param));
            }
            else if (dataCode.output.GetType() == SWDataType._UV)
            {
                StringAddLine(string.Format("\t\t\t\tfloat2 {0} = float2(0,0);", param));
            }
            else if (dataCode.output.GetType() == SWDataType._Alpha)
            {
                StringAddLine(string.Format("\t\t\t\tfloat {0} = 0;", param));
            }

            List <string> list      = new List <string> ();
            int           portIndex = 0;

            for (int i = 0; i < dataCode.inputs.Count; i++)
            {
                var    item = dataCode.inputs [i];
                string str  = "";
                if (item.IsParam())
                {
                    var paramUse = node.data.GetCodeParamUse(item.name);
                    if (item.type == CodeParamType.CustomParam)
                    {
                        str = paramUse.v;
                    }
                    else
                    {
                        str = string.Format("{0}_{1}", node.data.iName, paramUse.n);
                    }
                }
                else
                {
                    str = subs[portIndex].param + "*" + subs[portIndex].opFactor;
                    portIndex++;
                }
                list.Add(str);
            }

            if (dataCode.IsFunction())
            {
                string func = dataCode.name + "(";
                for (int i = 0; i < dataCode.inputs.Count; i++)
                {
                    if (i != 0)
                    {
                        func += ",";
                    }
                    func += list[i];
                }
                func += ")";

                StringAddLine(string.Format("\t\t\t\t{0} = {1};", param, func));
            }
            else
            {
                string content = "\t\t\t\t" + dataCode.code;
                content = content.Replace("\n", "\n\t\t\t\t");
                for (int i = 0; i < dataCode.inputs.Count; i++)
                {
                    content = SWRegex.ReplaceWord(content, dataCode.inputs[i].name, list[i]);
                }
                content = SWRegex.ReplaceWord(content, dataCode.output.name, param);
                StringAddLine(content);
            }



            SWOutputSub sub = new SWOutputSub();

            sub.processor = this;

            sub.type = node.data.GetCodeType();
            //sub.type = window.data.CodeOfName(node.data.code).output.type;
            sub.param = param;

            if (sub.type == SWDataType._Color)
            {
                sub.data     = new SWDataNode(SWNodeType.color);
                sub.depth    = node.data.depth;
                sub.op       = node.data.effectDataColor.op;
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataColor.param);
            }
            else if (sub.type == SWDataType._UV)
            {
                sub.data     = new SWDataNode(SWNodeType.uv);
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataUV.param);
                sub.uvOp     = node.data.effectDataUV.op;
            }
            else if (sub.type == SWDataType._Alpha)
            {
                sub.data     = new SWDataNode(SWNodeType.alpha);
                sub.op       = node.data.effectDataColor.op;
                sub.opFactor = string.Format("{0}*({1})", sub.opFactor, node.data.effectDataColor.param);
                sub.data.effectData.pop_final = node.data.effectData.pop_final;
            }
            sub.data.id = node.data.id;

            SWOutput result = new SWOutput();

            result.outputs.Add(sub);
            return(result);
        }