Some usage of unity view extension

I recently summarized some usages of unity view editing:

1. Crossing

     1. Add a public void OnDrawGizmos () method in any script, and then call this method in Gizmos.DrawLine to draw lines or other graphics in the Scene view

     2. In the Game view at runtime, call the _LineRenderer.SetVertexCount(_Nav.path.corners.Length) method to draw lines

2. Knowledge about GUI

    1. Add this private void OnGUI() method to any script, in this method you can call GUI related components, you can see related components in the Game view, for example

      GUIStyle style = new GUIStyle

        {

            border = new RectOffset(10, 10, 10, 10),

            fontSize = 50,

            fontStyle = FontStyle.BoldAndItalic,

        };

        // normal:Rendering settings for when the component is displayed normally.

        style.normal.textColor = new Color(200/255f, 180/255f, 150/255f); // Need to be divided by 255, because the range is 0-1

        GUI.Label(new Rect(100, 100, 200, 80), "aaa", style);

        GUI.Label(new Rect(Screen.width - 100, Screen.height - 100, 200, 80),

            "<color=#00ff00><size=30>"+"aaa"+"</size></color>", style);

   2. Inherit the Editor class, add tags ([CustomEditor(typeof(TileMousePosition))],[ExecuteInEditMode]), override the public override void OnInspectorGUI() method in the class to customize the components in the insertor: test.mRectValue = EditorGUILayout. RectField("Window coordinates", test.mRectValue), method void OnSceneGUI() can draw GUI components in the Scene view:

         Handles.BeginGUI ();

        GUIStyle style = new GUIStyle(); 

        style.normal.textColor = Color.red; 

        //Specify the GUI display area

        GUILayout.BeginArea (new Rect (0, 0, 500, 100));

        //GUI draws the text box

        GUILayout.Label("世界坐标:" + "X: " + worldPosition.x + " Y: " + -worldPosition.y*2 + " Z: " + worldPosition.z,style);  

        GUILayout.Label("格子坐标:" + "X: " + cellPosition.x + " Y: " + -cellPosition.y + " Z: " + cellPosition.z,style);   

 

        GUILayout.EndArea ();

    

        Handles.EndGUI();

Guess you like

Origin blog.csdn.net/u011105442/article/details/102943764