예제 #1
0
    public static SceneAssetRequest LoadSceneAsync(string path, bool additive, LoadedCallback loadedCallback = null)
    {
        if (string.IsNullOrEmpty(path))
        {
            GameLog.LogError("invalid path");
            return(null);
        }

        path = GetExistPath(path);
        var asset = new SceneAssetRequestAsync(path, additive);

        if (!additive)
        {
            if (_runningScene != null)
            {
                _runningScene.Release();;
                _runningScene = null;
            }
            _runningScene = asset;
        }
        if (loadedCallback != null)
        {
            asset.completed += loadedCallback;
        }

        asset.Load();
        asset.Retain();
        _scenes.Add(asset);
        GameLog.Log(string.Format("LoadScene:{0}", path));
        return(asset);
    }
예제 #2
0
    /// <summary>
    /// 场景包加载完真正异步加载场景
    /// </summary>
    /// <param name="name"></param>
    /// <param name="onLoaded"></param>
    private void __LoadScene(string name, LoadedCallback onLoaded, bool async)
    {
        LevelLoader sLoader = LoaderPool.Instance.GetLoader <LevelLoader> ();

        sLoader.Init(name, onLoaded, async);
        StartLoad(sLoader, async);
    }
예제 #3
0
    internal virtual bool Update()
    {
        if (checkRequires)
        {
            UpdateRequires();
        }
        if (!isDone)
        {
            return(true);
        }
        if (completed == null)
        {
            return(false);
        }
        try
        {
            completed.Invoke(this);
        }
        catch (Exception ex)
        {
            GameLog.LogException(ex);
        }

        completed = null;
        return(false);
    }
예제 #4
0
 protected void Complete()
 {
     if (completed != null)
     {
         completed(this);
         completed = null;
     }
 }
예제 #5
0
 public void Start(IUILoader uiLoader, LoadedCallback callback)
 {
     mActive           = true;
     visible           = true;
     mUILoader         = uiLoader;
     mOnLoadedCallback = callback;
     mUILoader.LoadPopup(name, mOnLoaded);
 }
예제 #6
0
            private void OnLoaded(GameObject go)
            {
                if (!mActive)
                {
                    mUILoader.UnloadInstance(go);
                    return;
                }
                gameObject = go;
                RectTransform rectTrans = go.transform as RectTransform;

                rectTrans.SetParent(popup_root, false);
                rectTrans.offsetMin     = Vector2.zero;
                rectTrans.offsetMax     = Vector2.zero;
                rectTrans.localRotation = Quaternion.identity;
                rectTrans.localScale    = Vector3.one;
                bool overlay = false;

                mBehaviours.Clear();
                go.GetComponents <MonoBehaviour>(mBehaviours);
                bool paraSet = false;

                for (int i = 0, imax = mBehaviours.Count; i < imax; i++)
                {
                    MonoBehaviour       behaviour = mBehaviours[i];
                    IUIParameterHandler handler   = behaviour as IUIParameterHandler;
                    if (handler != null)
                    {
                        try { handler.SetParameter(param); } catch (System.Exception e) { Debug.LogError(e); }
                        paraSet = true;
                    }
                    IPopupOverlay popupOverlay = behaviour as IPopupOverlay;
                    if (popupOverlay != null && popupOverlay.Overlay)
                    {
                        overlay = true;
                    }
                }
                if (param != null && !paraSet)
                {
                    Debug.LogErrorFormat(go, "[UIManager] No parameter handler found for '{0]' !", name);
                }
                if (mFocusState == 1)
                {
                    for (int i = 0, imax = mBehaviours.Count; i < imax; i++)
                    {
                        IUIFocusHandler handler = mBehaviours[i] as IUIFocusHandler;
                        if (handler != null)
                        {
                            try { handler.OnFocus(); } catch (System.Exception e) { Debug.LogException(e); }
                        }
                    }
                    mFocusState = 2;
                }
                go.SetActive(visible);
                LoadedCallback callback = mOnLoadedCallback;

                mOnLoadedCallback = null;
                callback(this, overlay);
            }
예제 #7
0
    public static AssetRequest LoadModel(string path, LoadedCallback loadedCallback = null)
    {
        Type type = typeof(GameObject);

        stringBuilder.Clear();
        stringBuilder.Append(ModelPathPrefix);
        stringBuilder.Append(path);
        return(LoadAssetAsync(stringBuilder.ToString(), type, loadedCallback));
    }
