示例#1
0
        public override void Init()
        {
            try
            {
                sc = SuperController.singleton;

                string pluginPath      = GetPluginPath();
                string defaultSavePath = pluginPath + "/groups";

                JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
                DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

                morphControl.GetMorphByDisplayName("Tongue In-Out").startValue      = 0;
                morphControl.GetMorphByDisplayName("Tongue Narrow-Wide").startValue = 0;
                morphControl.GetMorphByDisplayName("Tongue Roll 1").startValue      = 0;

                CreateButton("Zero All Morphs").button.onClick.AddListener(() =>
                {
                    ZeroMorphs(morphControl);
                });

                CreateButton("Save Morphs").button.onClick.AddListener(() =>
                {
                    sc.fileBrowserUI.defaultPath = defaultSavePath;
                    sc.fileBrowserUI.SetTextEntry(true);

                    sc.fileBrowserUI.Show((path) =>
                    {
                        //  cancel or invalid
                        if (string.IsNullOrEmpty(path))
                        {
                            return;
                        }

                        //  ensure extension
                        if (!path.EndsWith(".json"))
                        {
                            path += ".json";
                        }

                        sc.GetSaveJSON(containingAtom, true, true);

                        sc.SaveStringIntoFile(path, GetMorphJSON(morphControl).ToString(""));
                        SuperController.LogMessage("Wrote morph group file: " + path);
                    });
                });

                CreateButton("Apply Morphs").button.onClick.AddListener(() =>
                {
                    sc.fileBrowserUI.defaultPath = defaultSavePath;
                    sc.fileBrowserUI.SetTextEntry(false);
                    sc.fileBrowserUI.Show((path) =>
                    {
                        //  cancel or invalid
                        if (string.IsNullOrEmpty(path))
                        {
                            return;
                        }

                        //  ensure extension
                        if (!path.EndsWith(".json"))
                        {
                            path += ".json";
                        }

                        JSONClass node = JSON.Parse(sc.ReadFileIntoString(path)).AsObject;
                        SuperController.LogMessage("Read morph group file: " + path);
                        ApplyJSONMorphs(morphControl, node);
                    });
                });

                CreateButton("Load Morphs").button.onClick.AddListener(() =>
                {
                    sc.fileBrowserUI.defaultPath = defaultSavePath;
                    sc.fileBrowserUI.SetTextEntry(false);
                    sc.fileBrowserUI.Show((path) =>
                    {
                        //  cancel or invalid
                        if (string.IsNullOrEmpty(path))
                        {
                            return;
                        }

                        //  ensure extension
                        if (!path.EndsWith(".json"))
                        {
                            path += ".json";
                        }

                        JSONClass node = JSON.Parse(sc.ReadFileIntoString(path)).AsObject;

                        SuperController.LogMessage("Read morph group file: " + path);
                        ZeroMorphs(morphControl);
                        ApplyJSONMorphs(morphControl, node);
                    });
                });
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }