UnityEngine.GUILayout.Button(UnityEngine.GUIContent, UnityEngine.GUIStyle, params UnityEngine.GUILayoutOption[])

Here are the examples of the csharp api UnityEngine.GUILayout.Button(UnityEngine.GUIContent, UnityEngine.GUIStyle, params UnityEngine.GUILayoutOption[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

904 Examples 7

19 View Source File : CheckResources.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
		{
				if (GUILayout.Button ("Refresh"))
						CheckResources ();
				GUILayout.BeginHorizontal ();
				GUILayout.Label ("Materials " + ActiveMaterials.Count);
				GUILayout.Label ("Textures " + ActiveTextures.Count + " - " + FormatSizeString (TotalTextureMemory));
				GUILayout.Label ("Meshes " + ActiveMeshDetails.Count + " - " + TotalMeshVertices + " verts");
				GUILayout.EndHorizontal ();
				ActiveInspectType = (InspectType)GUILayout.Toolbar ((int)ActiveInspectType, inspectToolbarStrings);
		
				ctrlPressed = Event.current.control || Event.current.command;
		
				switch (ActiveInspectType) {
				case InspectType.Textures:
						ListTextures ();
						break;
				case InspectType.Materials:
						ListMaterials ();
						break;
				case InspectType.Meshes:
						ListMeshes ();
						break;	
			
			
				}
		}

19 View Source File : BMFontTool.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI()
    {
        targetFont = EditorGUILayout.ObjectField("Target Font", targetFont, typeof(Font), false) as Font;
        fntData = EditorGUILayout.ObjectField("Fnt Data", fntData, typeof(Textreplacedet), false) as Textreplacedet;
        fontMaterial = EditorGUILayout.ObjectField("Font Material", fontMaterial, typeof(Material), false) as Material;
        fontTexture = EditorGUILayout.ObjectField("Font Texture", fontTexture, typeof(Texture2D), false) as Texture2D;

        if (GUILayout.Button("CreateFont"))
        {
            fontMaterial.SetTexture(0, fontTexture);//把图片赋给材质球

            Font font = targetFont; //把我们创建的字体加载进来
            XmlDoreplacedent xml = new XmlDoreplacedent();
            xml.Load(replacedetDatabase.GetreplacedetPath(fntData));//这是在BMFont里得到的那个.fnt文件,因为是xml文件,所以我们就用xml来解析
            List<CharacterInfo> chtInfoList = new List<CharacterInfo>();
            XmlNode node = xml.SelectSingleNode("font/chars");
            foreach (XmlNode nd in node.ChildNodes)
            {
                XmlElement xe = (XmlElement)nd;
                int x = int.Parse(xe.GetAttribute("x"));
                int y = int.Parse(xe.GetAttribute("y"));
                int width = int.Parse(xe.GetAttribute("width"));
                int height = int.Parse(xe.GetAttribute("height"));
                int advance = int.Parse(xe.GetAttribute("xadvance"));
                CharacterInfo chtInfo = new CharacterInfo();
                float texWidth = fontTexture.width;
                float texHeight = fontTexture.width;

                chtInfo.glyphHeight = fontTexture.height;
                chtInfo.glyphWidth = fontTexture.width;
                chtInfo.index = int.Parse(xe.GetAttribute("id"));
                //这里注意下UV坐标系和从BMFont里得到的信息的坐标系是不一样的哦,前者左下角为(0,0),
                //右上角为(1,1)。而后者则是左上角上角为(0,0),右下角为(图宽,图高)
                chtInfo.uvTopLeft = new Vector2((float)x / fontTexture.width, 1 - (float)y / fontTexture.height);
                chtInfo.uvTopRight = new Vector2((float)(x + width) / fontTexture.width, 1 - (float)y / fontTexture.height);
                chtInfo.uvBottomLeft = new Vector2((float)x / fontTexture.width, 1 - (float)(y + height) / fontTexture.height);
                chtInfo.uvBottomRight = new Vector2((float)(x + width) / fontTexture.width, 1 - (float)(y + height) / fontTexture.height);

                chtInfo.minX = 0;
                chtInfo.minY = -height;
                chtInfo.maxX = width;
                chtInfo.maxY = 0;

                chtInfo.advance = advance;

                chtInfoList.Add(chtInfo);
            }
            font.characterInfo = chtInfoList.ToArray();
            replacedetDatabase.Refresh();
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        var obj = (GameBattleEx)target;
        if (GUILayout.Button("ShowWayPoint")) {
            obj.ShowWayPoint(true);
        }
        if (GUILayout.Button("HideWayPoint")) {
            obj.ShowWayPoint(false);
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("Change"))
        {
            var obj = (ChangeShader)target;
            obj.Change();

        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("Save"))
        {
            var obj = (PMDSave)target;
            string file = EditorUtility.SaveFilePanel("save pmd file", "", "", "pmd");
            if (!string.IsNullOrEmpty(file))
                obj.Save(file);
        }

        if (GUILayout.Button("SaveMap"))
        {
            var obj = (PMDSave)target;
            string file = EditorUtility.SaveFilePanel("save pmd file", "", "", "pmd");
            if (!string.IsNullOrEmpty(file))
                obj.SaveMap(file);
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        Loader myTarget = (Loader)target;
        if (GUILayout.Button("CreateSpwanPoint")) {
            myTarget.CreateSpawnPoint();
        }
        if (GUILayout.Button("AddSceneObjsFromDes"))
        {
            myTarget.LoadSceneObjsFromDes(myTarget.defFile);
        }
        //if (GUILayout.Button("SaveFixedSceneObjs"))
        //{
            //myTarget.SaveFixedSceneObjs();
        //}
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        FMCPlayer myTarget = (FMCPlayer)target;
        pos = GUILayout.TextField(pos);
        if (GUILayout.Button("ChangePose"))
        {
            myTarget.ChangePose(int.Parse(pos), 0);
        }

        if (GUILayout.Button("LoadFile"))
        {
            myTarget.Init(myTarget.fmcFile);
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        IFLLoader myTarget = (IFLLoader)target;
        if (GUILayout.Button("LoadIFL"))
        {
            myTarget.LoadIFL();
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI() {
        base.OnInspectorGUI();
        CalcDistance myTarget = (CalcDistance)target;
        if (GUILayout.Button("CalcDis")) {
            myTarget.CalcDis();
        }
        if (GUILayout.Button("CalcAngle")) {
            myTarget.CalcAngle();
        }
        if (GUILayout.Button("LookAt")) {
            myTarget.LookAt();
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        MapLoader myTarget = (MapLoader)target;
        if (GUILayout.Button("LoadFromXls"))
        {
            myTarget.LoadMap(myTarget.levelId);
        }
        if (GUILayout.Button("LoadFromDes"))
        {
            myTarget.LoadDesMap(myTarget.desFile);
        }
        if (GUILayout.Button("SaveMaterial"))
        {
            myTarget.SaveMaterial();
        }
        if (GUILayout.Button("SaveMesh"))
        {
            myTarget.SaveMesh();
        }
        if (GUILayout.Button("LoadMesh"))
        {
            myTarget.LoadMeshFromPath();
        }
        if (GUILayout.Button("LoadWayPoint"))
        {
            myTarget.LoadWayPoint();
        }
        if (GUILayout.Button("CheckName")) {
            myTarget.CheckName();
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        MeteorUnit myTarget = (MeteorUnit)target;
        way = GUILayout.TextField(way);
        action = GUILayout.TextField(action);
        if (GUILayout.Button("GetWayIndex"))
        {
            wayIndex = PathMng.Ins.GetWayIndex(myTarget.mSkeletonPivot);
            way = wayIndex.ToString();
        }

        if (GUILayout.Button("GetWayIndex2"))
        {
            wayIndex = PathMng.Ins.GetWayIndex(myTarget.mSkeletonPivot);
            way = wayIndex.ToString();
        }

        if (GUILayout.Button("FaceToTarget"))
        {
            if (vecTarget == null)
                vecTarget = GameObject.Find("facetotarget");
            if (vecTarget == null)
                return;
            myTarget.StateMachine.ChangeState(myTarget.StateMachine.FaceToState, vecTarget.transform.position);
        }

        if (GUILayout.Button("ChangeAction")) {
            int act = int.Parse(action);
            myTarget.ActionMgr.ChangeAction(act, 0.1f);
        }

        //if (GUILayout.Button("BakeAnimation")) {
        //    int act = int.Parse(action);
        //    myTarget.ActionMgr.BakePose(act);
        //}

        if (GUILayout.Button("StopAllAction")) {
            
        }

        if (GUILayout.Button("SampleFrame")) {
            //PoseState FadeOutState = myTarget.ActionMgr.AddState(0);//从原先的动作
            //FadeInState.SetEnabled(true);
            //FadeInState.SetNormalizedTime(FadeIn);
            //FadeInState.SetWeight(1);
            //FadeOutState.SetEnabled(true);
            //FadeOutState.SetNormalizedTime(1 - FadeIn);
            //FadeOutState.SetWeight(1);
            //FrameReplay.deltaTime = Time.deltaTime;
            //FrameReplay.Instance.time += Time.deltaTime;
            
        }
    }

19 View Source File : LoadInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI() {
        base.OnInspectorGUI();
        FrameReplay frameReplay = (FrameReplay)target;
        trackerid = GUILayout.TextField(trackerid);
        if (GUILayout.Button("SetTrackerId")) {
            int track = 0;
            if (int.TryParse(trackerid, out track))
                FrameSnapShot.Ins.NewTracker(track);
        }
    }

19 View Source File : TransformInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI() {
            EditorGUIUtility.labelWidth = 15f;
        
            serializedObject.Update();
        
            DrawPosition();
            DrawRotation();
            DrawScale();
        
            GUILayout.BeginHorizontal();
            GUI.color = new Color(0.7f, 0.7f, 0.7f);
            EditorGUILayout.Vector3Field(new GUIContent("World Pos"), ((Transform) serializedObject.targetObject).position);
            GUI.color = Color.white;
            GUILayout.EndHorizontal();

            Quaternion q = ((Transform)serializedObject.targetObject).rotation;
            Vector3 vec = new Vector4(q.eulerAngles.x, q.eulerAngles.y, q.eulerAngles.z);
            GUILayout.BeginHorizontal();
            EditorGUILayout.Vector3Field(new GUIContent("World Rot"), vec);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                string info = LocalPosition.FindPropertyRelative("x").floatValue + ";" +
                              LocalPosition.FindPropertyRelative("y").floatValue + ";" +
                              LocalPosition.FindPropertyRelative("z").floatValue + ";" +
                              LocalRotation.FindPropertyRelative("x").floatValue + ";" +
                              LocalRotation.FindPropertyRelative("y").floatValue + ";" +
                              LocalRotation.FindPropertyRelative("z").floatValue + ";" +
                              LocalRotation.FindPropertyRelative("w").floatValue + ";" +
                              LocalScale.FindPropertyRelative("x").floatValue + ";" +
                              LocalScale.FindPropertyRelative("y").floatValue + ";" +
                              LocalScale.FindPropertyRelative("z").floatValue;
            
                bool copy = GUILayout.Button("Copy", GUILayout.Width(50f));
                bool paste = GUILayout.Button("Paste", GUILayout.Width(50f));
                bool reset = GUILayout.Button("Idenreplacedy", GUILayout.Width(70f));
                bool uniformScale = GUILayout.Button("Z - Uniform Scale", GUILayout.Width(110f));
            
                if (copy)
                    EditorGUIUtility.systemCopyBuffer = info;
                if (paste) {
                    string line = EditorGUIUtility.systemCopyBuffer;
                    if (info != line) {
                        bool success = false;
                        string[] atts = line.Split(';');
                        if (atts.Length == 10) {
                            float[] values = new float[10];
                            for (int i = 0; i < atts.Length; i++) {
                                float.TryParse(atts[i], out values[i]);
                            }
                            LocalPosition.vector3Value = new Vector3(values[0], values[1], values[2]);
                            LocalRotation.quaternionValue = new Quaternion(values[3], values[4], values[5], values[6]);
                            LocalScale.vector3Value = new Vector3(values[7], values[8], values[9]);
                            success = true;
                        }
                        if (!success)
                            Debug.LogError("Failed pasting data");
                    
                    }
                }
                if (uniformScale) {
                    float v = LocalScale.FindPropertyRelative("z").floatValue;
                    LocalScale.FindPropertyRelative("x").floatValue = v;
                    LocalScale.FindPropertyRelative("y").floatValue = v;
                }
            
                if (reset) {
                    LocalPosition.vector3Value = Vector3.zero;
                    LocalRotation.quaternionValue = Quaternion.idenreplacedy;
                    LocalScale.vector3Value = Vector3.one;
                }
            }
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();
        }

19 View Source File : TransformInspector.cs
License : Apache License 2.0
Project Creator : 365082218

private void DrawPosition() {
            GUILayout.BeginHorizontal();
            {
                bool reset = GUILayout.Button("P", GUILayout.Width(20f));
            
                EditorGUILayout.PropertyField(LocalPosition.FindPropertyRelative("x"));
                EditorGUILayout.PropertyField(LocalPosition.FindPropertyRelative("y"));
                EditorGUILayout.PropertyField(LocalPosition.FindPropertyRelative("z"));
            
                if (reset)
                    LocalPosition.vector3Value = Vector3.zero;
            }
            GUILayout.EndHorizontal();
        }

19 View Source File : TransformInspector.cs
License : Apache License 2.0
Project Creator : 365082218

void DrawScale() {
            GUILayout.BeginHorizontal();
            {
                bool reset = GUILayout.Button("S", GUILayout.Width(20f));
            
                EditorGUILayout.PropertyField(LocalScale.FindPropertyRelative("x"));
                EditorGUILayout.PropertyField(LocalScale.FindPropertyRelative("y"));
                EditorGUILayout.PropertyField(LocalScale.FindPropertyRelative("z"));

                if (reset)
                    LocalScale.vector3Value = Vector3.one;
            }
            GUILayout.EndHorizontal();
        }

19 View Source File : TransformInspector.cs
License : Apache License 2.0
Project Creator : 365082218

void DrawRotation() {
            GUILayout.BeginHorizontal();
            {
                bool reset = GUILayout.Button("R", GUILayout.Width(20f));
            
                Vector3 visible = (serializedObject.targetObject as Transform).localEulerAngles;
            
                visible.x = WrapAngle(visible.x);
                visible.y = WrapAngle(visible.y);
                visible.z = WrapAngle(visible.z);
            
                Axes changed = CheckDifference(LocalRotation);
                Axes altered = Axes.None;
            
                GUILayoutOption opt = GUILayout.MinWidth(30f);
            
                if (FloatField("X", ref visible.x, (changed & Axes.X) != 0, false, opt))
                    altered |= Axes.X;
                if (FloatField("Y", ref visible.y, (changed & Axes.Y) != 0, false, opt))
                    altered |= Axes.Y;
                if (FloatField("Z", ref visible.z, (changed & Axes.Z) != 0, false, opt))
                    altered |= Axes.Z;
            
                if (reset) {
                    LocalRotation.quaternionValue = Quaternion.idenreplacedy;
                } else if (altered != Axes.None) {
                    RegisterUndo("Change Rotation", serializedObject.targetObjects);
                
                    foreach (Object obj in serializedObject.targetObjects) {
                        Transform t = obj as Transform;
                        Vector3 v = t.localEulerAngles;
                    
                        if ((altered & Axes.X) != 0)
                            v.x = visible.x;
                        if ((altered & Axes.Y) != 0)
                            v.y = visible.y;
                        if ((altered & Axes.Z) != 0)
                            v.z = visible.z;
                    
                        t.localEulerAngles = v;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }

19 View Source File : CheckResources.cs
License : Apache License 2.0
Project Creator : 365082218

void ListTextures ()
		{
				textureListScrollPos = EditorGUILayout.BeginScrollView (textureListScrollPos);
		
				foreach (TextureDetails tDetails in ActiveTextures) {			
			
						GUILayout.BeginHorizontal ();
						GUILayout.Box (tDetails.texture, GUILayout.Width (ThumbnailWidth), GUILayout.Height (ThumbnailHeight));
			
						if (GUILayout.Button (tDetails.texture.name, GUILayout.Width (150))) {
								SelectObject (tDetails.texture, ctrlPressed);
						}
			
						string sizeLabel = "" + tDetails.texture.width + "x" + tDetails.texture.height;
						if (tDetails.isCubeMap)
								sizeLabel += "x6";
						sizeLabel += " - " + tDetails.mipMapCount + "mip";
						sizeLabel += "\n" + FormatSizeString (tDetails.memSizeKB) + " - " + tDetails.format + "";
			
						GUILayout.Label (sizeLabel, GUILayout.Width (120));
			
						if (GUILayout.Button (tDetails.FoundInMaterials.Count + " Mat", GUILayout.Width (50))) {
								SelectObjects (tDetails.FoundInMaterials, ctrlPressed);
						}
			
						if (GUILayout.Button (tDetails.FoundInRenderers.Count + " GO", GUILayout.Width (50))) {
								List<Object> FoundObjects = new List<Object> ();
								foreach (Renderer renderer in tDetails.FoundInRenderers)
										FoundObjects.Add (renderer.gameObject);
								SelectObjects (FoundObjects, ctrlPressed);
						}
			
						GUILayout.EndHorizontal ();	
				}
				if (ActiveTextures.Count > 0) {
						GUILayout.BeginHorizontal ();
						GUILayout.Box (" ", GUILayout.Width (ThumbnailWidth), GUILayout.Height (ThumbnailHeight));
			
						if (GUILayout.Button ("Select All", GUILayout.Width (150))) {
								List<Object> AllTextures = new List<Object> ();
								foreach (TextureDetails tDetails in ActiveTextures)
										AllTextures.Add (tDetails.texture);
								SelectObjects (AllTextures, ctrlPressed);
						}
						EditorGUILayout.EndHorizontal ();
				}
				EditorGUILayout.EndScrollView ();
		}

19 View Source File : MemoryProfilerWindow.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI(){
			var svrGo = GameObject.FindObjectOfType<LuaSvrGameObject>();
			if(svrGo == null){
				GUILayout.Label("There is no LuaSvrGameObject in you scene. Run your game first");
				return;
			}
			if(GUILayout.Button("Capture")){
				System.GC.Collect ();
				LuaDLL.lua_gc(svrGo.state.L, LuaGCOptions.LUA_GCCOLLECT, 0);
				_destroyedObjectNames = ObjectCache.GetAlreadyDestroyedObjectNames();
				_allObjectNames = ObjectCache.GetAllManagedObjectNames();
				cachedDelegateCount = LuaState.main.cachedDelegateCount;
			}

			GUILayout.Label ("LuaDelegate count:" + cachedDelegateCount);
			_showDestroyedObject = EditorGUILayout.Foldout(_showDestroyedObject,"Already Destroyed Unity Object:"+_destroyedObjectNames.Count);
			if(_showDestroyedObject){
				_scrollPos = GUILayout.BeginScrollView(_scrollPos);
				foreach(var name in _destroyedObjectNames){
					GUILayout.Label(name);
				}
				GUILayout.EndScrollView();
			}

			_showAllObject = EditorGUILayout.Foldout(_showAllObject,"All Managed C# Object:"+_allObjectNames.Count);

			if(_showAllObject){
				_scrollPos2 = GUILayout.BeginScrollView(_scrollPos2);
				foreach(var name in _allObjectNames){
					GUILayout.Label(name);
				}
				GUILayout.EndScrollView();
			}



		}

19 View Source File : LuaConsole.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI()
        {
            if (!initedStyle)
            {
                GUIStyle entryInfoTyle = "CN EntryInfo";
                textAreaStyle.richText = true;
                textAreaStyle.normal.textColor = entryInfoTyle.normal.textColor;
                initedStyle = true;
            }


            string[] statehints = new string[LuaState.statemap.Count];
            LuaState[] states = new LuaState[LuaState.statemap.Count];
            int n = 0;
            foreach(var k in LuaState.statemap.Values) {
                states[n] = k;
                statehints[n++] = k.Name;
            }

            stateIndex = EditorGUILayout.Popup(stateIndex,statehints);

            LuaState l = null;
            if (stateIndex >= 0 && stateIndex <states.Length)
				l = states[stateIndex];

            if (current != null && current != l)
            {
                current.logDelegate -= AddLog;
                current.errorDelegate -= AddError;
            }

            if(current!=l && l!=null) {
				l.logDelegate += AddLog;
				l.errorDelegate += AddError;
				current = l;
            }




            //Output Text Area
			scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.ExpandHeight(true));
			EditorGUILayout.TextArea(outputText, textAreaStyle, GUILayout.ExpandHeight(true));
            GUILayout.EndScrollView();

            //Filter Option Toggles
            GUILayout.BeginHorizontal();
            bool oldToggleLog = toggleLog;
            bool oldToggleErr = toggleErr;
            toggleLog = GUILayout.Toggle(oldToggleLog, "log", GUILayout.ExpandWidth(false));
            toggleErr = GUILayout.Toggle(oldToggleErr, "error", GUILayout.ExpandWidth(false));

            //Filter Input Field
            GUILayout.Space(10f);
            GUILayout.Label("filter:", GUILayout.ExpandWidth(false));
            string oldFilterPattern = filterText;
            filterText = GUILayout.TextField(oldFilterPattern, GUILayout.Width(200f));

            //Menu Buttons
            if (GUILayout.Button("clear", GUILayout.ExpandWidth(false)))
            {
                recordList.Clear();
                ConsoleFlush();
            }
            GUILayout.EndHorizontal();

            if (toggleLog != oldToggleLog || toggleErr != oldToggleErr || filterText != oldFilterPattern)
            {
                ConsoleFlush();
            }

            if (Event.current.type == EventType.Repaint)
            {
                inputAreaPosY = GUILayoutUtility.GetLastRect().yMax;
            }

            //Drag Spliter
            ResizeScrollView();

            //Input Area
            GUI.SetNextControlName("Input");
            inputText = EditorGUILayout.TextField(inputText, GUILayout.Height(inputAreaHeight));

            if (Event.current.isKey && Event.current.type == EventType.KeyUp)
            {
                bool refresh = false;
                if (Event.current.keyCode == KeyCode.Return)
                {
                    if (inputText != "")
                    {
                        if (history.Count == 0 || history[history.Count - 1] != inputText)
                        {
                            history.Add(inputText);
                        }
                        AddLog(inputText);
                        DoCommand(inputText);
                        inputText = "";
                        refresh = true;
                        historyIndex = history.Count;
                    }
                }
                else if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    if (history.Count > 0)
                    {
                        historyIndex = historyIndex - 1;
                        if (historyIndex < 0)
                        {
                            historyIndex = 0;
                        }
                        else
                        {
                            inputText = history[historyIndex];
                            refresh = true;
                        }
                    }
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (history.Count > 0)
                    {
                        historyIndex = historyIndex + 1;
                        if (historyIndex > history.Count - 1)
                        {
                            historyIndex = history.Count - 1;
                        }
                        else
                        {
                            inputText = history[historyIndex];
                            refresh = true;
                        }
                    }
                }

                if (refresh)
                {
                    Repaint();
                    EditorGUIUtility.editingTextField = false;
                    GUI.FocusControl("Input");
                }
            }
        }

19 View Source File : UIAtlasInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI ()
	{
		EditorGUIUtility.LookLikeControls(80f);
		mAtlas = target as UIAtlas;

		NGUIEditorTools.DrawSeparator();

		if (mAtlas.replacement != null)
		{
			mType = AtlasType.Reference;
			mReplacement = mAtlas.replacement;
		}

		AtlasType after = (AtlasType)EditorGUILayout.EnumPopup("Atlas Type", mType);

		if (mType != after)
		{
			if (after == AtlasType.Normal)
			{
				OnSelectAtlas(null);
			}
			else
			{
				mType = AtlasType.Reference;
			}
		}

		if (mType == AtlasType.Reference)
		{
			ComponentSelector.Draw<UIAtlas>(mAtlas.replacement, OnSelectAtlas);

			NGUIEditorTools.DrawSeparator();
			GUILayout.Label("You can have one atlas simply point to\n" +
				"another one. This is useful if you want to be\n" +
				"able to quickly replace the contents of one\n" +
				"atlas with another one, for example for\n" +
				"swapping an SD atlas with an HD one, or\n" +
				"replacing an English atlas with a Chinese\n" +
				"one. All the sprites referencing this atlas\n" +
				"will update their references to the new one.");

			if (mReplacement != mAtlas && mAtlas.replacement != mReplacement)
			{
				NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
				mAtlas.replacement = mReplacement;
				UnityEditor.EditorUtility.SetDirty(mAtlas);
			}
			return;
		}

		if (!mConfirmDelete)
		{
			NGUIEditorTools.DrawSeparator();
			Material mat = EditorGUILayout.ObjectField("Material", mAtlas.spriteMaterial, typeof(Material), false) as Material;

			if (mAtlas.spriteMaterial != mat)
			{
				NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
				mAtlas.spriteMaterial = mat;

				// Ensure that this atlas has valid import settings
				if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

				mAtlas.MarkAsDirty();
				mConfirmDelete = false;
			}

			if (mat != null)
			{
				Textreplacedet ta = EditorGUILayout.ObjectField("TP Import", null, typeof(Textreplacedet), false) as Textreplacedet;

				if (ta != null)
				{
					// Ensure that this atlas has valid import settings
					if (mAtlas.texture != null) NGUIEditorTools.ImportTexture(mAtlas.texture, false, false);

					NGUIEditorTools.RegisterUndo("Import Sprites", mAtlas);
					NGUIJson.LoadSpriteData(mAtlas, ta);
					if (mSprite != null) mSprite = mAtlas.GetSprite(mSprite.name);
					mAtlas.MarkAsDirty();
				}
				
				UIAtlas.Coordinates coords = (UIAtlas.Coordinates)EditorGUILayout.EnumPopup("Coordinates", mAtlas.coordinates);

				if (coords != mAtlas.coordinates)
				{
					NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
					mAtlas.coordinates = coords;
					mConfirmDelete = false;
				}

				float pixelSize = EditorGUILayout.FloatField("Pixel Size", mAtlas.pixelSize, GUILayout.Width(120f));

				if (pixelSize != mAtlas.pixelSize)
				{
					NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
					mAtlas.pixelSize = pixelSize;
					mConfirmDelete = false;
				}
			}
		}

		if (mAtlas.spriteMaterial != null)
		{
			Color blue = new Color(0f, 0.7f, 1f, 1f);
			Color green = new Color(0.4f, 1f, 0f, 1f);

			if (mConfirmDelete)
			{
				if (mSprite != null)
				{
					// Show the confirmation dialog
					NGUIEditorTools.DrawSeparator();
					GUILayout.Label("Are you sure you want to delete '" + mSprite.name + "'?");
					NGUIEditorTools.DrawSeparator();

					GUILayout.BeginHorizontal();
					{
						GUI.backgroundColor = Color.green;
						if (GUILayout.Button("Cancel")) mConfirmDelete = false;
						GUI.backgroundColor = Color.red;

						if (GUILayout.Button("Delete"))
						{
							NGUIEditorTools.RegisterUndo("Delete Sprite", mAtlas);
							mAtlas.spriteList.Remove(mSprite);
							mConfirmDelete = false;
						}
						GUI.backgroundColor = Color.white;
					}
					GUILayout.EndHorizontal();
				}
				else mConfirmDelete = false;
			}
			else
			{
				if (mSprite == null && mAtlas.spriteList.Count > 0)
				{
					string spriteName = EditorPrefs.GetString("NGUI Selected Sprite");
					if (!string.IsNullOrEmpty(spriteName)) mSprite = mAtlas.GetSprite(spriteName);
					if (mSprite == null) mSprite = mAtlas.spriteList[0];
				}

				if (!mConfirmDelete && mSprite != null)
				{
					NGUIEditorTools.DrawSeparator();
					NGUIEditorTools.AdvancedSpriteField(mAtlas, mSprite.name, SelectSprite, true);

					if (mSprite == null) return;

					Texture2D tex = mAtlas.spriteMaterial.mainTexture as Texture2D;

					if (tex != null)
					{
						Rect inner = mSprite.inner;
						Rect outer = mSprite.outer;

						if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
						{
							GUI.backgroundColor = green;
							outer = NGUIEditorTools.IntRect("Dimensions", mSprite.outer);

							Vector4 border = new Vector4(
								mSprite.inner.xMin - mSprite.outer.xMin,
								mSprite.inner.yMin - mSprite.outer.yMin,
								mSprite.outer.xMax - mSprite.inner.xMax,
								mSprite.outer.yMax - mSprite.inner.yMax);

							GUI.backgroundColor = blue;
							border = NGUIEditorTools.IntPadding("Border", border);
							GUI.backgroundColor = Color.white;

							inner.xMin = mSprite.outer.xMin + border.x;
							inner.yMin = mSprite.outer.yMin + border.y;
							inner.xMax = mSprite.outer.xMax - border.z;
							inner.yMax = mSprite.outer.yMax - border.w;
						}
						else
						{
							// Draw the inner and outer rectangle dimensions
							GUI.backgroundColor = green;
							outer = EditorGUILayout.RectField("Outer Rect", mSprite.outer);
							GUI.backgroundColor = blue;
							inner = EditorGUILayout.RectField("Inner Rect", mSprite.inner);
							GUI.backgroundColor = Color.white;
						}

						if (outer.xMax < outer.xMin) outer.xMax = outer.xMin;
						if (outer.yMax < outer.yMin) outer.yMax = outer.yMin;

						if (outer != mSprite.outer)
						{
							float x = outer.xMin - mSprite.outer.xMin;
							float y = outer.yMin - mSprite.outer.yMin;

							inner.x += x;
							inner.y += y;
						}

						// Sanity checks to ensure that the inner rect is always inside the outer
						inner.xMin = Mathf.Clamp(inner.xMin, outer.xMin, outer.xMax);
						inner.xMax = Mathf.Clamp(inner.xMax, outer.xMin, outer.xMax);
						inner.yMin = Mathf.Clamp(inner.yMin, outer.yMin, outer.yMax);
						inner.yMax = Mathf.Clamp(inner.yMax, outer.yMin, outer.yMax);
						
						bool changed = false;
						
						if (mSprite.inner != inner || mSprite.outer != outer)
						{
							NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
							mSprite.inner = inner;
							mSprite.outer = outer;
							MarkSpriteAsDirty();
							changed = true;
						}

						EditorGUILayout.Separator();

						if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
						{
							int left	= Mathf.RoundToInt(mSprite.paddingLeft	 * mSprite.outer.width);
							int right	= Mathf.RoundToInt(mSprite.paddingRight	 * mSprite.outer.width);
							int top		= Mathf.RoundToInt(mSprite.paddingTop	 * mSprite.outer.height);
							int bottom	= Mathf.RoundToInt(mSprite.paddingBottom * mSprite.outer.height);

							NGUIEditorTools.IntVector a = NGUIEditorTools.IntPair("Padding", "Left", "Top", left, top);
							NGUIEditorTools.IntVector b = NGUIEditorTools.IntPair(null, "Right", "Bottom", right, bottom);

							if (changed || a.x != left || a.y != top || b.x != right || b.y != bottom)
							{
								NGUIEditorTools.RegisterUndo("Atlas Change", mAtlas);
								mSprite.paddingLeft		= a.x / mSprite.outer.width;
								mSprite.paddingTop		= a.y / mSprite.outer.height;
								mSprite.paddingRight	= b.x / mSprite.outer.width;
								mSprite.paddingBottom	= b.y / mSprite.outer.height;
								MarkSpriteAsDirty();
							}
						}
						else
						{
							// Create a button that can make the coordinates pixel-perfect on click
							GUILayout.BeginHorizontal();
							{
								GUILayout.Label("Correction", GUILayout.Width(75f));

								Rect corrected0 = outer;
								Rect corrected1 = inner;

								if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
								{
									corrected0 = NGUIMath.MakePixelPerfect(corrected0);
									corrected1 = NGUIMath.MakePixelPerfect(corrected1);
								}
								else
								{
									corrected0 = NGUIMath.MakePixelPerfect(corrected0, tex.width, tex.height);
									corrected1 = NGUIMath.MakePixelPerfect(corrected1, tex.width, tex.height);
								}

								if (corrected0 == mSprite.outer && corrected1 == mSprite.inner)
								{
									GUI.color = Color.grey;
									GUILayout.Button("Make Pixel-Perfect");
									GUI.color = Color.white;
								}
								else if (GUILayout.Button("Make Pixel-Perfect"))
								{
									outer = corrected0;
									inner = corrected1;
									GUI.changed = true;
								}
							}
							GUILayout.EndHorizontal();
						}
					}

					// This functionality is no longer used. It became obsolete when the Atlas Maker was added.
					/*NGUIEditorTools.DrawSeparator();

					GUILayout.BeginHorizontal();
					{
						EditorGUILayout.PrefixLabel("Add/Delete");

						if (GUILayout.Button("Clone Sprite"))
						{
							NGUIEditorTools.RegisterUndo("Add Sprite", mAtlas);
							UIAtlas.Sprite newSprite = new UIAtlas.Sprite();

							if (mSprite != null)
							{
								newSprite.name = "Copy of " + mSprite.name;
								newSprite.outer = mSprite.outer;
								newSprite.inner = mSprite.inner;
							}
							else
							{
								newSprite.name = "New Sprite";
							}

							mAtlas.spriteList.Add(newSprite);
							mSprite = newSprite;
						}

						// Show the delete button
						GUI.backgroundColor = Color.red;

						if (mSprite != null && GUILayout.Button("Delete", GUILayout.Width(55f)))
						{
							mConfirmDelete = true;
						}
						GUI.backgroundColor = Color.white;
					}
					GUILayout.EndHorizontal();*/

					if (NGUIEditorTools.previousSelection != null)
					{
						NGUIEditorTools.DrawSeparator();

						GUI.backgroundColor = Color.green;

						if (GUILayout.Button("<< Return to " + NGUIEditorTools.previousSelection.name))
						{
							NGUIEditorTools.SelectPrevious();
						}
						GUI.backgroundColor = Color.white;
					}
				}
			}
		}
	}

19 View Source File : CustomEditor.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
		{
			LuaSvrGameObject myTarget = (LuaSvrGameObject)target;
			int bytes = LuaDLL.lua_gc(myTarget.state.L, LuaGCOptions.LUA_GCCOUNT, 0);
			EditorGUILayout.LabelField("Memory(Kb)", bytes.ToString());
			if (GUILayout.Button("Lua GC"))
			{
				LuaDLL.lua_gc(myTarget.state.L, LuaGCOptions.LUA_GCCOLLECT, 0);
				System.GC.Collect ();
			}
		}

19 View Source File : LightbeamEditor.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        Lightbeam lightBeam = (target as Lightbeam);

        if (lightBeam.IsModifyingMesh == true && IsLightBeamMesh() == false)
        {
            Debug.LogWarning("Escaped lightbeam modification mode. No valid lightbeam mesh was found.");
            lightBeam.IsModifyingMesh = false;
        }

        if (lightBeam.IsModifyingMesh == false)
        {
            EditorGUILayout.BeginHorizontal();
            if (IsLightBeamMesh())
            {
                if (GUILayout.Button(new GUIContent("Modify", "Modify the lightbeam mesh.")))
                {
                    Undo.RegisterUndo(lightBeam, "Modify light beam");
                    ModifyMesh(lightBeam);
                    EditorUtility.SetDirty(lightBeam);
                }
            }
            else
            {
                GUI.enabled = false;
                if (GUILayout.Button(new GUIContent("Modify", "Missing a valid lightbeam mesh.")))
                {
                }
                GUI.enabled = true;
            }

            if (GUILayout.Button(new GUIContent("New Lightbeam Mesh", "Create a new lightbeam mesh for this object.")))
            {
                int result = EditorUtility.DisplayDialogComplex("Duplicate material", "Do you want to duplicate the material?\nIf you don't duplicate the same material will be used.", "Yes", "No", "Cancel");

                if (result == 0) // ok
                {
                    Undo.RegisterSceneUndo("New Lightbeam Mesh");
                    SaveNewreplacedet(lightBeam, true);
                    ModifyMesh(lightBeam);
                    EditorUtility.SetDirty(lightBeam);
                }
                if (result == 1) // no
                {
                    Undo.RegisterSceneUndo("New Lightbeam Mesh");
                    SaveNewreplacedet(lightBeam, false);
                    ModifyMesh(lightBeam);
                    EditorUtility.SetDirty(lightBeam);
                }

            }
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.BeginVertical();

            string RadiusTopTooltip = "The top radius of the lightbeam.";
            string RadiusBottomTooltip = "The bottom radius of the lightbeam.";
            string LengthTooltip = "Length of the lightbeam.";
            string SubdivisionsTooltip = "Horizontal Subdivisions\n\nIncreasing this will smoothen the lightbeam by adding vertices.";
            string SubdivisionsHeightTooltip = "Vertical Subdivisions\n\nIncreasing this will smoothen the lightbeam by adding vertices.";

            lightBeam.RadiusTop = EditorGUILayout.FloatField(new GUIContent("Radius Top", RadiusTopTooltip), lightBeam.RadiusTop);
            lightBeam.RadiusBottom = EditorGUILayout.FloatField(new GUIContent("Radius Bottom", RadiusBottomTooltip), lightBeam.RadiusBottom);
            lightBeam.Length = EditorGUILayout.FloatField(new GUIContent("Length", LengthTooltip), lightBeam.Length);
            lightBeam.Subdivisions = EditorGUILayout.IntSlider(new GUIContent("Subdivisions", SubdivisionsTooltip), lightBeam.Subdivisions, 3, 50);
            lightBeam.SubdivisionsHeight = EditorGUILayout.IntSlider(new GUIContent("Subdivisions Height", SubdivisionsHeightTooltip), lightBeam.SubdivisionsHeight, 1, 10);

            if (lightBeam.RadiusTop <= 0.01f)
                lightBeam.RadiusTop = 0.01f;
            if (lightBeam.RadiusBottom <= 0.01f)
                lightBeam.RadiusBottom = 0.01f;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Done", "Finish modifying the lightbeam mesh.")))
            {
                Undo.RegisterUndo(lightBeam, "Finished Modifying Lightbeam Mesh");
                lightBeam.IsModifyingMesh = false;
                EditorUtility.SetDirty(lightBeam);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }

        if (GUI.changed)
        {
            Undo.SetSnapshotTarget(lightBeam.Settings, "Modify Lightbeam Mesh");
            Undo.CreateSnapshot();
            Undo.RegisterSnapshot();
            lightBeam.GenerateBeam();
            EditorUtility.SetDirty(lightBeam);
        }
    }

19 View Source File : ComponentSelector.cs
License : Apache License 2.0
Project Creator : 365082218

static public void Draw<T> (string buttonName, T obj, OnSelectionCallback cb, params GUILayoutOption[] options) where T : MonoBehaviour
	{
		GUILayout.BeginHorizontal();
		bool show = GUILayout.Button(buttonName, "DropDownButton", GUILayout.Width(76f));
#if !UNITY_3_4
		GUILayout.BeginVertical();
		GUILayout.Space(5f);
#endif
		T o = EditorGUILayout.ObjectField(obj, typeof(T), false, options) as T;
#if !UNITY_3_4
		GUILayout.EndVertical();
#endif
		if (o != null && Selection.activeObject != o.gameObject && GUILayout.Button("Edit", GUILayout.Width(40f)))
		{
			Selection.activeObject = o.gameObject;
		}
		GUILayout.EndHorizontal();
		if (show) Show<T>(cb);
		else if (o != obj) cb(o);
	}

19 View Source File : ComponentSelector.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		EditorGUIUtility.LookLikeControls(80f);
		GUILayout.Label("Recently used components", "LODLevelNotifyText");
		NGUIEditorTools.DrawSeparator();

		if (mObjects.Length == 0)
		{
			EditorGUILayout.HelpBox("No recently used " + mType.ToString() + " components found.\nTry drag & dropping one instead, or creating a new one.", MessageType.Info);

			bool isDone = false;

			EditorGUILayout.Space();
			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();

			if (mType == typeof(UIFont))
			{
				if (GUILayout.Button("Open the Font Maker", GUILayout.Width(150f)))
				{
					EditorWindow.GetWindow<UIFontMaker>(false, "Font Maker", true);
					isDone = true;
				}
			}
			else if (mType == typeof(UIAtlas))
			{
				if (GUILayout.Button("Open the Atlas Maker", GUILayout.Width(150f)))
				{
					EditorWindow.GetWindow<UIAtlasMaker>(false, "Atlas Maker", true);
					isDone = true;
				}
			}

			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			if (isDone) Close();
		}
		else
		{
			MonoBehaviour sel = null;

			foreach (MonoBehaviour o in mObjects)
			{
				if (DrawObject(o))
				{
					sel = o;
				}
			}

			if (sel != null)
			{
				mCallback(sel);
				Close();
			}
		}
	}

19 View Source File : ComponentSelector.cs
License : Apache License 2.0
Project Creator : 365082218

bool DrawObject (MonoBehaviour mb)
	{
		bool retVal = false;

		GUILayout.BeginHorizontal();
		{
			if (EditorUtility.IsPersistent(mb.gameObject))
			{
				GUILayout.Label("Prefab", "AS TextArea", GUILayout.Width(80f), GUILayout.Height(20f));
			}
			else
			{
				GUI.color = Color.grey;
				GUILayout.Label("Object", "AS TextArea", GUILayout.Width(80f), GUILayout.Height(20f));
			}

			GUILayout.Label(NGUITools.GetHierarchy(mb.gameObject), "AS TextArea", GUILayout.Height(20f));
			GUI.color = Color.white;

			retVal = GUILayout.Button("Select", "ButtonLeft", GUILayout.Width(60f), GUILayout.Height(16f));
		}
		GUILayout.EndHorizontal();
		return retVal;
	}

19 View Source File : NGUIEditorTools.cs
License : Apache License 2.0
Project Creator : 365082218

static public void SpriteField (string fieldName, UIAtlas atlas, string spriteName,
		SpriteSelector.Callback callback, params GUILayoutOption[] options)
	{
		GUILayout.BeginHorizontal();
		GUILayout.Label(fieldName, GUILayout.Width(76f));

		if (GUILayout.Button(spriteName, "MiniPullDown", options))
		{
			SpriteSelector.Show(atlas, spriteName, callback);
		}
		GUILayout.EndHorizontal();
	}

19 View Source File : NGUIEditorTools.cs
License : Apache License 2.0
Project Creator : 365082218

static public void SpriteField (string fieldName, string caption, UIAtlas atlas, string spriteName, SpriteSelector.Callback callback)
	{
		GUILayout.BeginHorizontal();
		GUILayout.Label(fieldName, GUILayout.Width(76f));

		if (atlas.GetSprite(spriteName) == null)
			spriteName = "";

		if (GUILayout.Button(spriteName, "MiniPullDown", GUILayout.Width(120f)))
		{
			SpriteSelector.Show(atlas, spriteName, callback);
		}
		
		if (!string.IsNullOrEmpty(caption))
		{
			GUILayout.Space(20f);
			GUILayout.Label(caption);
		}
		GUILayout.EndHorizontal();
	}

19 View Source File : NGUIEditorTools.cs
License : Apache License 2.0
Project Creator : 365082218

static public bool SimpleSpriteField (UIAtlas atlas, string spriteName, SpriteSelector.Callback callback, params GUILayoutOption[] options)
	{
		if (atlas.GetSprite(spriteName) == null)
			spriteName = "";

		if (GUILayout.Button(spriteName, "DropDown", options))
		{
			SpriteSelector.Show(atlas, spriteName, callback);
			return true;
		}
		return false;
	}

19 View Source File : NGUIEditorTools.cs
License : Apache License 2.0
Project Creator : 365082218

static public void AdvancedSpriteField (UIAtlas atlas, string spriteName, SpriteSelector.Callback callback, bool editable,
		params GUILayoutOption[] options)
	{
		// Give the user a warning if there are no sprites in the atlas
		if (atlas.spriteList.Count == 0)
		{
			EditorGUILayout.HelpBox("No sprites found", MessageType.Warning);
			return;
		}

		// Sprite selection drop-down list
		GUILayout.BeginHorizontal();
		{
			if (GUILayout.Button("Sprite", "DropDownButton", GUILayout.Width(76f)))
			{
				SpriteSelector.Show(atlas, spriteName, callback);
			}

			if (editable)
			{
				string sn = GUILayout.TextField(spriteName);

				if (sn != spriteName)
				{
					UIAtlas.Sprite sp = atlas.GetSprite(spriteName);

					if (sp != null)
					{
						NGUIEditorTools.RegisterUndo("Edit Sprite Name", atlas);
						sp.name = sn;
						spriteName = sn;
					}
				}
			}
			else
			{
				GUILayout.BeginHorizontal();
				GUILayout.Label(spriteName, "HelpBox", GUILayout.Height(18f));
				GUILayout.Space(18f);
				GUILayout.EndHorizontal();

				if (GUILayout.Button("Edit", GUILayout.Width(40f)))
				{
					EditorPrefs.SetString("NGUI Selected Sprite", spriteName);
					Select(atlas.gameObject);
				}
			}
		}
		GUILayout.EndHorizontal();
	}

19 View Source File : NGUITransformInspector.cs
License : Apache License 2.0
Project Creator : 365082218

static bool DrawButton(string replacedle, string tooltip, bool enabled, float width)
	{
		if (enabled)
		{
			// Draw a regular button
			return GUILayout.Button(new GUIContent(replacedle, tooltip), GUILayout.Width(width));
		}
		else
		{
			// Button should be disabled -- draw it darkened and ignore its return value
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, 0.25f);
			GUILayout.Button(new GUIContent(replacedle, tooltip), GUILayout.Width(width));
			GUI.color = color;
			return false;
		}
	}

19 View Source File : SpriteSelector.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		EditorGUIUtility.LookLikeControls(80f);

		if (mAtlas == null)
		{
			GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
		}
		else
		{
			bool close = false;
			GUILayout.Label(mAtlas.name + " Sprites", "LODLevelNotifyText");
			NGUIEditorTools.DrawSeparator();

			GUILayout.BeginHorizontal();
			GUILayout.Space(84f);

			string before = NGUISettings.partialSprite;
			string after = EditorGUILayout.TextField("", before, "SearchTextField");
			NGUISettings.partialSprite = after;

			if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
			{
				NGUISettings.partialSprite = "";
				GUIUtility.keyboardControl = 0;
			}
			GUILayout.Space(84f);
			GUILayout.EndHorizontal();

			Texture2D tex = mAtlas.texture as Texture2D;

			if (tex == null)
			{
				GUILayout.Label("The atlas doesn't have a texture to work with");
				return;
			}

			BetterList<string> sprites = mAtlas.GetListOfSprites(NGUISettings.partialSprite);
			
			float size = 80f;
			float padded = size + 10f;
			int columns = Mathf.FloorToInt(Screen.width / padded);
			if (columns < 1) columns = 1;

			int offset = 0;
			Rect rect = new Rect(10f, 0, size, size);

			GUILayout.Space(10f);
			mPos = GUILayout.BeginScrollView(mPos);

			while (offset < sprites.size)
			{
				GUILayout.BeginHorizontal();
				{
					int col = 0;
					rect.x = 10f;

					for (; offset < sprites.size; ++offset)
					{
						UIAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]);
						if (sprite == null) continue;

						// Button comes first
						if (GUI.Button(rect, ""))
						{
							float delta = Time.realtimeSinceStartup - mClickTime;
							mClickTime = Time.realtimeSinceStartup;

							if (spriteName != sprite.name)
							{
								if (mSprite != null)
								{
									NGUIEditorTools.RegisterUndo("Atlas Selection", mSprite);
									mSprite.spriteName = sprite.name;
									mSprite.MakePixelPerfect();
									EditorUtility.SetDirty(mSprite.gameObject);
								}
								else if (mCallback != null)
								{
									mName = sprite.name;
									mCallback(sprite.name);
								}
							}
							else if (delta < 0.5f) close = true;
						}
						
						if (Event.current.type == EventType.Repaint)
						{
							// On top of the button we have a checkboard grid
							NGUIEditorTools.DrawTiledTexture(rect, NGUIEditorTools.backdropTexture);
	
							Rect uv = sprite.outer;
							if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
								uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height);
	
							// Calculate the texture's scale that's needed to display the sprite in the clipped area
							float scaleX = rect.width / uv.width;
							float scaleY = rect.height / uv.height;
	
							// Stretch the sprite so that it will appear proper
							float aspect = (scaleY / scaleX) / ((float)tex.height / tex.width);
							Rect clipRect = rect;
	
							if (aspect != 1f)
							{
								if (aspect < 1f)
								{
									// The sprite is taller than it is wider
									float padding = size * (1f - aspect) * 0.5f;
									clipRect.xMin += padding;
									clipRect.xMax -= padding;
								}
								else
								{
									// The sprite is wider than it is taller
									float padding = size * (1f - 1f / aspect) * 0.5f;
									clipRect.yMin += padding;
									clipRect.yMax -= padding;
								}
							}
	
							GUI.DrawTextureWithTexCoords(clipRect, tex, uv);
	
							// Draw the selection
							if (spriteName == sprite.name)
							{
								NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
							}
						}

						if (++col >= columns)
						{
							++offset;
							break;
						}
						rect.x += padded;
					}
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(padded);
				rect.y += padded;
			}
			GUILayout.EndScrollView();
			if (close) Close();
		}
	}

19 View Source File : UIAtlasMaker.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		bool create = false;
		bool update = false;
		bool replace = false;

		string prefabPath = "";
		string matPath = "";

		// If we have an atlas to work with, see if we can figure out the path for it and its material
		if (NGUISettings.atlas != null && NGUISettings.atlas.name == NGUISettings.atlasName)
		{
			prefabPath = replacedetDatabase.GetreplacedetPath(NGUISettings.atlas.gameObject.GetInstanceID());
			if (NGUISettings.atlas.spriteMaterial != null) matPath = replacedetDatabase.GetreplacedetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID());
		}

		// replacedume default values if needed
		if (string.IsNullOrEmpty(NGUISettings.atlasName)) NGUISettings.atlasName = "New Atlas";
		if (string.IsNullOrEmpty(prefabPath)) prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.atlasName + ".prefab";
		if (string.IsNullOrEmpty(matPath)) matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.atlasName + ".mat";

		// Try to load the prefab
		GameObject go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;
		if (NGUISettings.atlas == null && go != null) NGUISettings.atlas = go.GetComponent<UIAtlas>();

		EditorGUIUtility.LookLikeControls(80f);

		GUILayout.Space(6f);
		GUILayout.BeginHorizontal();

		if (go == null)
		{
			GUI.backgroundColor = Color.green;
			create = GUILayout.Button("Create", GUILayout.Width(76f));
		}
		else
		{
			GUI.backgroundColor = Color.red;
			create = GUILayout.Button("Replace", GUILayout.Width(76f));
		}

		GUI.backgroundColor = Color.white;
		NGUISettings.atlasName = GUILayout.TextField(NGUISettings.atlasName);
		GUILayout.EndHorizontal();

		if (create)
		{
			// If the prefab already exists, confirm that we want to overwrite it
			if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " +
				NGUISettings.atlasName + " atlas with the textures currently selected in the Project View? All other sprites will be deleted.", "Yes", "No"))
			{
				replace = true;

				// Try to load the material
				Material mat = replacedetDatabase.LoadreplacedetAtPath(matPath, typeof(Material)) as Material;

				// If the material doesn't exist, create it
				if (mat == null)
				{
					Shader shader = Shader.Find("Unlit/Transparent Colored");
					mat = new Material(shader);

					// Save the material
					replacedetDatabase.Createreplacedet(mat, matPath);
					replacedetDatabase.Refresh();

					// Load the material so it's usable
					mat = replacedetDatabase.LoadreplacedetAtPath(matPath, typeof(Material)) as Material;
				}

				if (NGUISettings.atlas == null || NGUISettings.atlas.name != NGUISettings.atlasName)
				{
					// Create a new prefab for the atlas
#if UNITY_3_4
					Object prefab = (go != null) ? go : EditorUtility.CreateEmptyPrefab(prefabPath); 
#else
					Object prefab = (go != null) ? go : PrefabUtility.CreateEmptyPrefab(prefabPath);
#endif
					// Create a new game object for the atlas
					go = new GameObject(NGUISettings.atlasName);
					go.AddComponent<UIAtlas>().spriteMaterial = mat;

					// Update the prefab
#if UNITY_3_4
					EditorUtility.ReplacePrefab(go, prefab);
#else
					PrefabUtility.ReplacePrefab(go, prefab);
#endif
					DestroyImmediate(go);
					replacedetDatabase.Savereplacedets();
					replacedetDatabase.Refresh();

					// Select the atlas
					go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;
					NGUISettings.atlas = go.GetComponent<UIAtlas>();
				}
			}
		}

		ComponentSelector.Draw<UIAtlas>("Select", NGUISettings.atlas, OnSelectAtlas);

		List<Texture> textures = GetSelectedTextures();

		if (NGUISettings.atlas != null && NGUISettings.atlas.name == NGUISettings.atlasName)
		{
			Material mat = NGUISettings.atlas.spriteMaterial;
			Texture tex = NGUISettings.atlas.texture;

			// Material information
			GUILayout.BeginHorizontal();
			{
				if (mat != null)
				{
					if (GUILayout.Button("Material", GUILayout.Width(76f))) Selection.activeObject = mat;
					GUILayout.Label(" " + mat.name);
				}
				else
				{
					GUI.color = Color.grey;
					GUILayout.Button("Material", GUILayout.Width(76f));
					GUI.color = Color.white;
					GUILayout.Label(" N/A");
				}
			}
			GUILayout.EndHorizontal();

			// Texture atlas information
			GUILayout.BeginHorizontal();
			{
				if (tex != null)
				{
					if (GUILayout.Button("Texture", GUILayout.Width(76f))) Selection.activeObject = tex;
					GUILayout.Label(" " + tex.width + "x" + tex.height);
				}
				else
				{
					GUI.color = Color.grey;
					GUILayout.Button("Texture", GUILayout.Width(76f));
					GUI.color = Color.white;
					GUILayout.Label(" N/A");
				}
			}
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			NGUISettings.atlasPadding = Mathf.Clamp(EditorGUILayout.IntField("Padding", NGUISettings.atlasPadding, GUILayout.Width(100f)), 0, 8);
			GUILayout.Label((NGUISettings.atlasPadding == 1 ? "pixel" : "pixels") + " in-between of sprites");
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			NGUISettings.atlasTrimming = EditorGUILayout.Toggle("Trim Alpha", NGUISettings.atlasTrimming, GUILayout.Width(100f));
			GUILayout.Label("Remove empty space");
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			NGUISettings.unityPacking = EditorGUILayout.Toggle("Unity Packer", NGUISettings.unityPacking, GUILayout.Width(100f));
			GUILayout.Label("if off, use a custom packer");
			GUILayout.EndHorizontal();

			if (!NGUISettings.unityPacking)
			{
				GUILayout.BeginHorizontal();
				NGUISettings.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", NGUISettings.forceSquareAtlas, GUILayout.Width(100f));
				GUILayout.Label("if on, forces a square atlas texture");
				GUILayout.EndHorizontal();
			}

#if UNITY_IPHONE || UNITY_ANDROID
			GUILayout.BeginHorizontal();
			NGUISettings.allow4096 = EditorGUILayout.Toggle("4096x4096", NGUISettings.allow4096, GUILayout.Width(100f));
			GUILayout.Label("if off, limit atlases to 2048x2048");
			GUILayout.EndHorizontal();
#endif
			if (textures.Count > 0)
			{
				GUI.backgroundColor = Color.green;
				update = GUILayout.Button("Add/Update All");
				GUI.backgroundColor = Color.white;
			}
			else
			{
				NGUIEditorTools.DrawSeparator();
				GUILayout.Label("You can reveal more options by selecting\none or more textures in the Project View\nwindow.");
			}
		}
		else
		{
			NGUIEditorTools.DrawSeparator();
			GUILayout.Label("You can create a new atlas by selecting\none or more textures in the Project View\nwindow, then clicking \"Create\".");
		}

		Dictionary<string, int> spriteList = GetSpriteList(textures);

		if (spriteList.Count > 0)
		{
			NGUIEditorTools.DrawHeader("Sprites");
			GUILayout.Space(-7f);

			mScroll = GUILayout.BeginScrollView(mScroll);

			bool delete = false;
			int index = 0;
			foreach (KeyValuePair<string, int> iter in spriteList)
			{
				++index;
				NGUIEditorTools.HighlightLine(new Color(0.6f, 0.6f, 0.6f));
				GUILayout.BeginHorizontal();
				GUILayout.Label(index.ToString(), GUILayout.Width(24f));
				GUILayout.Label(iter.Key);

				if (iter.Value == 2)
				{
					GUI.color = Color.green;
					GUILayout.Label("Add", GUILayout.Width(27f));
					GUI.color = Color.white;
				}
				else if (iter.Value == 1)
				{
					GUI.color = Color.cyan;
					GUILayout.Label("Update", GUILayout.Width(45f));
					GUI.color = Color.white;
				}
				else
				{
					if (mDelNames.Contains(iter.Key))
					{
						GUI.backgroundColor = Color.red;

						if (GUILayout.Button("Delete", GUILayout.Width(60f)))
						{
							delete = true;
						}
						GUI.backgroundColor = Color.green;
						if (GUILayout.Button("X", GUILayout.Width(22f)))
						{
							mDelNames.Remove(iter.Key);
							delete = false;
						}
						GUI.backgroundColor = Color.white;
					}
					else
					{
						// If we have not yet selected a sprite for deletion, show a small "X" button
						if (GUILayout.Button("X", GUILayout.Width(22f))) mDelNames.Add(iter.Key);
					}
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndScrollView();

			// If this sprite was marked for deletion, remove it from the atlas
			if (delete)
			{
				List<SpriteEntry> sprites = new List<SpriteEntry>();
				ExtractSprites(NGUISettings.atlas, sprites);

				for (int i = sprites.Count; i > 0; )
				{
					SpriteEntry ent = sprites[--i];

					if (mDelNames.Contains(ent.tex.name))
					{
						sprites.RemoveAt(i);
					}
				}
				UpdateAtlas(NGUISettings.atlas, sprites);
				mDelNames.Clear();
			}
			else if (update) UpdateAtlas(textures, true);
			else if (replace) UpdateAtlas(textures, false);
			return;
		}
	}

19 View Source File : UICameraTool.cs
License : Apache License 2.0
Project Creator : 365082218

void DrawRow (Camera cam)
	{
		if (cam != null) NGUIEditorTools.HighlightLine(new Color(0.6f, 0.6f, 0.6f));

		GUILayout.BeginHorizontal();
		{
			bool enabled = (cam == null || (NGUITools.GetActive(cam.gameObject) && cam.enabled));

			GUI.color = Color.white;

			if (cam != null)
			{
				if (enabled != EditorGUILayout.Toggle(enabled, GUILayout.Width(20f)))
				{
					cam.enabled = !enabled;
					EditorUtility.SetDirty(cam.gameObject);
				}
			}
			else
			{
				GUILayout.Space(30f);
			}

			bool highlight = (cam == null || Selection.activeGameObject == null) ? false :
				(0 != (cam.cullingMask & (1 << Selection.activeGameObject.layer)));

			if (enabled)
			{
				GUI.color = highlight ? new Color(0f, 0.8f, 1f) : Color.white;
			}
			else
			{
				GUI.color = highlight ? new Color(0f, 0.5f, 0.8f) : Color.grey;
			}

			string camName, camLayer;

			if (cam == null)
			{
				camName = "Camera's Name";
				camLayer = "Layer";
			}
			else
			{
				camName = cam.name + (cam.orthographic ? " (2D)" : " (3D)");
				camLayer = LayerMask.LayerToName(cam.gameObject.layer);
			}

#if UNITY_3_4
			if (GUILayout.Button(camName, EditorStyles.structHeadingLabel, GUILayout.MinWidth(100f)) && cam != null)
#else
			if (GUILayout.Button(camName, EditorStyles.label, GUILayout.MinWidth(100f)) && cam != null)
#endif
			{
				Selection.activeGameObject = cam.gameObject;
				EditorUtility.SetDirty(cam.gameObject);
			}
			GUILayout.Label(camLayer, GUILayout.Width(70f));

			GUI.color = enabled ? Color.white : new Color(0.7f, 0.7f, 0.7f);

			if (cam == null)
			{
				GUILayout.Label("EV", GUILayout.Width(26f));
			}
			else
			{
				UICamera uic = cam.GetComponent<UICamera>();
				bool ev = (uic != null && uic.enabled);

				if (ev != EditorGUILayout.Toggle(ev, GUILayout.Width(20f)))
				{
					if (uic == null) uic = cam.gameObject.AddComponent<UICamera>();
					uic.enabled = !ev;
				}
			}

			if (cam == null)
			{
				GUILayout.Label("Mask", GUILayout.Width(100f));
			}
			else
			{
				int mask = LayerMaskField(cam.cullingMask, GUILayout.Width(105f));

				if (cam.cullingMask != mask)
				{
					NGUIEditorTools.RegisterUndo("Camera Mask Change", cam);
					cam.cullingMask = mask;
				}
			}
		}
		GUILayout.EndHorizontal();
	}

19 View Source File : UICreateNewUIWizard.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		EditorGUIUtility.LookLikeControls(80f);

		GUILayout.Label("Create a new UI with the following parameters:");
		NGUIEditorTools.DrawSeparator();

		GUILayout.BeginHorizontal();
		NGUISettings.layer = EditorGUILayout.LayerField("Layer", NGUISettings.layer, GUILayout.Width(200f));
		GUILayout.Space(20f);
		GUILayout.Label("This is the layer your UI will reside on");
		GUILayout.EndHorizontal();

		GUILayout.BeginHorizontal();
		camType = (CameraType)EditorGUILayout.EnumPopup("Camera", camType, GUILayout.Width(200f));
		GUILayout.Space(20f);
		GUILayout.Label("Should this UI have a camera?");
		GUILayout.EndHorizontal();

		NGUIEditorTools.DrawSeparator();
		GUILayout.BeginHorizontal();
		EditorGUILayout.PrefixLabel("When ready,");
		bool create = GUILayout.Button("Create Your UI", GUILayout.Width(120f));
		GUILayout.EndHorizontal();

		if (create) CreateNewUI();
	}

19 View Source File : UICreateWidgetWizard.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		// Load the saved preferences
		if (!mLoaded) { mLoaded = true; Load(); }

		EditorGUIUtility.LookLikeControls(80f);
		GameObject go = NGUIEditorTools.SelectedRoot();

		if (go == null)
		{
			GUILayout.Label("You must create a UI first.");
			
			if (GUILayout.Button("Open the New UI Wizard"))
			{
				EditorWindow.GetWindow<UICreateNewUIWizard>(false, "New UI", true);
			}
		}
		else
		{
			GUILayout.Space(4f);

			GUILayout.BeginHorizontal();
			ComponentSelector.Draw<UIAtlas>(NGUISettings.atlas, OnSelectAtlas, GUILayout.Width(140f));
			GUILayout.Label("Texture atlas used by widgets", GUILayout.MinWidth(10000f));
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			ComponentSelector.Draw<UIFont>(NGUISettings.font, OnSelectFont, GUILayout.Width(140f));
			GUILayout.Label("Font used by labels", GUILayout.MinWidth(10000f));
			GUILayout.EndHorizontal();

			GUILayout.Space(-2f);
			NGUIEditorTools.DrawSeparator();

			GUILayout.BeginHorizontal();
			WidgetType wt = (WidgetType)EditorGUILayout.EnumPopup("Template", mType, GUILayout.Width(200f));
			GUILayout.Space(20f);
			GUILayout.Label("Select a widget template to use");
			GUILayout.EndHorizontal();

			if (mType != wt) { mType = wt; Save(); }

			switch (mType)
			{
				case WidgetType.Label:			CreateLabel(go); break;
				case WidgetType.Sprite:			CreateSprite(go, mSprite); break;
				case WidgetType.Texture:		CreateSimpleTexture(go); break;
				case WidgetType.Button:			CreateButton(go); break;
				case WidgetType.ImageButton:	CreateImageButton(go); break;
				case WidgetType.Checkbox:		CreateCheckbox(go); break;
				case WidgetType.ProgressBar:	CreateSlider(go, false); break;
				case WidgetType.Slider:			CreateSlider(go, true); break;
				case WidgetType.Input:			CreateInput(go); break;
				case WidgetType.PopupList:		CreatePopup(go, true); break;
				case WidgetType.PopupMenu:		CreatePopup(go, false); break;
				case WidgetType.ScrollBar:		CreateScrollBar(go); break;
			}
		}
	}

