日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Unity3D 場(chǎng)景編輯器擴(kuò)展學(xué)習(xí)筆記

 kiki的號(hào) 2017-03-10
Description

Custom 3D GUI controls and drawing in the scene view.

Handles are the 3D controls that Unity uses to manipulate items in the scene view. There are a number of built-in Handle GUIs, such as the familiar tools to position, scale and rotate an object via the Transform component. However, it is also possible to define your own Handle GUIs to use with custom component editors. Such GUIs can be a very useful way to edit procedurally-generated scene content, "invisible" items and groups of related objects, such as waypoints and location markers.

You can also supplement the 3D Handle GUI in the scene with 2D buttons and other controls overlaid on the scene view. This is done by enclosing standard Unity GUI calls in a Handles.BeginGUI / EndGUI pair within the /OnSceneGUI/ function. You can use HandleUtility.GUIPointToWorldRay and HandleUtility.WorldToGUIPoint to convert coordinates between 2D GUI and 3D world coordinates.


總的來說,Handles就是在SceneView里畫一些能響應(yīng)用戶操作的幾何圖案,并影響指定的變量數(shù)值。
這個(gè)類的接口大致分為以下幾種:

Draw類:繪制元幾何體,如點(diǎn)、線、面等。

DrawAAPolyLine Draw anti-aliased line specified with point array and width.
DrawBezier Draw textured bezier line through start and end points with the given tangents. To get an anti-aliased effect use a texture that is 1x2 pixels with one transparent white pixel and one opaque white pixel. The bezier curve will be swept using this texture.
DrawLine Draw a line from p1 to p2.
DrawPolyLine Draw a line going through the list of all points.
DrawSolidArc Draw a circular sector (pie piece) in 3D space.
DrawSolidDisc Draw a solid flat disc in 3D space.
DrawSolidRectangleWithOutline Draw a solid outlined rectangle in 3D space.
DrawWireArc Draw a circular arc in 3D space.
DrawWireDisc Draw the outline of a flat disc in 3D space.


Handle類:可視化操作數(shù)值,比如Vector3,Vector2,float等

DoPositionHandle 類似對(duì)象移動(dòng)的三向操作器
DoRotationHandle 類似對(duì)象旋轉(zhuǎn)的三向圓環(huán)操作器
DoScaleHandle 類似對(duì)象縮放的三軸操作器
FreeMoveHandle Make an unconstrained movement handle.
FreeRotateHandle Make an unconstrained rotation handle.
PositionHandle Make a 3D Scene view position handle.
RadiusHandle Make a Scene view radius handle.
RotationHandle Make a Scene view rotation handle.
ScaleHandle Make a Scene view scale handle.
ScaleValueHandle Make a single-float draggable handle.


Caps類:繪制多邊形幾何體,比如方塊,點(diǎn)精靈,球形,圓錐等。

ArrowCapDraw an arrow like those used by the move tool.
SphereCapDraw a Sphere. Pass this into handle functions.
CircleCap Draw a camera-facing Circle. Pass this into handle functions.
ConeCap Draw a Cone. Pass this into handle functions.
CubeCap Draw a cube. Pass this into handle functions.
CylinderCap Draw a Cylinder. Pass this into handle functions.
DotCap Draw a camera-facing dot. Pass this into handle functions.
RectangleCap 畫個(gè)矩形
SelectionFrameDraw a camera facing selection frame.


2DGUI類:用GUILayout或EditorGUILayout代替吧。

BeginGUIBegin a 2D GUI block inside the 3D handle GUI.
EndGUIEnd a 2D GUI block and get back to the 3D handle GUI.
Slider2D Slide a handle in a 2D plane.


Camera類:沒弄懂,求教

DrawCameraDraws a camera inside a rectangle.
SetCameraSet the current camera so all Handles and Gizmos are draw with its settings.
ClearCamera Clears the camera.
SnapValue Rounds the value val to the closest multiple of snap (snap can only be posiive).


Event
Namespace: UnityEngine
Description

A UnityGUI event.

Events correspond to user input (key presses, mouse actions), or are UnityGUI layout or rendering events.

For each event OnGUI is called in the scripts; so OnGUI is potentially called multiple times per frame. Event.current corresponds to "current" event inside OnGUI call.



