예제 #1
0
        /// <summary>
        /// Load texture (*.dds, *.jpg, *.png, *.tga) from mod assets folder
        /// </summary>
        /// <example>
        /// You need to enter file name from your mod's asset folder.<code source="Examples.cs" region="LoadTexture" lang="C#"
        /// title="Example for change texture when we press key" /></example>
        /// <param name="mod">Mod instance.</param>
        /// <param name="fileName">File name to load from assets folder (for example "texture.dds")</param>
        /// <param name="normalMap">Normal mapping (default false)</param>
        /// <returns>Returns unity Texture2D</returns>
        public static Texture2D LoadTexture(Mod mod, string fileName, bool normalMap = false)
        {
            string fn = Path.Combine(ModLoader.GetModAssetsFolder(mod), fileName);

            if (!File.Exists(fn))
            {
                throw new FileNotFoundException(string.Format("<b>LoadTexture() Error:</b> File not found: {0}{1}", fn, Environment.NewLine), fn);
            }
            string ext = Path.GetExtension(fn).ToLower();

            if (ext == ".png" || ext == ".jpg")
            {
                Texture2D t2d = new Texture2D(1, 1);
                t2d.LoadImage(File.ReadAllBytes(fn));
                return(t2d);
            }
            else if (ext == ".dds")
            {
                Texture2D returnTex = LoadDDS(fn);
                return(returnTex);
            }
            else if (ext == ".tga")
            {
                Texture2D returnTex = LoadTGA(fn);
                return(returnTex);
            }
            else
            {
                throw new NotSupportedException(string.Format("<b>LoadTexture() Error:</b> Texture not supported: {0}{1}", fileName, Environment.NewLine));
            }
        }
예제 #2
0
        public static Mesh LoadOBJMesh(Mod mod, string fileName)
        {
            string fn = Path.Combine(ModLoader.GetModAssetsFolder(mod), fileName);

            if (!File.Exists(fn))
            {
                throw new FileNotFoundException(
                          string.Format("<b>LoadOBJ() Error:</b> File not found: {0}{1}", fn,
                                        Environment.NewLine),
                          fn);
            }
            string ext = Path.GetExtension(fn).ToLower();

            if (ext == ".obj")
            {
                OBJLoader obj  = new OBJLoader();
                Mesh      mesh = obj.ImportFile(
                    Path.Combine(ModLoader.GetModAssetsFolder(mod), fileName));
                mesh.name = Path.GetFileNameWithoutExtension(fn);
                return(mesh);
            }
            else
            {
                throw new NotSupportedException(string.Format(
                                                    "<b>LoadOBJ() Error:</b> Only (*.obj) files are supported{0}",
                                                    Environment.NewLine));
            }
        }
예제 #3
0
        public static AssetBundle LoadBundle(Mod mod, string bundleName)
        {
            string bundle = Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName);

            if (File.Exists(bundle))
            {
                try { ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName)); } catch { }
                return(AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(bundle)));
            }
            else
            {
                throw new FileNotFoundException(string.Format("<b>LoadBundle() Error:</b> File not found: <b>{0}</b>{1}", bundleName, Environment.NewLine), bundleName);
            }
        }