19 View Source File : UIFontInspector.cs
License : Apache License 2.0
Project Creator : 365082218

override public void OnInspectorGUI ()
	{
		mFont = target as UIFont;
		EditorGUIUtility.LookLikeControls(80f);

		NGUIEditorTools.DrawSeparator();

        //Lindean
        if (mFont.dynamicFont != null)
        {
            mType = FontType.Dynamic;
        }

		if (mFont.replacement != null)
		{
			mType = FontType.Reference;
			mReplacement = mFont.replacement;
		}
		else if (mFont.dynamicFont_1 != null)
		{
			mType = FontType.Dynamic;
		}

		GUILayout.BeginHorizontal();
		FontType fontType = (FontType)EditorGUILayout.EnumPopup("Font Type", mType);
		GUILayout.Space(18f);
		GUILayout.EndHorizontal();

		if (mType != fontType)
		{
			if (fontType == FontType.Normal)
			{
				OnSelectFont(null);
			}
			else
			{
				mType = fontType;
			}

            //Lindean
			if (mType != FontType.Dynamic && mFont.dynamicFont_1 != null)
				mFont.dynamicFont_1 = null;
		}

        //Lindean
        if (mType == FontType.Dynamic)
        {
            //Lindean - Draw settings for dynamic font
            bool changed = false;
            Font f = EditorGUILayout.ObjectField("Font", mFont.dynamicFont, typeof(Font), false) as Font;
            if (f != mFont.dynamicFont)
            {
                mFont.dynamicFont = f;
                changed = true;
            }

            Material mat = EditorGUILayout.ObjectField("Material", mFont.dynamicFontMaterial_1, typeof(Material), false) as Material;
            if (mat != mFont.dynamicFontMaterial_1)
            {
                mFont.dynamicFontMaterial_1 = mat;
                changed = true;
            }
            if (mFont.dynamicFontMaterial_1 == null)
                GUILayout.Label("Warning: no coloring or clipping when using default font material");

            int i = EditorGUILayout.IntField("Size", mFont.dynamicFontSize);
            if (i != mFont.dynamicFontSize)
            {
                mFont.dynamicFontSize = i;
                changed = true;
            }

            FontStyle style = (FontStyle)EditorGUILayout.EnumPopup("Style", mFont.dynamicFontStyle);
            if (style != mFont.dynamicFontStyle)
            {
                mFont.dynamicFontStyle = style;
                changed = true;
            }

            if (changed)
            {
                //force access to material property as it refreshes the texture replacedignment
                Debug.Log("font changed...");
                Material fontMat = mFont.material;
                if (fontMat.mainTexture == null)
                    Debug.Log("font material texture issue...");
                UIFont.OnFontRebuilt(mFont);
            }

            NGUIEditorTools.DrawSeparator();

            // Font spacing
            GUILayout.BeginHorizontal();
            {
                EditorGUIUtility.LookLikeControls(0f);
                GUILayout.Label("Spacing", GUILayout.Width(60f));
                GUILayout.Label("X", GUILayout.Width(12f));
                int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
                GUILayout.Label("Y", GUILayout.Width(12f));
                int y = EditorGUILayout.IntField(mFont.verticalSpacing);
                EditorGUIUtility.LookLikeControls(80f);

                if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
                {
                    NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
                    mFont.horizontalSpacing = x;
                    mFont.verticalSpacing = y;
                }
            }
            GUILayout.EndHorizontal();
        }
        //Lindean

		if (mType == FontType.Reference)
		{
			ComponentSelector.Draw<UIFont>(mFont.replacement, OnSelectFont);

			NGUIEditorTools.DrawSeparator();
			GUILayout.Label("You can have one font simply point to\n" +
				"another one. This is useful if you want to be\n" +
				"able to quickly replace the contents of one\n" +
				"font with another one, for example for\n" +
				"swapping an SD font with an HD one, or\n" +
				"replacing an English font with a Chinese\n" +
				"one. All the labels referencing this font\n" +
				"will update their references to the new one.");

			if (mReplacement != mFont && mFont.replacement != mReplacement)
			{
				NGUIEditorTools.RegisterUndo("Font Change", mFont);
				mFont.replacement = mReplacement;
				UnityEditor.EditorUtility.SetDirty(mFont);
			}
			return;
		}
		else if (mType == FontType.Dynamic)
		{
#if UNITY_3_5
			EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
			NGUIEditorTools.DrawSeparator();
			Font fnt = EditorGUILayout.ObjectField("TTF Font", mFont.dynamicFont_1, typeof(Font), false) as Font;
			
			if (fnt != mFont.dynamicFont_1)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.dynamicFont_1 = fnt;
			}

			GUILayout.BeginHorizontal();
			int size = EditorGUILayout.IntField("Size", mFont.dynamicFontSize_1, GUILayout.Width(120f));
			FontStyle style = (FontStyle)EditorGUILayout.EnumPopup(mFont.dynamicFontStyle_1);
			GUILayout.Space(18f);
			GUILayout.EndHorizontal();

			if (size != mFont.dynamicFontSize_1)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.dynamicFontSize_1 = size;
			}

			if (style != mFont.dynamicFontStyle_1)
			{
				NGUIEditorTools.RegisterUndo("Font change", mFont);
				mFont.dynamicFontStyle_1 = style;
			}

			Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

			if (mFont.material != mat)
			{
				NGUIEditorTools.RegisterUndo("Font Material", mFont);
				mFont.material = mat;
			}
