Beispiel #1
0
        protected void UpdateRandomParams()
        {
            JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
            DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
            GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

            // define the random values to switch to
            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                if (toggles.ContainsKey(name) == false)
                {
                    return;
                }

                if (toggles[name].toggle.isOn)
                {
                    if (morph.animatable == false)
                    {
                        float valeur         = UnityEngine.Random.Range(minSlider.val, maxSlider.val) * multiSlider.val;
                        newMorphValues[name] = valeur;
                    }
                }
            });
        }
Beispiel #2
0
        private void UpdateCurrentMorphs()
        {
            GenerateDAZMorphsControlUI morphControl = returnMorphs();

            morphControl.GetMorphDisplayNames().ForEach((name) => {
                CurrentMorphsValues[name] = morphControl.GetMorphByDisplayName(name).morphValue;
            });
        }
        public List <string> GetMorphNamesByGroup(string group)
        {
            List <string> names = new List <string>();


            GenerateDAZMorphsControlUI morphControl = GetMorphControl();
            List <string> morphNames = morphControl.GetMorphDisplayNames();

            return(names);
        }
Beispiel #4
0
        private void UpdateInitialMorphs()
        {
            JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
            DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
            GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                initialMorphValues[name] = morphControl.GetMorphByDisplayName(name).morphValue;
            });
        }
Beispiel #5
0
        private void UpdateNewMorphs()
        {
            GenerateDAZMorphsControlUI morphControl = returnMorphs();

            morphControl.GetMorphDisplayNames().ForEach((name) => {
                if (toggles.ContainsKey(name))
                {
                    newMorphValues[name] = morphControl.GetMorphByDisplayName(name).morphValue;
                }
            });
        }
Beispiel #6
0
 void ZeroMorphs(GenerateDAZMorphsControlUI morphControl)
 {
     morphControl.GetMorphDisplayNames().ForEach((name) =>
     {
         DAZMorph morph = morphControl.GetMorphByDisplayName(name);
         if (morph.isPoseControl)
         {
             morph.SetValue(morph.startValue);
             morph.SyncJSON();
         }
     });
 }
Beispiel #7
0
 void ClearExpressionMorphs()
 {
     morphControl.GetMorphDisplayNames().ForEach((name) =>
     {
         DAZMorph morph = morphControl.GetMorphByDisplayName(name);
         if (morph.isPoseControl || morph.region.Contains("Expressions"))
         {
             morph.SetValue(morph.startValue);
             morph.SyncJSON();
         }
     });
 }
Beispiel #8
0
        private void ResetMorphs()
        {
            GenerateDAZMorphsControlUI morphControl = returnMorphs();

            morphControl.GetMorphDisplayNames().ForEach((name) => {
                if (toggleRelations.ContainsKey(name))
                {
                    if (toggles.ContainsKey(name))
                    {
                        DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                        morph.morphValue = initialMorphValues[name];
                    }
                }
            });
        }
Beispiel #9
0
        private void ResetMorphs()
        {
            JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
            DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
            GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                if (toggleRelations.ContainsKey(name))
                {
                    DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                    morph.morphValue = initialMorphValues[name];
                }
            });
        }
Beispiel #10
0
        private void ZeroMorphs()
        {
            GenerateDAZMorphsControlUI morphControl = returnMorphs();

            morphControl.GetMorphDisplayNames().ForEach((name) => {
                if (toggleRelations.ContainsKey(name))
                {
                    if (toggles.ContainsKey(name) && toggles[name].toggle.isOn)
                    {
                        DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                        morph.morphValue = 0;
                    }
                }
            });
        }
Beispiel #11
0
        private void ZeroSelectedMorphs(GenerateDAZMorphsControlUI morphControl)
        {
            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                if (toggles.ContainsKey(morph.region) == false)
                {
                    return;
                }

                if (toggles[morph.region].toggle.isOn)
                {
                    morph.morphValue = 0.0f;
                }
            });
        }
Beispiel #12
0
        private void ResetMorphs()
        {
            JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
            DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
            GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                if (initialMorphValues.ContainsKey(name) == false)
                {
                    Debug.Log("morph was not initially found: " + name + ", not resetting this morph");
                    return;
                }
                morph.morphValue = initialMorphValues[name];
            });
        }
Beispiel #13
0
        JSONClass GetMorphJSON(GenerateDAZMorphsControlUI morphControl)
        {
            JSONClass node = new JSONClass();

            node["morphs"] = new JSONArray();

            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                if (morph.morphValue != morph.startValue && morph.isPoseControl)
                {
                    JSONClass morphNode = new JSONClass();
                    morphNode["name"]   = morph.displayName;
                    morphNode["value"]  = morph.morphValue.ToString();
                    node["morphs"].Add(morphNode);
                }
            });

            return(node);
        }
        private void saveLoadMorphs(bool saveM)
        {
            int                        C            = 0;
            JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
            DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
            GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                if (saveM == true)
                {
                    morphDict[name] = morphControl.GetMorphByDisplayName(name).morphValue;
                }
                else
                {
                    morphControl.GetMorphByDisplayName(name).morphValue = morphDict[name];
                }
                C++;
            });
            SuperController.LogMessage("Morph total : " + C.ToString());
        }
Beispiel #15
0
        protected void FixedUpdate()
        {
            if (toggles["Play"].toggle.isOn)
            {
                JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
                DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

                // morph progressively every morphs to their new values
                morphControl.GetMorphDisplayNames().ForEach((name) =>
                {
                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                    if (toggles.ContainsKey(name) && toggles[name].toggle.isOn)
                    {
                        if (morph.animatable == false)
                        {
                            float valeur     = Mathf.Lerp(CurrentMorphsValues[name], newMorphValues[name], Time.deltaTime * animLengthSlider.val);
                            morph.morphValue = valeur;
                        }
                    }
                });
                UpdateCurrentMorphs();
            }
        }
