unity 镜头标签

发布时间:2023-12-05 19:30

标签代码

using System;
using UnityEngine;

[Serializable]
public class Item
{
    public Vector3 direction;
    public string content;
    public float length;
    public Transform transform;
    public bool show;//是否显示
    //public GameObject lable;//显示的标签
}

镜头显示标签代码

using System.Collections.Generic;
using UnityEngine;
using FrameWork;
using UnityEngine.Rendering;

/// 
/// 屏幕标签
/// 
public class ScreenDrowLine : MonoBehaviour
{
    [SerializeField] Material mat;
    [SerializeField] List Texts = new List();
    public List items = new List();

    [SerializeField] Transform lablesTra;

    private void Start()
    {
        GameEvent.typeEventSystem.Register(InstantiateLable);
    }

    #region URP渲染模式需另加代码
    private void OnEnable()
    {
        RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
    }

    private void OnDisable()
    {
        RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
    }

    private void OnEndCameraRendering(ScriptableRenderContext arg1, Camera arg2)
    {
        OnPostRender();
    }

    #endregion

    void OnPostRender()
    {
        GL.Color(Color.red);
        GL.PushMatrix();
        GL.LoadOrtho();
        mat.SetPass(0);
        for (int i = 0; i < items.Count; i++)
        {
            //if (items[i].show && items[i].transform.gameObject.activeSelf)
            //{
            //    Texts[i].gameObject.SetActive(true);
                GL.Begin(GL.LINES);
                var pos = Camera.main.WorldToScreenPoint(items[i].transform.position);
                GL.Vertex(new Vector2(pos.x / Screen.width, pos.y / Screen.height));

                pos = Camera.main.WorldToScreenPoint(items[i].transform.position + items[i].direction * items[i].length);

                if (pos.x > 1550 || pos.x < 45 || pos.y > 870 || pos.y < 110)
                {
                    items[i].length = Mathf.Lerp(items[i].length, 0, Time.deltaTime * 5);
                    pos = Camera.main.WorldToScreenPoint(items[i].transform.position + items[i].direction * items[i].length);
                }
                else
                {
                    var len = Mathf.Lerp(items[i].length, 2, Time.deltaTime * 5);
                    var temp = Camera.main.WorldToScreenPoint(items[i].transform.position + items[i].direction * len);
                    if (temp.x < 1540 && temp.x > 55 && temp.y < 860 && temp.y > 120)
                    {
                        pos = temp;
                        items[i].length = len;
                    }
                }
                GL.Vertex(new Vector2(pos.x / Screen.width, pos.y / Screen.height));
                GL.End();
                Texts[i].transform.position = pos;
            //}
            //else
            //{
            //    Texts[i].gameObject.SetActive(false);
            //}

        }
        GL.PopMatrix();
    }

    /// 
    /// 实例标签
    /// 
    public void InstantiateLable(InstantiateLable instantiateLable)
    {
        LableItem ll = Instantiate(Resources.Load(\"UI/Prefab/LableItem\"), lablesTra);
        ll.SetText($\"{instantiateLable.readyInfo.post}-{instantiateLable.readyInfo.name}\");
        Texts.Add(ll.gameObject);
        Item item = new Item();
        item.direction = new Vector3(0, 0, 0);
        item.length = 2;
        item.transform = instantiateLable.pepleTra;
        item.show = true;
        items.Add(item);
    }
}

属性窗口

\"unity

 

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号