private void ExportFileSelected(string path) { if (string.IsNullOrEmpty(path)) { return; } if (!path.ToLower().EndsWith($".{_saveExt}")) { path += $".{_saveExt}"; } try { var jc = plugin.GetAnimationJSON(_exportAnimationsJSON.val == "(All)" ? null : _exportAnimationsJSON.val); jc["AtomType"] = plugin.containingAtom.type; var atomState = new JSONClass(); var allTargets = new HashSet <FreeControllerV3>( animation.clips .Where(c => _exportAnimationsJSON.val == "(All)" || c.animationName == _exportAnimationsJSON.val) .SelectMany(c => c.targetControllers) .Select(t => t.controller) .Distinct()); foreach (var fc in plugin.containingAtom.freeControllers) { if (fc.name == "control") { continue; } if (!fc.name.EndsWith("Control")) { continue; } atomState[fc.name] = new JSONClass { { "currentPositionState", ((int)fc.currentPositionState).ToString() }, { "localPosition", AtomAnimationSerializer.SerializeVector3(fc.transform.localPosition) }, { "currentRotationState", ((int)fc.currentRotationState).ToString() }, { "localRotation", AtomAnimationSerializer.SerializeQuaternion(fc.transform.localRotation) } }; } jc["ControllersState"] = atomState; SuperController.singleton.SaveJSON(jc, path); SuperController.singleton.DoSaveScreenshot(path); } catch (Exception exc) { SuperController.LogError($"VamTimeline: Failed to export animation: {exc}"); } }
private JSONClass GetAtomStateJson() { var atomState = new JSONClass(); IEnumerable <FreeControllerV3> controllers; switch (_exportAnimationsJSON.val) { case _poseAndAllAnimations: controllers = plugin.containingAtom.freeControllers; break; case _allAnimations: controllers = animation.clips .SelectMany(c => c.targetControllers) .Select(t => t.controller) .Distinct(); break; default: controllers = animation.clips .First(c => c.animationName == _exportAnimationsJSON.val) .targetControllers .Select(t => t.controller); break; } foreach (var fc in controllers) { if (fc.name == "control") { continue; } if (!fc.name.EndsWith("Control")) { continue; } atomState[fc.name] = new JSONClass { { "currentPositionState", ((int)fc.currentPositionState).ToString() }, { "localPosition", AtomAnimationSerializer.SerializeVector3(fc.transform.localPosition) }, { "currentRotationState", ((int)fc.currentRotationState).ToString() }, { "localRotation", AtomAnimationSerializer.SerializeQuaternion(fc.transform.localRotation) } }; } return(atomState); }