{"id":1323,"date":"2017-10-14T13:38:48","date_gmt":"2017-10-14T05:38:48","guid":{"rendered":"http:\/\/39.100.100.179\/?p=1323"},"modified":"2020-09-16T22:33:55","modified_gmt":"2020-09-16T14:33:55","slug":"unity%e7%bc%96%e8%be%91%e5%99%a8editor%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=1323","title":{"rendered":"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"<p>\u56e0\u4e3aUnity\u7684\u7f16\u8f91\u5668\u4e00\u4e9b\u65b9\u6cd5\uff0c\u662f\u9879\u76ee\u4e2d\u4e0d\u5e38\u7528\u5230\u7684\uff0c\u4e3a\u4e86\u907f\u514d\u4ee5\u540e\u5fd8\u8bb0<\/p>\n<p>\u4eca\u5929\u7279\u610f\u62bd\u65f6\u95f4\u628a\u6700\u8fd1\u4f7f\u7528\u548c\u4e00\u4e9b\u4e0d\u5e38\u7528\u7684Editor\u7528\u5230\u7684\u65b9\u6cd5\u90fd\u5217\u4e3e\u51fa\u6765<\/p>\n<p>\u6709\u4e9b\u5199\u4e86\u6ce8\u91ca\uff0c\u540e\u9762\u5c31\u61d2\u5f97\u5199\u6ce8\u91ca\u4e86\uff0c\u4e0d\u8fc7\u770b\u9884\u89c8\u6548\u679c\uff0c\u90fd\u80fd\u627e\u5f97\u5230\u3002<\/p>\n<p>\u4e0a\u9884\u89c8\u56fe\uff1a<\/p>\n<p><a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20171014153041.png\" data-lightbox=\"image_lg\"><img title=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"wp-image-1327  aligncenter\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20171014153041.png\" width=\"555\" height=\"861\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20171014153041.png 555w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20171014153041-193x300.png 193w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a> <img title=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c2\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"wp-image-2067 size-full aligncenter\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221906.jpg\" alt=\"\" width=\"423\" height=\"468\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221906.jpg 423w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221906-271x300.jpg 271w\" sizes=\"(max-width: 423px) 100vw, 423px\" \/> <img title=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"Unity\u7f16\u8f91\u5668Editor\u5e38\u7528\u547d\u4ee4 - \u7b2c3\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" loading=\"lazy\" class=\"wp-image-2068 size-full aligncenter\" src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221854.jpg\" alt=\"\" width=\"419\" height=\"419\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221854.jpg 419w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221854-300x300.jpg 300w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2017\/10\/QQ\u622a\u56fe20200916221854-150x150.jpg 150w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><span style=\"font-size: inherit;\">\u5177\u4f53\u5185\u5bb9\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a<\/span><\/p>\n<pre class=\"lang:c# decode:true  \">using UnityEngine;\nusing System.Collections;\nusing UnityEditor;\n\n\npublic class EditorTest : EditorWindow\n{\n    enum EnumTest { \u7f51, \u866b, \u6d4b, \u8bd5 }\n\n    static EditorTest window;\n    [MenuItem(\"Tools\/\u6d4b\u8bd5\u7f16\u8f91\u5668\u529f\u80fd\")]\n    static void Test()\n    {\n        window = (EditorTest)EditorWindow.GetWindow(typeof(EditorTest), false, \"\u6d4b\u8bd5\u7f16\u8f91\u5668\u529f\u80fd\");\n        window.Show();\n    }\n\n    #region \u5c5e\u6027\n    int testInt = 0;\n    float testFloat = 0;\n    float floatSlider = 0;\n    float maxValue = 20;\n    float minValue = -50;\n    string testStr = \"\u7f51\u866b\u866b\";\n    bool testBool = true;\n    int toolbarOption = 0;\n    string[] toolbarStr = new string[] { \"\u8fd9\", \"\u662f\", \"Toolbar\" };\n    EnumTest enumTest;\n    EnumTest enumTest2;\n    int enumInt = 0;\n    int selectedSize = 1;\n    string[] names = { \"\u7f51\", \"\u866b\", \"\u6d4b\", \"\u8bd5\" };\n    int[] sizes = { 1, 2, 4 };\n    string tagStr = \"\";\n    int layerInt = 0;\n    int maskInt = 0;\n    Vector3 testVector3;\n    Color testColor;\n    Rect testRect;\n    GameObject gameObject;\n    Texture texture;\n    bool isShowScrollView = false;\n    Vector2 scrollPosition;\n    #endregion\n    private void OnGUI()\n    {\n        this.Repaint();     \/\/ \u5f3a\u5236\u91cd\u7ed8\n        if(secondWindow || secondWindow2)\n            GUI.enabled = false;\n\n        GUILayout.Label(testStr);        \/\/ \u6587\u672c\u683c\u5f0f:\u7f51\u866b\u866b      \u4e0d\u53ef\u8f93\u5165\u3001\u4e0d\u53ef\u9009\n\n        GUIStyle fontStyle = new GUIStyle();\n        fontStyle.normal.background = null;    \/\/\u8bbe\u7f6e\u80cc\u666f\u586b\u5145  \n        fontStyle.normal.textColor = new Color(1, 0, 0);   \/\/\u8bbe\u7f6e\u5b57\u4f53\u989c\u8272  \n        fontStyle.fontStyle = FontStyle.BoldAndItalic;      \/\/ \u5b57\u4f53\u52a0\u7c97\u503e\u659c\n        fontStyle.fontSize = 18;       \/\/\u5b57\u4f53\u5927\u5c0f  \n\n        GUILayout.Label(testStr, fontStyle);       \/\/ \u6587\u672c\u683c\u5f0f:\u7f51\u866b\u866b      \u4e0d\u53ef\u8f93\u5165\u3001\u4e0d\u53ef\u9009  \u6dfb\u52a0\u5b57\u4f53\u6837\u5f0f\n\n        GUILayout.TextField(testStr);        \/\/ \u6587\u672c\u683c\u5f0f:\u7f51\u866b\u866b      \u53ef\u8f93\u5165\u3001\u4e0d\u53ef\u9009\n        \n        EditorGUILayout.LabelField(\"\u59d3\u540d\uff1a\", testStr);       \/\/ \u6587\u672c\u683c\u5f0f: \u59d3\u540d\uff1a\u7f51\u866b\u866b      \u4e0d\u53ef\u8f93\u5165\u3001\u4e0d\u53ef\u9009\n\n        testStr = EditorGUILayout.TextField(\"\u59d3\u540d\uff1a\", testStr);       \/\/ \u6587\u672c\u683c\u5f0f:\u59d3\u540d\uff1a\u7f51\u866b\u866b      \u53ef\u8f93\u5165\u3001\u4e0d\u53ef\u9009\n\n        testInt = EditorGUILayout.IntField(\"IntField\uff1a\", testInt);\n\n        testFloat = EditorGUILayout.FloatField(\"FloatField\uff1a\", testFloat);\n\n        testStr = GUILayout.TextArea(testStr, GUILayout.Height(40));    \/\/ \u533a\u57df\u8f93\u5165\u6587\u672c\n\n        EditorGUILayout.SelectableLabel(testStr);       \/\/ \u53ef\u9009\u62e9\u6587\u672c\n\n        testStr = GUILayout.PasswordField(testStr, \"*\"[0]);\n\n        testStr = EditorGUILayout.PasswordField(\"\u5bc6\u7801:\", testStr);\n\n        floatSlider = EditorGUILayout.Slider(floatSlider, 1, 100);\n\n        EditorGUILayout.MinMaxSlider(ref minValue, ref maxValue, -100, 100);\n\n        testBool = GUILayout.Toggle(testBool, \"\u5f00\u5173\");\n\n        testBool = EditorGUILayout.Toggle(\"\u5f00\u5173\uff1a\", testBool);\n\n        toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarStr);\n        switch (toolbarOption)\n        {\n            case 0:\n                GUILayout.Label(\"1111111111111111111\");\n                break;\n            case 1:\n                GUILayout.Label(\"2222222222222222222\");\n                break;\n            case 2:\n                GUILayout.Label(\"3333333333333333333\");\n                break;\n        }\n\n        EditorGUILayout.Space();        \/\/ \u7a7a\u4e00\u884c\n\n        enumTest = (EnumTest)EditorGUILayout.EnumPopup(\"Enum\u7c7b\u578bPopup\uff1a\", enumTest);\n\n        enumTest2 = (EnumTest)EditorGUILayout.EnumMaskField(\"Enum\u679a\u4e3e\u591a\u9009:\", enumTest2);\n\n        enumInt = EditorGUILayout.Popup(\"String\u7c7b\u578bPopup\uff1a\", enumInt, names);\n\n        selectedSize = EditorGUILayout.IntPopup(\"Int\u7c7b\u578bPopup: \", selectedSize, names, sizes);\n\n        tagStr = EditorGUILayout.TagField(\"\u9009\u62e9Tag:\", tagStr);\n\n        layerInt = EditorGUILayout.LayerField(\"\u9009\u62e9Layer:\", layerInt);\n\n        maskInt = EditorGUILayout.MaskField(\"\u6570\u7ec4\u591a\u9009:\", maskInt, names);\n\n        testColor = EditorGUILayout.ColorField(\"\u989c\u8272:\", testColor);\n\n        GUI.backgroundColor = Color.magenta;     \/\/ \u4fee\u6539\u80cc\u666f\u989c\u8272\n        testVector3 = EditorGUILayout.Vector3Field(\"Vector3\u5750\u6807:\", testVector3);\n\n        GUI.backgroundColor = Color.green;\n        testRect = EditorGUILayout.RectField(\"Rect\u5c3a\u5bf8:\", testRect);\n        GUI.backgroundColor = Color.gray * 1.8f;        \/\/ \u6062\u590d\u80cc\u666f\u9ed8\u8ba4\u989c\u8272\n\n        gameObject = (GameObject)EditorGUILayout.ObjectField(\"\u4efb\u610f\u7c7b\u578b \u4e3e\u4f8bGameObject:\", gameObject, typeof(GameObject));\n\n        texture = EditorGUILayout.ObjectField(\"\u4efb\u610f\u7c7b\u578b \u4e3e\u4f8b\u8d34\u56fe\", texture, typeof(Texture), true) as Texture;\n\n        GUILayout.BeginHorizontal();\n        GUILayout.Label(\"\u6a2a\u5411\u81ea\u52a8\u6392\u5217\u6f14\u793a\uff1a\");\n        testStr = GUILayout.PasswordField(testStr, \"*\"[0]);\n        testBool = GUILayout.Toggle(testBool, \"\u5f00\u5173\");\n        GUILayout.Button(\"\u6309\u94ae\");\n        GUILayout.EndHorizontal();\n\n        if (GUILayout.Button(\"\u70b9\u51fb\u6309\u94ae \u5f39\u51fa\u7cfb\u7edf\u63d0\u793a\u6d88\u606f\"))\n            ShowNotification(new GUIContent(\"\u8fd9\u662f\u7f51\u866b\u866b\u63d0\u793a\u6d88\u606f~~\"));\n        if (GUILayout.Button(\"\u70b9\u51fb\u6309\u94ae \u663e\u793a\u6eda\u52a8\u89c6\u56fe\"))\n            isShowScrollView = !isShowScrollView;\n        if (isShowScrollView)\n        {\n            scrollPosition = GUILayout.BeginScrollView(scrollPosition);\n            for (int i = 0; i &lt; 100; i++)\n            {\n                GUILayout.Label(i.ToString());\n            }\n            GUILayout.EndScrollView();\n        }\n        if (GUILayout.Button(\"\u70b9\u51fb\u6309\u94ae \u663e\u793a\u4e8c\u7ea7\u7a97\u53e3\"))\n            secondWindow = !secondWindow;\n        if (secondWindow)\n        {\n            GUI.enabled = true;\n            BeginWindows();\n            secondWindowRect = GUILayout.Window(1, secondWindowRect, SecondWindow, \"\u4e8c\u7ea7\u7a97\u53e3\");\n            EndWindows();\n        }\n\n        if (GUILayout.Button(\"\u70b9\u51fb\u6309\u94ae \u7ed8\u5236\u56fe\u5f62\"))\n            secondWindow2 = !secondWindow2;\n        if (secondWindow2)\n        {\n            GUI.backgroundColor = Color.red \/ 2;     \/\/ \u4fee\u6539\u80cc\u666f\u989c\u8272\n            GUI.enabled = true;\n            BeginWindows();\n            secondWindowRect2 = GUILayout.Window(2, secondWindowRect2, SecondWindow2, \"\u7ed8\u5236\u56fe\u5f62\");\n            EndWindows();\n        }\n        GUI.backgroundColor = Color.gray * 1.8f;        \/\/ \u6062\u590d\u80cc\u666f\u9ed8\u8ba4\u989c\u8272\n\n        GUI.enabled = false;\n        GUILayout.Button(\"\u7f6e\u7070\u6309\u94ae\");\n        GUI.enabled = true;\n    }\n    Rect secondWindowRect = new Rect(0, 0, 400, 400);\n    bool secondWindow = false;\n    void SecondWindow(int unusedWindowID)\n    {\n        Application.targetFrameRate = EditorGUILayout.IntSlider(\"\u9650\u5b9a\u5e27\u7387\uff1a\", Application.targetFrameRate, 10, 300);\n        Application.runInBackground = EditorGUILayout.Toggle(\"\u5141\u8bb8Unity\u540e\u53f0\u8fd0\u884c\uff1a\", Application.runInBackground);\n        gameObject = (GameObject)EditorGUILayout.ObjectField(\"\u5f53\u524d\u9009\u4e2d\u7684\u7269\u4f53\uff1a\", Selection.activeGameObject, typeof(GameObject));\n        EditorGUILayout.Vector3Field(\"\u9f20\u6807\u5728Scene\u89c6\u56fe\u7684\u5750\u6807\uff1a\", mousePosition);\n        EditorGUILayout.Vector3Field(\"\u9f20\u6807\u5728\u5f53\u524d\u4e8c\u7ea7\u7a97\u53e3\u5750\u6807\uff1a\", Event.current.mousePosition);\n        hitGo = (GameObject)EditorGUILayout.ObjectField(\"\u9f20\u6807\u53d1\u9001\u5c04\u7ebf\uff1a\", hitGo != null ? hitGo : null, typeof(GameObject));\n\n        GUILayout.Label(\"UsedTextureCount: \" + UnityStats.usedTextureCount);\n        GUILayout.Label(\"UsedTextureMemorySize: \" + (UnityStats.usedTextureMemorySize \/ 1000000f + \"Mb\"));\n        GUILayout.Label(\"RenderTextureCount: \" + UnityStats.renderTextureCount);\n        GUILayout.Label(\"FrameTime: \" + UnityStats.frameTime);\n        GUILayout.Label(\"RenderTime: \" + UnityStats.renderTime);\n        GUILayout.Label(\"DrawCalls: \" + UnityStats.drawCalls);\n        GUILayout.Label(\"Batchs: \" + UnityStats.batches);\n        GUILayout.Label(\"Static Batch DC: \" + UnityStats.staticBatchedDrawCalls);\n        GUILayout.Label(\"Static Batch: \" + UnityStats.staticBatches);\n        GUILayout.Label(\"DynamicBatch DC: \" + UnityStats.dynamicBatchedDrawCalls);\n        GUILayout.Label(\"DynamicBatch: \" + UnityStats.dynamicBatches);\n        GUILayout.Label(\"Triangles: \" + UnityStats.triangles);\n        GUILayout.Label(\"Vertices: \" + UnityStats.vertices);\n\n        if (GUILayout.Button(\"\u5173\u95ed\u4e8c\u7ea7\u7a97\u53e3\"))\n            secondWindow = false;\n        GUI.DragWindow();\/\/\u753b\u51fa\u5b50\u7a97\u53e3\n    }\n\n    Rect secondWindowRect2 = new Rect(0, 0, 400, 400);\n    bool secondWindow2 = false;\n    int capSize = -50;\n    Vector3 capEuler = new Vector3(200, 200, 200);\n\n    void SecondWindow2(int unusedWindowID)\n    {\n        capSize = EditorGUILayout.IntField(\"\u5c3a\u5bf8\uff1a\", capSize);\n        capEuler = EditorGUILayout.Vector3Field(\"testVector3\uff1a\", capEuler);\n\n        if (GUILayout.Button(\"\u5173\u95ed\u7ed8\u5236\u56fe\u5f62\"))\n            secondWindow2 = false;\n\n        Handles.color = Color.red;\n        Handles.DrawLine(new Vector2(75, 100), new Vector3(150, 200));\n        Handles.CircleCap(1, new Vector2(300, 150), Quaternion.identity, capSize);\n\n        Handles.color = Color.green;\n        Handles.SphereCap(2, new Vector2(100, 250), Quaternion.Euler(capEuler), capSize);\n        Handles.CubeCap(3, new Vector2(300, 250), Quaternion.Euler(capEuler), capSize);\n\n        Handles.color = Color.blue;\n        Handles.CylinderCap(4, new Vector2(100, 350), Quaternion.Euler(capEuler), capSize);\n        Handles.ConeCap(5, new Vector2(300, 350), Quaternion.Euler(capEuler), capSize);\n\n        GUI.DragWindow();\/\/\u753b\u51fa\u5b50\u7a97\u53e3\n    }\n\n    private void OnEnable()\n    {\n        SceneView.onSceneGUIDelegate += SceneGUI;\n    }\n\n    private void OnDisable()\n    {\n        SceneView.onSceneGUIDelegate -= SceneGUI;\n    }\n\n    GameObject hitGo;\n    Vector3 mousePosition;\n    void SceneGUI(SceneView sceneView)\n    {\n        if (Event.current.type == EventType.mouseMove)\n        {\n            mousePosition = Event.current.mousePosition;\n            RaycastHit hit;\n            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);\n            if (Physics.Raycast(ray, out hit))\n            {\n                hitGo = hit.collider.gameObject;\n            }\n            else\n                hitGo = null;\n        }\n    }\n\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3aUnity\u7684\u7f16\u8f91\u5668\u4e00\u4e9b\u65b9\u6cd5\uff0c\u662f\u9879\u76ee\u4e2d\u4e0d\u5e38\u7528\u5230\u7684\uff0c\u4e3a\u4e86\u907f\u514d\u4ee5\u540e\u5fd8\u8bb0 \u4eca\u5929\u7279\u610f\u62bd &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=1323\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[297],"tags":[293,300],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1323"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1323"}],"version-history":[{"count":7,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":2069,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions\/2069"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}