/// <summary> /// Draw the atlas and Image selection fields. /// </summary> protected void SpriteGUI() { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); //图集 if (SUGUIEditorTool.DrawPrefixButton("Atlas")) { AtlasSelector.ShowWind(SelectAtlas); } SUGUIEditorTool.DrawObjectField <SpriteAtlas>(m_SpriteAtlas, ""); EditorGUILayout.EndHorizontal(); SUGUIEditorTool.DrawAtlasSpriteField(m_SpriteAtlas.objectReferenceValue as SpriteAtlas, m_SpriteName.stringValue, SelectSprite); if (EditorGUI.EndChangeCheck()) { var newSprite = m_Sprite.objectReferenceValue as Sprite; if (newSprite) { Image.Type oldType = (Image.Type)m_Type.enumValueIndex; if (newSprite.border.SqrMagnitude() > 0) { m_Type.enumValueIndex = (int)Image.Type.Sliced; } else if (oldType == Image.Type.Sliced) { m_Type.enumValueIndex = (int)Image.Type.Simple; } } (serializedObject.targetObject as Image).DisableSpriteOptimizations(); } }
/// <summary> /// Show the sprite selection wizard. /// </summary> public static void ShowSelected() { if (SUGUISetting.atlas != null) { Show(delegate(SpriteAtlas atlas, string sel) { SUGUIEditorTool.SelectSprite(sel); }); } }
//TextStyle public virtual void DrawTextStyle() { SUGUIEditorTool.DrawObjectField <TextStyle>(m_Style, "Text Style"); if (m_Style.objectReferenceValue == null) { ((SText)target).textStyle = SUGUISetting.textStyle; } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EditorGUILayout.PropertyField(m_TweenScale); bool tween = SUGUIEditorTool.GetBoolPropertyValue(m_TweenScale); BtnScaleCompoment.enabled = tween; EditorGUILayout.PropertyField(m_ContentText); EditorGUILayout.PropertyField(m_OnClickProperty); EditorGUILayout.PropertyField(m_OnDoubleClickProperty); EditorGUILayout.PropertyField(m_OnLongClickProperty); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { EditorGUIUtility.labelWidth = 80f; if (SUGUISetting.atlas == null) { GUILayout.Label("没有选择图集", "LODLevelNotifyText"); } else { SpriteAtlas atlas = SUGUISetting.atlas; bool close = false; GUILayout.Label(atlas.name + " Sprites", "LODLevelNotifyText"); //NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string before = SUGUISetting.partialSprite; //Debug.Log("----->before:" + before); string after = EditorGUILayout.TextField("", before, "SearchTextField"); //Debug.Log("----->after:" + after); if (before != after) { SUGUISetting.partialSprite = after; } if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { SUGUISetting.partialSprite = ""; GUIUtility.keyboardControl = 0; } GUILayout.Space(84f); GUILayout.EndHorizontal(); List <string> spritePathList = SUGUIEditorTool.GetAllSprites(atlas, SUGUISetting.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); int rows = 1; while (offset < spritePathList.Count) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < spritePathList.Count; ++offset) { Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(spritePathList[offset]); if (texture == null) { continue; } // Button comes first if (GUI.Button(rect, "")) { if (Event.current.button == 0) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; string spriteName = spritePathList[offset].GetFileNameByPath(); if (SUGUISetting.selectedSprite != spriteName) { if (mSprite != null) { SUGUIEditorTool.RegisterUndo("Atlas Selection", mSprite); mSprite.SetNativeSize(); EditorUtility.SetDirty(mSprite.gameObject); } SUGUISetting.selectedSprite = spriteName; if (mCallback != null) { mCallback(atlas, spriteName); } } else if (delta < 0.5f) { close = true; } } else { //NGUIContextMenu.AddItem("Edit", false, EditSprite, sprite); //NGUIContextMenu.AddItem("Delete", false, DeleteSprite, sprite); //NGUIContextMenu.Show(); } } if (Event.current.type == EventType.Repaint) { SUGUIEditorTool.DrawTiledTexture(rect, SUGUIEditorTool.backdropTexture); Rect clipRect = rect; GUI.DrawTexture(clipRect, texture); //GUI.DrawTextureWithTexCoords(clipRect, tex, uv); // Draw the selection if (SUGUISetting.selectedSprite.GetFileNameByPathWithoutExtention() == texture.name) { SUGUIEditorTool.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } } GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), texture.name, "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; if (++col >= columns) { ++offset; break; } rect.x += padded; } } GUILayout.EndHorizontal(); GUILayout.Space(padded); rect.y += padded + 26; ++rows; } GUILayout.Space(rows * 26); GUILayout.EndScrollView(); if (close) { Close(); } } }