123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- [CustomEditor(typeof(Auxiliary))]
- public class EditorAuxiliary : Editor
- {
- #region 变量
- private Auxiliary Script;
- #endregion
- private void OnEnable()
- {
- Script = (Auxiliary) target;
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- if (GUILayout.Button("ChangeFont"))
- {
- ChangeFont();
- }
- if (GUILayout.Button("PrintBounds"))
- {
- PrintBounds();
- }
- if (GUILayout.Button("ChangePivot"))
- {
- ChangePivot();
- }
- if (GUILayout.Button("AddSuffix"))
- {
- AddSuffix();
- }
- if (GUILayout.Button("AddPrefix"))
- {
- AddPrefix();
- }
- if (GUILayout.Button("ChangePrefix"))
- {
- ChangePrefix();
- }
- if (GUILayout.Button("Reset"))
- {
- //ResetAll();
- }
- if (GUILayout.Button("Temp"))
- {
- Vector3 position = Script.GoList[0].GetChild(0).localPosition;
- for (int i = 1; i < Script.GoList.Count; i++)
- {
- Script.GoList[i].GetChild(0).localPosition = position;
- }
- }
- }
- private void ResetAll()
- {
- for (int i = 0; i < Script.GoList.Count; i++)
- {
- Text[] texts = Script.GoList[i].GetComponentsInChildren<Text>(true); ;
- Graphic[] graphics = Script.GoList[i].GetComponentsInChildren<Graphic>(true);
- for (int j = 0; j < texts.Length; j++)
- {
- texts[j].supportRichText = false;
- texts[j].verticalOverflow = VerticalWrapMode.Truncate;
- texts[j].horizontalOverflow = HorizontalWrapMode.Wrap;
- }
- for (int j = 0; j < graphics.Length; j++)
- {
- graphics[j].raycastTarget = true;
- }
- }
- }
- private void ChangeFont()
- {
- for (int j = 0; j < Script.GoList.Count; j++)
- {
- Transform[] transforms = Script.GoList[j].GetComponentsInChildren<Transform>(true);
- for (int i = 0; i < transforms.Length; i++)
- {
- Text text = transforms[i].GetComponent<Text>();
- TextMesh textMesh = transforms[i].GetComponent<TextMesh>();
- if (text != null)
- {
- text.font = Script.Font;
- text.fontStyle = FontStyle.Normal;
- }
- if (textMesh != null)
- {
- textMesh.font = Script.Font;
- textMesh.fontStyle = FontStyle.Normal;
- }
- }
- }
- }
- private void PrintBounds()
- {
- Bounds bounds = Script.Go.GetComponent<Renderer>().bounds;
- Debug.Log(string.Format("x : {0:0.00} y : {1:0.00} z : {2:0.00}", bounds.extents.x, bounds.extents.y, bounds.extents.z));
- }
- private void ChangePivot()
- {
- for (int i = 0; i < Script.SrList.Count; i++)
- {
- string path = AssetDatabase.GetAssetPath(Script.SrList[i].sprite);
- TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(path);
- float offsetX = -Script.SrList[i].transform.position.x * 100 / Script.SrList[i].sprite.texture.width;
- float offsetY = -Script.SrList[i].transform.position.y * 100 / Script.SrList[i].sprite.texture.height;
- textureImporter.spritePivot = new Vector2(textureImporter.spritePivot.x + offsetX, textureImporter.spritePivot.y + offsetY);
- AssetDatabase.ImportAsset(path);
- }
- }
- private void AddSuffix()
- {
- Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
- for (int i = 0; i < transforms.Length; i++)
- {
- transforms[i].name = transforms[i].name + Script.String;
- }
- }
- private void AddPrefix()
- {
- Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
- for (int i = 0; i < transforms.Length; i++)
- {
- transforms[i].name = Script.String + transforms[i].name;
- }
- }
- private void ChangePrefix()
- {
- Transform[] transforms = Script.Go.GetComponentsInChildren<Transform>(true);
- for (int i = 0; i < transforms.Length; i++)
- {
- int index = transforms[i].name.IndexOf('_');
- transforms[i].name = Script.String + transforms[i].name.Remove(0, index + 1);
- }
- }
- }
|