예제 #8
0
    public void LoadScene(string name, LoadedCallback onLoaded, bool async, bool enter = true)
    {
        if (string.IsNullOrEmpty(name))
        {
            Util.LogWarning("资源路径不能为空---");
            return;
        }
        string sceneName = name.Substring(name.LastIndexOf("/") + 1);

        if (AppConst.UseAssetBundle)
        {
            string abPath = "Scenes/" + sceneName;
            LoadAssetBundle(abPath, delegate(object data){
                if (data == null)
                {
                    Util.LogError("Load Scene Bundle Fail, name: " + sceneName);
                    if (onLoaded != null)
                    {
                        onLoaded(data);
                    }

                    return;
                }
                if (enter)
                {
                    __LoadScene(sceneName, onLoaded, async);
                }
                else
                {
                    string abName = FileHelper.CheckBundleName(abPath);
                    if (!m_handLoad.Contains(abName))
                    {
                        m_handLoad.Add(abName);
                    }

                    if (onLoaded != null)
                    {
                        onLoaded(data);
                    }
                }
            }, async);
        }
        else
        {
            if (enter)
            {
                __LoadScene(sceneName, onLoaded, async);
            }
            else
            {
                if (onLoaded != null)
                {
                    onLoaded(null);
                }
            }
        }
    }
예제 #9
0
    public static AssetRequest LoadAssetAsync(string path, Type type, LoadedCallback loadedCallback = null)
    {
        AssetRequest assetRequest = LoadAsset(path, type, true);

        // todo 这个loadedCallback 是我自己加的,源码里是怎么实现异步加载的
        if (loadedCallback != null)
        {
            assetRequest.completed += loadedCallback;
        }
        return(assetRequest);
    }
예제 #10
0
    public static AssetRequest LoadUI(string path, LoadedCallback loadedCallback = null)
    {
        Type   type   = typeof(GameObject);
        string suffix = GetSuffixOfAsset(type);

        stringBuilder.Clear();
        stringBuilder.Append(UIPathPrefix);
        stringBuilder.Append(path);
        stringBuilder.Append(".");
        stringBuilder.Append(suffix);
        return(LoadAssetAsync(stringBuilder.ToString(), type, loadedCallback));
    }
예제 #11
0
    public void LoadPrefab(string strPath, LoadedCallback onLoaded)
    {
        if (string.IsNullOrEmpty(strPath))
        {
            Util.LogWarning("资源路径不能为空---");
            return;
        }

        string[] items = strPath.Split('/');
        string   name  = items[items.Length - 1];

        LoadAssetFromBundle(strPath, name, typeof(GameObject), onLoaded, true);
    }
예제 #12
0
 /// <summary>
 /// 主动加载时有加载完回调
 /// </summary>
 /// <param name="callback"></param>
 public void AddHandleCallBack(LoadedCallback callback)
 {
     if (callback != null)
     {
         if (m_onRefLoaded == null)
         {
             m_onRefLoaded = callback;
         }
         else
         {
             m_onRefLoaded += callback;
         }
     }
 }
예제 #13
0
 /**
  * If the db is loaded, call the callback immediately, otherwise, register the callback
  */
 public static void loadOrCallback(LoadedCallback loadCallback)
 {
     lock (isloadedCallback)
     {
         if (db != null)
         {
             loadCallback.Invoke(db);
         }
         else
         {
             isloadedCallback += loadCallback;
         }
     }
 }
예제 #14
0
    public override void Reset()
    {
        base.Reset();

        m_stateCurrent = 0;
        m_stageCount   = 1;

        m_parents.Clear();
        m_childs.Clear();
        allChildsPassed = false;
        m_onRefLoaded   = null;

        m_abRequest = null;

        if (m_wwwRequest != null)
        {
            m_wwwRequest.Dispose();
            m_wwwRequest = null;
        }
    }
