Example #1
0
 public void AddBundle(string bundleName, AssetBundle assetBundle, GameObject instantiatedObject)
 {
     if (!this.assetBundles.ContainsKey(bundleName))
     {
         AssetBundleContainer assetBundleContainer = new AssetBundleContainer();
         assetBundleContainer.ThisAssetBundle = assetBundle;
         assetBundleContainer.ObjectList.Add(instantiatedObject);
         assetBundleContainer.BundleName = bundleName;
         this.assetBundles.Add(bundleName, assetBundleContainer);
     }
     else
     {
         AssetBundleContainer assetBundleContainer2 = null;
         this.assetBundles.TryGetValue(bundleName, out assetBundleContainer2);
         if (assetBundleContainer2 != null)
         {
             assetBundleContainer2.ObjectList.Add(instantiatedObject);
         }
         else
         {
             Debug.LogError(string.Concat(new string[]
             {
                 "AssetBundleManager.cs: Couldn't get the container for assetbundle: ",
                 bundleName,
                 ". Removal Management for object:",
                 instantiatedObject.name,
                 " will not work"
             }));
         }
     }
 }
    IEnumerator CreateAllRessources(AssetBundle bundle)
    {
        AssetBundleContainer container = Instantiate(sampleContainer);

        container.name = "Container_" + mBundleName;

        AssetBundleRequest bundleRequest = bundle.LoadAllAssetsAsync();

        while (!bundleRequest.isDone)
        {
            //Progress
            float progress = bundleRequest.progress;
            yield return(0);
        }
        Object[] objects = bundleRequest.allAssets;
        container.textures = new List <Texture2D>();

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() == (typeof(Texture2D)))
            {
                container.textures.Add((Texture2D)objects[i]);
            }
        }

        yield break;
    }
Example #3
0
    /// <summary>
    /// Adds the bundle for removal management, if no gameobjects are using the assetbundle it will be
    /// removed automatically(if you use this method for all objects created from asset bundles)
    /// </summary>
    public void AddBundle(string bundleName, AssetBundle assetBundle, GameObject instantiatedObject)
    {
        //Check if the assetbundle already has a container in the dictionary
        if (!assetBundles.ContainsKey(bundleName))
        {
            //Create a new container and store the referenced game object
            AssetBundleContainer bundleContainer = new AssetBundleContainer();
            bundleContainer.ThisAssetBundle = assetBundle;
            bundleContainer.ObjectList.Add(instantiatedObject);
            bundleContainer.BundleName = bundleName;
            assetBundles.Add(bundleName, bundleContainer);
        }
        else
        {
            //if the key exists, get the container and add the referenced object to its list.
            AssetBundleContainer bundleContainer = null;
            assetBundles.TryGetValue(bundleName, out bundleContainer);

            if (bundleContainer != null)
            {
                bundleContainer.ObjectList.Add(instantiatedObject);
            }
            else
            {
                Debug.LogError("AssetBundleManager.cs: Couldn't get the container for assetbundle: " + bundleName + ". " +
                               "Removal Management for object:" + instantiatedObject.name + " will not work");
            }
        }
    }
Example #4
0
    public static void CreateItem()
    {
        TextAsset json = AssetBundleContainer.LoadAsset <TextAsset>("jsons", "Item_Table");

        if (json != null)
        {
            Log.Print("Item AssetBundle load Succes");
        }

        else
        {
            Log.PrintError("Error: Failed to load Item AssetBundle");
        }

        var itemDatas = JsonManager.LoadJson <Serialization <string, ItemData> >(json).ToDictionary();

        if (json != null)
        {
            Log.Print("Item Json data load Succes");
        }

        else
        {
            Log.PrintError("Error: Failed to load Item Json da");
        }

        foreach (var datas in itemDatas)
        {
            itemCtnr.Add(int.Parse(datas.Key), datas.Value);
        }
    }
    public static void LoadBundleData()
    {
        TextAsset json = AssetBundleContainer.LoadAsset <TextAsset>("jsons", "Item_Bundle_Table");

        if (json != null)
        {
            Log.Print("Drop table AssetBundle load Succes");
        }

        else
        {
            Log.PrintError("Error: Failed to load Drop table AssetBundle");
        }

        var bundleDatas = JsonManager.LoadJson <Serialization <string, DropBundleData> >(json).ToDictionary();

        if (json != null)
        {
            Log.Print("Drop table Json data load Succes");
        }

        else
        {
            Log.PrintError("Error: Failed to load Drop table Json data");
        }

        foreach (var datas in bundleDatas)
        {
            bundleCtnr.Add(int.Parse(datas.Key), datas.Value);
        }
    }
