diff --git a/HeelAdjust2Core.cs b/HeelAdjust2Core.cs index 0aca527..475ca46 100644 --- a/HeelAdjust2Core.cs +++ b/HeelAdjust2Core.cs @@ -411,7 +412,9 @@ namespace CheesyFX HandShakeWithFlexIt(); for (int i = 0; i < clothes.childCount; i++) { - clothes.GetChild(i).gameObject.AddComponent(); + var obj = clothes.GetChild(i).gameObject; + if (obj.GetComponent() == null) continue; + obj.AddComponent(); } if (sceneData != null) { @@ -444,7 +447,7 @@ namespace CheesyFX private void OnDestroy() { - OnDisable(); + // OnDisable(); // it is called by SuperController already GPUCollidersManager.DeregisterLineSphereCollider(lHeelGPUCapsule); GPUCollidersManager.DeregisterLineSphereCollider(lToeGPUCapsule); GPUCollidersManager.DeregisterLineSphereCollider(rHeelGPUCapsule); @@ -454,6 +457,8 @@ namespace CheesyFX Destroy(lToeColliderBase.gameObject); Destroy(lHeelColliderBase.gameObject); + // otherwise onClothingItemToggled(dci, false) are fired for every equipped clothing item + ClothingEquippedEventHandler.skip = true; for (int i = 0; i < clothes.childCount; i++) { Destroy(clothes.GetChild(i).GetComponent()); @@ -474,6 +479,7 @@ namespace CheesyFX rfootCTRL.GetFloatJSONParam("jointDriveYTarget").setCallbackFunction -= OnJointDriveChanged; rfootCTRL.GetFloatJSONParam("jointDriveZTarget").setCallbackFunction -= OnJointDriveChanged; HandShakeWithFlexIt(); + SuperController.LogMessage("HellAdjust after OnDestroy"); } private void SwitchTab(int id) @@ -597,7 +603,7 @@ namespace CheesyFX private void CreateAdditionalItemsUI() { - RemoveTextField(lockedInfo); + if(lockedInfo != null) RemoveTextField(lockedInfo); RemoveUIElements(UIElementsSliders); linkAdditionalButton.label = "Return"; linkAdditionalButton.button.onClick.RemoveAllListeners(); @@ -977,6 +983,14 @@ namespace CheesyFX toeColliderOffset.SetValToDefault(); toeColliderRotation.SetValToDefault(); toeColliderScale.SetValToDefault(); + // SuperController.LogMessage(new StackTrace(true).ToString()); + string msg = "Reset @"+Time.realtimeSinceStartup.ToString(); + float rotation = lFoot.transform.localRotation.eulerAngles.x; + msg += $" right rot={rotation}"; + rotation = rFoot.transform.localRotation.eulerAngles.x; + msg += $"left rot={rotation}"; + SuperController.LogMessage(msg); + rToeGPUCapsule.enabled = lToeGPUCapsule.enabled = lHeelGPUCapsule.enabled = rHeelGPUCapsule.enabled = false; reloadButton.label = reloadLabel = "Toggle: None"; if (!autoCalculateDeltas.val) @@ -1299,6 +1313,7 @@ namespace CheesyFX var col = collisionEnabled.val; collisionEnabled.val = false; SetFootPose(0f); + SuperController.LogMessage($"SetFootPose(0) @{Time.realtimeSinceStartup}"); yield return new WaitForSeconds(.5f); CalculateDeltas(); OnFootPoseChanged(); @@ -1327,8 +1342,16 @@ namespace CheesyFX private void CalculateDeltas() { - rFootSlopeDelta.val = rDelta = GetDelta(rFoot.transform.localRotation.eulerAngles.x); - lFootSlopeDelta.val = lDelta = GetDelta(lFoot.transform.localRotation.eulerAngles.x); + string msg = "deltas @"+Time.realtimeSinceStartup.ToString(); + float rotation = lfootCTRL.transform.localRotation.eulerAngles.x; + //float rotation = lFoot.transform.localRotation.eulerAngles.x; + msg += $" right rot={rotation}"; + rFootSlopeDelta.val = rDelta = GetDelta(rotation); + //rotation = rFoot.transform.localRotation.eulerAngles.x; + rotation = rfootCTRL.transform.localRotation.eulerAngles.x; + msg += $"left rot={rotation}"; + SuperController.LogMessage(msg); + lFootSlopeDelta.val = lDelta = GetDelta(rotation); } private float GetDelta(float rotation) @@ -1389,13 +1412,24 @@ namespace CheesyFX if (preset != null) { toggleItemButton.label = toggleItemLabel = $"Toggle {StripNonAlphaNum(GetItemNameFromCustomClothingUID(dci.uid))}"; + itemToStore.val = itemName; // TODO: this caption is not red right after plugin starts if(enabled) { + SuperController.LogMessage($"equip @{Time.realtimeSinceStartup}:{preset}"); + float delta = Time.realtimeSinceStartup - lastClothingDisabled; + if (delta < 0.05) // 50 ms - a clothing preset changed + { + SuperController.LogMessage($"delta={delta} cancel Reset()"); + StopCoroutine(currentCoroutine); + } LoadFromPath(preset); if(autoCalculateDeltas.val) { - if (currentPreset != null) StartCoroutine(IECalculateDeltas()); - else CalculateDeltas(); + /*if (currentPreset != null) StartCoroutine(IECalculateDeltas()); + else*/ CalculateDeltas(); } } currentPreset = preset; @@ -1406,19 +1440,39 @@ namespace CheesyFX { activeItems.Remove(itemName); activeItemNames.Remove(itemName); - if (currentPreset == null || currentPreset == preset) + if (currentPreset != null && currentPreset == preset) { + SuperController.LogMessage($"remove @{Time.realtimeSinceStartup}:{currentPreset}"); + // possibly the user make a preset with either the platform and the heel item, so we don't want to get here re╤Бursively + ClothingEquippedEventHandler.skip = true; if(currentPreset != null) EquipLinkedItems(LoadJSON(currentPreset).AsObject, false); - currentPreset = null; + ClothingEquippedEventHandler.skip = false; + if (currentCoroutine != null) StopCoroutine(currentCoroutine); + currentCoroutine = IEClothingDisabled(); + StartCoroutine(currentCoroutine); + lastClothingDisabled = Time.realtimeSinceStartup; // currentItem = null; // toggleItemButtonUid.label = "Current item: None" - Reset(); } } itemToStore.choices = activeItemNames; aditionalItemChooser.choices = activeItemNames; } + float lastClothingDisabled = 0; + private IEnumerator currentCoroutine; + + private IEnumerator IEClothingDisabled() + { + yield return new WaitForSeconds(.2f); + SuperController.LogMessage($"reset @{Time.realtimeSinceStartup} after clothing remove"+currentPreset); + // EquipLinkedItems(LoadJSON(currentPreset).AsObject, false); + currentPreset = null; + Reset(); + itemToStore.val = "None"; + currentCoroutine = null; + } + private void HandShakeWithFlexIt() { for (int i = 0; i < transform.parent.childCount; i++) @@ -1938,6 +1992,7 @@ namespace CheesyFX public class ClothingEquippedEventHandler : MonoBehaviour { + public static bool skip; private void OnEnable() { var dci = gameObject.GetComponent(); @@ -1947,6 +2002,7 @@ namespace CheesyFX private void OnDisable() { + if (skip) return; var dci = gameObject.GetComponent(); HeelAdjust2.onClothingItemToggled(dci, false); // $"{gameObject.GetComponent().uid} unequipped".Print();