Beispiel #16
0
        public override void Init()
        {
            try {
                //  The atom in the scene we're going to copy morphs from
                Atom sceneAtom = null;

                //  The JSON we're copying morphs from, if we are copying from a file
                JSONClass filePersonJSON = null;

                //  In a save file, mapped set of all people to their IDs
                Dictionary <string, JSONClass> idToPersonFromFile = null;


                UpdateInitialMorphs();

                #region Select from Scene or File
                UIDynamicButton selectFileButton = null;

                UIDynamicTextField selectedFileTextField = null;

                JSONStorableStringChooser personChoice = null;

                selectionStyle = new JSONStorableStringChooser("selectionStyle", new List <string>()
                {
                    "Scene", "File"
                }, "Scene", "Select Via", (string choice) =>
                {
                    if (choice == "File")
                    {
                        selectFileButton             = CreateButton("Choose from File");
                        selectFileButton.textColor   = Color.black;
                        selectFileButton.buttonColor = new Color(0.5f, 0.96f, 0.5f);
                        selectFileButton.button.onClick.AddListener(() =>
                        {
                            SuperController.singleton.GetScenePathDialog((filePath) =>
                            {
                                if (String.IsNullOrEmpty(filePath))
                                {
                                    return;
                                }

                                if (filePath.ToLower().Contains(".vac"))
                                {
                                    SuperController.LogError("loading VAC files not supported");
                                    return;
                                }

                                List <JSONClass> people = LoadPeopleFromFile(filePath);

                                if (people.Count <= 0)
                                {
                                    return;
                                }

                                idToPersonFromFile = new Dictionary <string, JSONClass>();
                                people.ForEach((person) =>
                                {
                                    string id = person["id"];
                                    idToPersonFromFile[id] = person;
                                });

                                filePersonJSON = idToPersonFromFile.Values.ToArray()[0];

                                List <string> names = people.Select((person) => {
                                    string id = person["id"];
                                    return(id);
                                }).ToList();

                                if (personChoice != null)
                                {
                                    personChoice.choices        = names;
                                    personChoice.displayChoices = names;

                                    if (names.Count > 0)
                                    {
                                        personChoice.SetVal(names[0]);
                                    }
                                }

                                if (selectedFileTextField != null)
                                {
                                    Destroy(selectedFileTextField.gameObject);
                                }
                                selectedFileTextField = CreateTextField(new JSONStorableString("file path", filePath));
                            });
                        });
                    }
                    else
                    {
                        if (selectFileButton != null)
                        {
                            RemoveButton(selectFileButton);
                        }

                        if (selectedFileTextField != null)
                        {
                            Destroy(selectedFileTextField.gameObject);
                        }
                    }
                });

                CreateScrollablePopup(selectionStyle);
                #endregion

                #region Choose Atom
                personChoice = new JSONStorableStringChooser("copyFrom", GetPeopleNamesFromScene(), null, "Copy From", delegate(string otherName)
                {
                    if (SelectingFromScene())
                    {
                        sceneAtom = GetAtomById(otherName);
                    }
                    else
                    {
                        if (idToPersonFromFile == null)
                        {
                            return;
                        }

                        if (idToPersonFromFile.ContainsKey(otherName) == false)
                        {
                            return;
                        }

                        filePersonJSON = idToPersonFromFile[otherName];
                        //Debug.Log(filePersonJSON);
                    }
                });
                personChoice.storeType = JSONStorableParam.StoreType.Full;
                UIDynamicPopup scenePersonChooser = CreateScrollablePopup(personChoice, false);
                scenePersonChooser.popupPanelHeight = 250f;
                RegisterStringChooser(personChoice);

                scenePersonChooser.popup.onOpenPopupHandlers += () =>
                {
                    // refresh from scene if we are looking for people in the current scene
                    if (SelectingFromScene())
                    {
                        personChoice.choices = GetPeopleNamesFromScene();
                    }
                };
                #endregion

                #region Region Group Buttons
                UIDynamicButton selectAll = CreateButton("Select All", true);
                selectAll.button.onClick.AddListener(delegate(){
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = true;
                    });
                });
                selectAll.buttonColor = Color.white;

                UIDynamicButton selectNone = CreateButton("Select None", true);
                selectNone.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = false;
                    });
                });
                selectNone.buttonColor = Color.white;

                UIDynamicButton selectHead = CreateButton("Select Head", true);
                selectHead.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        entry.Value.toggle.isOn = headRegion.Any((str) => entry.Key.Contains(str));
                    }
                });
                selectHead.buttonColor = Color.white;

                UIDynamicButton selectBody = CreateButton("Select Body", true);
                selectBody.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        entry.Value.toggle.isOn = bodyRegion.Any((str) => entry.Key.Contains(str));
                    }
                });
                selectBody.buttonColor = Color.white;

                UIDynamicButton selectPose = CreateButton("Select Pose Controls", true);
                selectPose.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        entry.Value.toggle.isOn = entry.Key.Contains("Pose Controls");
                    }
                });
                selectPose.buttonColor = Color.white;

                UIDynamicButton selectOfficial = CreateButton("Select Official Controls", true);
                selectOfficial.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        entry.Value.toggle.isOn = officialRegion.Any((str) => entry.Key == str);
                    }
                });
                selectOfficial.buttonColor = Color.white;

                UIDynamicButton selectInvert = CreateButton("Invert Selection", true);
                selectInvert.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        entry.Value.toggle.isOn = !entry.Value.toggle.isOn;
                    }
                });
                selectInvert.buttonColor = Color.white;

                CreateSpacer(true);

                //JSONStorableString stringFilter = new JSONStorableString("filter", "", (string value)=>
                //{
                //    if (string.IsNullOrEmpty(value))
                //    {
                //        return;
                //    }

                //    foreach (KeyValuePair<string, UIDynamicToggle> entry in toggles)
                //    {
                //        entry.Value.toggle.isOn = entry.Key.Contains(value);
                //    }
                //});

                //stringFilter.inputField.enabled = true;

                //UIDynamicTextField filterField = CreateTextField(stringFilter);
                //filterField.enabled = true;
                //filterField.UItext.enabled = true;


                #endregion

                #region Region Toggle Buttons
                JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
                DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

                HashSet <string> regions = new HashSet <string>();
                morphControl.GetMorphDisplayNames().ForEach((name) =>
                {
                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                    regions.Add(morph.region);
                });

                foreach (string region in regions)
                {
                    bool isOnByDefault = defaultOff.Any((str) => region.Contains(str)) == false;
                    toggles[region] = CreateToggle(new JSONStorableBool(region, isOnByDefault), true);
                }
                #endregion

                #region Additive Toggle
                JSONStorableBool additiveToggle = new JSONStorableBool("Additive", false);
                CreateToggle(additiveToggle).labelText.text = "Additively Copy Morphs";
                #endregion

                #region Copy Button
                UIDynamicButton copyButton = CreateButton("Copy Morphs", false);
                copyButton.buttonColor = new Color(0, 0, 0.5f);
                copyButton.textColor   = new Color(1, 1, 1);
                copyButton.button.onClick.AddListener(delegate()
                {
                    //  copy morphs directly from an existing atom in the current scene
                    if (SelectingFromScene())
                    {
                        if (sceneAtom == null)
                        {
                            Debug.Log("other atom is null");
                            SuperController.LogMessage("Select an atom first");
                            return;
                        }

                        JSONStorable otherGeometry                   = sceneAtom.GetStorableByID("geometry");
                        DAZCharacterSelector otherCharacter          = otherGeometry as DAZCharacterSelector;
                        GenerateDAZMorphsControlUI otherMorphControl = otherCharacter.morphsControlUI;

                        if (additiveToggle.val == false)
                        {
                            ZeroSelectedMorphs(morphControl);
                        }

                        morphControl.GetMorphDisplayNames().ForEach((name) =>
                        {
                            DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                            if (toggles.ContainsKey(morph.region) == false)
                            {
                                return;
                            }

                            if (toggles[morph.region].toggle.isOn)
                            {
                                morph.morphValue = otherMorphControl.GetMorphByDisplayName(name).morphValue;
                            }
                        });

                        //  also copy morphs that weren't included with this atom, such as imported morphs
                        otherMorphControl.GetMorphDisplayNames().ForEach((name) =>
                        {
                            DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                            if (toggles.ContainsKey(morph.region) == false)
                            {
                                return;
                            }

                            if (toggles[morph.region].toggle.isOn)
                            {
                                morph.morphValue = otherMorphControl.GetMorphByDisplayName(name).morphValue;
                            }
                        });
                    }

                    //  copy morphs from a JSON person atom
                    else
                    if (filePersonJSON != null)
                    {
                        JSONClass storableGeometry = null;

                        //  find geometry storable...
                        JSONArray storables = filePersonJSON["storables"].AsArray;
                        for (int i = 0; i < storables.Count; i++)
                        {
                            JSONClass storable = storables[i].AsObject;
                            string id          = storable["id"];
                            if (id == "geometry")
                            {
                                storableGeometry = storable;
                                break;
                            }
                        }

                        if (storableGeometry == null)
                        {
                            return;
                        }

                        if (additiveToggle.val == false)
                        {
                            ZeroSelectedMorphs(morphControl);
                        }

                        //  build a morph value dictionary...
                        Dictionary <string, float> otherMorphNameToValue = new Dictionary <string, float>();
                        if (storableGeometry != null)
                        {
                            JSONArray morphs = storableGeometry["morphs"].AsArray;
                            for (int i = 0; i < morphs.Count; i++)
                            {
                                JSONClass morphStorable     = morphs[i].AsObject;
                                string name                 = morphStorable["name"];
                                float value                 = morphStorable["value"].AsFloat;
                                otherMorphNameToValue[name] = value;
                            }
                        }

                        morphControl.GetMorphDisplayNames().ForEach((name) =>
                        {
                            DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                            if (morph == null)
                            {
                                Debug.Log("morph " + name + " does not exist in this context");
                                return;
                            }

                            if (toggles.ContainsKey(morph.region) == false)
                            {
                                return;
                            }

                            if (otherMorphNameToValue.ContainsKey(name) == false)
                            {
                                return;
                            }

                            if (toggles[morph.region].toggle.isOn)
                            {
                                morph.morphValue = otherMorphNameToValue[name];
                            }
                        });

                        otherMorphNameToValue.Keys.ToList().ForEach((name) =>
                        {
                            DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                            if (morph == null)
                            {
                                Debug.Log("morph " + name + " does not exist in this context");
                                return;
                            }
                            if (toggles.ContainsKey(morph.region) == false)
                            {
                                return;
                            }

                            if (toggles[morph.region].toggle.isOn)
                            {
                                morph.morphValue = otherMorphNameToValue[name];
                            }
                        });
                    }
                });

                CreateSpacer();
                #endregion

                #region Reset Button
                UIDynamicButton resetButton = CreateButton("Reset", false);
                resetButton.buttonColor = new Color(0.96f, 0.45f, 0.45f);
                resetButton.button.onClick.AddListener(delegate()
                {
                    ResetMorphs();
                });
                CreateSpacer();
                #endregion

                #region Zero Selected Button
                UIDynamicButton zeroButton = CreateButton("Zero Selected", false);
                zeroButton.buttonColor = new Color(0, 0, 0.5f);
                zeroButton.textColor   = new Color(1, 1, 1);
                zeroButton.button.onClick.AddListener(delegate()
                {
                    ZeroSelectedMorphs(morphControl);
                });
                #endregion

                #region Clear Animatable Button
                UIDynamicButton animatableButton = CreateButton("Clear Animatable", false);
                animatableButton.buttonColor = new Color(0, 0, 0.5f);
                animatableButton.textColor   = new Color(1, 1, 1);
                animatableButton.button.onClick.AddListener(delegate()
                {
                    morphControl.GetMorphDisplayNames().ForEach((name) =>
                    {
                        DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                        morph.animatable = false;
                    });
                });

                CreateSpacer();
                #endregion
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #17
0
        public override void Init()
        {
            try {
                UpdateInitialMorphs();
                UpdateNewMorphs();
                UpdateCurrentMorphs();

                #region Sliders
                minSlider           = new JSONStorableFloat("Minimum value", -0.15f, -1f, 1.0f, true);
                minSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(minSlider);
                CreateSlider(minSlider, false);

                maxSlider           = new JSONStorableFloat("Maximum value", 0.35f, -1f, 1.0f, true);
                maxSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(maxSlider);
                CreateSlider(maxSlider, false);

                multiSlider           = new JSONStorableFloat("Multiplier", 1f, 0f, 2f, true);
                multiSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(multiSlider);
                CreateSlider(multiSlider, false);
                #endregion

                #region Region Buttons Preparation
                GenerateDAZMorphsControlUI morphControl = returnMorphs();

                HashSet <string>            regions          = new HashSet <string>();
                HashSet <string>            LastRegions      = new HashSet <string>();
                Dictionary <string, string> temporaryToggles = new Dictionary <string, string>();

                JSONStorableBool playingBool = new JSONStorableBool("Play", true);
                playingBool.storeType = JSONStorableParam.StoreType.Full;
                RegisterBool(playingBool);
                toggles["Play"] = CreateToggle((playingBool), false);

                smoothToggle = new JSONStorableBool("Smooth transitions", true);
                RegisterBool(smoothToggle);
                CreateToggle((smoothToggle), false);

                abaToggle = new JSONStorableBool("Reset used expressions at loop", true);
                RegisterBool(abaToggle);
                CreateToggle((abaToggle), false);

                manualToggle = new JSONStorableBool("Trigger transitions manually", false);
                RegisterBool(manualToggle);
                CreateToggle((manualToggle), false);

                JSONStorableAction manualTrigger = new JSONStorableAction("Trigger transition", () => { UpdateRandomParams(); });
                RegisterAction(manualTrigger);

                morphControl.GetMorphDisplayNames().ForEach((name) =>
                {
                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                    regions.Add(morph.region);

                    if (
                        (poseRegion.Any((str) => morph.region.Contains(str)) &&
                         !bodyRegion.Any((str) => morph.region.Contains(str))) ||
                        tailorList.Any((str) => name.Contains(str))
                        )
                    {
                        string[] posePaths      = Regex.Split(morph.region, "/");
                        string morphUpperRegion = "";

                        foreach (string posePath in posePaths)
                        {
                            morphUpperRegion = posePath;
                        }

                        LastRegions.Add(morphUpperRegion);
                        toggleRelations[name]  = morphUpperRegion;
                        temporaryToggles[name] = morphUpperRegion + "/" + name;
                    }
                });

                #region Region Helper Buttons
                UIDynamicButton selectAll = CreateButton("Select All", true);
                selectAll.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = true;
                    });
                });

                UIDynamicButton selectNone = CreateButton("Select None", true);
                selectNone.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = false;
                    });
                });

                UIDynamicButton selectDefault = CreateButton("Select Default", true);
                selectDefault.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        if (entry.Key != "Play")
                        {
                            toggles[entry.Key].toggle.isOn = defaultOn.Any((str) => entry.Key.Equals(str));
                        }
                    }
                    ;
                });

                UIDynamicButton selectPres1 = CreateButton("Select preset 1", true);
                selectPres1.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        if (entry.Key != "Play")
                        {
                            toggles[entry.Key].toggle.isOn = preset1.Any((str) => entry.Key.Equals(str));
                        }
                    }
                    ;
                });

                UIDynamicButton selectPres2 = CreateButton("Select preset 2", true);
                selectPres2.button.onClick.AddListener(delegate() {
                    foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                    {
                        if (entry.Key != "Play")
                        {
                            toggles[entry.Key].toggle.isOn = preset2.Any((str) => entry.Key.Equals(str));
                        }
                    }
                    ;
                });
                CreateSpacer(true).height = 10f;;
                #endregion

                #region Region checkbox generation
                foreach (KeyValuePair <string, string> entry in temporaryToggles)
                {
                    JSONStorableBool checkBoxTick = new JSONStorableBool(entry.Value, defaultOn.Any((str) => entry.Key.Equals(str)), (bool on) => {
                        togglesOn = toggles.Where(t => t.Value.toggle.isOn).ToDictionary(p => p.Key, p => p.Value);

                        if (!on && entry.Key != "Play")
                        {
                            DAZMorph morph   = morphControl.GetMorphByDisplayName(entry.Key);
                            morph.morphValue = 0;
                        }
                    });
                    checkBoxTick.storeType = JSONStorableParam.StoreType.Full;
                    RegisterBool(checkBoxTick);

                    toggles[entry.Key] = CreateToggle(checkBoxTick, true);
                }
                togglesOn = toggles.Where(t => t.Value.toggle.isOn).ToDictionary(p => p.Key, p => p.Value);
                #endregion

                #endregion

                //CreateSpacer();
                UIDynamicButton transitionButton = CreateButton("Trigger transition", false);
                transitionButton.button.onClick.AddListener(delegate() {
                    UpdateRandomParams();
                });
                transitionButton.buttonColor = new Color(0.5f, 1f, 0.5f);

                UIDynamicButton animatableButton = CreateButton("Clear Animatable (from selected)", false);
                animatableButton.button.onClick.AddListener(delegate()
                {
                    morphControl.GetMorphDisplayNames().ForEach((name) =>
                    {
                        DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                        if (toggles.ContainsKey(name) && toggles[name].toggle.isOn)
                        {
                            morph.animatable = false;
                        }
                    });
                });

                #region SetAsDef button
                UIDynamicButton setasdefButton = CreateButton("Set current state as default", false);
                setasdefButton.button.onClick.AddListener(delegate()
                {
                    UpdateInitialMorphs();
                });
                #endregion

                #region Reset button
                UIDynamicButton resetButton = CreateButton("Reset", false);
                resetButton.button.onClick.AddListener(delegate()
                {
                    toggles["Play"].toggle.isOn = false;
                    ResetMorphs();
                });
                #endregion

                #region ZeroMorph button
                UIDynamicButton ZeroMorphButton = CreateButton("Zero Selected", false);
                ZeroMorphButton.button.onClick.AddListener(delegate()
                {
                    toggles["Play"].toggle.isOn = false;
                    ZeroMorphs();
                });
                #endregion

                masterSpeedSlider           = new JSONStorableFloat("Master speed", 1f, 0f, 10f, true);
                masterSpeedSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(masterSpeedSlider);
                CreateSlider(masterSpeedSlider, false);

                animWaitSlider           = new JSONStorableFloat("Loop length", 2f, 0.1f, 20f, true);
                animWaitSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(animWaitSlider);
                CreateSlider(animWaitSlider, false);

                animLengthSlider           = new JSONStorableFloat("Morphing speed", 1.0f, 0.1f, 20f, true);
                animLengthSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(animLengthSlider);
                CreateSlider(animLengthSlider, false);

                morphList = new JSONStorableString("FooString", "");
                UIDynamic morphListText = CreateTextField(morphList, false);
                morphListText.height = 320;
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }
        public override void Init()
        {
            try {
                UpdateInitialMorphs();
                UpdateNewMorphs();
                UpdateCurrentMorphs();

                Dictionary <string, UIDynamicToggle> toggles         = new Dictionary <string, UIDynamicToggle>();
                Dictionary <string, UIDynamicButton> buttons         = new Dictionary <string, UIDynamicButton>();
                Dictionary <string, string>          toggleRelations = new Dictionary <string, string>();

                #region Sliders
                minSlider           = new JSONStorableFloat("Minimum value", -0.3f, -1f, 1.0f, true);
                minSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(minSlider);
                CreateSlider(minSlider, false);

                maxSlider           = new JSONStorableFloat("Maximum value", 0.3f, -1f, 1.0f, true);
                maxSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(maxSlider);
                CreateSlider(maxSlider, false);

                multiSlider           = new JSONStorableFloat("Multiplier", 1f, 0f, 2f, true);
                multiSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(multiSlider);
                CreateSlider(multiSlider, false);
                #endregion

                #region Region Buttons Preparation
                JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
                DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

                HashSet <string>            regions          = new HashSet <string>();
                HashSet <string>            LastRegions      = new HashSet <string>();
                Dictionary <string, string> temporaryToggles = new Dictionary <string, string>();

                JSONStorableBool playingBool = new JSONStorableBool("Play", false);
                playingBool.storeType = JSONStorableParam.StoreType.Full;
                RegisterBool(playingBool);
                toggles["Play"] = CreateToggle((playingBool), false);

                morphControl.GetMorphDisplayNames().ForEach((name) =>
                {
                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                    regions.Add(morph.region);

                    if (
                        poseRegion.Any((str) => morph.region.Contains(str)) &&
                        !bodyRegion.Any((str) => morph.region.Contains(str)) &&
                        !morph.region.Contains("Reloaded")
                        )
                    {
                        string[] posePaths      = Regex.Split(morph.region, "/");
                        string morphUpperRegion = "";

                        foreach (string posePath in posePaths)
                        {
                            morphUpperRegion = posePath;
                        }

                        LastRegions.Add(morphUpperRegion);
                        toggleRelations[name]  = morphUpperRegion;
                        temporaryToggles[name] = morphUpperRegion + "/" + name;
                    }
                });

                #region Region Helper Buttons
                UIDynamicButton selectAll = CreateButton("Select All", true);
                selectAll.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = true;
                    });
                });
                UIDynamicButton selectNone = CreateButton("Select None", true);
                selectNone.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = false;
                    });
                });

                foreach (string LastRegion in LastRegions)
                {
                    buttons[LastRegion] = CreateButton(LastRegion, true);
                    buttons[LastRegion].button.onClick.AddListener(delegate() {
                        ResetMorphs();
                        foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                        {
                            if (toggleRelations.ContainsKey(entry.Key))
                            {
                                entry.Value.toggle.isOn = (toggleRelations[entry.Key] == LastRegion);
                            }
                        }
                    });
                }
                #endregion

                #region Region checkbox generation
                foreach (KeyValuePair <string, string> entry in temporaryToggles)
                {
                    JSONStorableBool checkBoxTick = new JSONStorableBool(entry.Value, false);
                    checkBoxTick.storeType = JSONStorableParam.StoreType.Full;
                    RegisterBool(checkBoxTick);

                    toggles[entry.Key] = CreateToggle(checkBoxTick, true);
                }
                #endregion

                #endregion

                #region Play Loop

                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;

                    while (true)
                    {
                        if (toggles["Play"].toggle.isOn)
                        {
                            // define the random values to switch to
                            morphControl.GetMorphDisplayNames().ForEach((name) =>
                            {
                                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                                if (toggles.ContainsKey(name) == false)
                                {
                                    return;
                                }

                                if (toggles[name].toggle.isOn)
                                {
                                    if (morph.animatable == false)
                                    {
                                        float valeur         = UnityEngine.Random.Range(minSlider.val, maxSlider.val) * multiSlider.val;
                                        newMorphValues[name] = valeur;
                                    }
                                }
                            });

                            // morph progressively every morphs to their new values
                            int etape = (int)(1000 * animLengthSlider.val / 60);
                            for (int i = 0; i < etape; i++)
                            {
                                morphControl.GetMorphDisplayNames().ForEach((name) =>
                                {
                                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                                    if (toggles.ContainsKey(name) == false)
                                    {
                                        return;
                                    }

                                    if (toggles[name].toggle.isOn)
                                    {
                                        if (morph.animatable == false)
                                        {
                                            morph.morphValue += ((newMorphValues[name] - CurrentMorphsValues[name]) / (etape)) * 0.99f;
                                        }
                                    }
                                });
                                System.Threading.Thread.Sleep((int)(1000 * animLengthSlider.val / 60));
                            }
                            // update current state without touching the initial value for later reset
                            UpdateCurrentMorphs();
                        }
                        // sleep so no fast empty loop if no morph has been selected
                        System.Threading.Thread.Sleep((int)(100));
                    }
                }).Start();
                #endregion

                //CreateSpacer();

                #region SetAsDef button
                UIDynamicButton setasdefButton = CreateButton("Set current as default", false);
                setasdefButton.button.onClick.AddListener(delegate()
                {
                    UpdateInitialMorphs();
                });
                #endregion

                UIDynamicButton animatableButton = CreateButton("Clear Animatable", false);
                animatableButton.button.onClick.AddListener(delegate()
                {
                    morphControl.GetMorphDisplayNames().ForEach((name) =>
                    {
                        DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                        morph.animatable = false;
                    });
                });

                #region Reset button
                UIDynamicButton resetButton = CreateButton("Reset", false);
                resetButton.button.onClick.AddListener(delegate()
                {
                    ResetMorphs();
                });
                #endregion


                animLengthSlider           = new JSONStorableFloat("Loop Length (s)", 3.0f, 0.01f, 10f, true);
                animLengthSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(animLengthSlider);
                CreateSlider(animLengthSlider, false);
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #19
0
        public Appearance(DollMaker dm) : base(dm)
        {
            JSONArray bodyUI = DollMaker.CONFIG_JSON["bodyUI"].AsArray;

            for (int i = 0; i < bodyUI.Count; i++)
            {
                JSONClass uiPart     = bodyUI[i].AsObject;
                string    title      = uiPart["title"].Value;
                string    boneName   = uiPart["bone"].Value;
                string    searchTerm = uiPart["search"].Value;
                float     x          = uiPart["offset"]["x"].AsFloat;
                float     y          = uiPart["offset"]["y"].AsFloat;
                float     z          = uiPart["offset"]["z"].AsFloat;

                DAZBone bone = person.GetStorableByID(boneName) as DAZBone;

                BoneAttachedUI boneUI = new BoneAttachedUI(title, bone, ui, new Vector3(x, y, z));
                boneUI.button.button.onClick.AddListener(() =>
                {
                    UpdateSearch(searchTerm);
                    searchBox.text = searchTerm;
                });
                baUI.Add(boneUI);
            }

            searchBox = ui.CreateTextInput("Search For Morph", 1200, 120);
            searchBox.transform.localPosition = new Vector3(0, -120, 0);


            //textInput.gameObject.AddComponent<InputPressedHandler>();

            ScrollRect sr = ui.CreateScrollRect(1200, 800);

            sr.transform.localPosition = new Vector3(0, -600, 0);

            VerticalLayoutGroup vlg = ui.CreateVerticalLayout(1200, 1200);

            vlg.transform.SetParent(sr.transform, false);
            vlg.padding = new RectOffset(0, 0, 25, 25);

            RectTransform vlgrt = vlg.GetComponent <RectTransform>();

            vlgrt.pivot            = new Vector2(0.5f, 1);
            vlgrt.anchoredPosition = new Vector2(0, 0);
            sr.content             = vlgrt;

            ContentSizeFitter csf = vlg.gameObject.AddComponent <ContentSizeFitter>();

            csf.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
            csf.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

            DAZCharacterSelector personGeometry = person.GetStorableByID("geometry") as DAZCharacterSelector;

            morphControl = personGeometry.morphsControlUI;

            regions = new HashSet <string>();
            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                regions.Add(morph.region);
            });

            List <string> morphNames = personGeometry.GetFloatParamNames();

            morphNames.ForEach((s) =>
            {
                //  For testing scroll rect
                //if (morphNameToSlider.Keys.Count > 20)
                //{
                //    return;
                //}

                UIDynamicSlider morphSlider = ui.CreateSlider(s, 800, 80, false);
                morphSlider.gameObject.SetActive(false);

                //Image image = morphSlider.labelText.transform.parent.gameObject.GetComponentInChildren<Image>();
                morphSlider.transform.SetParent(vlg.transform, false);

                personGeometry.GetFloatJSONParam(s).slider = morphSlider.slider;

                morphNameToSlider[s] = morphSlider;
            });

            searchBox.onValueChanged.AddListener(UpdateSearch);
        }
