using SimpleJSON; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace VAM_Decal_Maker { class Decal_Maker : MVRScript { private JSONClass SaveData; private MVRScript core; private List floatShims = new List(); public override void Init() { SuperController.LogMessage("DecalMaker version 1 to version 2 save migration plugin loaded. If YOU chose this via the plugin menu and selected VAM_Decal_Maker.cs\nPlease select the load.cslist file instead. "); } public IEnumerator AddPlugins(Atom person, bool forceVar = false) { while (SuperController.singleton.isLoading) { yield return null; // yield return new WaitForSeconds(.5f); } yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame(); var dcs = person.GetComponentInChildren(); while ((object)dcs == null) { yield return new WaitForSeconds(.5f); dcs = person.GetComponentInChildren(); } while (!dcs.selectedCharacter.ready) { yield return new WaitForSeconds(.5f); } var pm = person.GetComponentInChildren(); //Debug.Log("WHILES FINISHED "); try { var script = pm.CreatePlugin(); script.pluginURLJSON.val = GetPackagePath(this) + "Custom/Scripts/Chokaphi/VAM_Decal_Maker/load.cslist"; string selfName = null; var MVRScripts = pm.GetComponentsInChildren(); foreach (MVRScript m in MVRScripts) { if (m.name.EndsWith("VAM_Decal_Maker_2.Core")) { //Pass save json to the new DecalMaker 2 script m.RestoreFromJSON(SaveData, true, true, null, true); core = m; } if (m.name.EndsWith("VAM_Decal_Maker.Decal_Maker")) { //store our name to remove this script later selfName = m.name; } } ////extract the plugin UID from the name of the script //string[] p = selfName?.Split('_'); //if (p?[0] != null) //{ //destroys this script // pm.RemovePluginWithUID(p[0]); //} Debug.Log("***************Plugin added, waiting for it to load"); CreateStorablesShims(core); } catch (Exception e) { SuperController.LogError("Error: " + e); } yield return null; } private void CreateStorablesShims(MVRScript core) { Debug.Log("Creating float storables"); List floatParams = core.GetFloatParamNames(); foreach (string item in floatParams) { Debug.Log(item); string[] c = item.Split('_'); CreateFloatLinks(c, item); } } //classic Alpha_face_DecalTex26418OGO // strength_26418OGO_face_DecalTex //[Info : Unity Log] texScale_26418OGO_face_DecalTex //[Info : Unity Log] texRot_26418OGO_face_DecalTex //[Info : Unity Log] texTransX_26418OGO_face_DecalTex //[Info : Unity Log] texTransY_26418OGO_face_DecalTex //[Info : Unity Log] texCnterX_26418OGO_face_DecalTex //[Info : Unity Log] texCnterY_26418OGO_face_DecalTex private void CreateFloatLinks(string[] strings, string coreFloatParam) { string param = strings[0]; string id = strings[1]; string region = strings[2]; string slot = strings[3]; JSONStorableFloat a = null; string shimName = string.Empty; switch (param) { case "strength": if (slot.StartsWith("Decal")) { shimName = string.Format("Alpha_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 1, (x) => core.SetFloatParamValue(coreFloatParam, x), -10, 10, false); } else { shimName = string.Format("Strength_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 1, (x) => core.SetFloatParamValue(coreFloatParam, x), -10, 10, false); } break; case "texScale": shimName = string.Format("texScale_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 1, (x) => core.SetFloatParamValue(coreFloatParam, x), -10, 10, false); break; case"texRot": shimName = string.Format("texRot_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 0, (x) => core.SetFloatParamValue(coreFloatParam, x), -360, 360, false); break; case "texTransX": shimName = string.Format("texTransX_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 0, (x) => core.SetFloatParamValue(coreFloatParam, x), -2, 2, false); break; case "texTransY": shimName = string.Format("texTransY_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 0, (x) => core.SetFloatParamValue(coreFloatParam, x), -2, 2, false); break; case "texCnterX": shimName = string.Format("texCnterX_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 0.5f, (x) => core.SetFloatParamValue(coreFloatParam, x), 0, 1, false); break; case "texCnterY": shimName = string.Format("texCnterY_{0}_{1}{2}", region, slot, id); a = new JSONStorableFloat(shimName, 0.5f, (x) => core.SetFloatParamValue(coreFloatParam, x), 0, 1, false); break; } if (a != null) { floatShims.Add(a); RegisterFloat(a); } } public override void RestoreFromJSON(JSONClass jc, bool restorePhysical = true, bool restoreAppearance = true, JSONArray presetAtoms = null, bool setMissingToDefault = true) { base.RestoreFromJSON(jc, restorePhysical, restoreAppearance, presetAtoms); SaveData = jc; StartCoroutine(AddPlugins(containingAtom)); } void Ondestroy() { foreach (var item in floatShims) { this.DeregisterFloat(item); } } public string GetPluginPath(MVRScript self) { string id = self.name.Substring(0, self.name.IndexOf('_')); string filename = self.manager.GetJSON()["plugins"][id].Value; return filename.Substring(0, filename.LastIndexOfAny(PathSeparatorChars)); } // Get path prefix of the package that contains our plugin. public string GetPackagePath(MVRScript self) { string filename = GetPluginPath(this); int idx = filename.IndexOf(":/"); if (idx >= 0) return filename.Substring(0, idx + 2); else return string.Empty; } private static char[] PathSeparatorChars = new char[] { '/', '\\' }; } }