Event類和常見的Input系統(tǒng)里傳遞的參數(shù)差不多,只是多了來自于U3D編輯器的菜單欄操作信息。

鼠標(biāo)相關(guān)
button Which mouse button was pressed.
clickCountHow many consecutive mouse clicks have we received.
mousePositionThe mouse position.

鍵盤相關(guān)

character The character typed.
keyCode The raw key code for keyboard events.
modifiers Which modifier keys are held down.

其他信息
delta The relative movement of the mouse compared to last event.
type The type of event.

編輯器類-特別的

commandNameThe name of an ExecuteCommand or ValidateCommand Event.

查詢類

command Is Command/Windows key held down? (Read Only)
isKey Is this event a keyboard event? (Read Only)
isMouse Is this event a mouse event? (Read Only)
alt Is Alt/Option key held down? (Read Only)
shift Is Shift held down? (Read Only)
capsLock Is Caps Lock on? (Read Only)
control Is Control key held down? (Read Only)
functionKeyIs the current keypress a function key? (Read Only)
numeric Is the current keypress on the numeric keyboard? (Read Only)


范例代碼:

[csharp] view plain copy 在CODE上查看代碼片派生到我的代碼片
  1. using UnityEngine;  
  2. using System.Collections;  
  3.   
  4. public class SceneTag : MonoBehaviour {  
  5.   
  6.     // Use this for initialization  
  7.     void Start () {  
  8.       
  9.     }  
  10.       
  11.     // Update is called once per frame  
  12.     void Update () {  
  13.       
  14.     }  
  15.   
  16.     public Vector3 vectorPoint = Vector3.zero;  
  17.     public Vector3 vectorPoint2 = Vector3.zero;  
  18.       
  19.     public float shieldArea = 5;  
  20.     public Quaternion rot = Quaternion.identity;  
  21. }  