#endif
		}
		else
		{
			NGUIEditorTools.DrawSeparator();

			ComponentSelector.Draw<UIAtlas>(mFont.atlas, OnSelectAtlas);

			if (mFont.atlas != null)
			{
				if (mFont.bmFont.isValid)
				{
					NGUIEditorTools.AdvancedSpriteField(mFont.atlas, mFont.spriteName, SelectSprite, false);
				}
				EditorGUILayout.Space();
			}
			else
			{
				// No atlas specified -- set the material and texture rectangle directly
				Material mat = EditorGUILayout.ObjectField("Material", mFont.material, typeof(Material), false) as Material;

				if (mFont.material != mat)
				{
					NGUIEditorTools.RegisterUndo("Font Material", mFont);
					mFont.material = mat;
				}
			}

			// For updating the font's data when importing from an external source, such as the texture packer
			bool resetWidthHeight = false;

			if (mFont.atlas != null || mFont.material != null)
			{
				Textreplacedet data = EditorGUILayout.ObjectField("Import Data", null, typeof(Textreplacedet), false) as Textreplacedet;

				if (data != null)
				{
					NGUIEditorTools.RegisterUndo("Import Font Data", mFont);
					BMFontReader.Load(mFont.bmFont, NGUITools.GetHierarchy(mFont.gameObject), data.bytes);
					mFont.MarkAsDirty();
					resetWidthHeight = true;
					Debug.Log("Imported " + mFont.bmFont.glyphCount + " characters");
				}
			}

			if (mFont.bmFont.isValid)
			{
				Color green = new Color(0.4f, 1f, 0f, 1f);
				Texture2D tex = mFont.texture;

				if (tex != null)
				{
					if (mFont.atlas == null)
					{
						// Pixels are easier to work with than UVs
						Rect pixels = NGUIMath.ConvertToPixels(mFont.uvRect, tex.width, tex.height, false);

						// Automatically set the width and height of the rectangle to be the original font texture's dimensions
						if (resetWidthHeight)
						{
							pixels.width = mFont.texWidth;
							pixels.height = mFont.texHeight;
						}

						// Font sprite rectangle
						GUI.backgroundColor = green;
						pixels = EditorGUILayout.RectField("Pixel Rect", pixels);
						GUI.backgroundColor = Color.white;

						// Create a button that can make the coordinates pixel-perfect on click
						GUILayout.BeginHorizontal();
						{
							Rect corrected = NGUIMath.MakePixelPerfect(pixels);

							if (corrected == pixels)
							{
								GUI.color = Color.grey;
								GUILayout.Button("Make Pixel-Perfect");
								GUI.color = Color.white;
							}
							else if (GUILayout.Button("Make Pixel-Perfect"))
							{
								pixels = corrected;
								GUI.changed = true;
							}
						}
						GUILayout.EndHorizontal();

						// Convert the pixel coordinates back to UV coordinates
						Rect uvRect = NGUIMath.ConvertToTexCoords(pixels, tex.width, tex.height);

						if (mFont.uvRect != uvRect)
						{
							NGUIEditorTools.RegisterUndo("Font Pixel Rect", mFont);
							mFont.uvRect = uvRect;
						}
						//NGUIEditorTools.DrawSeparator();
						EditorGUILayout.Space();
					}
				}
			}
		}

		// The font must be valid at this point for the rest of the options to show up
		if (mFont.isDynamic || mFont.bmFont.isValid)
		{
			// Font spacing
			GUILayout.BeginHorizontal();
			{
				EditorGUIUtility.LookLikeControls(0f);
				GUILayout.Label("Spacing", GUILayout.Width(60f));
				GUILayout.Label("X", GUILayout.Width(12f));
				int x = EditorGUILayout.IntField(mFont.horizontalSpacing);
				GUILayout.Label("Y", GUILayout.Width(12f));
				int y = EditorGUILayout.IntField(mFont.verticalSpacing);
				GUILayout.Space(18f);
				EditorGUIUtility.LookLikeControls(80f);

				if (mFont.horizontalSpacing != x || mFont.verticalSpacing != y)
				{
					NGUIEditorTools.RegisterUndo("Font Spacing", mFont);
					mFont.horizontalSpacing = x;
					mFont.verticalSpacing = y;
				}
			}
			GUILayout.EndHorizontal();

			if (mFont.atlas == null)
			{
				mView = View.Font;
				mUseShader = false;

				float pixelSize = EditorGUILayout.FloatField("Pixel Size", mFont.pixelSize, GUILayout.Width(120f));

				if (pixelSize != mFont.pixelSize)
				{
					NGUIEditorTools.RegisterUndo("Font Change", mFont);
					mFont.pixelSize = pixelSize;
				}
			}
			EditorGUILayout.Space();
		}

		// Preview option
		if (!mFont.isDynamic && mFont.atlas != null)
		{
			GUILayout.BeginHorizontal();
			{
				mView = (View)EditorGUILayout.EnumPopup("Preview", mView);
				GUILayout.Label("Shader", GUILayout.Width(45f));
				mUseShader = EditorGUILayout.Toggle(mUseShader, GUILayout.Width(20f));
			}
			GUILayout.EndHorizontal();
		}

		// Dynamic fonts don't support emoticons
		if (!mFont.isDynamic && mFont.bmFont.isValid)
		{
			if (mFont.atlas != null)
			{
				NGUIEditorTools.DrawHeader("Symbols and Emoticons");

				List<BMSymbol> symbols = mFont.symbols;

				for (int i = 0; i < symbols.Count; )
				{
					BMSymbol sym = symbols[i];

					GUILayout.BeginHorizontal();
					GUILayout.Label(sym.sequence, GUILayout.Width(40f));
					if (NGUIEditorTools.SimpleSpriteField(mFont.atlas, sym.spriteName, ChangeSymbolSprite))
						mSelectedSymbol = sym;

					if (GUILayout.Button("Edit", GUILayout.Width(40f)))
					{
						if (mFont.atlas != null)
						{
							EditorPrefs.SetString("NGUI Selected Sprite", sym.spriteName);
							NGUIEditorTools.Select(mFont.atlas.gameObject);
						}
					}

					GUI.backgroundColor = Color.red;

					if (GUILayout.Button("X", GUILayout.Width(22f)))
					{
						NGUIEditorTools.RegisterUndo("Remove symbol", mFont);
						mSymbolSequence = sym.sequence;
						mSymbolSprite = sym.spriteName;
						symbols.Remove(sym);
						mFont.MarkAsDirty();
					}
					GUI.backgroundColor = Color.white;
					GUILayout.EndHorizontal();
					GUILayout.Space(4f);
					++i;
				}

				if (symbols.Count > 0)
				{
					NGUIEditorTools.DrawSeparator();
				}

				GUILayout.BeginHorizontal();
				mSymbolSequence = EditorGUILayout.TextField(mSymbolSequence, GUILayout.Width(40f));
				NGUIEditorTools.SimpleSpriteField(mFont.atlas, mSymbolSprite, SelectSymbolSprite);

				bool isValid = !string.IsNullOrEmpty(mSymbolSequence) && !string.IsNullOrEmpty(mSymbolSprite);
				GUI.backgroundColor = isValid ? Color.green : Color.grey;

				if (GUILayout.Button("Add", GUILayout.Width(40f)) && isValid)
				{
					NGUIEditorTools.RegisterUndo("Add symbol", mFont);
					mFont.AddSymbol(mSymbolSequence, mSymbolSprite);
					mFont.MarkAsDirty();
					mSymbolSequence = "";
					mSymbolSprite = "";
				}
				GUI.backgroundColor = Color.white;
				GUILayout.EndHorizontal();

				if (symbols.Count == 0)
				{
					EditorGUILayout.HelpBox("Want to add an emoticon to your font? In the field above type ':)', choose a sprite, then hit the Add button.", MessageType.Info);
				}
				else GUILayout.Space(4f);
			}
		}
	}

