using UnityEngine;
using System.Collections;
using UnityEditor;
//2.枚舉下拉框
//public enum OPTIONS {
// CUBE=0,
// SPHERE,
// PLANE,
//}
public class Texts : MonoBehaviour {
//1.經過拖這個腳本能夠改變顏色和曲線
//public Color myColor;
//public AnimationCurve curveX = AnimationCurve.Linear(0, 0, 10, 10);
//public AnimationCurve curveY = AnimationCurve.Linear(0, 0, 10, 10);
//public AnimationCurve curveZ = AnimationCurve.Linear(0, 0, 10, 10);
//public Rect myRect;
//public Texture myTexture;
//void Update() {
// if (Input.GetKeyUp(KeyCode.A)) {
// print("MyColor" + myColor); //輸出顏色
// print("curveX" + curveX.Evaluate(Time.time)); //利用時間獲取曲線的值
// print("curveY" + curveY.Evaluate(Time.time));
// print("curveZ" + curveZ.Evaluate(Time.time));
// print("myRect" + myRect); //打印Rect的x,y,width,height
// print("myTexture" + myTexture); //打印Texture
// }
// //根據三個曲線,實時獲取他們的值,來設置該對象的位置
// transform.position = new Vector3(curveX.Evaluate(Time.time), curveY.Evaluate(Time.time), curveZ.Evaluate(Time.time));
//}
//2.枚舉下拉框
//public OPTIONS options = OPTIONS.PLANE;
//public float number;
//public StaticEditorFlags staticFlagMask = 0;
//3.顯示transform,rotation,scal
//public Transform myTransform;
//public Vector3 myRotation;
//public Vector3 myLocal;
//public int number;
//4.Slider
//public int xx = 3;
//public int yy = 5;
//public int zz = 80;
//5.Layer, Mask, Tag
//public int selectLayer = 0;
//public int selectFlag = 0;
//public string[] options = { "CanJump", "CanShoot", "CanSwim" };
//public string tagStr = "";
//6.Password
//public string text = "Some text Here";
//7.TextField Toggle
//public string MyName;
//public bool showBtn = true;
//8.vector2,vector3,vector4
//public Vector2 p2;
//public Vector3 p3;
//public Vector4 p4;
//9.Button
//public string MyName;
//public bool showBtn = true;
//10.Toggle-Button-Label
//public void MyTestA() {
// Debug.Log("Click");
//}
//11.toolbar
//public void MyTestA() {
// Debug.Log("Click");
//}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEditor;
//[CustomEditor(typeof(Texts))]
//10
//[CanEditMultipleObjects]
//[CustomEditor(typeof(Texts))]
//public class MyEditor : Editor{
//10.
//private Texts texts;
//private bool isTrue = true;
//private void OnEnable() {
//texts = (Texts)target;
//}
//public override void OnInspectorGUI() { //該方法會繪製在inspector面板上
//1.經過拖這個腳本能夠改變顏色和曲線
//Texts myTexts = (Texts)target;
////顏色
//myTexts.myColor = EditorGUILayout.ColorField("New Color", myTexts.myColor);
////曲線
//myTexts.curveX = EditorGUILayout.CurveField("Animation On X", myTexts.curveX);
//myTexts.curveY = EditorGUILayout.CurveField("Animation On Y", myTexts.curveY);
//myTexts.curveZ = EditorGUILayout.CurveField("Animation On Z", myTexts.curveZ);
////rect
//myTexts.myRect = EditorGUILayout.RectField("窗口", myTexts.myRect);
////texture
//myTexts.myTexture = EditorGUILayout.ObjectField("貼圖", myTexts.myTexture,typeof(Texture),true)as Texture;
//base.OnInspectorGUI();
//2.枚舉類型和 系統自帶的 靜態Mask枚舉
//Texts myTexts = (Texts)target;
//myTexts.options = (OPTIONS)EditorGUILayout.EnumPopup("options", myTexts.options);
//myTexts.number = EditorGUILayout.FloatField("number", myTexts.number);
//myTexts.staticFlagMask = (StaticEditorFlags)EditorGUILayout.EnumMaskField("static Flags", myTexts.staticFlagMask);
//3.修改transform
//Texts myTexts = (Texts)target;
//myTexts.myTransform = myTexts.transform;
//myTexts.myTransform.position = EditorGUILayout.Vector3Field("MyPosition", myTexts.transform.position);
//EditorGUILayout.Space();
//Quaternion rot = myTexts.transform.rotation; //將Quaternion轉換爲vector3
//Vector3 rotation = new Vector3(rot.eulerAngles.x, rot.eulerAngles.y, rot.eulerAngles.z);
//myTexts.myRotation = EditorGUILayout.Vector3Field("myRotation", rotation);
//myTexts.myLocal = EditorGUILayout.Vector3Field("myLocal", myTexts.transform.localScale);
//myTexts.number = EditorGUILayout.IntField("number", myTexts.number);
//4.Slider
//myTexts.xx = EditorGUILayout.IntSlider(myTexts.xx, 1, 10);
//myTexts.yy = EditorGUILayout.IntSlider(myTexts.yy, 2, 8);
//myTexts.zz = EditorGUILayout.IntSlider(myTexts.zz, 0, 100);
//5.Layer, Mask, Tag
//myTexts.selectLayer = EditorGUILayout.LayerField("Layer Objects", myTexts.selectLayer);
//myTexts.selectFlag = EditorGUILayout.MaskField("player Flags ", myTexts.selectFlag, myTexts.options);
//myTexts.tagStr = EditorGUILayout.TagField("Tag for Objects:", myTexts.tagStr);
//6.password
//myTexts.text = EditorGUILayout.PasswordField("Type Somthing", myTexts.text);
//7.TextField Toggle
//myTexts.MyName = EditorGUILayout.TextField("Object Name", myTexts.MyName);
//myTexts.showBtn = EditorGUILayout.Toggle("Show Button", myTexts.showBtn);
//8.vector2,vector3,vector4
//myTexts.p2 = EditorGUILayout.Vector2Field("Point 2", myTexts.p2);
//myTexts.p3 = EditorGUILayout.Vector3Field("Point 3", myTexts.p3);
//myTexts.p4 = EditorGUILayout.Vector4Field("Point 4", myTexts.p4);
//9.button
//EditorGUILayout.HelpBox("abcde", MessageType.Error); //錯誤提示框
//if (GUILayout.Button("Add Path Points")) {
// Debug.Log("ABCDE");
// return;
//}
//10.Toggle-Button-Label
//EditorGUILayout.BeginVertical("box"); //開始水平佈局,「box」爲一個 方框區域
//EditorGUILayout.LabelField("ABCDE"); //不可點的lable
//EditorGUILayout.SelectableLabel("asdadsa"); //可點的label
//if (GUILayout.Button("Click")) { //建立button, 當點擊按鈕時,調用相應方法
// texts.MyTestA();
//}
//EditorGUILayout.EndVertical();
//EditorGUILayout.Space(); //空格行
//isTrue = EditorGUILayout.Toggle("isTrigger", isTrue);
//EditorGUILayout.BeginVertical();
//EditorGUI.BeginDisabledGroup(isTrue); //若是isTrue爲真,則下方顯示在面板上(灰色)不可操做,爲假則可操做
//if (GUILayout.Button("Button")) {
// texts.MyTestA();
//}
//EditorGUI.EndDisabledGroup();
//EditorGUILayout.EndVertical();
//EditorGUILayout.HelpBox("help help help", MessageType.Warning); //顯示幫助框,類型爲警告
//EditorGUILayout.Space();
//EditorGUILayout.HelpBox("aaa aa a", MessageType.Error); //顯示幫助框,類型爲錯誤
//11.toolbar
// private Texts texts;
// private int select = 0;
// private int selected = 0;
// private string[] names = { "one", "two", "three", "four" };
// private static GUIContent[] myGUIContent = new GUIContent[4];
// private Texture2D[] myTexture = new Texture2D[4];
// private void OnEnable() {
// texts = (Texts)target;
// Init();
// }
// private void Init() //初始化獲取圖片
// {
// for (int i = 0; i < 4; i++) {
// //經過路徑獲取圖片資源
// myTexture[i] = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/MyTexture/1.png", typeof(Texture2D));
// //將圖片數組和字符串數組存進去
// myGUIContent[i] = new GUIContent(myTexture[i], names[i]);
// }
// }
// public override void OnInspectorGUI() //繪製在Inspector面板上
// {
// EditorGUILayout.BeginVertical();
// //建立 Toolbar , 返回值爲選中的項, 參數1 爲 選中的項, 參數 2 每項上的文字
// select = GUILayout.Toolbar(select, names);
// EditorGUILayout.Space();
// EditorGUILayout.Space();
// //參數 1, 選中的項, 參數2 每項的圖片, 參數3 整個Toolbar的寬度, 參數4 Toolbar的高度
// selected = GUILayout.Toolbar(selected, myGUIContent, GUILayout.Width(300), GUILayout.Height(64));
// EditorGUILayout.Space();
// EditorGUILayout.EndVertical();
// }
//}
//12.window
//public class MyEditor : EditorWindow {
// public string[] savedCopies = new string[5]; //定義一個字符串數組
// public bool load = false;
// [MenuItem("Examples/Improved copy buffer")] //在工具欄建立按鈕
// static void Init() {
// MyEditor window = (MyEditor)EditorWindow.GetWindow(typeof(MyEditor)); //定義一個窗口對象
// }
// void OnGUI() {
// load = EditorGUILayout.Toggle("Load:", load); //建立一個 Toggle
// EditorGUILayout.BeginHorizontal(); //開始水平佈局
// for (int i = 0; i < savedCopies.Length; i++) {
// if (GUILayout.Button(i.ToString())) // 建立這些按鈕,而且當點擊按鈕時觸發條件
// {
// if (load) {
// EditorGUIUtility.systemCopyBuffer = savedCopies[i]; // 獲取值
// } else {
// savedCopies[i] = "123"; //給每個字符串賦值
// }
// }
// }
// EditorGUILayout.EndHorizontal(); //結束水平佈局
// for (int j = 0; j < savedCopies.Length; j++) {
// EditorGUILayout.LabelField("Saved " + j, savedCopies[j]); //將全部已字符串以Label的形式顯示出來
// }
// EditorGUILayout.LabelField("Current buffer:", EditorGUIUtility.systemCopyBuffer); //將獲取的值以Label的形式顯示出來
// if (GUILayout.Button("Clear all saves")) //清空全部的緩存
// {
// int i = 0;
// foreach (string s in savedCopies) {
// savedCopies[i] = "";
// i++;
// }
// }
// }
// void OnInspectorUpdate() {
// this.Repaint(); //從新畫窗口
// }
//}
//13.實時獲取攝像機的視野,攝像機視野內的全部對象都可被重畫
//public class MyEditor : EditorWindow {
// Camera myCamera = Camera.main; //獲取攝像機
// RenderTexture renderTexture; //
// [MenuItem("Examples/Camera Viewer")] //在菜單欄建立按鈕
// static void Init()
// {
// EditorWindow editorWindows = GetWindow(typeof(MyEditor)); //建立新窗口
// editorWindows.autoRepaintOnSceneChange = true;
// editorWindows.Show();
// }
// public void Awake() //當跳出窗口時首先調用該方法
// {
// Debug.Log("Awake");
// renderTexture = new RenderTexture((int)position.width,
// (int)position.height, (int)RenderTextureFormat.ARGB32); //獲取renderTexture
// }
// public void Update() //跳出窗口後每幀調用該方法
// {
// Debug.Log("update");
// if (myCamera != null)
// {
// myCamera.targetTexture = renderTexture;
// myCamera.Render();
// myCamera.targetTexture = null;
// }
// if (renderTexture != null)
// {
// if (renderTexture.width != position.width || renderTexture.height != position.height)
// {
// renderTexture = new RenderTexture((int)position.width, (int)position.height,
// (int)RenderTextureFormat.ARGB32); //實時更新
// }
// }
// }
// void OnGUI()
// {
// if (renderTexture != null)
// {
// GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), renderTexture); //該方法一直繪製攝像機視野內的物體
// }
// }
//}
//14.window_button
// public class MyEditor : EditorWindow {
// private bool WantsMouseMove = false;
// [MenuItem("Example/Window postion")]
// static void Init()
// {
// MyEditor window = (MyEditor)EditorWindow.GetWindow(typeof(MyEditor));
// window.position = new Rect(100, 100, 300, 300); // 窗口的座標
// }
// void OnGUI()
// {
// GUILayout.Space(20);
// if (GUILayout.Button("myButton")) //在窗口上建立一個按鈕
// {
// Debug.Log("button");
// }
// //在窗口建立Toggle 而且獲取 Toggle的
// WantsMouseMove = EditorGUILayout.Toggle("Receive MoveMent", WantsMouseMove);
// //
// EditorGUILayout.LabelField("Mouse Postion:", Event.current.mousePosition.ToString());
// if (Event.current.type == EventType.MouseMove)//當事件爲移動鼠標
// {
// Repaint(); //從新繪製
// }
// }
//}
//15.scrollview
//public class MyEditor : EditorWindow {
// Rect windowRect = new Rect(100, 100, 200, 200);
// Vector3 scrollPos = Vector2.zero;
// [MenuItem("Example/Window postion")]
// static void Init()
// {
// MyEditor window = (MyEditor)EditorWindow.GetWindow(typeof(MyEditor));
// window.position = new Rect(100, 100, 300, 300); // 窗口的座標
// }
// void OnGUI()
// {
// //建立 scrollView 窗口
// scrollPos = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height),
// scrollPos, new Rect(0, 0, 1000, 1000));
// GUILayout.Space(100); // 100 像素寬的空格
// if (GUILayout.Button("ButtonA")) //建立按鈕
// {
// Debug.Log("AAA");
// }
// GUILayout.Space(50);
// if (GUILayout.Button("ButtonB")) //建立按鈕
// {
// Debug.Log("BBB");
// }
// GUI.EndScrollView(); //結束 ScrollView 窗口
// if (GUILayout.Button("ButtonC"))
// {
// Debug.Log("CCC");
// }
// }
//}
//16.Notification通知
//public class MyEditor : EditorWindow {
// string notification = "This is a Notification"; //通知內容
// [MenuItem("Example/Notification usage")]
// static void Init() {
// MyEditor window = (MyEditor)EditorWindow.GetWindow(typeof(MyEditor));
// window.Show();
// }
// void OnGUI() {
// notification = EditorGUILayout.TextField(notification);
// if (GUILayout.Button("Show Notification")) {
// this.ShowNotification(new GUIContent(notification)); //調用該方法發送通知
// }
// if (GUILayout.Button("Remove Notification")) {
// this.RemoveNotification(); //取消通知
// }
// }
// void OnInspectorUpdate() //該方法每秒調用 10 幀
// {
// this.Repaint();
// }
// void OnHierarchyChange() //當Hierarchy面板發生變化時,調用該方法
// {
// }
// void OnProjectChange() //當 Project 面板發生變化時調用該方法
// {
// }
// void OnSelectionChange() //當選擇的對象改變時調用該方法
// {
// }
// void Update() //每秒調用 100 次
// {
// }
//}