Example #6
0
    private void LoadToJsonData(int ID)
    {
        //테이블 ID는 1부터 시작
        //ID가 기본값이면 에러로그 출력
        AssetBundle localAssetBundle = AssetBundleContainer.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "jsons"));

        if (localAssetBundle == null)
        {
            Log.PrintError("Failed to load AssetBundle!");
        }

        if (ID == 0)
        {
            Log.PrintError("Failed to Player Data, ID is null or 0");
            return;
        }

        TextAsset json = localAssetBundle.LoadAsset <TextAsset>("Characters_Table");

        //Json 파싱
        var playerDatas = JsonManager.LoadJson <Serialization <string, PlayerData> >(json).ToDictionary();

        //ID 값으로 해당되는 Data 저장
        //ID는 각 몬스터 스크립트에서 할당
        playerData = playerDatas[ID.ToString()];
    }
Example #7
0
        private bool LoadToJsonData(int ID)
        {
            Log.Print("Monster: Load JsonData to Monster ID");
            //Json 파싱
            AssetBundle localAssetBundle = AssetBundleContainer.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "jsons"));

            if (localAssetBundle == null)
            {
                Log.PrintError("LoadToJosnData: Failed to load AssetBundle!");
                return(false);
            }
            TextAsset monsterTable = localAssetBundle.LoadAsset <TextAsset>("MonsterTable");

            var json = JsonManager.LoadJson <Serialization <string, MonsterDataTable> >(monsterTable).ToDictionary();

            //데이터에 몬스터에 해당하는 키가 없으면 return
            if (json.ContainsKey(ID.ToString()) == false)
            {
                Log.PrintError("Failed to Monster Data. ID is null or 0");
                return(false);
            }

            dataTable = json[ID.ToString()];
            return(true);
        }
Example #8
0
    public AssetBundleContainer GetAssetBundle(string bundleName)
    {
        AssetBundleContainer result = null;

        this.assetBundles.TryGetValue(bundleName, out result);
        return(result);
    }
Example #9
0
    private void Awake()
    {
        var text = AssetBundleContainer.LoadAsset <TextAsset>("jsons", "ShopKeepperTable");

        if (text == null)
        {
            AssetBundle result = AssetBundleContainer.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "jsons"));

            text = result.LoadAsset <TextAsset>("ShopKeepperTable");
        }

        //TODO: 본 게임에 들어갈때 삭제 할 코드
        //ItemContainer.CreateItem();

        Data = JsonManager.LoadJson <Serialization <string, ShopKeepperData> >(text).ToDictionary()[ID];

        _ShopCanvas = GetComponentInChildren <ShopCanvas>();

        nameText.text = Data.NPCName;

        List <int> copyItemID = new List <int>(Data.ItemID);

        _ShopCanvas.LinkingItems(copyItemID);

        _ShopCanvas.CloseCanvas();
    }
Example #10
0
    /// <summary>
    /// Gets the asset bundle for the specified key.
    /// </summary>
    /// <returns>
    /// The asset bundle.
    /// </returns>
    /// <param name='bundleName'>
    /// Bundle name key.
    /// </param>
    public AssetBundleContainer GetAssetBundle(string bundleName)
    {
        AssetBundleContainer thisBundle = null;

        assetBundles.TryGetValue(bundleName, out thisBundle);

        return(thisBundle);
    }
Example #11
0
    private void LoadMapDatas()
    {
        AssetBundle result = AssetBundleContainer.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "jsons"));

        if (result == null)
        {
            Log.PrintError("Failed to Load Jsons");
        }

        CurrentLoadCount++;
    }
Example #12
0
 public void LoadAssetBundle(AssetBundleContainer assetBundle, Action <string, AssetBundle> callback)
 {
     MainAPI.Instance.SendRequst(MainAPI.HTTPMethod.GET, assetBundle.manifest, "", (res, err) =>
     {
         AssetBundleManifestData manifestData = new AssetBundleManifestData
         {
             manifestText   = res,
             assetBundleUrl = assetBundle.asset
         };
         StartCoroutine(LoadActualAsset(manifestData, callback));
     });
 }
    public void DownloadAsset()
    {
        this.assetManager = AssetBundleManager.Instance;
        AssetBundleContainer assetBundle = this.assetManager.GetAssetBundle(this.bundleName);

        if (assetBundle == null)
        {
            base.StartCoroutine(this.DownloadAssetBundle(this.assetName, this.bundleName, this.version));
        }
        else
        {
            this.loadedAsset = assetBundle.ThisAssetBundle.LoadAsset(this.assetName, typeof(GameObject));
            this.isDone      = true;
        }
    }