19 View Source File : UIFontMaker.cs
License : Apache License 2.0
Project Creator : 365082218

void OnGUI ()
	{
		string prefabPath = "";
		string matPath = "";

		if (NGUISettings.font != null && NGUISettings.font.name == NGUISettings.fontName)
		{
			prefabPath = replacedetDatabase.GetreplacedetPath(NGUISettings.font.gameObject.GetInstanceID());
			if (NGUISettings.font.material != null) matPath = replacedetDatabase.GetreplacedetPath(NGUISettings.font.material.GetInstanceID());
		}

		// replacedume default values if needed
		if (string.IsNullOrEmpty(NGUISettings.fontName)) NGUISettings.fontName = "New Font";
		if (string.IsNullOrEmpty(prefabPath)) prefabPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".prefab";
		if (string.IsNullOrEmpty(matPath)) matPath = NGUIEditorTools.GetSelectionFolder() + NGUISettings.fontName + ".mat";

		EditorGUIUtility.LookLikeControls(80f);
		NGUIEditorTools.DrawHeader("Input");

		GUILayout.BeginHorizontal();
		mType = (FontType)EditorGUILayout.EnumPopup("Type", mType);
		GUILayout.Space(18f);
		GUILayout.EndHorizontal();
		int create = 0;

		if (mType == FontType.Dynamic)
		{
			NGUISettings.dynamicFont = EditorGUILayout.ObjectField("Font TTF", NGUISettings.dynamicFont, typeof(Font), false) as Font;

			GUILayout.BeginHorizontal();
			NGUISettings.dynamicFontSize = EditorGUILayout.IntField("Font Size", NGUISettings.dynamicFontSize, GUILayout.Width(120f));
			NGUISettings.dynamicFontStyle = (FontStyle)EditorGUILayout.EnumPopup(NGUISettings.dynamicFontStyle);
			GUILayout.Space(18f);
			GUILayout.EndHorizontal();

			if (NGUISettings.dynamicFont != null)
			{
				NGUIEditorTools.DrawHeader("Output");

				GUILayout.BeginHorizontal();
				GUILayout.Label("Font Name", GUILayout.Width(76f));
				GUI.backgroundColor = Color.white;
				NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName);
				GUILayout.EndHorizontal();
			}
			NGUIEditorTools.DrawSeparator();

#if UNITY_3_5
			EditorGUILayout.HelpBox("Dynamic fonts require Unity 4.0 or higher.", MessageType.Error);
#else
			// Helpful info
			if (NGUISettings.dynamicFont == null)
			{
				EditorGUILayout.HelpBox("Dynamic font creation happens right in Unity. Simply specify the TrueType font to be used as source.", MessageType.Info);
			}
			EditorGUILayout.HelpBox("Please note that dynamic fonts can't be made a part of an atlas, and they will always be drawn in a separate draw call. You WILL need to adjust transform position's Z rather than depth!", MessageType.Warning);

			if (NGUISettings.dynamicFont != null)
			{
				NGUIEditorTools.DrawSeparator();

				GUILayout.BeginHorizontal();
				GUILayout.FlexibleSpace();
				GUI.backgroundColor = Color.green;

				GameObject go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;

				if (go != null)
				{
					if (go.GetComponent<UIFont>() != null)
					{
						GUI.backgroundColor = Color.red;
						if (GUILayout.Button("Replace the Font", GUILayout.Width(140f))) create = 1;
					}
					else
					{
						GUI.backgroundColor = Color.grey;
						GUILayout.Button("Rename Your Font", GUILayout.Width(140f));
					}
				}
				else
				{
					GUI.backgroundColor = Color.green;
					if (GUILayout.Button("Create the Font", GUILayout.Width(140f))) create = 1;
				}

				GUI.backgroundColor = Color.white;
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
#endif
		}
		else
		{
			NGUISettings.fontData = EditorGUILayout.ObjectField("Font Data", NGUISettings.fontData, typeof(Textreplacedet), false) as Textreplacedet;
			NGUISettings.fontTexture = EditorGUILayout.ObjectField("Texture", NGUISettings.fontTexture, typeof(Texture2D), false) as Texture2D;

			// Draw the atlas selection only if we have the font data and texture specified, just to make it easier
			if (NGUISettings.fontData != null && NGUISettings.fontTexture != null)
			{
				NGUIEditorTools.DrawHeader("Output");

				GUILayout.BeginHorizontal();
				GUILayout.Label("Font Name", GUILayout.Width(76f));
				GUI.backgroundColor = Color.white;
				NGUISettings.fontName = GUILayout.TextField(NGUISettings.fontName);
				GUILayout.EndHorizontal();

				ComponentSelector.Draw<UIFont>("Select", NGUISettings.font, OnSelectFont);
				ComponentSelector.Draw<UIAtlas>(NGUISettings.atlas, OnSelectAtlas);
			}
			NGUIEditorTools.DrawSeparator();

			// Helpful info
			if (NGUISettings.fontData == null)
			{
				EditorGUILayout.HelpBox("The bitmap font creation mostly takes place outside of Unity. You can use BMFont on" +
					"Windows or your choice of Glyph Designer or the less expensive bmGlyph on the Mac.\n\n" +
					"Either of these tools will create a FNT file for you that you will drag & drop into the field above.", MessageType.Info);
			}
			else if (NGUISettings.fontTexture == null)
			{
				EditorGUILayout.HelpBox("When exporting your font, you should get two files: the TXT, and the texture. Only one texture can be used per font.", MessageType.Info);
			}
			else if (NGUISettings.atlas == null)
			{
				EditorGUILayout.HelpBox("You can create a font that doesn't use a texture atlas. This will mean that the text " +
					"labels using this font will generate an extra draw call, and will need to be sorted by " +
					"adjusting the Z instead of the Depth.\n\nIf you do specify an atlas, the font's texture will be added to it automatically.", MessageType.Info);

				NGUIEditorTools.DrawSeparator();

				GUILayout.BeginHorizontal();
				GUILayout.FlexibleSpace();
				GUI.backgroundColor = Color.red;
				if (GUILayout.Button("Create a Font without an Atlas", GUILayout.Width(200f))) create = 2;
				GUI.backgroundColor = Color.white;
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
			else
			{
				GUILayout.BeginHorizontal();
				GUILayout.FlexibleSpace();

				GameObject go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;

				if (go != null)
				{
					if (go.GetComponent<UIFont>() != null)
					{
						GUI.backgroundColor = Color.red;
						if (GUILayout.Button("Replace the Font", GUILayout.Width(140f))) create = 3;
					}
					else
					{
						GUI.backgroundColor = Color.grey;
						GUILayout.Button("Rename Your Font", GUILayout.Width(140f));
					}
				}
				else
				{
					GUI.backgroundColor = Color.green;
					if (GUILayout.Button("Create the Font", GUILayout.Width(140f))) create = 3;
				}
				GUI.backgroundColor = Color.white;
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
			}
		}

		if (create != 0)
		{
			GameObject go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;

			if (go == null || EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to replace the contents of the " +
				NGUISettings.fontName + " font with the currently selected values? This action can't be undone.", "Yes", "No"))
			{
				// Try to load the material
				Material mat = null;
				
				// Non-atlased font
				if (create == 2)
				{
					mat = replacedetDatabase.LoadreplacedetAtPath(matPath, typeof(Material)) as Material;

					// If the material doesn't exist, create it
					if (mat == null)
					{
						Shader shader = Shader.Find("Unlit/Transparent Colored");
						mat = new Material(shader);

						// Save the material
						replacedetDatabase.Createreplacedet(mat, matPath);
						replacedetDatabase.Refresh();

						// Load the material so it's usable
						mat = replacedetDatabase.LoadreplacedetAtPath(matPath, typeof(Material)) as Material;
					}
					mat.mainTexture = NGUISettings.fontTexture;
				}

				// Font doesn't exist yet
				if (go == null || go.GetComponent<UIFont>() == null)
				{
					// Create a new prefab for the atlas
					Object prefab = CreateEmptyPrefab(prefabPath);

					// Create a new game object for the font
					go = new GameObject(NGUISettings.fontName);
					NGUISettings.font = go.AddComponent<UIFont>();
					CreateFont(NGUISettings.font, create, mat);

					// Update the prefab
					ReplacePrefab(go, prefab);
					DestroyImmediate(go);
					replacedetDatabase.Refresh();

					// Select the atlas
					go = replacedetDatabase.LoadreplacedetAtPath(prefabPath, typeof(GameObject)) as GameObject;
					NGUISettings.font = go.GetComponent<UIFont>();
				}
				else
				{
					NGUISettings.font = go.GetComponent<UIFont>();
					CreateFont(NGUISettings.font, create, mat);
				}
				MarkAsChanged();
			}
		}
	}

