Beispiel #1
0
        /// <summary>
        /// 异步加载资源(带进度条功能)
        /// </summary>
        public IEnumerator GetAsyncObject(Action <UnityEngine.Object> handle, Action <float> progress)
        {
            // 如果 _prefab 不为空说明已经读取完成,执行 yield break 之后不再执行下面语句
            if (_prefab != null)
            {
                handle(_prefab); yield break;
            }

            UnityEngine.ResourceRequest resRequest = UnityEngine.Resources.LoadAsync(path);

            while (!resRequest.isDone)
            {
                if (progress != null)
                {
                    progress(resRequest.progress);
                }
                yield return(null);
            }
            _prefab = resRequest.asset;

            if (handle != null)
            {
                handle(_prefab);
            }
            yield return(resRequest);
        }
Beispiel #2
0
        static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *__ret = ILIntepreter.Minus(__esp, 0);

            var result_of_this_method = new UnityEngine.ResourceRequest();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #3
0
 protected override void OnUnLoad()
 {
     if (Tresource.value != null)
     {
         UnityEngine.Resources.UnloadAsset(Tresource.value);
         Tresource.value = default(T);
     }
     _request = null;
 }
        static int _g_get_asset(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.ResourceRequest gen_to_be_invoked = (UnityEngine.ResourceRequest)translator.FastGetCSObj(L, 1);
                translator.Push(L, gen_to_be_invoked.asset);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
        internal static bool Prefix_Async(ref UnityEngine.ResourceRequest __result, string path)
        {
            if (ModPrefab.TryGetFromFileName(path, out ModPrefab prefab))
            {
                __result = new UnityEngine.ResourceRequest();
                AssetsInfo.SetValue(__result, prefab.GetGameObject(), null);

                MPathInfo.SetValue(__result, path);
                MTypeInfo.SetValue(__result, prefab.GetGameObject().GetType());

                return(false);
            }

            return(true);
        }
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    UnityEngine.ResourceRequest gen_ret = new UnityEngine.ResourceRequest();
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.ResourceRequest constructor!"));
        }
        static StackObject *get_asset_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.ResourceRequest instance_of_this_method = (UnityEngine.ResourceRequest) typeof(UnityEngine.ResourceRequest).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.asset;

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #8
0
        public static bool Prefix_Async(ref UnityEngine.ResourceRequest __result, string path)
        {
            foreach (var prefab in CustomPrefabHandler.customPrefabs)
            {
                if (prefab.PrefabFileName.ToLowerInvariant() == path.ToLowerInvariant())
                {
                    //__result = prefab.Object;

                    __result = new UnityEngine.ResourceRequest();
                    AssetsInfo.SetValue(__result, prefab.GetResource(), null);

                    MPathInfo.SetValue(__result, path);
                    MTypeInfo.SetValue(__result, prefab.GetResource().GetType());

                    return(false);
                }
            }

            return(true);
        }
        static int _m_LoadAsync_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && (LuaAPI.lua_isnil(L, 1) || LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TSTRING))
                {
                    string _path = LuaAPI.lua_tostring(L, 1);

                    UnityEngine.ResourceRequest gen_ret = UnityEngine.Resources.LoadAsync(
                        _path);
                    translator.Push(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 1) || LuaAPI.lua_type(L, 1) == LuaTypes.LUA_TSTRING) && translator.Assignable <System.Type>(L, 2))
                {
                    string      _path = LuaAPI.lua_tostring(L, 1);
                    System.Type _type = (System.Type)translator.GetObject(L, 2, typeof(System.Type));

                    UnityEngine.ResourceRequest gen_ret = UnityEngine.Resources.LoadAsync(
                        _path,
                        _type);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Resources.LoadAsync!"));
        }
Beispiel #10
0
        public override void start(System.Object obj)
        {
            System.Type resType = null;
            switch (m_resId)
            {
            case FResID.ASSETBUNDLE:
                resType = typeof(UnityEngine.Object);
                break;

            case FResID.PREFAB:
                resType = typeof(UnityEngine.Object);
                break;

            case FResID.TEXTURE:
                resType = typeof(UnityEngine.Texture);
                break;

            case FResID.SPRITE:
                resType = typeof(UnityEngine.Sprite);
                break;

            case FResID.FONT:
                resType = typeof(UnityEngine.Object);
                break;

            case FResID.AUDIO:
                resType = typeof(UnityEngine.Object);
                break;

            case FResID.FX:
                resType = typeof(UnityEngine.Object);
                break;

            default:
                resType = typeof(UnityEngine.Object);
                break;
            }

            m_request = UnityEngine.Resources.LoadAsync(m_resPath, resType);
        }
Beispiel #11
0
        public static bool Prefix_Async(ref UnityEngine.ResourceRequest __result, string path)
        {
            foreach (var prefab in CustomPrefabHandler.customPrefabs)
            {
                if (prefab.PrefabFileName.ToLowerInvariant() == path.ToLowerInvariant())
                {
                    //__result = prefab.Object;

                    var request = new UnityEngine.ResourceRequest();
                    typeof(UnityEngine.ResourceRequest).GetProperty("asset").SetValue(request, prefab.Object, null);

                    typeof(UnityEngine.ResourceRequest).GetField("m_Path", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(request, path);
                    typeof(UnityEngine.ResourceRequest).GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(request, prefab.Object.GetType());

                    __result = request;

                    return(false);
                }
            }

            return(true);
        }
Beispiel #12
0
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.File.OnFileCoroutine_CallBackInterface a_callback_interface, Fee.File.Path a_path)
        {
            //result
            this.result = null;

            //ロード。
            UnityEngine.Object t_result_object = null;
            {
                UnityEngine.ResourceRequest t_request = null;

                try{
                    t_request = UnityEngine.Resources.LoadAsync(a_path.GetPath());
                    if (t_request == null)
                    {
                        //エラー。
                        this.result = new ResultType(null, "Unknown Error : LoadResourcesTextureFile : " + a_path.GetPath());
                        yield break;
                    }
                }catch (System.Exception t_exception) {
                    //エラー。
                    this.result = new ResultType(null, "Unknown Error : LoadResourcesPrefabFile : " + a_path.GetPath() + " : " + t_exception.Message);
                    yield break;
                }

                do
                {
                    //キャンセルチェック。
                    {
                        if (a_callback_interface != null)
                        {
                            if (a_callback_interface.OnFileCoroutine(t_request.progress) == false)
                            {
                                //t_request.Cancel();
                            }
                        }
                    }

                    yield return(null);
                }while(t_request.isDone == false);

                if (t_request.asset == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Load Error : LoadResourcesTextureFile : " + a_path.GetPath());
                    yield break;
                }

                t_result_object = t_request.asset;
            }

            //コンバート。
            UnityEngine.Texture2D t_result_texture = null;
            {
                UnityEngine.Texture2D t_result = t_result_object as UnityEngine.Texture2D;

                if (t_result == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadResourcesTextureFile : " + a_path.GetPath());
                    yield break;
                }

                t_result_texture = t_result;
            }

            //成功。
            this.result = new ResultType(t_result_texture, null);
            yield break;
        }
Beispiel #13
0
 public FLoadAsset(int resId, string resPath)
 {
     m_resId   = resId;
     m_resPath = resPath;
     m_request = null;
 }
Beispiel #14
0
 public ResourceProvider(SynchronizationContext mainThread, UnityEngine.ResourceRequest request)
 {
     _mainThread = mainThread;
     _request    = request;
 }