Ejemplo n.º 1
0
    public static void Test_Sync()
    {
        var        getter = ResHelper.LoadGameObject("prefabs/cube");
        GameObject go     = getter.Get();

        ResHelper.DestroyGameObject(go);

        getter = ResHelper.LoadGameObject("prefabs/cube");
        GameObject go2 = getter.Get();
        //ResHelper.DestroyGameObject(go);
    }
 static int DestroyGameObject(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckObject(L, 1, typeof(UnityEngine.GameObject));
         ResHelper.DestroyGameObject(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 3
0
    //异步实例化模型
    public static void AsyncInstantiateModel(string name, CheckAction check, UnityAction <GameObject> omComplete)
    {
        name = name.toLower();
        var obj = modelPools.PopItem(name);

        if (obj != null)
        {
            obj.transform.localScale = Vector3.one;
            if (check == null || check(name))
            {
                omComplete(obj);
            }
            else
            {
                ResHelper.DestroyGameObject(ref obj);
            }
        }
        else
        {
            UnityAction <UnityEngine.Object> onLoadComplete = (UnityEngine.Object mainAsset) =>
            {
                if (check != null && !check(name))
                {
                    return;
                }
                var        prefab = mainAsset as GameObject;
                GameObject newObj = null;
                if (prefab != null)
                {
                    newObj = GameObject.Instantiate(prefab);
                    newObj.transform.resetLocal();
                }
                omComplete(newObj);
            };
            AsyncLoadModel(name, onLoadComplete);
        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// 释放之前N宫格不在当前N宫格内的trunk
        /// 因为是异步加载,可能本次释放不完。
        /// </summary>
        /// <param name="idx"></param>
        void UnLoadPreNTrunk(Vector2_Bit idx)
        {
            int x = idx.x;
            int y = idx.y;

            if (trunkDic.GetNonNullCount() <= (trunkEdgeNum * trunkEdgeNum))
            {
                return;
            }

            unloadTrunkLst.Clear();
            foreach (var kv in trunkDic)
            {
                Vector2_Bit preIdx = new Vector2_Bit(kv.Key);
                int         preX   = preIdx.x;
                int         preY   = preIdx.y;

                if (Mathf.Abs(preX - x) > trunkOffset || Mathf.Abs(preY - y) > trunkOffset)
                {
                    //Debug.Log(preIdx);
                    if (kv.Value != null)
                    {
                        ResHelper.DestroyGameObject(kv.Value);
                        unloadTrunkLst.Add(kv.Key);
                    }
                }
            }

            for (int i = 0; i < unloadTrunkLst.Count; i++)
            {
                trunkDic.Remove(unloadTrunkLst[i]);
            }

            //释放bundle
            ResHelper.RealseAllUnUse();
        }