19 View Source File : UIPanelInspector.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI ()
	{
		UIPanel panel = target as UIPanel;
		BetterList<UIDrawCall> drawcalls = panel.drawCalls;
		EditorGUIUtility.LookLikeControls(80f);

		//NGUIEditorTools.DrawSeparator();
		EditorGUILayout.Space();

		float alpha = EditorGUILayout.Slider("Alpha", panel.alpha, 0f, 1f);

		if (alpha != panel.alpha)
		{
			NGUIEditorTools.RegisterUndo("Panel Alpha", panel);
			panel.alpha = alpha;
		}

		if (panel.showInPanelTool != EditorGUILayout.Toggle("Panel Tool", panel.showInPanelTool))
		{
			panel.showInPanelTool = !panel.showInPanelTool;
			EditorUtility.SetDirty(panel);
			EditorWindow.FocusWindowIfItsOpen<UIPanelTool>();
		}

		panel.isTop = EditorGUILayout.Toggle("IsTop",panel.isTop);
		panel.isLeft = EditorGUILayout.Toggle("IsLeft",panel.isLeft);
		GUILayout.BeginHorizontal();
		bool norms = EditorGUILayout.Toggle("Normals", panel.generateNormals, GUILayout.Width(100f));
		GUILayout.Label("Needed for lit shaders");
		GUILayout.EndHorizontal();

		if (panel.generateNormals != norms)
		{
			panel.generateNormals = norms;
			panel.UpdateDrawcalls();
			EditorUtility.SetDirty(panel);
		}

		GUILayout.BeginHorizontal();
		bool depth = EditorGUILayout.Toggle("Depth Preplaced", panel.depthPreplaced, GUILayout.Width(100f));
		GUILayout.Label("Doubles draw calls, saves fillrate");
		GUILayout.EndHorizontal();

		if (panel.depthPreplaced != depth)
		{
			panel.depthPreplaced = depth;
			panel.UpdateDrawcalls();
			EditorUtility.SetDirty(panel);
		}

		if (depth)
		{
			UICamera cam = UICamera.FindCameraForLayer(panel.gameObject.layer);

			if (cam == null || cam.GetComponent<Camera>().orthographic)
			{
				EditorGUILayout.HelpBox("Please note that depth preplaced will only save fillrate when used with 3D UIs, and only UIs drawn by the game camera. If you are using a separate camera for the UI, you will not see any benefit!", MessageType.Warning);
			}
		}

		GUILayout.BeginHorizontal();
		bool stat = EditorGUILayout.Toggle("Static", panel.widgetsAreStatic, GUILayout.Width(100f));
		GUILayout.Label("Check if widgets won't move");
		GUILayout.EndHorizontal();

		if (panel.widgetsAreStatic != stat)
		{
			panel.widgetsAreStatic = stat;
			panel.UpdateDrawcalls();
			EditorUtility.SetDirty(panel);
		}

		EditorGUILayout.LabelField("Widgets", panel.widgets.size.ToString());
		EditorGUILayout.LabelField("Draw Calls", drawcalls.size.ToString());

		UIPanel.DebugInfo di = (UIPanel.DebugInfo)EditorGUILayout.EnumPopup("Debug Info", panel.debugInfo);

		if (panel.debugInfo != di)
		{
			panel.debugInfo = di;
			EditorUtility.SetDirty(panel);
		}

		UIDrawCall.Clipping clipping = (UIDrawCall.Clipping)EditorGUILayout.EnumPopup("Clipping", panel.clipping);

		if (panel.clipping != clipping)
		{
			panel.clipping = clipping;
			EditorUtility.SetDirty(panel);
		}

		if (panel.clipping != UIDrawCall.Clipping.None)
		{
			Vector4 range = panel.clipRange;

			GUILayout.BeginHorizontal();
			GUILayout.Space(80f);
			Vector2 pos = EditorGUILayout.Vector2Field("Center", new Vector2(range.x, range.y));
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			GUILayout.Space(80f);
			Vector2 size = EditorGUILayout.Vector2Field("Size", new Vector2(range.z, range.w));
			GUILayout.EndHorizontal();

			if (size.x < 0f) size.x = 0f;
			if (size.y < 0f) size.y = 0f;

			range.x = pos.x;
			range.y = pos.y;
			range.z = size.x;
			range.w = size.y;

			if (panel.clipRange != range)
			{
				NGUIEditorTools.RegisterUndo("Clipping Change", panel);
				panel.clipRange = range;
				EditorUtility.SetDirty(panel);
			}

			if (panel.clipping == UIDrawCall.Clipping.SoftClip)
			{
				GUILayout.BeginHorizontal();
				GUILayout.Space(80f);
				Vector2 soft = EditorGUILayout.Vector2Field("Softness", panel.clipSoftness);
				GUILayout.EndHorizontal();

				if (soft.x < 1f) soft.x = 1f;
				if (soft.y < 1f) soft.y = 1f;

				if (panel.clipSoftness != soft)
				{
					NGUIEditorTools.RegisterUndo("Clipping Change", panel);
					panel.clipSoftness = soft;
					EditorUtility.SetDirty(panel);
				}
			}

#if UNITY_ANDROID || UNITY_IPHONE
			if (PlayerSettings.targetGlesGraphics == TargetGlesGraphics.OpenGLES_1_x)
			{
				EditorGUILayout.HelpBox("Clipping requires shader support!\n\nOpen File -> Build Settings -> Player Settings -> Other Settings, then set:\n\n- Graphics Level: OpenGL ES 2.0.", MessageType.Error);
			}
#endif
		}

		if (clipping == UIDrawCall.Clipping.HardClip)
		{
			EditorGUILayout.HelpBox("Hard clipping has been removed due to major performance issues on certain Android devices. Alpha clipping will be used instead.", MessageType.Warning);
		}

		if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
		{
			EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);
			
			if (GUILayout.Button("Auto-fix"))
			{
				NGUIEditorTools.FixUniform(panel.gameObject);
			}
		}

		foreach (UIDrawCall dc in drawcalls)
		{
			NGUIEditorTools.DrawSeparator();
			EditorGUILayout.ObjectField("Material", dc.material, typeof(Material), false);
			EditorGUILayout.LabelField("Triangles", dc.triangles.ToString());

			if (clipping != UIDrawCall.Clipping.None && !dc.isClipped)
			{
				EditorGUILayout.HelpBox("You must switch this material's shader to Unlit/Transparent Colored or Unlit/Premultiplied Colored in order for clipping to work.",
					MessageType.Warning);
			}
		}
	}