예제 #15
0
    public void LoadAsset(string path, LoadedCallback onLoaded, System.Type type = null, bool async = true, AssetType assetType = AssetType.GameObject)
    {
        string ext      = SenLib.Helper.GetExtOfAsset(assetType);
        string fullPath = string.Format("Assets/{0}{1}{2}", AppConst.ResDataDir, path, ext);

        if (!FileHelper.CheckFileExist(fullPath))
        {
            SG.LogMgr.UnityError(string.Format("Load Asset, Path:[ {0} ] not exist!  ", fullPath));
            if (onLoaded != null)
            {
                onLoaded(null);
            }
            return;
        }

        AssetLoader aLoader = LoaderPool.Instance.GetLoader <AssetLoader> ();

        aLoader.Init(fullPath, type, onLoaded, async);
        StartLoad(aLoader, async);
    }
예제 #16
0
    public BundleLoader.BundleState LoadAssetBundle(string path, LoadedCallback onLoaded, bool async = true, BundleLoader parent = null)
    {
        string abName = FileHelper.CheckBundleName(path);

        if (!ManifestHasBundleInfo(abName))
        {
            if (onLoaded != null)
            {
                onLoaded(null);
            }
            return(BundleLoader.BundleState.NotExist);
        }

        LoadedBundle loadedCache = LoadedBundleCtrl.Instance.ReferenceLoadedBundle(abName);

        if (loadedCache != null)
        {
            if (onLoaded != null)
            {
                onLoaded(loadedCache);
            }
            return(BundleLoader.BundleState.Loaded);
        }

        BundleLoader loadingCache = BundleLoaderCtrl.Instance.GetBundleLoader(abName);

        if (loadingCache != null)
        {
            loadingCache.AddHandleCallBack(onLoaded);
            loadingCache.AddParent(parent);
            return(BundleLoader.BundleState.Loading);
        }

        string fullpath = FileHelper.SearchFilePath(GetManifestType(abName).ToString(), abName);           //包最终加载路径

        BundleLoader bLoader = LoaderPool.Instance.GetLoader <BundleLoader>();

        bLoader.Init(fullpath, abName, onLoaded, async, parent);

        return(BundleLoader.BundleState.JustLoad);
    }
예제 #17
0
    public void Init(LoadedCallback onInit)
    {
        if (AppConst.UseAssetBundle)
        {
            m_bundleNames.Clear();

            LoadManifest(ManifestType.Lua_Bundles);
            LoadManifest(ManifestType.UI_Bundles);
            LoadManifest(ManifestType.World_Bundles);

            Util.Log("LoadManifest manifest over---------");
        }

        FileHelper.AddBigBundleName("UI/Materials");
        LoadedBundleCtrl.Instance.SetPersistentBundles(new string[] { "shaders" });

        if (null != onInit)
        {
            onInit(null);
        }
    }
예제 #18
0
    public void Init(string path, string abName, LoadedCallback refCallback, bool async = true, BundleLoader parent = null, bool manifest = false)
    {
        base.Init(path, null, async);           //null不使用父类回调
        Util.Log(string.Format("Init BundleLoader path:{0}, name:{1}", path, abName));

        m_abName = abName;
        AddHandleCallBack(refCallback);
        AddParent(parent);

        BundleLoaderCtrl.Instance.AddBundleLoader(abName, this);

        if (manifest)
        {
            StartLoad();
        }
        else
        {
            string[] dependencies = LoadModule.Instance.GetDependencies(abName);
            for (int i = 0; i < dependencies.Length; ++i)
            {
                m_childs.Add(dependencies[i]);

                if (i == dependencies.Length - 1)
                {
                    allChildsPassed = true;
                }

                BundleState state = LoadModule.Instance.LoadAssetBundle(dependencies[i], null, async, this);
                if (state == BundleState.NotExist || state == BundleState.Loaded)
                {
                    m_childs.Remove(dependencies[i]);
                }
            }

            if (m_childs.Count == 0 && m_state != LoaderState.FINISHED) //无依赖直接加载自己
            {
                StartLoad();
            }
        }
    }
예제 #19
0
		private new void Initialize ()
		{
			// FIXME this should not be handled using Events.AddHandler, since those handlers are removable via the plugin

			// hook up the TemplateApplied callback so we
			// can notify controls when their template has
			// been instantiated as a visual tree.
			Events.AddHandler (this, EventIds.FrameworkElement_TemplateAppliedEvent, template_applied);

			if (OverridesLayoutMethod ("MeasureOverride"))
				measure_cb = new MeasureOverrideCallback (InvokeMeasureOverride);
			if (OverridesLayoutMethod ("ArrangeOverride"))
				arrange_cb = new ArrangeOverrideCallback (InvokeArrangeOverride);
			if (OverridesGetDefaultTemplate ())
				get_default_template_cb = InvokeGetDefaultTemplate;
			loaded_hook_cb = InvokeLoadedHook;
			NativeMethods.framework_element_register_managed_overrides (native, measure_cb, arrange_cb, get_default_template_cb, loaded_hook_cb);
		}
