예제 #1
0
 // 销毁对象
 public static void Destroy(UnityEngine.Object obj)
 {
     if (obj != null)
     {
         if (obj as GameObject)
         {
             UtilApi.DestroyComponent(obj as GameObject);
             (obj as GameObject).transform.SetParent(null);      // 这个仅仅是移除场景中
             UtilApi.DestroyTexMat(obj as GameObject);
         }
         UnityEngine.Object.Destroy(obj);
         obj = null;
     }
     else
     {
         Ctx.m_instance.m_logSys.log("Destroy Object is null");
     }
 }
예제 #2
0
        // 深度遍历移除 Sprite Image
        public static void DestroyComponent(GameObject go_)
        {
            // 每一个 GameObject 只能有一个 Image 组件
            Image image = go_.GetComponent <Image>();

            if (image != null && image.sprite != null)
            {
                if (image.sprite.texture != null)
                {
                }
                image.sprite = null;
            }

            int       childCount = go_.transform.childCount;
            int       idx        = 0;
            Transform childTrans = null;

            for (idx = 0; idx < childCount; ++idx)
            {
                childTrans = go_.transform.GetChild(idx);
                UtilApi.DestroyComponent(childTrans.gameObject);
            }
        }