コード例 #1
0
ファイル: ModEntryPoint.cs プロジェクト: phobos2077/atomrpg
 // 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);
 }
コード例 #2
0
ファイル: AssetViewerDB.cs プロジェクト: sosonaka/modkit
    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();
    }
コード例 #3
0
ファイル: AssetViewerDB.cs プロジェクト: atomrpg/modkit
    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");
            }
        }
    }
コード例 #4
0
ファイル: ModEntryPoint.cs プロジェクト: sosonaka/modkit
    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);
    }
コード例 #5
0
ファイル: PlayInEditor.cs プロジェクト: atomrpg/modkit
    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);
            }
        }
    }
コード例 #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();
    }
コード例 #7
0
ファイル: PlayInEditor.cs プロジェクト: atomrpg/modkit
    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
        {
        }
    }