19 View Source File : ColorCorrectionLookupEditor.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI () {
            serObj.Update ();

            EditorGUILayout.LabelField("Converts textures into color lookup volumes (for grading)", EditorStyles.miniLabel);

            //EditorGUILayout.LabelField("Change Lookup Texture (LUT):");
            //EditorGUILayout.BeginHorizontal ();
            //Rect r = GUILayoutUtility.GetAspectRect(1.0ff);

            Rect r; Texture2D t;

            //EditorGUILayout.Space();
            tempClutTex2D = EditorGUILayout.ObjectField (" Based on", tempClutTex2D, typeof(Texture2D), false) as Texture2D;
            if (tempClutTex2D == null) {
                t = replacedetDatabase.LoadMainreplacedetAtPath(((ColorCorrectionLookup)target).basedOnTempTex) as Texture2D;
                if (t) tempClutTex2D = t;
            }

            Texture2D tex = tempClutTex2D;

            if (tex && (target as ColorCorrectionLookup).basedOnTempTex != replacedetDatabase.GetreplacedetPath(tex))
            {
                EditorGUILayout.Separator();
                if (!(target as ColorCorrectionLookup).ValidDimensions(tex))
                {
                    EditorGUILayout.HelpBox ("Invalid texture dimensions!\nPick another texture or adjust dimension to e.g. 256x16.", MessageType.Warning);
                }
                else if (GUILayout.Button ("Convert and Apply"))
                {
                    string path = replacedetDatabase.GetreplacedetPath (tex);
                    TextureImporter textureImporter = replacedetImporter.GetAtPath(path) as TextureImporter;
                    bool doImport = textureImporter.isReadable == false;
                    if (textureImporter.mipmapEnabled == true) {
                        doImport = true;
                    }
                    if (textureImporter.textureFormat != TextureImporterFormat.AutomaticTruecolor) {
                        doImport = true;
                    }

                    if (doImport)
                    {
                        textureImporter.isReadable = true;
                        textureImporter.mipmapEnabled = false;
                        textureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
                        replacedetDatabase.Importreplacedet (path, ImportreplacedetOptions.ForceUpdate);
                        //tex = replacedetDatabase.LoadMainreplacedetAtPath(path);
                    }

                    (target as ColorCorrectionLookup).Convert(tex, path);
                }
            }

            if ((target as ColorCorrectionLookup).basedOnTempTex != "")
            {
                EditorGUILayout.HelpBox("Using " + (target as ColorCorrectionLookup).basedOnTempTex, MessageType.Info);
                t = replacedetDatabase.LoadMainreplacedetAtPath(((ColorCorrectionLookup)target).basedOnTempTex) as Texture2D;
                if (t) {
                    r = GUILayoutUtility.GetLastRect();
                    r = GUILayoutUtility.GetRect(r.width, 20);
                    r.x += r.width * 0.05f/2.0f;
                    r.width *= 0.95f;
                    GUI.DrawTexture (r, t);
                    GUILayoutUtility.GetRect(r.width, 4);
                }
            }

            //EditorGUILayout.EndHorizontal ();

            serObj.ApplyModifiedProperties();
        }

