using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using SimpleJSON; namespace VamWizard { public class SoftPhysicsSelector : MVRScript { DAZPhysicsMesh[] originalPhysicsMeshes; DAZPhysicsMesh lips; DAZPhysicsMesh breasts; DAZPhysicsMesh glutes; DAZCharacterRun dazCharacterRun; bool unexpectedOriginalPhysicsMeshes; public JSONStorableBool lipsOn; public JSONStorableBool breastsOn; public JSONStorableBool glutesOn; public override void Init() { try { } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } void Start() { try { var parentTransforms = this.GetComponentsInParent(); Transform root = null; try { foreach (var item in parentTransforms) { if (item.name == "reParentObject") { root = item.parent; break; } } } catch (Exception e) { SuperController.LogError("p1 Exception caught: " + e); } dazCharacterRun = root.GetComponentInChildren(); try { if (dazCharacterRun.physicsMeshes.Length != 3) { unexpectedOriginalPhysicsMeshes = true; SuperController.LogError("3 PhysicsMeshes were expected, but only " + dazCharacterRun.physicsMeshes.Length.ToString() + " were identified"); return; } } catch (Exception e) { SuperController.LogError("p2 Exception caught: " + e); } try { originalPhysicsMeshes = dazCharacterRun.physicsMeshes; lips = originalPhysicsMeshes[0]; breasts = originalPhysicsMeshes[2]; glutes = originalPhysicsMeshes[1]; } catch (Exception e) { SuperController.LogError("p4 Exception caught: " + e); } /// try { lipsOn = new JSONStorableBool("Lips", true, UpdatePhysicsMeshesCallback); lipsOn.storeType = JSONStorableParam.StoreType.Full; CreateToggle(lipsOn, false); RegisterBool(lipsOn); breastsOn = new JSONStorableBool("Breasts", true, UpdatePhysicsMeshesCallback); breastsOn.storeType = JSONStorableParam.StoreType.Full; CreateToggle(breastsOn, false); RegisterBool(breastsOn); glutesOn = new JSONStorableBool("Glutes", true, UpdatePhysicsMeshesCallback); glutesOn.storeType = JSONStorableParam.StoreType.Full; CreateToggle(glutesOn, false); RegisterBool(glutesOn); } catch (Exception e) { SuperController.LogError("p4 Exception caught: " + e); } } catch (Exception e) { SuperController.LogError("p3 Exception caught: " + e); } } protected void UpdatePhysicsMeshesCallback(bool on) { if (!unexpectedOriginalPhysicsMeshes) { try { UserPreferences.singleton.softPhysics = false; List list = new List(); if (lipsOn.val) { list.Add(lips); } if (breastsOn.val) { list.Add(breasts); } if (glutesOn.val) { list.Add(glutes); } dazCharacterRun.physicsMeshes = list.ToArray(); StartCoroutine(WaitAFrameAndEnableSoftPhysics()); //UserPreferences.singleton.softPhysics = true; } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } } IEnumerator WaitAFrameAndEnableSoftPhysics() { yield return null; UserPreferences.singleton.softPhysics = true; } void OnDestroy() { if (!unexpectedOriginalPhysicsMeshes) { try { dazCharacterRun.physicsMeshes = originalPhysicsMeshes; } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } } } }