Author Topic: NGUITools.AddChild !!  (Read 2066 times)

chaos3d

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
NGUITools.AddChild !!
« on: June 08, 2017, 05:28:12 AM »
NGUI 3.11.4

< NGUITools.cs >

   static public GameObject AddChild (this GameObject parent, GameObject prefab, int layer)
   {
      var go = GameObject.Instantiate(prefab) as GameObject;
#if UNITY_EDITOR
      if (!Application.isPlaying)
         UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create Object");
#endif
      if (go != null)
      {
         go.name = prefab.name;

         if (parent != null)
         {
            Transform t = go.transform;
            t.parent = parent.transform;
            t.localPosition = Vector3.zero;
            t.localRotation = Quaternion.identity;
            t.localScale = Vector3.one;
            if (layer == -1) go.layer = parent.layer;
            else if (layer > -1 && layer < 32) go.layer = layer;
         }
         go.SetActive(true);  <---------- What the hell !!!  >:( >:( >:(
      }
      return go;
   }


It was never before!
Someone can bug hard!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild !!
« Reply #1 on: June 10, 2017, 06:34:45 AM »
And what's the issue? Game objects must be active when created. This was added because in TNet prefabs can be instantiated from a pool of inactive game objects, and I wanted them to be in a consistent state.