Esempio n. 1
0
        IEnumerable load(AssetDefinition asset)
        {
            AssetLoader.Loader loader = null;
            if (!AssetLoader.LoadAssets(l => { loader = l; }, asset))
            {
                Utils.Log("Asset load request invalid: {}", asset.path);
                yield break;
            }
            while (loader == null)
            {
                yield return(null);
            }
            if (loader.objects[0] == null)
            {
                Utils.Log("Failed loading asset: {}", asset.path);
                yield break;
            }
            var obj = loader.objects[0] as GameObject;

            if (obj == null)
            {
                Utils.Log("Loaded object is not a GO: {}", asset.path);
                yield break;
            }
            loaded_assets[asset.name] = obj;
        }
        void LoadAssets(AssetLoader.Loader loader)
        {
            for (int i = 0; i < loader.definitions.Length; i++)
            {
                UnityEngine.Object o = loader.objects[i];
                if (o == null)
                {
                    continue;
                }

                Type oType = o.GetType();

                // FARLogger.Info("Object " + i + " in bundle: " + o);
                if (oType == typeof(Material))
                {
                    FARLogger.Info("Adding material " + loader.definitions[i].name + " to dictionary");
                    materialDict.Add(loader.definitions[i].name, o as Material);
                }

                else if (oType == typeof(Shader))
                {
                    FARLogger.Info("Adding shader " + loader.definitions[i].name + " to dictionary");
                    shaderDict.Add(loader.definitions[i].name, o as Shader);
                }
            }
        }
Esempio n. 3
0
        void AssetLoaded(AssetLoader.Loader loader)
        {
            Debug.Log("BDArmory loaded shaders: ");
            for (int i = 0; i < loader.objects.Length; i++)
            {
                Shader s = (Shader)loader.objects[i];
                if (s == null)
                {
                    continue;
                }

                Debug.Log("- " + s.name);

                if (s.name == "BDArmory/Bullet")
                {
                    BulletShader = s;
                }
                else if (s.name == "BDArmory/Unlit Black")
                {
                    UnlitBlackShader = s;
                }
                else if (s.name == "BDArmory/Grayscale Effect")
                {
                    GrayscaleEffectShader = s;
                }
            }
        }
        void AssetLoaded(AssetLoader.Loader loader)
        {
            // You get a object that contains all the object that match your laoding request
            for (int i = 0; i < loader.definitions.Length; i++)
            {
                UnityEngine.Object o = loader.objects[i];
                if (o == null)
                {
                    continue;
                }

                if (o.GetType() == typeof(Canvas))
                {
                    kscCanvas = o as Canvas;
                }
            }
            assetBundleLoaded = true;
        }
Esempio n. 5
0
        void LoadAssets(AssetLoader.Loader loader)
        {
            for (int i = 0; i < loader.definitions.Length; i++)
            {
                UnityEngine.Object o = loader.objects[i];
                if (o == null)
                {
                    continue;
                }

                Type oType = o.GetType();

                if (oType == typeof(Shader))
                {
                    shaderDict.Add(loader.definitions[i].name, o as Shader);
                }
            }
        }
        public void Initialized(AssetLoader.Loader loader)
        // thanks moarDV - https://github.com/Mihara/RasterPropMonitor/blob/5c9fa8b259dd391892fe121724519413ccbb6b59/RasterPropMonitor/Core/UtilityFunctions.cs
        {
            var cache = new AssetBundleCache();

            Debug.Log("KVV: Cache is being initialized");

            var aShaderName = string.Empty;

            for (var i = 0; i < loader.objects.Length; ++i)
            {
                var o = loader.objects[i];
                if ((o != null) && o is Shader)
                {
                    // We'll remember the name of whichever shader we were
                    // able to load.
                    aShaderName = o.name;
                    break;
                }
            }

            if (string.IsNullOrEmpty(aShaderName))
            {
                Debug.Log(string.Format("KVV: Unable to find a shader named \"{0}\".", aShaderName));
                return;
            }

            var loadedBundles = AssetLoader.LoadedBundles;

            if (loadedBundles == null)
            {
                Debug.Log("KVV: Unable to find any loaded bundles in AssetLoader.");
                return;
            }

            // Iterate over all loadedBundles.  Experimentally, my bundle was
            // the only one in the array, but I expect that to change as other
            // mods use asset bundles (maybe none of the mods I have load this
            // early).
            for (var i = 0; i < loadedBundles.Count; ++i)
            {
                Shader[] shaders        = null;
                var      theRightBundle = false;

                try
                {
                    // Try to get a list of all the shaders in the bundle.
                    shaders = loadedBundles[i].LoadAllAssets <Shader>();
                    if (shaders != null && shaders.Any(t => t.name == aShaderName))
                    {
                        theRightBundle = true;
                    }
                }
                catch
                {
                    Debug.Log("KVV: Exception ended our shader search for bundle " + i);
                }

                if (theRightBundle)
                {
                    // If we found our bundle, set up our parsedShaders
                    // dictionary and bail - our mission is complete.
                    for (var j = 0; j < shaders.Length; ++j)
                    {
#if DEBUG
                        if (!shaders[j].isSupported)
                        {
                            Debug.Log(string.Format("KVV: Shader {0} - unsupported in this configuration",
                                                    shaders[j].name));
                        }
#endif

                        Debug.Log("KVV: Setting shader key " + shaders[j].name);
                        cache.Shaders[shaders[j].name] = shaders[j];
                    }

                    Debug.Log("KVV: Cached " + cache.Shaders.Count + " shaders...");
                }
            }

            _result = cache;
        }