Example #14
0
    private void Awake()
    {
        var text = AssetBundleContainer.LoadAsset <TextAsset>("jsons", "NPCTable");

        if (text == null)
        {
            AssetBundle result = AssetBundleContainer.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "jsons"));

            text = result.LoadAsset <TextAsset>("NPCTable");
        }
        var data = JsonManager.LoadJson <Serialization <string, NPCDataTable> >(text).ToDictionary();

        Texts    = data[ID].Text.Split('\n');
        nameText = data[ID].NpcName;

        conversationCanvas.Initialize();
    }
    /// <summary>
    /// Initiates the download of the asset bundle. Only works if properties have been set with QueueBundleDownload first.
    /// </summary>
    public void DownloadAsset()
    {
        assetManager = AssetBundleManager.Instance;
        //Check from in the assetBundleManager if this bundle is already downloaded.
        AssetBundleContainer thisBundle = assetManager.GetAssetBundle(bundleName);

        if (thisBundle == null)
        {
            //if not, download it
            StartCoroutine(DownloadAssetBundle(assetName, bundleName, version));
        }
        else
        {
            //if it is, just load the asset directly
            loadedAsset = thisBundle.ThisAssetBundle.Load(assetName, typeof(GameObject));
            isDone      = true;
        }
    }
Example #16
0
    public void DestroyAssetBundle(string bundleName)
    {
        AssetBundleContainer assetBundleContainer = null;

        this.assetBundles.TryGetValue(bundleName, out assetBundleContainer);
        if (assetBundleContainer != null)
        {
            foreach (GameObject current in assetBundleContainer.ObjectList)
            {
                if (current != null)
                {
                    UnityEngine.Object.Destroy(current);
                }
            }
            assetBundleContainer.ObjectList.Clear();
            assetBundleContainer.Unload();
            this.assetBundles.Remove(bundleName);
        }
    }
Example #17
0
    /// <summary>
    /// Destroys and unloads an asset bundle and all its referenced objects with
    /// the specified key.
    /// </summary>
    /// <param name='bundleName'>
    /// Bundle name.
    /// </param>
    public void DestroyAssetBundle(string bundleName)
    {
        AssetBundleContainer thisBundle = null;

        assetBundles.TryGetValue(bundleName, out thisBundle);
        if (thisBundle != null)
        {
            //Destroy all the game objects that are referencing to this bundle
            foreach (GameObject obj in thisBundle.ObjectList)
            {
                if (obj != null)
                {
                    Destroy(obj);
                }
            }
            thisBundle.ObjectList.Clear();
            thisBundle.Unload();
            assetBundles.Remove(bundleName);
        }
    }
Example #18
0
    // Use this for initialization
    IEnumerator Start()
    {
        AssetBundleContainer container = AssetBundleManager.Instance.LoadBundleAsync(this.BaseURL + AssetBundleManager.GetPlatformFolder(Application.platform) + "/" + this.AssetBundleName);

        while (!container.IsReady)
        {
            yield return(0);
        }
        if (container.IsError)
        {
            Debug.LogError(container.ErrorMsg);
            yield break;
        }
        foreach (var asset in container.FileList)
        {
            Debug.Log(asset.Name + " in " + container.name);
        }

#if UNITY_5
        var flag = container.AssetBundle.LoadAsset <GameObject>("Flag");
#else
        var flag = container.AssetBundle.Load("Flag", typeof(GameObject)) as GameObject;
#endif
        Debug.Log(flag);
        if (flag)
        {
#if UNITY_5
            // Because you can't use ClothRenderer on Unity5.
            var go = Instantiate(flag, base.transform.position, base.transform.rotation) as GameObject;
            Debug.Log(go);
            var basego = new GameObject("Base");
            basego.transform.position    = -new Vector3(0, 0, 5);
            basego.transform.localScale *= 0.2f;
            go.transform.SetParent(basego.transform, false);
#else
            var go = Instantiate(flag, base.transform.position, base.transform.rotation);
            Debug.Log(go);
#endif
        }
        //AssetBundleManager.Instance.UnloadBundle( container );
    }
    /// <summary>
    /// Adds the bundle for removal management, if no gameobjects are using the assetbundle it will be
    /// removed automatically(if you use this method for all objects created from asset bundles)
    /// </summary>
    public void AddBundle(string bundleName, AssetBundle assetBundle, GameObject instantiatedObject)
    {
        //Check if the assetbundle already has a container in the dictionary
        if (!assetBundles.ContainsKey(bundleName))
        {
            //Create a new container and store the referenced game object
            AssetBundleContainer bundleContainer = new AssetBundleContainer();
            bundleContainer.ThisAssetBundle = assetBundle;
            bundleContainer.ObjectList.Add(instantiatedObject);
            bundleContainer.BundleName = bundleName;
            assetBundles.Add(bundleName, bundleContainer);
        }
        else
        {
            //if the key exists, get the container and add the referenced object to its list.
            AssetBundleContainer bundleContainer = null;
            assetBundles.TryGetValue(bundleName, out bundleContainer);

            if (bundleContainer != null)
            {
                bundleContainer.ObjectList.Add(instantiatedObject);
            }
            else
            {
                Debug.LogError("AssetBundleManager.cs: Couldn't get the container for assetbundle: " + bundleName + ". " +
                    "Removal Management for object:" + instantiatedObject.name + " will not work");
            }
        }
    }