Beispiel #1
0
    public void LoadBundleAsync(string assetName, Action <UnityEngine.Object, LoadEventData> loadComplete, LoadEventData evData)
    {
        // 先检查包是否存在
        if (!File.Exists(PackagePath))
        {
            RGLog.Error("<color=red>LoadBundleAsync</color> PackagePath not exits!!! -> <color=yellow>{0}</color>", PackagePath);

            if (loadComplete != null)
            {
                loadComplete(null, evData);
            }

            return;
        }

        if (IsLoading)
        {
            AddCache(assetName, loadComplete, evData);

            RGLog.Debug("<color=green>Bundle Loading ! Add Cache {0} -> {1}</color>", _packageName, assetName);
        }
        else
        {
            AddCallback(assetName, loadComplete, evData);

            CoroutineManager.Instance.StartCoroutine(IELoadBundleAsync(assetName, loadComplete, evData));
        }
    }
Beispiel #2
0
 // 永久 bundle
 public static void LoadForeverBundleAsync(string path, Action <AssetBundle, LoadEventData> loadComplete, params object[] data)
 {
     if (string.IsNullOrEmpty(path))
     {
         RGLog.Error("<color=red> 加载 永久 Bundle 资源路径为空!!!</color>");
         if (loadComplete != null)
         {
             loadComplete.Invoke(null, ParseFrom(data));
         }
         return;
     }
     if (data != null)
     {
         object[] tempData = new object[data.Length + 1];
         tempData.SetValue(LOAD_BUNDLE_FOREVER_FLAG, 0);
         for (int i = 0; i < data.Length; i++)
         {
             tempData.SetValue(data[i], i + 1);
         }
         LoadAsync <AssetBundle>(path, "", loadComplete, ParseFrom(tempData));
     }
     else
     {
         object[] tempData = new object[1];
         tempData.SetValue(LOAD_BUNDLE_FOREVER_FLAG, 0);
         LoadAsync <AssetBundle>(path, "", loadComplete, ParseFrom(tempData));
     }
 }
Beispiel #3
0
    // 同步方式加载bundle
    private AssetBundle LoadBundle(string assetName)
    {
        // 先检查包是否存在
        if (!File.Exists(PackagePath))
        {
            RGLog.Error("<color=red>LoadBundle</color> PackagePath not exits!!!-><color=yellow>{0}</color>", PackagePath);

            return(null);
        }
        byte[]      stream = null;
        AssetBundle bundle = null;

        stream = File.ReadAllBytes(PackagePath);
        if (stream != null)
        {
            bundle = AssetBundle.LoadFromMemory(stream);
        }
        else
        {
            RGLog.Error("Load Bundle From File Error :" + PackagePath);
        }

        _bundle = bundle;

        IsLoading = false;

        return(bundle);
    }
Beispiel #4
0
 // Scene
 public static void LoadSceneAsync(string path, Action <AssetBundle, LoadEventData> loadComplete, params object[] data)
 {
     if (string.IsNullOrEmpty(path))
     {
         RGLog.Error("<color=red>加载 Scene 资源路径为空!!!</color>");
         if (loadComplete != null)
         {
             loadComplete.Invoke(null, ParseFrom(data));
         }
         return;
     }
     LoadAsync <AssetBundle>(path, "unity", loadComplete, ParseFrom(data));
 }
Beispiel #5
0
 // Texture2D
 public static void LoadTexture2DAsync(string path, Action <Texture2D, LoadEventData> loadComplete, params object[] data)
 {
     if (string.IsNullOrEmpty(path))
     {
         RGLog.Error("<color=red> 加载 Texture2D Bundle 资源路径为空!!!</color>");
         if (loadComplete != null)
         {
             loadComplete.Invoke(null, ParseFrom(data));
         }
         return;
     }
     LoadAsync <Texture2D>(path, "png", loadComplete, ParseFrom(data));
 }
Beispiel #6
0
 public static void LoadSoundEffectAsync(string path, Action <AudioClip, LoadEventData> loadComplete, params object[] data)
 {
     if (string.IsNullOrEmpty(path))
     {
         RGLog.Error("<color=red> 加载 Sound Bundle 资源路径为空!!!</color>");
         if (loadComplete != null)
         {
             loadComplete.Invoke(null, ParseFrom(data));
         }
         return;
     }
     LoadAsync <AudioClip>(path, "ogg", loadComplete, ParseFrom(data));
 }
Beispiel #7
0
 //Gameobject
 public static void LoadGameObjectAsync(string path, Action <GameObject, LoadEventData> loadComplete, params object[] data)
 {
     if (string.IsNullOrEmpty(path))
     {
         RGLog.Error("<color=red> 加载 GameObject Bundle 资源路径为空!!!</color>");
         if (loadComplete != null)
         {
             loadComplete.Invoke(GameObject.CreatePrimitive(PrimitiveType.Cube), ParseFrom(data));
         }
         return;
     }
     LoadAsync <GameObject>(path, "prefab", loadComplete, ParseFrom(data));
 }
Beispiel #8
0
    public static void LoadUIAsync(string path, Action <AssetBundle, LoadEventData> loadComplete, params object[] data)
    {
        if (string.IsNullOrEmpty(path))
        {
            RGLog.Error("资源为空 ---------->" + path);
            if (loadComplete != null)
            {
                loadComplete.Invoke(null, ParseFrom(data));
            }

            return;
        }
        LoadAsync <AssetBundle>(path, "", loadComplete, ParseFrom(data));
    }
        // 从 cnd 上获取 配置信息
        IEnumerator GetConfig(string tandbyAddress = "")
        {
            string configUrl = "";

            if (VersionInfo.BType == VersionInfo.BUILD_TYPE.DEVELOP ||
                VersionInfo.BType == VersionInfo.BUILD_TYPE.DEVELOP_SPECITFY_SERVER ||
                VersionInfo.BType == VersionInfo.BUILD_TYPE.DEVELOP_SELECT_SERVER)
            {
                configUrl = "http://192.168.1.253./platform/devConfig.json";
            }
            else if (VersionInfo.BType == VersionInfo.BUILD_TYPE.LIVE || VersionInfo.BType == VersionInfo.BUILD_TYPE.LIVE_LOG)
            {
                if (string.IsNullOrEmpty(tandbyAddress))
                {
                    configUrl = "http://www.baidu.com";
                }
                else
                {
                    configUrl = tandbyAddress;
                }
            }

            Debug.Log("Config Url" + configUrl);

            WWW www = new WWW(configUrl);

            yield return(www);

            if (www.error != null)
            {
                RGLog.Warn("[GameManager] > GetConfig 02");
                RGLog.Error(www.error);

                // 错误提示弹窗
                hotUI.ShowPopup("错误", "提示", () =>
                {
                    Timers.inst.StartCoroutine(GetConfig("http://www.baidu.com/备用"));
                },
                                () =>
                {
                    Application.Quit();
                }, "Retry", "Quit");
            }
            else
            {
                if (www.isDone)
                {
                    ConfigJson config = JsonUtility.FromJson <ConfigJson>(www.text);

                    AppConst.WebUrl = config.UpdateUrl;

                    if (VersionInfo.BType == VersionInfo.BUILD_TYPE.LIVE_LOG)
                    {
                        //资源更新地址
                        AppConst.WebUrl = "http://192.168.1.253/platform/";
                        //备用资源更新地址
                        AppConst.UpdateUrl2 = "http://192.168.1.253/platform";
                    }

                    //校验版本
                    Timers.inst.StartCoroutine(CheckVersionInfo());
                }
            }
        }