예제 #4
0
        /// <summary>
        /// Load texture (*.dds, *.jpg, *.png, *.tga) from mod assets folder
        /// </summary>
        /// <example>
        /// You need to enter file name from your mod's asset folder.<code source="Examples.cs" region="LoadTexture" lang="C#"
        /// title="Example for change texture when we press key" /></example>
        /// <param name="mod">Mod instance.</param>
        /// <param name="fileName">File name to load from assets folder (for example "texture.dds")</param>
        /// <param name="normalMap">Normal mapping (default false)</param>
        /// <returns>Returns unity Texture2D</returns>
        public static Texture2D LoadTexture(Mod mod, string fileName, bool normalMap = false)
        {
            string fn = Path.Combine(ModLoader.GetModAssetsFolder(mod), fileName);

            if (!File.Exists(fn))
            {
                ModConsole.Error(string.Format("<b>LoadTexture() Error:</b>{1}File not found: {0}", fn, Environment.NewLine));
                return(null);
            }
            string ext = Path.GetExtension(fn).ToLower();

            if (ext == ".png" || ext == ".jpg")
            {
                Texture2D t2d = new Texture2D(1, 1);
                t2d.LoadImage(File.ReadAllBytes(fn));
                if (normalMap)
                {
                    SetNormalMap(ref t2d);
                }
                return(t2d);
            }
            else if (ext == ".dds")
            {
                Texture2D returnTex = LoadDDSManual(fn);
                if (normalMap)
                {
                    SetNormalMap(ref returnTex);
                }
                return(returnTex);
            }
            else if (ext == ".tga")
            {
                Texture2D returnTex = LoadTGA(fn);
                if (normalMap)
                {
                    SetNormalMap(ref returnTex);
                }
                return(returnTex);
            }
            else
            {
                ModConsole.Error(string.Format("<b>LoadTexture() Error:</b>{1}Texture not supported: {0}", fileName, Environment.NewLine));
            }
            return(null);
        }
예제 #5
0
        /// <summary>
        /// A function for Loading AssetBundles Synchronously (without coroutines)
        /// </summary>
        /// <note>
        /// Not recomended for big files, may increase loading times.
        /// </note>
        /// <example> Example based on loading settings assets.
        /// <code source="Examples.cs" region="LoadBundle" lang="C#"/></example>
        /// <param name="mod">Mod instance.</param>
        /// <param name="bundleName">File name to load (for example "something.unity3d")</param>
        /// <returns>Returns unity AssetBundle</returns>
        public static AssetBundle LoadBundle(Mod mod, string bundleName)
        {
            string bundle = Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName);

            if (File.Exists(bundle))
            {
                try
                {
                    ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName));
                }
                catch (Exception)
                {
                    //nothing can be done if console is not loaded. Skip that error.
                }
                return(AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(bundle)));
            }
            else
            {
                ModConsole.Error(string.Format("<b>LoadBundle() Error:</b>{1}File not found: {0}", bundleName, Environment.NewLine));
                return(null);
            }
        }
예제 #6
0
        /// <summary>
        /// A Coroutine for Loading AssetBundles asynchronously (prefered to call from another Corountine)
        /// </summary>
        /// <example>
        /// You need to enter file name from your mod's asset folder.
        /// <note type="important">
        /// Only coroutine waits for other coroutine to finish. Starting this coroutine from function will always return null.
        /// </note>
        /// Example based on loading settings assets.
        /// <code source="Examples.cs" region="LoadBundleAsync" lang="C#"/></example>
        /// <param name="mod">Mod instance.</param>
        /// <param name="bundleName">File name to load (for example "something.unity3d")</param>
        /// <param name="ab">Returned AssetBundle</param>
        /// <returns>Returns AssetBundle to your coroutine</returns>
        public IEnumerator LoadBundleAsync(Mod mod, string bundleName, Action <AssetBundle> ab)
        {
            using (WWW www = new WWW("file:///" + Path.Combine(ModLoader.GetModAssetsFolder(mod), bundleName)))
            {
                while (www.progress < 1)
                {
                    ModConsole.Print(string.Format("Loading Asset: {0}...", bundleName));
                    yield return(new WaitForSeconds(.1f));
                }
                yield return(www);

                if (www.error != null)
                {
                    ModConsole.Error(www.error);
                    yield break;
                }
                else
                {
                    ab(www.assetBundle);
                    yield return(www.assetBundle);
                }
            }
        }
