29.Handles弧线圆立方体几何体

29.Scene窗口拓展-Handles-弧线圆立方体几何体


29.1 知识点

Handles中的弧线(圆弧)

绘制线框弧线
Handles.DrawWireArc(圆心, 法线, 绘制朝向, 角度, 半径);
绘制填充弧线
Handles.DrawSolidArc(圆心, 法线, 绘制朝向, 角度, 半径);

private void OnSceneGUI()
{       
    // 弧线(圆弧)
    Handles.color = Color.white;
    // 如果向圆弧跟着对象动,第二个参数传入本地坐标,例如testSceneMono.transform.up,
    Handles.DrawWireArc(testSceneMono.transform.position, Vector3.up, testSceneMono.transform.forward, 30, 5);
    // Handles.DrawSolidArc(testSceneMono.transform.position, Vector3.up, testSceneMono.transform.forward, 30, 4);
    // 向左旋转15度 这样以人物正前方为等分
    Handles.DrawSolidArc(testSceneMono.transform.position, testSceneMono.transform.up, Quaternion.Euler(0,-15,0)* testSceneMono.transform.forward, 30, 4);
}



Handles中的圆

绘制填充圆
Handles.DrawSolidDisc(圆心, 法线, 半径);
绘制线框圆
Handles.DrawWireDisc(圆心, 法线, 半径);

private void OnSceneGUI()
{        
    // 圆
    Handles.color = Color.gray;
    Handles.DrawSolidDisc(testSceneMono.transform.position, testSceneMono.transform.up, 2);
    Handles.DrawWireDisc(testSceneMono.transform.position, testSceneMono.transform.up, 3);
}

Handles中的立方体线框

Handles.DrawWireCube(中心点, xyz大小);

private void OnSceneGUI()
{
    // 立方体
    Handles.color = Color.red;
    Handles.DrawWireCube(testSceneMono.transform.position, Vector3.one);
}

Handles中的几何体

Handles.DrawAAConvexPolygon(几何体各顶点);

private void OnSceneGUI()
{
    // 几何体
    //(0,0,0)
    //(1,0,0)
    //(1,0,1)
    //(0,0,z)
    Handles.DrawAAConvexPolygon(Vector3.zero, Vector3.right, Vector3.right + Vector3.forward, Vector3.forward);
}


29.2 知识点代码

Lesson29_Scene窗口拓展_Handles_弧线圆立方体几何体

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson29_Scene窗口拓展_Handles_弧线圆立方体几何体 : MonoBehaviour
{
    void Start()
    {
        #region 知识点一 Handles中的弧线(圆弧)

        //绘制线框弧线
        //Handles.DrawWireArc(圆心, 法线, 绘制朝向, 角度, 半径); 
        // 绘制填充弧线
        //Handles.DrawSolidArc(圆心, 法线, 绘制朝向, 角度, 半径); 

        #endregion

        #region 知识点二 Handles中的圆

        //绘制填充圆
        //Handles.DrawSolidDisc(圆心, 法线, 半径); 
        //绘制线框圆
        //Handles.DrawWireDisc(圆心, 法线, 半径); 

        #endregion

        #region 知识点三 Handles中的立方体线框

        //Handles.DrawWireCube(中心点, xyz大小);

        #endregion

        #region 知识点四 Handles中的几何体

        //Handles.DrawAAConvexPolygon(几何体各顶点);

        #endregion
    }
}

TestSceneMonoEditor

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(TestSceneMono))]
public class TestSceneMonoEditor : Editor
{
    private TestSceneMono testSceneMono;

    private void OnEnable()
    {
        testSceneMono = target as TestSceneMono;
    }


    private void OnSceneGUI()
    {
        //选中挂载TestSceneMono的对象会打印
        // Debug.Log("Scene窗口拓展相关逻辑");

        #region Lesson28_Scene窗口拓展_Handles_文本线段虚线

        //颜色
        Handles.color = new Color(0, 1, 0, 1f);

        //文本
        Handles.Label(testSceneMono.transform.position, "测试文本显示");

        //线段
        Handles.DrawLine(testSceneMono.transform.position,
            testSceneMono.transform.position + testSceneMono.transform.right * 5, 5);

        //虚线
        Handles.color = new Color(0, 0, 1, 1f);
        Handles.DrawDottedLine(testSceneMono.transform.position,
            testSceneMono.transform.position + testSceneMono.transform.forward * 5, 5);

        #endregion

        #region Lesson29_Scene窗口拓展_Handles_弧线圆立方体几何体

        //弧线(圆弧)
        Handles.color = Color.white;
        //如果向圆弧跟着对象动,第二个参数传入本地坐标 例如testSceneMono.transform.up,
        Handles.DrawWireArc(testSceneMono.transform.position, Vector3.up, testSceneMono.transform.forward, 30, 5);
        // Handles.DrawSolidArc(testSceneMono.transform.position, Vector3.up, testSceneMono.transform.forward, 30, 4);
        //向左旋转15度 这样以人物正前方为等分
        Handles.DrawSolidArc(testSceneMono.transform.position, testSceneMono.transform.up,
            Quaternion.Euler(0, -15, 0) * testSceneMono.transform.forward, 30, 4);


        //圆
        Handles.color = Color.gray;
        Handles.DrawSolidDisc(testSceneMono.transform.position, testSceneMono.transform.up, 2);
        Handles.DrawWireDisc(testSceneMono.transform.position, testSceneMono.transform.up, 3);

        //立方体
        Handles.color = Color.red;
        Handles.DrawWireCube(testSceneMono.transform.position, Vector3.one);


        //几何体
        //(0,0,0)
        //(1,0,0)
        //(1,0,1)
        //(0,0,z)
        Handles.DrawAAConvexPolygon(Vector3.zero, Vector3.right, Vector3.right + Vector3.forward, Vector3.forward);

        #endregion
    }
}


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 785293209@qq.com

×

喜欢就点赞,疼爱就打赏