19 View Source File : SunShaftsEditor.cs
License : Apache License 2.0
Project Creator : 365082218

public override void OnInspectorGUI () {
            serObj.Update ();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField (useDepthTexture, new GUIContent ("Rely on Z Buffer?"));
            if ((target as SunShafts).GetComponent<Camera>())
                GUILayout.Label("Current camera mode: "+ (target as SunShafts).GetComponent<Camera>().depthTextureMode, EditorStyles.miniBoldLabel);

            EditorGUILayout.EndHorizontal();

            // depth buffer need
            /*
		bool  newVal = useDepthTexture.boolValue;
		if (newVal != oldVal) {
			if (newVal)
				(target as SunShafts).camera.depthTextureMode |= DepthTextureMode.Depth;
			else
				(target as SunShafts).camera.depthTextureMode &= ~DepthTextureMode.Depth;
		}
		*/

            EditorGUILayout.PropertyField (resolution,  new GUIContent("Resolution"));
            EditorGUILayout.PropertyField (screenBlendMode, new GUIContent("Blend mode"));

            EditorGUILayout.Separator ();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField (sunTransform, new GUIContent("Shafts caster", "Chose a transform that acts as a root point for the produced sun shafts"));
            if ((target as SunShafts).sunTransform && (target as SunShafts).GetComponent<Camera>()) {
                if (GUILayout.Button("Center on " + (target as SunShafts).GetComponent<Camera>().name)) {
                    if (EditorUtility.DisplayDialog ("Move sun shafts source?", "The SunShafts caster named "+ (target as SunShafts).sunTransform.name +"\n will be centered along "+(target as SunShafts).GetComponent<Camera>().name+". Are you sure? ", "Please do", "Don't")) {
                        Ray ray = (target as SunShafts).GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f,0.5f,0));
                        (target as SunShafts).sunTransform.position = ray.origin + ray.direction * 500.0f;
                        (target as SunShafts).sunTransform.LookAt ((target as SunShafts).transform);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator ();

            EditorGUILayout.PropertyField (sunThreshold,  new GUIContent ("Threshold color"));
            EditorGUILayout.PropertyField (sunColor,  new GUIContent ("Shafts color"));
            maxRadius.floatValue = 1.0f - EditorGUILayout.Slider ("Distance falloff", 1.0f - maxRadius.floatValue, 0.1f, 1.0f);

            EditorGUILayout.Separator ();

            sunShaftBlurRadius.floatValue = EditorGUILayout.Slider ("Blur size", sunShaftBlurRadius.floatValue, 1.0f, 10.0f);
            radialBlurIterations.intValue = EditorGUILayout.IntSlider ("Blur iterations", radialBlurIterations.intValue, 1, 3);

            EditorGUILayout.Separator ();

            EditorGUILayout.PropertyField (sunShaftIntensity,  new GUIContent("Intensity"));

            serObj.ApplyModifiedProperties();
        }

19 View Source File : CheckResources.cs
License : Apache License 2.0
Project Creator : 365082218

void ListMaterials ()
		{
				materialListScrollPos = EditorGUILayout.BeginScrollView (materialListScrollPos);
		
				foreach (MaterialDetails tDetails in ActiveMaterials) {			
						if (tDetails.material != null) {
								GUILayout.BeginHorizontal ();
				
								if (tDetails.material.mainTexture != null)
										GUILayout.Box (tDetails.material.mainTexture, GUILayout.Width (ThumbnailWidth), GUILayout.Height (ThumbnailHeight));
								else {
										GUILayout.Box ("n/a", GUILayout.Width (ThumbnailWidth), GUILayout.Height (ThumbnailHeight));
								}
				
								if (GUILayout.Button (tDetails.material.name, GUILayout.Width (150))) {
										SelectObject (tDetails.material, ctrlPressed);
								}
				
								string shaderLabel = tDetails.material.shader != null ? tDetails.material.shader.name : "no shader";
								GUILayout.Label (shaderLabel, GUILayout.Width (200));
				
								if (GUILayout.Button (tDetails.FoundInRenderers.Count + " GO", GUILayout.Width (50))) {
										List<Object> FoundObjects = new List<Object> ();
										foreach (Renderer renderer in tDetails.FoundInRenderers)
												FoundObjects.Add (renderer.gameObject);
										SelectObjects (FoundObjects, ctrlPressed);
								}
				
				
								GUILayout.EndHorizontal ();	
						}
				}
				EditorGUILayout.EndScrollView ();		
		}

19 View Source File : CheckResources.cs
License : Apache License 2.0
Project Creator : 365082218

void ListMeshes ()
		{
				meshListScrollPos = EditorGUILayout.BeginScrollView (meshListScrollPos);
		
				foreach (MeshDetails tDetails in ActiveMeshDetails) {			
						if (tDetails.mesh != null) {
								GUILayout.BeginHorizontal ();
								/*
				if (tDetails.material.mainTexture!=null) GUILayout.Box(tDetails.material.mainTexture, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));
				else	
				{
					GUILayout.Box("n/a",GUILayout.Width(ThumbnailWidth),GUILayout.Height(ThumbnailHeight));
				}
				*/
				
								if (GUILayout.Button (tDetails.mesh.name, GUILayout.Width (150))) {
										SelectObject (tDetails.mesh, ctrlPressed);
								}
								string sizeLabel = "" + tDetails.mesh.vertexCount + " vert";
				
								GUILayout.Label (sizeLabel, GUILayout.Width (100));
				
				
								if (GUILayout.Button (tDetails.FoundInMeshFilters.Count + " GO", GUILayout.Width (50))) {
										List<Object> FoundObjects = new List<Object> ();
										foreach (MeshFilter meshFilter in tDetails.FoundInMeshFilters)
												FoundObjects.Add (meshFilter.gameObject);
										SelectObjects (FoundObjects, ctrlPressed);
								}
				
								if (GUILayout.Button (tDetails.FoundInSkinnedMeshRenderer.Count + " GO", GUILayout.Width (50))) {
										List<Object> FoundObjects = new List<Object> ();
										foreach (SkinnedMeshRenderer skinnedMeshRenderer in tDetails.FoundInSkinnedMeshRenderer)
												FoundObjects.Add (skinnedMeshRenderer.gameObject);
										SelectObjects (FoundObjects, ctrlPressed);
								}
				
				
								GUILayout.EndHorizontal ();	
						}
				}
				EditorGUILayout.EndScrollView ();		
		}

19 View Source File : UICreateWidgetWizard.cs
License : Apache License 2.0
Project Creator : 365082218

static public bool ShouldCreate (GameObject go, bool isValid)
	{
		GUI.color = isValid ? Color.green : Color.grey;

		GUILayout.BeginHorizontal();
		bool retVal = GUILayout.Button("Add To", GUILayout.Width(76f));
		GUI.color = Color.white;
		GameObject sel = EditorGUILayout.ObjectField(go, typeof(GameObject), true, GUILayout.Width(140f)) as GameObject;
		GUILayout.Label("Select the parent in the Hierarchy View", GUILayout.MinWidth(10000f));
		GUILayout.EndHorizontal();

		if (sel != go) Selection.activeGameObject = sel;

		if (retVal && isValid)
		{
			NGUIEditorTools.RegisterUndo("Add a Widget");
			return true;
		}
		return false;
	}

19 View Source File : UIPanelTool.cs
License : Apache License 2.0
Project Creator : 365082218

bool DrawRow (Entry ent, UIPanel selected, bool isChecked)
	{
		bool retVal = false;
		string panelName, layer, widgetCount, drawCalls, clipping;

		if (ent != null)
		{
			panelName = ent.panel.name;
			layer = LayerMask.LayerToName(ent.panel.gameObject.layer);
			widgetCount = ent.widgets.Count.ToString();
			drawCalls = ent.panel.drawCalls.size.ToString();
			clipping = (ent.panel.clipping != UIDrawCall.Clipping.None) ? "Yes" : "";
		}
		else
		{
			panelName = "Panel's Name";
			layer = "Layer";
			widgetCount = "WG";
			drawCalls = "DC";
			clipping = "Clip";
		}

		if (ent != null) NGUIEditorTools.HighlightLine(ent.isEnabled ? new Color(0.6f, 0.6f, 0.6f) : Color.black);

		GUILayout.BeginHorizontal();
		{
			GUI.color = Color.white;

			if (isChecked != EditorGUILayout.Toggle(isChecked, GUILayout.Width(20f))) retVal = true;

			if (ent == null)
			{
				GUI.contentColor = Color.white;
			}
			else if (ent.isEnabled)
			{
				GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.8f, 1f) : Color.white; 
			}
			else
			{
				GUI.contentColor = (ent.panel == selected) ? new Color(0f, 0.5f, 0.8f) : Color.grey;
			}

#if UNITY_3_4
			if (GUILayout.Button(panelName, EditorStyles.structHeadingLabel, GUILayout.MinWidth(100f)))
#else
			if (GUILayout.Button(panelName, EditorStyles.label, GUILayout.MinWidth(100f)))
#endif
			{
				if (ent != null)
				{
					Selection.activeGameObject = ent.panel.gameObject;
					EditorUtility.SetDirty(ent.panel.gameObject);
				}
			}

			GUILayout.Label(layer, GUILayout.Width(ent == null ? 65f : 70f));
			GUILayout.Label(widgetCount, GUILayout.Width(30f));
			GUILayout.Label(drawCalls, GUILayout.Width(30f));
			GUILayout.Label(clipping, GUILayout.Width(30f));

			if (ent == null)
			{
				GUILayout.Label("Giz", GUILayout.Width(24f));
			}
			else
			{
				GUI.contentColor = ent.isEnabled ? Color.white : new Color(0.7f, 0.7f, 0.7f);
				bool debug = (ent.panel.debugInfo == UIPanel.DebugInfo.Gizmos);

				if (debug != EditorGUILayout.Toggle(debug, GUILayout.Width(20f)))
				{
					// debug != value, so it's currently inverse
					ent.panel.debugInfo = debug ? UIPanel.DebugInfo.None : UIPanel.DebugInfo.Gizmos;
					EditorUtility.SetDirty(ent.panel.gameObject);
				}
			}
		}
		GUILayout.EndHorizontal();
		return retVal;
	}

