zoukankan      html  css  js  c++  java
  • 从世界坐标转换成ui的rect坐标的方法

    这个东西整整折磨了我一个通宵。原谅我先这样放上来。明天整理整理

     1 using UnityEngine;
     2 using System.Collections;
     3 using UnityEngine.UI;
     4 
     5 public class test_temp2 : MonoBehaviour {
     6 public GameObject 要出现的世界点;
     7 public Camera 摄像机;
     8 private RectTransform 要修改的屏幕点;
     9 public GameObject 预制件;
    10 private GameObject 脚跟死皮;
    11 //预制件的名字是 canvas/jiafen
    12 
    13 
    14 public void 大狗逼熬夜一晚上才整明白的傻逼方法()
    15 {
    16 
    17 //你妈的无论是GetComponent还是GetComponentInChildren()都只能获得canvas预制件的父组件,尼玛有什么用啊 害我一晚上没睡
    18 脚跟死皮 = Instantiate(预制件);
    19 脚跟死皮.GetComponent<RectTransform>().FindChild("jiafen").GetComponent<RectTransform>().anchoredPosition=
    20 RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
    21 //temp.GetComponentInChildren<RectTransform>().anchoredPosition= RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
    22 //temp.GetComponentInChildren<Text>().text = temp.GetComponentInChildren<RectTransform>().FindChild("jiafen").GetComponent<RectTransform>().anchoredPosition.ToString();
    23 //temp.GetComponentInChildren<RectTransform>().anchoredPosition = new Vector2(320.6f, 70.1f);
    24 //temp.GetComponentInChildren<RectTransform>().anchoredPosition;
    25 //要修改的屏幕点 = temp.GetComponentInChildren<RectTransform>();//获得要修改坐标的物体
    26 //要修改的屏幕点.anchoredPosition= RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
    27 //temp.GetComponentInChildren<Text>().text= "asdlkfjalsdkf";
    28 Destroy(脚跟死皮.gameObject, 1f);
    29 //草泥马终于整明白了。原来temp.GetComponentInChildren<RectTransform>()获得的还是父物体
    30 
    31 }
    32 }
  • 相关阅读:
    方法引用(method reference)
    函数式接口
    Lambda 表达式
    LinkedList 源码分析
    ArrayList 源码分析
    Junit 学习笔记
    Idea 使用 Junit4 进行单元测试
    Java 定时器
    【干货】Mysql的"事件探查器"-之Mysql-Proxy代理实战一(安装部署与实战sql拦截与性能监控)
    python-flask框架web服务接口开发实例
  • 原文地址:https://www.cnblogs.com/vsdog/p/5060212.html
Copyright © 2011-2022 走看看