예제 #20
0
    /// <summary>
    /// 手动从Bundle中加载资源唯一入口
    /// </summary>
    /// <param name="path"></param>
    /// <param name="name"></param>
    /// <param name="type"></param>
    /// <param name="onLoaded"></param>
    /// <param name="async"></param>
    private void LoadAssetFromBundle(string path, string assetName, System.Type type, LoadedCallback onLoaded, bool async, AssetType assetType = AssetType.GameObject)
    {
        if (AppConst.UseAssetBundle)
        {
            Util.Log(string.Format("LoadAssetFromBundle, bundle:{0}, asset:{1}", path, assetName));

            LoadAssetBundle(path, (data) => {
                LoadedBundle abCache = data as LoadedBundle;
                object asset         = null;
                if (abCache != null)
                {
                    string abName = FileHelper.CheckBundleName(path);
                    var cache     = LoadedBundleCtrl.Instance.UnReferenceLoadedBundle(abName);
                    if (cache != null && 0 == cache.ReferencedCount)
                    {
                        cache.ReferencedCount = 1;

                        if (!m_handLoad.Contains(abName))
                        {
                            m_handLoad.Add(abName);
                        }
                    }

                    if (!string.IsNullOrEmpty(assetName))
                    {
                        asset = abCache.LoadAsset(assetName, type);
                        if (type != null && type == typeof(GameObject))
                        {
                            abCache.UnloadSelf();
                        }
                    }
                    else
                    {
                        asset = abCache.Bundle;
                    }
                }

                if (asset == null)
                {
                    Util.LogError(string.Format("LoadAssetFromBundle, path:{0},name:{1}, asset is null", path, assetName));
                }

                if (onLoaded != null)
                {
                    onLoaded(asset);
                }
            }, async);
        }
        else
        {
            LoadAsset(path, onLoaded, type, false, assetType);
        }
    }
예제 #21
0
        private static IEnumerator loadAssetBundleCoroutine(string path, int version, bool isFixed, LoadedCallback callback)
        {
            string         keyName = makeKey(path, version);
            AssetBundleRef abRef;

            if (_refs.TryGetValue(keyName, out abRef))
            {
                refreshRef(abRef);
                if (abRef.assetBundle != null)
                {
                    callback(abRef.assetBundle);
                    yield return(null);
                }
                else
                {   // in www loading ...
                    abRef.callbacks.Add(callback);
                }
            }
            else
            {
                abRef = new AssetBundleRef(null, path, version);
                abRef.callbacks.Add(callback);
                addRef(keyName, isFixed, abRef);

                using (WWW www = WWW.LoadFromCacheOrDownload(path, version))
                {
                    yield return(www);

                    if (www.error != null)
                    {
                        _refs.Remove(keyName);
                        throw new Exception("WWW download:" + www.error + "! [path]" + path);
                    }

                    abRef = null;
                    if (_refs.TryGetValue(keyName, out abRef))
                    {
                        abRef.assetBundle = www.assetBundle;
                        for (int i = 0, n = abRef.callbacks.Count; i < n; i++)
                        {
                            abRef.callbacks[i](abRef.assetBundle);
                        }
                        abRef.callbacks.Clear();
                    }
                    else
                    {
                        www.assetBundle.Unload(true);
                        throw new Exception("loadAssetBundleCoroutine: can not find keyName:" + keyName);
                    }
                }
            }
        }
예제 #22
0
 public static void loadAssetBundle(string path, int version, bool isFixed, LoadedCallback callback)
 {
     _behaviour.StartCoroutine(loadAssetBundleCoroutine(path, version, isFixed, callback));
 }
예제 #23
0
 public void Init(string path, System.Type type, LoadedCallback onLoaded, bool async = true)
 {
     base.Init(path, onLoaded, async);
     m_assetType = type;
 }