19 View Source File : NoiseEditor.cs
License : MIT License
Project Creator : adrianpolimeni

public override void OnInspectorGUI()
        {
            noise = (Noise)target;
            texTab = GUILayout.Toolbar(texTab, new string[] { "Shape", "Detail" });
            noise.activeTextureType = (Noise.NoiseType)texTab;
            switch (texTab)
            {
                case 0:
                    DrawShapeMenu();
                    break;
                case 1:
                    DrawDetailMenu();
                    break;
            }
            if (defaultFoldout = EditorGUILayout.Foldout(defaultFoldout, "Shader Setup"))
            {
                DrawDefaultInspector();
            }
            if (GUILayout.Button("Save Noise Settings")) {
                noise.SaveSettings();
            }
        }

19 View Source File : NoiseEditor.cs
License : MIT License
Project Creator : adrianpolimeni

void DrawChannelMenu(int type, int channel) {
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Noise Settings", EditorStyles.boldLabel);
            noise.OnSettingsChange();
            NoiseSettings noiseSettings = noise.activeSettings;
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Seed");
            if (GUILayout.Button("Generate New Seed")) {
                rand = new System.Random(noiseSettings.seed);
                noiseSettings.seed = rand.Next();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
                    GUILayout.Label("Cell Divisions of Layers");
                    noiseSettings.frequencyA = EditorGUILayout.IntSlider( noiseSettings.frequencyA, 1, 64);
                    EditorGUILayout.Separator();
                    noiseSettings.frequencyB = EditorGUILayout.IntSlider( noiseSettings.frequencyB, 1, 64);
                    EditorGUILayout.Separator();
                    noiseSettings.frequencyC = EditorGUILayout.IntSlider( noiseSettings.frequencyC, 1, 64);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                    GUILayout.Label("Mix");
                    noiseSettings.mix = GUILayout.VerticalSlider( noiseSettings.mix, 0, 1);
                EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            if (textureFoldout = EditorGUILayout.Foldout(textureFoldout, "View Cross Section"))
            {
                Texture2D display = GetCrossSection(type, channel, sliceIndex);

                if (display != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (sliceIndex > display.width - 1)
                        sliceIndex = 0;
                    sliceIndex = (int)GUILayout.VerticalSlider(sliceIndex, 0, display.width - 1);
                    GUILayout.Label(display);
                    EditorGUILayout.EndHorizontal();
                }
                else
                    EditorGUILayout.HelpBox("Texture not found!", MessageType.Warning); 
            }
        }

19 View Source File : GUILayout.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static bool Button(string text)
        {
            return UGUI.Button(text, Style.Button, DefaultOption);
        }

19 View Source File : GUILayout.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static bool Button(string text, GUILayoutOption[] opts)
        {
            return UGUI.Button(text, Style.Button, opts);
        }

19 View Source File : GUILayout.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static bool ToggleButton(bool val, string label)
        {
            UGUI.BeginHorizontal();
            UGUI.Label(label, Style.Label, DefaultOption);
            UGUI.Space(5f);
            val = UGUI.Button(val ? GUI.LabelEnabled : GUI.LabelDisabled, Style.TextButton, DefaultOption);
            UGUI.EndHorizontal();
            return val;
        }

19 View Source File : GUILayout.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static bool ToggleButton(bool val, string label, GUILayoutOption[] lblOpts, GUILayoutOption[] btnOpts)
        {
            UGUI.BeginHorizontal();
            UGUI.Label(label, Style.Label, lblOpts);
            UGUI.Space(5f);
            val = UGUI.Button(val ? GUI.LabelEnabled : GUI.LabelDisabled, Style.TextButton, btnOpts);
            UGUI.EndHorizontal();
            return val;
        }

See More Examples