예제 #7
0
        public void modButton(string name, string version, string author, Mod mod)
        {
            GameObject modButton;

            if (!mod.LoadInMenu && Application.loadedLevelName == "MainMenu")
            {
                if (mod.isDisabled)
                {
                    modButton = Instantiate(ms.ModButton);
                    modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.red;
                    modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=red>Mod is disabled!</color>";
                }
                else
                {
                    modButton = Instantiate(ms.ModButton);
                    modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.yellow;
                    modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=yellow>Ready to load</color>";
                }
            }
            else
            {
                if (mod.isDisabled)
                {
                    modButton = Instantiate(ms.ModButton);
                    modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.red;
                    modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=red>Mod is disabled!</color>";
                }
                else
                {
                    if (mod.ID.StartsWith("MSCLoader_"))
                    {
                        if (coreModCheckbox.isOn)
                        {
                            modButton = Instantiate(ms.ModButton);
                            modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.cyan;
                            modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=cyan>Core Module!</color>";
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        modButton = Instantiate(ms.ModButton);
                        modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.green;
                    }
                }
            }
            if (mod.ID.StartsWith("MSCLoader_")) //No details is needed for core modules
            {
                modButton.transform.GetChild(1).GetChild(4).GetChild(0).GetComponent <Button>().interactable = false;
            }
            modButton.transform.GetChild(1).GetChild(4).GetChild(0).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModDetailsShow(mod));

            foreach (Settings set in Settings.modSettings)
            {
                if (set.Mod == mod)
                {
                    modButton.transform.GetChild(1).GetChild(4).GetChild(1).GetComponent <Button>().interactable = true;
                    modButton.transform.GetChild(1).GetChild(4).GetChild(1).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModSettingsShow(mod));
                    break;
                }
            }
            foreach (Keybind key in Keybind.Keybinds)
            {
                if (key.Mod == mod)
                {
                    modButton.transform.GetChild(1).GetChild(4).GetChild(2).GetComponent <Button>().interactable = true;
                    modButton.transform.GetChild(1).GetChild(4).GetChild(2).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModKeybindsShow(mod));
                    break;
                }
            }

            if (name.Length > 24)
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = string.Format("{0}...", name.Substring(0, 22));
            }
            else
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = name;
            }

            modButton.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = string.Format("by <color=orange>{0}</color>", author);
            modButton.transform.GetChild(1).GetChild(2).GetComponent <Text>().text = version;
            modButton.transform.SetParent(modView.transform, false);
            if (mod.metadata != null && mod.metadata.icon.iconFileName != null && mod.metadata.icon.iconFileName != string.Empty)
            {
                Texture2D t2d = new Texture2D(1, 1);
                if (mod.metadata.icon.isIconRemote)
                {
                    if (File.Exists(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName)))
                    {
                        try
                        {
                            t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName)));
                            modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = t2d;
                        }
                        catch (Exception e)
                        {
                            ModConsole.Error(e.Message);
                            Debug.Log(e);
                        }
                    }
                }
                else if (mod.metadata.icon.isIconUrl)
                {
                    try
                    {
                        WWW www = new WWW(mod.metadata.icon.iconFileName);
                        modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = www.texture;
                    }
                    catch (Exception e)
                    {
                        ModConsole.Error(e.Message);
                        Debug.Log(e);
                    }
                }
                else
                {
                    if (File.Exists(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName)))
                    {
                        try
                        {
                            t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName)));
                            modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = t2d;
                        }
                        catch (Exception e)
                        {
                            ModConsole.Error(e.Message);
                            Debug.Log(e);
                        }
                    }
                }
            }
            if (mod.hasUpdate)
            {
                modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=lime>UPDATE AVAILABLE!</color>";
            }
            if (mod.UseAssetsFolder)
            {
                modButton.transform.GetChild(2).GetChild(2).gameObject.SetActive(true); //Add assets icon
            }
            if (mod.isDisabled)
            {
                modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive(true); //Add plugin Disabled icon
                modButton.transform.GetChild(2).GetChild(1).GetComponent <Image>().color = Color.red;
            }
            else
            {
                modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive(true); //Add plugin OK icon
            }
            if (mod.LoadInMenu)
            {
                modButton.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);//Add Menu Icon
            }
        }