Exemplo n.º 1
0
 // Start is called before the first frame update
 void Start()
 {
     Debug.Log("Mod Init");
     ResourceManager.AddBundle(AssetBundle.LoadFromFile(Application.persistentDataPath + "/Mods/MyMod/resources"));
     GlobalEvents.AddListener <GlobalEvents.GameStart>(GameLoaded);
     GlobalEvents.AddListener <GlobalEvents.LevelLoaded>(LevelLoaded);
 }
Exemplo n.º 2
0
    public static void Load()
    {
        loadedAssets.Clear();
        assetCategories.Clear();
        AssetBundle.UnloadAllAssetBundles(true);

        ResourceManager.Reset();
        ResourceManager.SetAssetGetPathCallback(GetBundleAssetPath);

        var categoriesSet = new HashSet <string>();

        foreach (string f in Directory.GetFiles(Application.streamingAssetsPath))
        {
            try
            {
                if (!Path.HasExtension(f))
                {
                    AssetBundle bundle = AssetBundle.LoadFromFile(f);
                    ResourceManager.AddBundle("", bundle);

                    string[] allAssetNames = bundle.GetAllAssetNames();
                    int      progress      = 0;
                    foreach (var asset in allAssetNames)
                    {
                        Object obj = bundle.LoadAsset(asset);
                        if (obj is ScriptableObject || obj is TextAsset)
                        {
                            var category = GetCategoryFromAssetName(asset);
                            loadedAssets.Add(new LoadedAsset
                            {
                                Asset         = obj,
                                AssetName     = asset,
                                AssetCategory = category,
                            });
                            categoriesSet.Add(category);
                        }

                        if (EditorUtility.DisplayCancelableProgressBar("Asset bundle", "Load Asset", (float)progress / allAssetNames.Length))
                        {
                            break;
                        }

                        ++progress;
                    }
                }
            }
            catch
            {
                Debug.Log("Bundle skip");
            }
        }

        assetCategories.AddRange(categoriesSet.OrderBy(x => x));
        EditorUtility.ClearProgressBar();

        IsLoaded = true;
        OnUpdated?.Invoke();
    }
Exemplo n.º 3
0
    private static void LoadBundles(string path, HashSet <string> categoriesSet)
    {
        if (path.Length == 0 || !Directory.Exists(path))
        {
            return;
        }

        foreach (string f in Directory.GetFiles(path))
        {
            try
            {
                if (!Path.HasExtension(f) || Path.GetExtension(f) == ".bundle")
                {
                    AssetBundle bundle = AssetBundle.LoadFromFile(f);
                    ResourceManager.AddBundle(bundle.name, bundle);

                    string[] allAssetNames = bundle.GetAllAssetNames();
                    int      progress      = 0;
                    foreach (var asset in allAssetNames)
                    {
                        if (asset.IndexOf(".asset") >= 0 || asset.IndexOf(".json") >= 0)
                        {
                            Object obj = bundle.LoadAsset(asset);
                            if (obj is ScriptableObject || obj is TextAsset)
                            {
                                var category = GetCategoryFromAssetName(asset);

                                if (asset.Contains("/levels")) // union one category
                                {
                                    category = "levels";
                                }

                                loadedAssets.Add(new LoadedAsset
                                {
                                    Asset         = obj,
                                    AssetName     = asset,
                                    AssetCategory = category,
                                });
                                categoriesSet.Add(category);
                            }
                        }

                        if (EditorUtility.DisplayCancelableProgressBar("Asset bundle", "Load Asset", (float)progress / allAssetNames.Length))
                        {
                            break;
                        }

                        ++progress;
                    }
                }
            }
            catch
            {
                Debug.Log("Bundle skip");
            }
        }
    }
Exemplo n.º 4
0
    void Start()
    {
        var    assembly = GetType().Assembly;
        string modName  = assembly.GetName().Name;
        string dir      = System.IO.Path.GetDirectoryName(assembly.Location);

        Debug.Log("Mod Init: " + modName + "(" + dir + ")");
        ResourceManager.AddBundle(modName, AssetBundle.LoadFromFile(dir + "/" + modName + "_resources"));
        GlobalEvents.AddListener <GlobalEvents.GameStart>(GameLoaded);
        GlobalEvents.AddListener <GlobalEvents.LevelLoaded>(LevelLoaded);
    }
