zoukankan      html  css  js  c++  java
  • Unity-WIKI 之 DrawArrow

    组件作用

    Unity画方向箭头类库,在Scene视图或在Game视图打开Gizmos查看效果

    效果预览

    HeadRotation  SpawnPoints image

    wiki地址

    http://wiki.unity3d.com/index.php/DrawArrow

    组件源码

    using UnityEngine;
    using System.Collections;
    
    public class DebugForward : MonoBehaviour {
        void Update()
        {
            //使用DwawArrow
            DrawArrow.ForDebug(transform.position, transform.forward, Color.green);
            //使用Unity自带的画线函数
            Debug.DrawLine(transform.position, Vector3.back, Color.red);
        }
    }
    
    DrawArrow.cs
    using UnityEngine;
    using System.Collections;
     
    public static class DrawArrow
    {
        public static void ForGizmo(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
        {
            Gizmos.DrawRay(pos, direction);
     
            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180+arrowHeadAngle,0) * new Vector3(0,0,1);
            Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180-arrowHeadAngle,0) * new Vector3(0,0,1);
            Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
            Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
        }
     
        public static void ForGizmo(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
        {
            Gizmos.color = color;
            Gizmos.DrawRay(pos, direction);
     
            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180+arrowHeadAngle,0) * new Vector3(0,0,1);
            Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180-arrowHeadAngle,0) * new Vector3(0,0,1);
            Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
            Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
        }
     
        public static void ForDebug(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
        {
            Debug.DrawRay(pos, direction);
     
            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180+arrowHeadAngle,0) * new Vector3(0,0,1);
            Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180-arrowHeadAngle,0) * new Vector3(0,0,1);
            Debug.DrawRay(pos + direction, right * arrowHeadLength);
            Debug.DrawRay(pos + direction, left * arrowHeadLength);
        }
        public static void ForDebug(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
        {
            Debug.DrawRay(pos, direction, color);
     
            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180+arrowHeadAngle,0) * new Vector3(0,0,1);
            Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0,180-arrowHeadAngle,0) * new Vector3(0,0,1);
            Debug.DrawRay(pos + direction, right * arrowHeadLength, color);
            Debug.DrawRay(pos + direction, left * arrowHeadLength, color);
        }
    }
  • 相关阅读:
    [转] s3c6410开发板研究笔记(一)从SD卡启动UBOOT(未完待续。。。)
    [转]解决aptget f install提示错误
    ubuntu 软件中心崩溃解决办法
    [转]Linux环境下Jlink配置
    [转]SD卡引脚 电路图及工作原理介绍
    [原]linux下安装运行supervivitransfertool
    [转]OclO 开发笔记
    [转]dnw for linux
    [转]使用JLink间接烧写uboot,supervivi到mini2440的方法
    Js 浏览器全屏代码(按F11)
  • 原文地址:https://www.cnblogs.com/zhaoqingqing/p/3648813.html
Copyright © 2011-2022 走看看