using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using UnityEditor; using System.IO; public class CreateZhanyouUI : Editor { [MenuItem("GameObject/UI/Zhanyou/Text")] public static void CreateText() { var textObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\Text.prefab"); InstantiateAsChild(textObj); } [MenuItem("GameObject/UI/Zhanyou/Button")] public static void CreateButton() { var textObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\Button.prefab"); InstantiateAsChild(textObj); } [MenuItem("GameObject/UI/Zhanyou/Toggle")] public static void CreateToggle() { var textObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\Toggle.prefab"); InstantiateAsChild(textObj); } [MenuItem("GameObject/UI/Zhanyou/ProcessBar")] public static void CreateProcessBar() { var uiObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\Processbar.prefab"); InstantiateAsChild(uiObj); } [MenuItem("GameObject/UI/Zhanyou/TagPanel")] public static void CreateTagPanel() { var uiObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\UITagPanel.prefab"); InstantiateAsChild(uiObj); } [MenuItem("GameObject/UI/Zhanyou/ContainerScoll")] public static void CreateContainerScoll() { var uiObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\UIContainerScroll.prefab"); InstantiateAsChild(uiObj); } [MenuItem("GameObject/UI/Zhanyou/ImgText")] public static void CreateImgText() { var uiObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\UIImgText.prefab"); InstantiateAsChild(uiObj); } private static void InstantiateAsChild(GameObject prefab) { GameObject itemGO = GameObject.Instantiate(prefab); itemGO.name = itemGO.name.Replace("(Clone)", ""); Object[] selection = Selection.GetFiltered(typeof(GameObject), SelectionMode.ExcludePrefab); if (selection.Length > 0 && selection[0] is GameObject) { var parentGO = selection[0] as GameObject; itemGO.transform.parent = parentGO.transform; itemGO.transform.localScale = new Vector3(1,1,1); itemGO.transform.localPosition = Vector3.zero; } } #region [MenuItem("GameObject/UI/Font/Mode1")] public static void ChangeFontMode1() { var text = GetPrefabText(); UseFontMode(text, 0); } [MenuItem("GameObject/UI/Font/Mode2")] public static void ChangeFontMode2() { var text = GetPrefabText(); UseFontMode(text, 1); } [MenuItem("GameObject/UI/Font/Mode3")] public static void ChangeFontMode3() { var text = GetPrefabText(); UseFontMode(text, 2); } [MenuItem("GameObject/UI/Font/Mode4")] public static void ChangeFontMode4() { var text = GetPrefabText(); UseFontMode(text, 3); } [MenuItem("GameObject/UI/Font/Mode5")] public static void ChangeFontMode5() { var text = GetPrefabText(); UseFontMode(text, 4); } [MenuItem("GameObject/UI/Font/Mode6")] public static void ChangeFontMode6() { var text = GetPrefabText(); UseFontMode(text, 5); } [MenuItem("GameObject/UI/Font/Mode8")] public static void ChangeFontMode8() { var text = GetPrefabText(); UseFontMode(text, 6); } [MenuItem("GameObject/UI/Font/Mode9")] public static void ChangeFontMode9() { var text = GetPrefabText(); UseFontMode(text, 7); } [MenuItem("GameObject/UI/Font/ChildMode1")] public static void ChangeFontChildMode1() { Object[] selection = Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel); if (selection.Length > 0 && selection[0] is GameObject) { var selectionPrefab = PrefabUtility.GetPrefabParent((selection[0] as GameObject)); var textObjs = (selectionPrefab as GameObject).GetComponentsInChildren(); foreach (var text in textObjs) { UseFontMode(text, 0); } } } [MenuItem("GameObject/UI/Font/Prefab")] public static void AutoEmoji() { GameObject uiPrefab = null; Object[] selection = Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel); if (selection.Length > 0 && selection[0] is GameObject) { var selectionPrefab = PrefabUtility.GetPrefabParent((selection[0] as GameObject)); uiPrefab = (selectionPrefab as GameObject); } if (uiPrefab == null) return; var textObjs = uiPrefab.GetComponentsInChildren(true); foreach (var textObj in textObjs) { int textMode = 0; var imgGroup = (textObj).GetComponentsInParent(true); foreach (var img in imgGroup) { if (img == null) continue; if (img.sprite == null) continue; if (img.sprite.name.Contains("按钮黄") || img.sprite.name.Contains("按钮蓝")) { Debug.Log("Btn text:" + textObj.name); textMode = 1; UseFontMode(textObj, textMode); break; } } Debug.Log("text mode:" + textMode); //UseFontMode(textObj, textMode); } } private static Text GetPrefabText() { Object[] selection = Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel); if (selection.Length > 0 && selection[0] is GameObject) { var selectionPrefab = PrefabUtility.GetPrefabParent((selection[0] as GameObject)); Debug.Log("Prefab:" + selectionPrefab.name); var text = (selectionPrefab as GameObject).GetComponent(); return text; } return null; } private static UIFontMode _PrefabFontMode; private static void UseFontMode(Text text, int mode) { if (_PrefabFontMode == null) { var uiObj = AssetDatabase.LoadAssetAtPath("Assets\\Project3D\\Tool\\Editor\\UI\\FontMode.prefab"); _PrefabFontMode = uiObj.GetComponent(); } var fontModeMark = text.gameObject.GetComponent(); if(fontModeMark == null) fontModeMark = text.gameObject.AddComponent(); fontModeMark.FontModeMark = mode; text.font = _PrefabFontMode._FontModeInfo[mode]._Font; text.color = _PrefabFontMode._FontModeInfo[mode]._FontColor; text.fontSize = _PrefabFontMode._FontModeInfo[mode]._FontSize; var outline = text.gameObject.GetComponent(); if (outline != null) { GameObject.DestroyImmediate(outline, true); } } #endregion }