NGUI HUDText

今天使用HUDText的时候,发现须要如今场景里创建一个UI2dRoot;不然位置不对

或许应该创建一个prefab这样每一个场景都加入一个就可以。


  1. using UnityEngine;
  2.  
  3.     using UnityEditor;    
  4.  
  5.     public class FixStupidEditorBehavior : MonoBehaviour {
  6.  
  7.         [MenuItem("GameObject/Create Empty Parent #&e")]
  8.         static void createEmptyParent() {
  9.             GameObject go = new GameObject("GameObject");
  10.             if(Selection.activeTransform != null)
  11.             {
  12.  
  13.                     go.transform.parent = Selection.activeTransform.parent;
  14.  
  15.                     go.transform.Translate(Selection.activeTransform.position);
  16.  
  17.                     Selection.activeTransform.parent = go.transform;
  18.  
  19.             }
  20.  
  21.         }  
  22.  
  23.  
  24.         [MenuItem("GameObject/Create Empty Duplicate #&d")]
  25.         static void createEmptyDuplicate() {
  26.  
  27.             GameObject go = new GameObject("GameObject");
  28.  
  29.             if(Selection.activeTransform != null)
  30.             {
  31.                 go.transform.parent = Selection.activeTransform.parent;
  32.                 go.transform.Translate(Selection.activeTransform.position);
  33.             }
  34.  
  35.         }
  36.  
  37.         [MenuItem("GameObject/Create Empty Child #&c")]
  38.         static void createEmptyChild() {
  39.  
  40.             GameObject go = new GameObject("GameObject");
  41.  
  42.             if(Selection.activeTransform != null)
  43.             {
  44.                     go.transform.parent = Selection.activeTransform;
  45.                     go.transform.Translate(Selection.activeTransform.position);
  46.             }
  47.  
  48.         }
  49.  
  50.     }



载入场景注意:异步载入场景的时候,NGUI是无法正常绘制的,须要用原生的OnGUI

原文地址:https://www.cnblogs.com/lcchuguo/p/5174831.html