[csharp] view plain copy 在CODE上查看代碼片派生到我的代碼片
  1. <pre snippet_file_name="blog_20140219_1_8902285" code_snippet_id="194224"></pre><pre class="csharp" name="code" snippet_file_name="blog_20140219_2_3504874" code_snippet_id="194224">using UnityEngine;  
  2. using UnityEditor;  
  3. using System.Collections;  
  4. using System;  
  5. using System.Text;  
  6.   
  7. [CustomEditor(typeof(SceneTag))]  
  8. public class SceneEditor : Editor {  
  9.       
  10.   
  11.     void OnEnable()  
  12.     {  
  13.     }  
  14.   
  15.     void OnDisable()  
  16.     {  
  17.   
  18.     }  
  19.   
  20.     void OnDestroy()  
  21.     {  
  22.   
  23.     }  
  24.   
  25.     void OnInspectorGUI()  
  26.     {  
  27.     }  
  28.   
  29.     void OnSceneGUI()  
  30.     {  
  31.         Test_Handles();  
  32.         Test_Event();  
  33.     }  
  34.   
  35.     private static void Test_Event()  
  36.     {  
  37.         Vector2 mousePosition = Event.current.mousePosition;  
  38.         StringBuilder sb = new StringBuilder();  
  39.         sb.AppendFormat("({0},{1})"  
  40.             , mousePosition.x  
  41.             , mousePosition.y);  
  42.         //Debug.Log(sb.ToString());  
  43.     }  
  44.   
  45.     private void Test_Handles()  
  46.     {  
  47.         SceneTag scene = target as SceneTag;  
  48.         Test_Color(scene);  
  49.         //Test_Button(scene);  
  50.         Test_ArrowCap(scene);  
  51.         Test_CircleCap(scene);  
  52.         Test_ChangeValue(scene);  
  53.         Test_DrawAAPolyLine(scene);  
  54.         Test_DrawSolidArc(scene);  
  55.         Test_ScaleValueHandle(scene);  
  56.         Test_FreeRotateHandle(scene);  
  57.         Test_FreeMoveHandle(scene);  
  58.         Test_BeginGUI(scene);  
  59.   
  60.         if (GUI.changed)  
  61.             EditorUtility.SetDirty(target);  
  62.     }  
  63.   
  64.     private static void Test_FreeMoveHandle(SceneTag scene)  
  65.     {  
  66.         scene.vectorPoint = Handles.FreeMoveHandle(scene.vectorPoint,  
  67.                                   Quaternion.identity,  
  68.                                   2.0f,  
  69.                                   Vector3.zero,  
  70.                                   Handles.ArrowCap);  
  71.     }  
  72.   
  73.     private static void Test_FreeRotateHandle(SceneTag scene)  
  74.     {  
  75.         scene.transform.rotation = Handles.FreeRotateHandle(scene.transform.rotation, scene.transform.position, 0.5f);  
  76.     }  
  77.   
  78.     private static void Test_ScaleValueHandle(SceneTag scene)  
  79.     {  
  80.         scene.shieldArea  
  81.                   = Handles.ScaleValueHandle(scene.shieldArea,  
  82.                                   scene.transform.position + scene.transform.forward * scene.shieldArea,  
  83.                                   scene.transform.rotation,  
  84.                                   1,  
  85.                                   Handles.ConeCap,  
  86.                                   1);  
  87.     }  
  88.   
  89.     private static void Test_DrawSolidArc(SceneTag scene)  
  90.     {  
  91.         Handles.color = new Color(1, 1, 1, 0.2f);  
  92.         Handles.DrawSolidArc(scene.transform.position,  
  93.                 scene.transform.up,  
  94.                 -scene.transform.right,  
  95.                 270,  
  96.                 scene.shieldArea);  
  97.         Handles.color = Color.white;  
  98.         scene.shieldArea =  
  99.         Handles.ScaleValueHandle(scene.shieldArea,  
  100.                         scene.transform.position + scene.transform.forward * scene.shieldArea,  
  101.                         scene.transform.rotation,  
  102.                         1,  
  103.                         Handles.ConeCap,  
  104.                         1);  
  105.     }  
  106.   
  107.     private static void Test_DrawAAPolyLine(SceneTag scene)  
  108.     {  
  109.         Vector3[] positions = new Vector3[]  
  110.         {  
  111.             new Vector3(2,0,0),  
  112.             new Vector3(2,1,0),  
  113.             new Vector3(2,1,1),  
  114.             new Vector3(1,2,1),  
  115.             new Vector3(1,2,2),  
  116.         };  
  117.         for (int i = 0; i < positions.Length; ++i)  
  118.         {  
  119.             positions[i] += scene.transform.position;  
  120.         }  
  121.         Handles.DrawAAPolyLine(positions);  
  122.     }  
  123.   
  124.     private static void Test_ChangeValue(SceneTag scene)  
  125.     {  
  126.         scene.rot =  
  127.                      Handles.Disc(scene.rot,  
  128.                              scene.transform.position,  
  129.                              new Vector3(1, 1, 0),  
  130.                              5,  
  131.                              false,  
  132.                              1);  
  133.         scene.vectorPoint = Handles.DoPositionHandle(scene.vectorPoint, Quaternion.identity);  
  134.         scene.vectorPoint2 = Handles.DoPositionHandle(scene.vectorPoint2, Quaternion.identity);  
  135.     }  
  136.   
  137.     private static void Test_CircleCap(SceneTag scene)  
  138.     {  
  139.         float circleSize = 1;  
  140.         Handles.color = Color.red;  
  141.         Handles.CircleCap(0,  
  142.                 scene.transform.position + new Vector3(5, 0, 0),  
  143.                 scene.transform.rotation,  
  144.                 circleSize);  
  145.         Handles.color = Color.green;  
  146.         Handles.CircleCap(0,  
  147.                 scene.transform.position + new Vector3(0, 5, 0),  
  148.                 scene.transform.rotation,  
  149.                 circleSize);  
  150.         Handles.color = Color.blue;  
  151.         Handles.CircleCap(0,  
  152.                 scene.transform.position + new Vector3(0, 0, 5),  
  153.                 scene.transform.rotation,  
  154.                 circleSize);  
  155.   
  156.         Handles.color = Color.red;  
  157.         Vector3 newpos = scene.transform.position + new Vector3(5, 0, 0);  
  158.         circleSize = HandleUtility.GetHandleSize(newpos);  
  159.         Handles.CircleCap(0,  
  160.                 newpos,  
  161.                 scene.transform.rotation,  
  162.                 circleSize);  
  163.         Handles.color = Color.green;  
  164.         newpos = scene.transform.position + new Vector3(0, 5, 0);  
  165.         circleSize = HandleUtility.GetHandleSize(newpos);  
  166.         Handles.CircleCap(0,  
  167.                 newpos,  
  168.                 scene.transform.rotation,  
  169.                 circleSize);  
  170.         Handles.color = Color.blue;  
  171.         newpos = scene.transform.position + new Vector3(0, 0, 5);  
  172.         circleSize = HandleUtility.GetHandleSize(newpos);  
  173.         Handles.CircleCap(0,  
  174.                 newpos,  
  175.                 scene.transform.rotation,  
  176.                 circleSize);  
  177.   
  178.     }  
  179.   
  180.     //note by kun 2014.2.18  
  181.     // 這玩意有啥用?巨難操作!;  
  182.     // 3D按鈕還會(huì)因?yàn)橐暯菃栴}呈現(xiàn)不一樣的大小。;  
  183.     // 而且按鈕的當(dāng)前狀態(tài)也更新不及時(shí),逗么?;  
  184.     private static void Test_Button(SceneTag scene)  
  185.     {  
  186.         Handles.Button(scene.transform.position + new Vector3(0, 2, 0),  
  187.                               Quaternion.identity,  
  188.                               3,  
  189.                               3,  
  190.                               Handles.RectangleCap);  
  191.     }  
  192.   
  193.     private static void Test_BeginGUI(SceneTag scene)  
  194.     {  
  195.         Handles.color = Color.blue;  
  196.         Handles.Label(scene.transform.position + Vector3.up * 2,  
  197.                 scene.transform.position.ToString() + "\nShieldArea: " +  
  198.                 scene.shieldArea.ToString());  
  199.           
  200.         Handles.color = Color.red;  
  201.         Handles.DrawWireArc(scene.transform.position,  
  202.                 scene.transform.up,  
  203.                 -scene.transform.right,  
  204.                 180,  
  205.                 scene.shieldArea);  
  206.         scene.shieldArea =  
  207.         Handles.ScaleValueHandle(scene.shieldArea,  
  208.                         scene.transform.position + scene.transform.forward * scene.shieldArea,  
  209.                         scene.transform.rotation,  
  210.                         1,  
  211.                         Handles.ConeCap,  
  212.                         1);  
  213.   
  214.         //comment by kun 2014.2.18  
  215.         // GUI相關(guān)的繪制需要在Handles的繪制之后,否則會(huì)被覆蓋掉;  
  216.         // 使用Handles.BeginGUI會(huì)導(dǎo)致無(wú)法旋轉(zhuǎn)攝像機(jī),原因不詳;  
  217.         GUILayout.BeginArea(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));  
  218.         //Handles.BeginGUI(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));  
  219.         try  
  220.         {  
  221.             float a = float.Parse(GUILayout.TextField(scene.shieldArea.ToString()));  
  222.             scene.shieldArea = a;  
  223.         }  
  224.         catch (System.Exception ex)  
  225.         {  
  226.               
  227.         }  
  228.         if (GUILayout.Button("Reset Area"))  
  229.             scene.shieldArea = 5;  
  230.         //Handles.EndGUI();  
  231.         GUILayout.EndArea();  
  232.     }  
  233.   
  234.     private static void Test_ArrowCap(SceneTag scene)  
  235.     {  
  236.         float arrowSize = 1;  
  237.         Handles.color = Color.red;  
  238.         Handles.ArrowCap(0,  
  239.                 scene.transform.position + new Vector3(5, 0, 0),  
  240.                 scene.transform.rotation,  
  241.                 arrowSize);  
  242.         Handles.color = Color.green;  
  243.         Handles.ArrowCap(0,  
  244.                 scene.transform.position + new Vector3(0, 5, 0),  
  245.                 scene.transform.rotation,  
  246.                 arrowSize);  
  247.         Handles.color = Color.blue;  
  248.         Handles.ArrowCap(0,  
  249.                 scene.transform.position + new Vector3(0, 0, 5),  
  250.                 scene.transform.rotation,  
  251.                 arrowSize);  
  252.     }  
  253.   
  254.     private void Test_Color(SceneTag scene)  
  255.     {  
  256.         Handles.color = Color.magenta;  
  257.         scene.vectorPoint = Handles.Slider(scene.vectorPoint,  
  258.                                 Vector3.zero - scene.transform.position);  
  259.     }  
  260.   
  261. }</pre>  
  262. <pre></pre>  
  263. <pre></pre>  

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多