public string Get(float Wrap){ ShaderGenerate SG = ShaderBase.Current.SG; if (Input!=null) { if (Input.SpecialType!=InputSpecialTypes.None&&!Input.InEditor){ UpdateToInput(false); string[] SInputTypes = new string[]{"None","_SSTime.y","_SSTime.z","_SSTime.y/2","_SSTime.y/6","_SSSinTime.w","sin(_SSTime.z)","_SSSinTime.z","_SSCosTime.w","cos(_SSTime.z)","_SSCosTime.z","SSShellDepth","SSParallaxDepth","((_SSSinTime.w+1)/2)","((sin(_SSTime.z)+1)/2)","((_SSSinTime.z+1)/2)","((_SSCosTime.w+1)/2)","((cos(_SSTime.z)+1)/2)","((_SSCosTime.z+1)/2))"}; if (SG!=null&&!SG.Temp) SInputTypes = new string[]{"None","_Time.y","_Time.z","_Time.y/2","_Time.y/6","_SinTime.w","sin(_Time.z)","_SinTime.z","_CosTime.w","cos(_Time.z)","_CosTime.z","SSShellDepth","SSParallaxDepth","((_SinTime.w+1)/2)","((sin(_Time.z)+1)/2)","((_SinTime.z+1)/2)","((_CosTime.w+1)/2)","((cos(_Time.z)+1)/2)","((_CosTime.z+1)/2)"}; InputSpecialTypes[] EInputTypes2 = new InputSpecialTypes[]{InputSpecialTypes.None,InputSpecialTypes.Time,InputSpecialTypes.TimeFast,InputSpecialTypes.TimeSlow,InputSpecialTypes.TimeVerySlow,InputSpecialTypes.SinTime,InputSpecialTypes.SinTimeFast,InputSpecialTypes.SinTimeSlow,InputSpecialTypes.CosTime,InputSpecialTypes.CosTimeFast,InputSpecialTypes.CosTimeSlow,InputSpecialTypes.ShellDepth,InputSpecialTypes.ParallaxDepth,InputSpecialTypes.ClampedSinTime,InputSpecialTypes.ClampedSinTimeFast,InputSpecialTypes.ClampedSinTimeSlow,InputSpecialTypes.ClampedCosTime,InputSpecialTypes.ClampedCosTimeFast,InputSpecialTypes.ClampedCosTimeSlow}; int Index = Array.IndexOf(EInputTypes2,Input.SpecialType); if (Index!=0) return SInputTypes[Index]; } else if (Input.InEditor||ShaderBase.Current.SG.Temp){ if (!(CType==Types.Float&&Input.Type==1)) return Input.Get(); else return Input.Get()+"."+(new string[]{"r","g","b","a"}[ColorComponent]); } } if (CType==Types.Vec) return "float4("+Vector.r.ToString()+", "+Vector.g.ToString()+", "+Vector.b.ToString()+", "+Vector.a.ToString()+")"; if (CType==Types.Float&&Wrap==0) return Float.ToString(); else if (CType==Types.Float) return (Float%Wrap).ToString(); return "Error"; }
void GUIInputs(Vector2 WinSize,Vector2 Position) { ShaderUtil.BeginGroup(new Rect(Position.x,Position.y,WinSize.x,WinSize.y)); if (OpenShader==null) { GUIStage = GUIType.Start; GUITrans.Reset(); } else { if (InputSwitch==null||InputSwitch.Count!=6){ InputSwitch = new Dictionary<string,bool>(); InputSwitch.Add("Type",false); InputSwitch.Add("Type2",false); InputSwitch.Add("Name",false); InputSwitch.Add("In Editor",false); InputSwitch.Add("Replacement",false); InputSwitch.Add("Value",false); } GUIStyle ButtonStyle = new GUIStyle(GUI.skin.button); ButtonStyle.fontSize = 20; if (GUI.Button( ShaderUtil.Rect2(RectDir.Diag,WinSize.x,WinSize.y,100,30),"Layers",ButtonStyle)) Goto(GUIType.Layers,ShaderTransition.TransDir.Forward); // int XX; // int YY; int X = -1; // int PerWidth = 3; GUI.skin.GetStyle("ButtonLeft").alignment = TextAnchor.MiddleLeft; GUI.skin.GetStyle("ButtonRight").alignment = TextAnchor.MiddleLeft; GUI.skin.GetStyle("ButtonMid").alignment = TextAnchor.MiddleLeft; //SeeShells = !GUI.Toggle(new Rect(251,10,100,25),!SeeShells,new GUIContent("Base",IconBase),GUI.skin.GetStyle("ButtonLeft")); //bool GUIChanged = GUI.changed; if (GUI.Button(new Rect(20,6,100,25),new GUIContent("Type"),GUI.skin.GetStyle("ButtonLeft"))){ if (!InputSwitch["Type"]) OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderBy(o=>o.Type).ToList(); else OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderByDescending(o=>o.Type).ToList(); InputSwitch["Type"] = !InputSwitch["Type"]; } if (GUI.Button(new Rect(120,6,90,25),new GUIContent("Fallback"),GUI.skin.GetStyle("ButtonMid"))){ if (!InputSwitch["Type2"]) OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderBy(o=>o.Type).ToList(); else OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderByDescending(o=>o.Type).ToList(); InputSwitch["Type2"] = !InputSwitch["Type2"]; } if (GUI.Button(new Rect(210,6,150,25),new GUIContent("Name"),GUI.skin.GetStyle("ButtonMid"))){ if (!InputSwitch["Name"]) OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderBy(o=>o.VisName).ToList(); else OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderByDescending(o=>o.VisName).ToList(); InputSwitch["Name"] = !InputSwitch["Name"]; } if (GUI.Button(new Rect(360,6,60,25),new GUIContent("Visible"),GUI.skin.GetStyle("ButtonMid"))){ if (!InputSwitch["In Editor"]) OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderBy(o=>o.InEditor).ToList(); else OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderByDescending(o=>o.InEditor).ToList(); InputSwitch["In Editor"] = !InputSwitch["In Editor"]; } if (GUI.Button(new Rect(420,6,140,25),new GUIContent("Replacement"),GUI.skin.GetStyle("ButtonRight"))){ if (!InputSwitch["Replacement"]) OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderBy(o=>o.SpecialType).ToList(); else OpenShader.ShaderInputs = OpenShader.ShaderInputs.OrderByDescending(o=>o.SpecialType).ToList(); InputSwitch["Replacement"] = !InputSwitch["Replacement"]; } if (GUI.Button(new Rect(WinSize.x-160,6,140,25),"Clean Inputs")){ List<ShaderVar> SVs = new List<ShaderVar>(); foreach (ShaderLayer SL in ShaderUtil.GetAllLayers()){ SL.UpdateShaderVars(true); SVs.AddRange(SL.ShaderVars); } SVs.AddRange(OpenShader.GetMyShaderVars()); foreach(ShaderInput SI in OpenShader.ShaderInputs){ SI.UsedCount = 0; foreach(ShaderVar SV in SVs){ if (SV.Input==SI) SI.UsedCount+=1; } } for (int i = OpenShader.ShaderInputs.Count-1;i>-1;i--){ ShaderInput SI = OpenShader.ShaderInputs[i]; if (SI.UsedCount==0){ OpenShader.ShaderInputs.Remove(SI); foreach(ShaderVar SV in SVs){ if (SV.Input==SI) SV.Input = null; } } } EditorGUIUtility.ExitGUI(); } // GUI.changed = GUIChanged; ButtonStyle = new GUIStyle(GUI.skin.button); ButtonStyle.padding = new RectOffset(0,0,0,0); ButtonStyle.margin = new RectOffset(0,0,0,0); if ((OpenShader.ShaderInputs.Count*50+36)>WinSize.y) InputScroll = ShaderUtil.BeginScrollView(new Rect(0,36,WinSize.x,WinSize.y-36),InputScroll,new Rect(0,0,230,OpenShader.ShaderInputs.Count*50),false,true); else ShaderUtil.BeginGroup(new Rect(0,36,WinSize.x,WinSize.y-36)); foreach(ShaderInput SI in OpenShader.ShaderInputs){ X++;//5 //XX = X % PerWidth;//1 0,1,2,0,1 //YY = (int)Mathf.Floor((float)X/(float)PerWidth);//1 //ShaderUtil.DrawEffects(new Rect(0,0,350,350),SI.InputEffects,SelectedEffect); //if (SI.AutoCreated) //GUI.enabled = false; ShaderUtil.BeginGroup(new Rect(20,X*50,WinSize.x-40,40),"button"); if (SI.Type!=3&&SI.Type!=4){ GUI.enabled = false; SI.Type = EditorGUI.IntPopup(new Rect(10,10,80,20),SI.Type,new string[]{"Color","Image","Cubemap","Float","Range"},new int[]{1,0,2,3,4},GUI.skin.GetStyle("MiniPopup")); GUI.enabled = true; } else{ SI.Type = EditorGUI.IntPopup(new Rect(10,10,80,20),SI.Type,new string[]{"Float","Range"},new int[]{3,4},GUI.skin.GetStyle("MiniPopup")); } //None,MainColor,MainTexture,BumpMap,MainCubemap,SpecularColor,Shininess,ReflectColor,Parallax,ParallaxMap string[] SInputTypes = new string[0]; InputMainTypes[] EInputTypes = new InputMainTypes[0]; SInputTypes = new string[]{"None"}; EInputTypes = new InputMainTypes[]{InputMainTypes.None}; if (SI.Type==0){ SInputTypes = new string[]{"None","Main Texture","Normal Map","Parallax Map","Terrain/Control","Terrain/Splat 0","Terrain/Splat 1","Terrain/Splat 2","Terrain/Splat 3","Terrain/Normal 0","Terrain/Normal 1","Terrain/Normal 2","Terrain/Normal 3"}; EInputTypes = new InputMainTypes[]{InputMainTypes.None,InputMainTypes.MainTexture,InputMainTypes.BumpMap,InputMainTypes.ParallaxMap,InputMainTypes.TerrainControl,InputMainTypes.TerrainSplat0,InputMainTypes.TerrainSplat1,InputMainTypes.TerrainSplat2,InputMainTypes.TerrainSplat3,InputMainTypes.TerrainNormal0,InputMainTypes.TerrainNormal1,InputMainTypes.TerrainNormal2,InputMainTypes.TerrainNormal3}; } if (SI.Type==1){ SInputTypes = new string[]{"None","Main Color","Specular Color","Reflect Color"}; EInputTypes = new InputMainTypes[]{InputMainTypes.None,InputMainTypes.MainColor,InputMainTypes.SpecularColor,InputMainTypes.ReflectColor}; } if (SI.Type==2){ SInputTypes = new string[]{"None","Main Cubemap"}; EInputTypes = new InputMainTypes[]{InputMainTypes.None,InputMainTypes.MainCubemap}; } if (SI.Type==3||SI.Type==4){ SInputTypes = new string[]{"None","Shininess","Parallax","Cutoff","Shell Distance"}; EInputTypes = new InputMainTypes[]{InputMainTypes.None,InputMainTypes.Shininess,InputMainTypes.Parallax,InputMainTypes.Cutoff,InputMainTypes.ShellDistance}; } int IndexOfType=0; if (Array.IndexOf(EInputTypes,SI.MainType)!=-1) IndexOfType = Array.IndexOf(EInputTypes,SI.MainType); SI.MainType = EInputTypes[EditorGUI.Popup(new Rect(100,10,80,20),"",IndexOfType,SInputTypes,GUI.skin.GetStyle("MiniPopup"))]; //SI.MainType = (InputMainTypes)EditorGUI.EnumPopup(new Rect(100,10,80,20),"",SI.MainType); SI.VisName = GUI.TextField(new Rect(190,10,140,20),SI.VisName); //if (Event.current.type==EventType.Repaint){ if (SI.Type==0||SI.Type==2){ SI.InEditor = true; GUI.enabled = false; } if (SI.InEditor) SI.InEditor = GUI.Toggle(new Rect(340,10,20,20),SI.InEditor,ShaderSandwich.Tick,ButtonStyle); else SI.InEditor = GUI.Toggle(new Rect(340,10,20,20),SI.InEditor,ShaderSandwich.Cross,ButtonStyle); if (SI.Type==0||SI.Type==2){ GUI.enabled = true; } //None,Time,TimeFast,TimeSlow,SinTime,SinTimeFast,SinTimeSlow,CosTime,CosTimeFast,CosTimeSlow InputSpecialTypes[] EInputTypes2 = new InputSpecialTypes[0]; SInputTypes = new string[]{"None"}; EInputTypes2 = new InputSpecialTypes[]{InputSpecialTypes.None}; if (SI.Type==3||SI.Type==4){ SInputTypes = new string[]{"None","Time/Basic/Standard","Time/Basic/Fast","Time/Basic/Slow","Time/Basic/Very Slow","Time/Sine/Standard","Time/Sine/Fast","Time/Sine/Slow","Time/Cosine/Standard","Time/Cosine/Fast","Time/Cosine/Slow","Time/Clamped Sine/Standard","Time/Clamped Sine/Fast","Time/Clamped Sine/Slow","Time/Clamped Cosine/Standard","Time/Clamped Cosine/Fast","Time/Clamped Cosine/Slow","Depth/Shell","Depth/Parallax Occlusion Mapping"}; EInputTypes2 = new InputSpecialTypes[]{InputSpecialTypes.None,InputSpecialTypes.Time,InputSpecialTypes.TimeFast,InputSpecialTypes.TimeSlow,InputSpecialTypes.TimeVerySlow,InputSpecialTypes.SinTime,InputSpecialTypes.SinTimeFast,InputSpecialTypes.SinTimeSlow,InputSpecialTypes.CosTime,InputSpecialTypes.CosTimeFast,InputSpecialTypes.CosTimeSlow, InputSpecialTypes.ClampedSinTime,InputSpecialTypes.ClampedSinTimeFast,InputSpecialTypes.ClampedSinTimeSlow,InputSpecialTypes.ClampedCosTime,InputSpecialTypes.ClampedCosTimeFast,InputSpecialTypes.ClampedCosTimeSlow,InputSpecialTypes.ShellDepth,InputSpecialTypes.ParallaxDepth}; } IndexOfType=0; if (Array.IndexOf(EInputTypes2,SI.SpecialType)!=-1) IndexOfType = Array.IndexOf(EInputTypes2,SI.SpecialType); if (SI.InEditor){ SI.SpecialType = InputSpecialTypes.None; GUI.enabled = false; EditorGUI.Popup(new Rect(400,10,140,20),"",IndexOfType,SInputTypes,GUI.skin.GetStyle("MiniPopup")); GUI.enabled = true; } else SI.SpecialType = EInputTypes2[EditorGUI.Popup(new Rect(400,10,140,20),"",IndexOfType,SInputTypes,GUI.skin.GetStyle("MiniPopup"))]; GUI.enabled = true; if (SI.Type==3){//Float SI.Number = EditorGUI.FloatField(new Rect(550,10,120,20),"",SI.Number,GUI.skin.textField); } if (SI.Type==4){//Range SI.Range0 = EditorGUI.FloatField(new Rect(550,10,30,20),"",SI.Range0,GUI.skin.textField); SI.Number = GUI.HorizontalSlider(new Rect(590,10,40,20),SI.Number,SI.Range0,SI.Range1); SI.Range1 = EditorGUI.FloatField(new Rect(640,10,30,20),"",SI.Range1,GUI.skin.textField); } Color OldColor = GUI.backgroundColor; //GUI.color = new Color(1,1,1,1); GUI.backgroundColor = new Color(1,1,1,1); if (SI.Type==0){//Image SI.Image = (Texture2D) EditorGUI.ObjectField (new Rect(550,10,120,20),SI.ImageS(), typeof (Texture2D),false); } if (SI.Type==1){//Color SI.Color = (ShaderColor)EditorGUI.ColorField(new Rect(550,10,140,20),"",(Color)SI.Color); } if (SI.Type==2){//Cubemap SI.Cube = (Cubemap) EditorGUI.ObjectField (new Rect(550,10,120,20),SI.CubeS(), typeof (Cubemap),false); } GUI.backgroundColor = OldColor; if (SI.Type==0){ GUI.Label(new Rect(680,10,200,20),"Normal Map: "); if (SI.NormalMap) SI.NormalMap = GUI.Toggle(new Rect(770,10,20,20),SI.NormalMap,ShaderSandwich.Tick,ButtonStyle); else SI.NormalMap = GUI.Toggle(new Rect(770,10,20,20),SI.NormalMap,ShaderSandwich.Cross,ButtonStyle); } //InputSpecialTypes //UnityEngine.Debug.Log("ASD"); if (X==0) GUI.enabled = false; if (GUI.Button(new Rect(WinSize.x-40-75,10,20,20),UPArrow,ButtonStyle)) { ShaderUtil.MoveItem(ref OpenShader.ShaderInputs,X,X-1);//MoveLayerUp = Pos; EditorGUIUtility.ExitGUI(); } GUI.enabled = true; if (GUI.Button(new Rect(WinSize.x-40-50,10,20,20),CrossRed,ButtonStyle)) { OpenShader.ShaderInputs.RemoveAt(X); List<ShaderVar> SVs = new List<ShaderVar>(); foreach (ShaderLayer SL in ShaderUtil.GetAllLayers()){ SL.UpdateShaderVars(true); SVs.AddRange(SL.ShaderVars); } SVs.AddRange(OpenShader.GetMyShaderVars()); foreach(ShaderVar SV in SVs){ if (SV.Input==SI) SV.Input = null; } //UEObject.DestroyImmediate(SL,false); EditorGUIUtility.ExitGUI(); } if (X>=OpenShader.ShaderInputs.Count-1) GUI.enabled = false; if (GUI.Button(new Rect(WinSize.x-40-25,10,20,20),DOWNArrow,ButtonStyle)) { //Pos2+=1; ShaderUtil.MoveItem(ref OpenShader.ShaderInputs,X,X+1);//MoveLayerDown = Pos; EditorGUIUtility.ExitGUI(); } GUI.enabled = true; //SI.InEditor = GUI.Toggle(new Rect(250,10,20,20),SI.InEditor); ShaderUtil.EndGroup(); GUI.enabled = true; } if ((OpenShader.ShaderInputs.Count*50+36)>WinSize.y) ShaderUtil.EndScrollView(); else ShaderUtil.EndGroup(); /*Features: Editor Inputs Inputs: (Composed of editor inputs and custom values) Can apply effects to inputs Interface: Two Tabs: Primary and secondary inputs. */ ChangeSaveTemp(null,true); ButtonStyle.fontSize = 20; //if (GUI.Button( ShaderUtil.Rect2(RectDir.Diag,WinSize.x,WinSize.y,100,30),"Layers",ButtonStyle)) // Goto(GUIType.Layers,ShaderTransition.TransDir.Forward); GUI.Toggle( ShaderUtil.Rect2(RectDir.Diag,WinSize.x,WinSize.y,100,30),GUIMouseHold&&(ShaderUtil.Rect2(RectDir.Diag,WinSize.x,WinSize.y,100,30).Contains(Event.current.mousePosition)),"Layers",ButtonStyle); } ShaderUtil.EndGroup(); }