//[MenuItem ("Window/ObjFieldTest")] public static void Init () { //ShaderObjectField windowG = (ShaderObjectField)EditorWindow.GetWindow (typeof (ShaderObjectField)); ShaderObjectField windowG = new ShaderObjectField(); windowG.ShowAuxWindow(); //windowG.wantsMouseMove = true; //windowG.minSize = new Vector2(750,360); }
bool Draw_Real(Rect rect,DrawTypes d,string S) { if (ForceGUIChange==true){ ForceGUIChange = false; GUI.changed = true; } LastUsedRect = SU.AddRectVector(rect,ShaderUtil.GetGroupVector()); bool RetVal = false; Rect InitialRect = rect; Color oldCol = GUI.backgroundColor; ShaderColor OldVector = Vector; RetVal = UpdateToInput(false); if (d == DrawTypes.Type) { if (ImagePaths==null||ImagePaths.Length==0){ rect.height*=Mathf.Ceil((float)Names.Length/(float)TypeDispL); int oldType = Type; Type = GUI.SelectionGrid(rect,Type,Names,TypeDispL); if (Type!=oldType) RetVal = true; rect.y+=rect.height; rect.height+=20; SU.Label(rect,Descriptions[Type],12); } else { //GUI.backgroundColor = new Color(0,0,0,1); if (Type>=Names.Length) Type = 0; if (Type<0) Type = Names.Length-1; GUI.Box(rect,"",GUI.skin.button); if (Images==null)Images = new Texture2D[ImagePaths.Length]; if (Images[Type]==null)Images[Type] = EditorGUIUtility.Load("Shader Sandwich/"+ImagePaths[Type]) as Texture2D; if (ImagePaths[Type]!=""){ GUI.DrawTexture( rect ,Images[Type]); GUI.DrawTexture( rect ,Images[Type]); GUI.DrawTexture( rect ,Images[Type]); GUI.DrawTexture( rect ,Images[Type]); } rect.y+=rect.height-20; rect.height = 20; GUI.Box(rect,"",GUI.skin.button); GUI.skin.label.alignment = TextAnchor.UpperCenter; SU.Label(rect,Names[Type],12); GUI.skin.label.alignment = TextAnchor.UpperLeft; rect.y+=20;//rect.height; rect.height = 30; rect.width = 40; if(GUI.Button( rect ,ShaderSandwich.LeftArrow))Type-=1; rect.x+=InitialRect.width-40; if(GUI.Button( rect ,ShaderSandwich.RightArrow))Type+=1; if (Type>=Names.Length) Type = 0; if (Type<0) Type = Names.Length-1; } } else { if (S!="") { if (d != DrawTypes.Toggle) DrawGear(rect); GUI.backgroundColor = Color.white; SU.Label(rect,S,12); //UseInput = GUI.Toggle(new Rect(rect.x+120,rect.y+2,20,20),UseInput,""); rect.x+=LabelOffset; rect.width-=LabelOffset; } GUI.backgroundColor = Color.white; if (d == DrawTypes.Slider01){ GUI.backgroundColor = new Color(0.2f,0.2f,0.2f,1f); if (NoSlider==false){ //if (S!="") rect.width-=60-20; EditorGUI.BeginChangeCheck(); Float = GUI.HorizontalSlider (rect,Float, Range0, Range1); if (EditorGUI.EndChangeCheck()) EditorGUIUtility.editingTextField = false; //if (S!="") { //rect.width+=10; Float = EditorGUI.FloatField( new Rect(rect.x+rect.width+10,rect.y,30,20),Float,ShaderUtil.EditorFloatInput); } } else { rect.x-=5; rect.width+=6; EditorGUIUtility.labelWidth = 30; if (NoArrows) Float = EditorGUI.FloatField( rect,Float,ShaderUtil.EditorFloatInput); else Float = EditorGUI.FloatField( rect,"<>",Float,ShaderUtil.EditorFloatInput); EditorGUIUtility.labelWidth = 0; //GUI.Box(rect,""); } } if (d == DrawTypes.Color){ Vector = new ShaderColor(EditorGUI.ColorField (rect,Vector.ToColor())); if (!OldVector.Cmp(Vector)) RetVal = true; } if (d == DrawTypes.Texture){ if (Image==null) Image = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(ImageGUID),typeof(Texture2D)); Texture2D oldImage = Image; Image = (Texture2D) EditorGUI.ObjectField (rect,Image, typeof (Texture2D),false); ImageGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Image)); if (oldImage!=Image) RetVal = true; } if (d == DrawTypes.Cubemap){ if (Cube==null) Cube = (Cubemap)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(CubeGUID),typeof(Cubemap)); Cubemap oldCube = Cube; Cube = (Cubemap) EditorGUI.ObjectField (rect,Cube, typeof (Cubemap),false); CubeGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Cube)); if (oldCube!=Cube) RetVal = true; } if (d == DrawTypes.Toggle){ //Debug.Log("Toggle!"); rect.x-=30;//+=(rect.width-50); rect.width = 17; rect.height = 17; GUI.backgroundColor = new Color(0.2f,0.2f,0.2f,1f); GUIStyle ButtonStyle = new GUIStyle(GUI.skin.button); ButtonStyle.padding = new RectOffset(0,0,0,0); ButtonStyle.margin = new RectOffset(0,0,0,0); if (On) On = GUI.Toggle(rect,On,ShaderSandwich.Tick,ButtonStyle); else On = GUI.Toggle(rect,On,ShaderSandwich.Cross,ButtonStyle); //On = EditorGUI.Toggle (rect,On); } if (d == DrawTypes.ObjectArray){ if (Event.current.type == EventType.Repaint) GUI.skin.GetStyle("ObjectFieldThumb").Draw(rect, false, false, false,ObjFieldOn); if ((ObjField!=null)){ //GUIUtility.hotControl = 0; ObjFieldOn = true; } if (ShaderSandwich.GUIMouseDown&&(rect.Contains(Event.current.mousePosition))) ObjFieldOn = true; if (GUIUtility.hotControl != 0&&ObjField==null) ObjFieldOn = false; //GUI.skin.GetStyle("ObjectFieldThumb").Draw(rect, bool isHover, bool isActive, bool on, bool hasKeyboardFocus); Rect newRect = rect; newRect.width-=2; newRect.height-=2; newRect.y+=1; newRect.x+=1; if (Obj!=null) GUI.DrawTexture(newRect,ObjFieldImage[Selected]); rect.x+=rect.width-32; rect.width = 32; rect.y+=rect.height-8; rect.height = 8; if (GUI.Button(rect,"Select",GUI.skin.GetStyle("ObjectFieldThumbOverlay2"))){ if (RGBAMasks){ ObjField = ShaderObjectField.Show(this,"Select Mask (RGBA Masks Only!)",ObjFieldObject,ObjFieldImage,ObjFieldEnabled,Selected); ObjField.SomethingOtherThanAMask = true; } else ObjField = ShaderObjectField.Show(this,"Select Mask",ObjFieldObject,ObjFieldImage,ObjFieldEnabled,Selected); } } } UpdateToVar(); GUI.backgroundColor = oldCol; if (RetVal&&OnChange!=null) OnChange(); return RetVal; }