Exemplo n.º 5
0
    private static void LoadBundles(string path)
    {
        if (path.Length == 0 || !Directory.Exists(path))
        {
            return;
        }

        foreach (string f in Directory.GetFiles(path))
        {
            if (!Path.HasExtension(f) || Path.GetExtension(f) == ".bundle")
            {
                AssetBundle bundle = AssetBundle.LoadFromFile(f);
                ResourceManager.AddBundle(bundle.name, bundle);
            }
        }
    }
Exemplo n.º 6
0
    public static void Load()
    {
        loadedAssets.Clear();
        AssetBundle.UnloadAllAssetBundles(true);

        ResourceManager.Reset();

        foreach (string f in Directory.GetFiles(Application.streamingAssetsPath))
        {
            try
            {
                if (!Path.HasExtension(f))
                {
                    AssetBundle bundle = AssetBundle.LoadFromFile(f);
                    ResourceManager.AddBundle(bundle);

                    string[] allAssetNames = bundle.GetAllAssetNames();
                    int      progress      = 0;
                    foreach (var asset in allAssetNames)
                    {
                        Object obj = bundle.LoadAsset(asset);
                        if (obj is ScriptableObject || obj is TextAsset)
                        {
                            loadedAssets.Add(obj, asset);
                        }

                        if (EditorUtility.DisplayCancelableProgressBar("Asset bundle", "Load Asset", (float)progress / allAssetNames.Length))
                        {
                            break;
                        }

                        ++progress;
                    }
                }
            }
            catch
            {
                Debug.Log("Bundle skip");
            }
        }
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 7
0
    void Awake()
    {
        if (EditorApplication.isPlaying)
        {
            Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;


            AssetBundle.UnloadAllAssetBundles(true);

            ResourceManager.Reset();
            ResourceManager.SetAssetGetPathCallback(null);


            AssetBundle gameBundle = null;

            ResourceManager.AddBundle("resources", new ResourcesBundle());

            LoadBundles(Application.streamingAssetsPath);

            var gdir = PlayerPrefs.GetString("GAME_CONTENT_DIR", "");
            LoadBundles(gdir);

            foreach (var f in AssetBundle.GetAllLoadedAssetBundles())
            {
                if (f != null)
                {
                    //ResourceManager.AddBundle(f.name, f);

                    if (f.name.IndexOf("editor") >= 0) //TODO
                    {
                        gameBundle = f;
                    }
                }
            }

            GameObject game = gameBundle.LoadAsset <GameObject>("Game");
            Instantiate(game);

            GameStorage.SetInt("PostImageEffects", 0);

            HBAOPlus.useHBOAPlus = false;

            if (spawnScene.Length > 0)
            {
                SpawnScene();
            }

            //fallback replace detect
            foreach (var obj in UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects())
            {
                foreach (EntityComponent r in obj.GetComponentsInChildren <EntityComponent>())
                {
                    if (!IsValidEntityObject(r.gameObject))
                    {
                        if (r.Entity == null)
                        {
                            Debug.LogError("PIE Error [Entity is null]" + r.name);
                            continue;
                        }
                        else if (r.Entity.Prototype == null)
                        {
                            Debug.LogError("PIE Error [Prototype is null]" + r.name);
                            continue;
                        }
                        else if (r.Entity.Prototype.Prefab == null)
                        {
                            Debug.LogError("PIE Error [Prefab is null]" + r.name);
                            continue;
                        }

                        var prefab = r.Entity.Prototype.Prefab;

                        var copy = Instantiate <GameObject>(r.Entity.Prototype.Prefab, r.gameObject.transform.position, r.gameObject.transform.rotation);
                        copy.transform.localScale = r.transform.lossyScale;
                        copy.name = r.name;

                        copy.GetComponent <EntityComponent>().SetEntity(r.Entity);
                        r.gameObject.SetActive(false);
                        r.gameObject.name += "_temp";
                    }
                }
            }

            if (_sunTestLight != null)
            {
                _sunTestLight.gameObject.SetActive(false);
            }
        }
        else
        {
        }
    }