Beispiel #20
0
        public override void Init()
        {
            try {
                UpdateInitialMorphs();
                UpdateNewMorphs();
                UpdateCurrentMorphs();

                #region Sliders
                minSlider           = new JSONStorableFloat("Minimum value", -0.3f, -1f, 1.0f, true);
                minSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(minSlider);
                CreateSlider(minSlider, false);

                maxSlider           = new JSONStorableFloat("Maximum value", 0.3f, -1f, 1.0f, true);
                maxSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(maxSlider);
                CreateSlider(maxSlider, false);

                multiSlider           = new JSONStorableFloat("Multiplier", 1f, 0f, 2f, true);
                multiSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(multiSlider);
                CreateSlider(multiSlider, false);
                #endregion

                #region Region Buttons Preparation
                JSONStorable               geometry     = containingAtom.GetStorableByID("geometry");
                DAZCharacterSelector       character    = geometry as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphControl = character.morphsControlUI;

                HashSet <string>            regions          = new HashSet <string>();
                HashSet <string>            LastRegions      = new HashSet <string>();
                Dictionary <string, string> temporaryToggles = new Dictionary <string, string>();

                JSONStorableBool playingBool = new JSONStorableBool("Play", false);
                playingBool.storeType = JSONStorableParam.StoreType.Full;
                RegisterBool(playingBool);
                toggles["Play"] = CreateToggle((playingBool), false);

                morphControl.GetMorphDisplayNames().ForEach((name) =>
                {
                    DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                    regions.Add(morph.region);

                    if (
                        poseRegion.Any((str) => morph.region.Contains(str)) &&
                        !bodyRegion.Any((str) => morph.region.Contains(str)) &&
                        !morph.region.Contains("Reloaded")
                        )
                    {
                        string[] posePaths      = Regex.Split(morph.region, "/");
                        string morphUpperRegion = "";

                        foreach (string posePath in posePaths)
                        {
                            morphUpperRegion = posePath;
                        }

                        LastRegions.Add(morphUpperRegion);
                        toggleRelations[name]  = morphUpperRegion;
                        temporaryToggles[name] = morphUpperRegion + "/" + name;
                    }
                });

                #region Region Helper Buttons
                UIDynamicButton selectAll = CreateButton("Select All", true);
                selectAll.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = true;
                    });
                });
                UIDynamicButton selectNone = CreateButton("Select None", true);
                selectNone.button.onClick.AddListener(delegate() {
                    toggles.Values.ToList().ForEach((toggle) =>
                    {
                        toggle.toggle.isOn = false;
                    });
                });

                foreach (string LastRegion in LastRegions)
                {
                    buttons[LastRegion] = CreateButton(LastRegion, true);
                    buttons[LastRegion].button.onClick.AddListener(delegate() {
                        ResetMorphs();
                        foreach (KeyValuePair <string, UIDynamicToggle> entry in toggles)
                        {
                            if (toggleRelations.ContainsKey(entry.Key))
                            {
                                entry.Value.toggle.isOn = (toggleRelations[entry.Key] == LastRegion);
                            }
                        }
                    });
                }
                #endregion

                #region Region checkbox generation
                foreach (KeyValuePair <string, string> entry in temporaryToggles)
                {
                    JSONStorableBool checkBoxTick = new JSONStorableBool(entry.Value, false);
                    checkBoxTick.storeType = JSONStorableParam.StoreType.Full;
                    RegisterBool(checkBoxTick);

                    toggles[entry.Key] = CreateToggle(checkBoxTick, true);
                }
                #endregion

                #endregion

                //CreateSpacer();

                #region SetAsDef button
                UIDynamicButton setasdefButton = CreateButton("Set current as default", false);
                setasdefButton.button.onClick.AddListener(delegate()
                {
                    UpdateInitialMorphs();
                });
                #endregion

                UIDynamicButton animatableButton = CreateButton("Clear Animatable", false);
                animatableButton.button.onClick.AddListener(delegate()
                {
                    morphControl.GetMorphDisplayNames().ForEach((name) =>
                    {
                        DAZMorph morph   = morphControl.GetMorphByDisplayName(name);
                        morph.animatable = false;
                    });
                });

                #region Reset button
                UIDynamicButton resetButton = CreateButton("Reset", false);
                resetButton.button.onClick.AddListener(delegate()
                {
                    ResetMorphs();
                });
                #endregion

                animWaitSlider           = new JSONStorableFloat("Loop length", 1f, 0.1f, 20f, true);
                animWaitSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(animWaitSlider);
                CreateSlider(animWaitSlider, false);

                animLengthSlider           = new JSONStorableFloat("Morphing speed", 1.0f, 0.1f, 20f, true);
                animLengthSlider.storeType = JSONStorableParam.StoreType.Full;
                RegisterFloat(animLengthSlider);
                CreateSlider(animLengthSlider, false);
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #21
0
        public override void Init()
        {
            try {
                UpdateInitialMorphs();


                #region Choose Atom
                Atom          otherAtom       = null;
                List <string> receiverChoices = SuperController.singleton.GetAtoms()
                                                .Where(atom => atom.GetStorableByID("geometry") != null && atom != containingAtom)
                                                .Select(atom => atom.name).ToList();
                JSONStorableStringChooser receiverChoiceJSON = new JSONStorableStringChooser("copyFrom", receiverChoices, null, "Copy From", delegate(string otherName)
                {
                    otherAtom = GetAtomById(otherName);
                });
                receiverChoiceJSON.storeType = JSONStorableParam.StoreType.Full;
                UIDynamicPopup dp = CreateScrollablePopup(receiverChoiceJSON, false);
                dp.popupPanelHeight = 250f;
                RegisterStringChooser(receiverChoiceJSON);
                #endregion


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

                JSONStorableFloat morphMixAmount = new JSONStorableFloat("morphMix", 0.0f, 0f, 1f, true);
                UIDynamicSlider   morphSlider    = CreateSlider(morphMixAmount, true);

                morphSlider.slider.onValueChanged.AddListener(delegate(float mixValue)
                {
                    if (otherAtom == null)
                    {
                        Debug.Log("other atom is null");
                        return;
                    }

                    JSONStorable otherGeometry                   = otherAtom.GetStorableByID("geometry");
                    DAZCharacterSelector otherCharacter          = otherGeometry as DAZCharacterSelector;
                    GenerateDAZMorphsControlUI otherMorphControl = otherCharacter.morphsControlUI;

                    morphControl.GetMorphDisplayNames().ForEach((name) =>
                    {
                        DAZMorph otherMorph = otherMorphControl.GetMorphByDisplayName(name);
                        DAZMorph morph      = morphControl.GetMorphByDisplayName(name);
                        float initialValue  = initialMorphValues[name];
                        float targetValue   = otherMorph.morphValue;
                        morph.morphValue    = initialValue + ((targetValue - initialValue) * mixValue);
                    });
                });
                #endregion


                #region Apply Button
                UIDynamicButton applyButton = CreateButton("Apply As Starting Value", true);
                applyButton.button.onClick.AddListener(delegate()
                {
                    UpdateInitialMorphs();
                });
                #endregion

                CreateSpacer();
                CreateTextField(new JSONStorableString("instructions", "\nPick a Person atom and use the slider to blend morphs."));
                CreateTextField(new JSONStorableString("instructions", "\nUse the Apply As Starting Value button to freeze morphs into place if you want to load a new target appearance."));
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Beispiel #22
0
        public MorphSearch(BaseModule baseModule)
        {
            UI        ui       = baseModule.ui;
            Transform moduleUI = baseModule.moduleUI;
            Atom      atom     = baseModule.atom;

            searchBox = ui.CreateTextInput("Search For Morph", 800, 100, moduleUI);
            searchBox.transform.localPosition = new Vector3(0, -110, 0);

            paginationSlider = ui.CreateSlider("Page", 930, 80, true, moduleUI);
            paginationSlider.transform.localPosition = new Vector3(0, -200, 0);

            paginationValue = new JSONStorableFloat("Page", 0, (float value) =>
            {
            }, 0, 10, true, true);
            paginationSlider.valueFormat = "n0";
            paginationValue.slider       = paginationSlider.slider;

            paginationSlider.gameObject.SetActive(false);

            GridLayoutGroup layout = ui.CreateGridLayout(1200, 800, moduleUI);

            layout.transform.localPosition = new Vector3(0, -1010, 0);
            layout.constraintCount         = 3;
            layout.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
            layout.GetComponent <RectTransform>().pivot = new Vector2(0, 0);

            layout.cellSize = new Vector2(400, 80);

            for (int i = 0; i < MAX_MORPHS_PER_PAGE - 1; i++)
            {
                UIDynamicSlider slider = ui.CreateMorphSlider("Slider " + i, 400, 80, moduleUI);
                slider.transform.SetParent(layout.transform, false);

                morphSliders.Add(slider);
                slider.gameObject.SetActive(false);
            }


            DAZCharacterSelector personGeometry = atom.GetStorableByID("geometry") as DAZCharacterSelector;

            morphControl = personGeometry.morphsControlUI;

            regions = new HashSet <string>();
            morphControl.GetMorphDisplayNames().ForEach((name) =>
            {
                DAZMorph morph = morphControl.GetMorphByDisplayName(name);
                regions.Add(morph.region);
            });

            morphNames = morphControl.GetMorphDisplayNames();

            searchBox.onValueChanged.AddListener(UpdateSearch);

            UIDynamicButton clearButton = ui.CreateButton("Clear", 120, 100, moduleUI);

            clearButton.transform.localPosition = new Vector3(810, -110, 0);
            clearButton.button.onClick.AddListener(() =>
            {
                searchBox.text = "";
                ClearSearch();
            });

            VerticalLayoutGroup commonTermsGroup = ui.CreateVerticalLayout(220, 0, moduleUI);

            commonTermsGroup.transform.localPosition = new Vector3(-230, -200, 0);
            commonTermsGroup.GetComponent <RectTransform>().pivot = new Vector2(0, 0);

            commonTermsGroup.childAlignment = TextAnchor.UpperLeft;


            for (int i = 0; i < MAX_TERMS; i++)
            {
                UIDynamicButton termButton = ui.CreateButton("Term", 220, 40, moduleUI);
                termButton.transform.SetParent(commonTermsGroup.transform, false);
                termButtons.Add(termButton);
                UI.ColorButton(termButton, Color.white, new Color(0.3f, 0.4f, 0.6f));

                termButton.gameObject.SetActive(false);

                ContentSizeFitter csf = termButton.gameObject.AddComponent <ContentSizeFitter>();
                csf.verticalFit = ContentSizeFitter.FitMode.MinSize;
            }

            //Debug.Log("----------------------------");
            //UIDynamicSlider testSlider = ui.CreateMorphSlider("test");
            //ui.DebugDeeper(testSlider.transform);
        }
Beispiel #23
0
        public override void Init()
        {
            try
            {
                JSONStorableBool dummy = new JSONStorableBool("dummy", false);
                RegisterBool(dummy);
                dummy.SetVal(true);

                mam = SuperController.singleton.motionAnimationMaster;

                recordButton             = CreateButton("Record");
                recordButton.buttonColor = Color.green;
                recordButton.button.onClick.AddListener(() =>
                {
                    isRecording = !isRecording;

                    // Should now be recording
                    if (isRecording)
                    {
                        mam.ResetAnimation();
                        mam.autoRecordStop   = true;
                        mam.showRecordPaths  = false;
                        mam.showStartMarkers = false;
                        mam.StartRecord();
                        recordButton.buttonColor = Color.red;
                    }
                    else
                    {
                        mam.StopRecord();
                        mam.StopPlayback();
                        recordButton.buttonColor = Color.green;
                    }
                });

                DAZCharacterSelector       dcs     = containingAtom.GetStorableByID("geometry") as DAZCharacterSelector;
                GenerateDAZMorphsControlUI morphUI = dcs.morphsControlUI;
                List <string> allMorphNames        = morphUI.GetMorphDisplayNames();


                List <DAZMorph> acceptableMorphs = allMorphNames
                                                   .Select((string name) =>
                {
                    return(morphUI.GetMorphByDisplayName(name));
                })
                                                   .ToList()
                                                   .Where((morph) =>
                {
                    return(acceptList.Exists((acceptString) =>
                    {
                        return morph.group.Contains(acceptString);
                    }));
                })
                                                   .ToList();

                animatableMorphs = acceptableMorphs;

                acceptableMorphs.ForEach((morph) =>
                {
                    groups.Add(morph.group);
                });

                CreateButton("Rewind").button.onClick.AddListener(() =>
                {
                    mam.SeekToBeginning();
                    GenerateAnimation();
                });

                CreateButton("Play").button.onClick.AddListener(() =>
                {
                    mam.StartPlayback();
                    mam.StopRecord();
                    recordButton.buttonColor = Color.green;
                    GenerateAnimation();
                });

                CreateButton("Stop").button.onClick.AddListener(() =>
                {
                    mam.StopRecord();
                    mam.StopPlayback();
                    recordButton.buttonColor = Color.green;
                    GenerateAnimation();
                });

                CreateButton("Clear All Poses").button.onClick.AddListener(() =>
                {
                    acceptableMorphs.ForEach((morph) =>
                    {
                        morph.Reset();
                    });
                });

                CreateSpacer();

                List <UIDynamicSlider>  morphSliders = new List <UIDynamicSlider>();
                List <JSONStorableBool> onGroups     = new List <JSONStorableBool>();

                groups.ToList().ForEach((groupName) =>
                {
                    JSONStorableBool groupOn = new JSONStorableBool(groupName, false, (bool isOn) =>
                    {
                        // Clear list of morphs.
                        morphSliders.ForEach((slider) =>
                        {
                            RemoveSlider(slider);
                        });
                        morphSliders = new List <UIDynamicSlider>();

                        List <string> onList = onGroups.Where((storableBool) => storableBool.val).ToList().Select((storableBool) => storableBool.name).ToList();

                        acceptableMorphs
                        .Where((morph) =>
                        {
                            return(onList.Exists((name) =>
                            {
                                return morph.group == name;
                            }));
                        })
                        .ToList()
                        .ForEach((morph) =>
                        {
                            bool highCost = IsHighCostMorph(morph);
                            JSONStorableFloat morphValue = new JSONStorableFloat(morph.displayName, morph.morphValue, (float value) =>
                            {
                                morph.SetValue(value);

                                if (isRecording)
                                {
                                    changesOnFrame.Add(new MorphChange()
                                    {
                                        morph = morph,
                                        value = value,
                                    });
                                }
                            }, morph.min, morph.max, false, true);
                            UIDynamicSlider slider = CreateSlider(morphValue, true);
                            slider.labelText.color = highCost ? Color.red : Color.black;
                            morphSliders.Add(slider);
                        });
                    });
                    UIDynamicToggle groupToggle = CreateToggle(groupOn);
                    onGroups.Add(groupOn);
                });
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }