Ejemplo n.º 1
0
    public void StartWizard()
    {
        if (_coroutine != null)
        {
            StopWizard();
        }
        if (context.LeftHand() == null || context.RightHand() == null)
        {
            statusJSON.val = _noHandsMessage;
            return;
        }

        context.diagnostics.Log("Wizard: Start");

        _navigationRigSnapshot = NavigationRigSnapshot.Snap();

        _poseJSON = containingAtom.GetStorableIDs()
                    .Select(s => containingAtom.GetStorableByID(s))
                    .Where(t => !t.exclude && t.gameObject.activeInHierarchy)
                    .Where(t => t is FreeControllerV3 || t is DAZBone)
                    .Select(t => t.GetJSON())
                    .Aggregate(new JSONArray(), (arrayJSON, storableJSON) =>
        {
            arrayJSON.Add(storableJSON);
            return(arrayJSON);
        });

        enabledJSON.val = true;
        _coroutine      = StartCoroutine(WizardCoroutine());
        statusChanged.Invoke(true);
    }
Ejemplo n.º 2
0
    public void StopWizard(string message = null)
    {
        if (!enabledJSON.val)
        {
            return;
        }

        context.diagnostics.Log("Wizard: Stop");

        StopCoroutine(_coroutine);
        _coroutine = null;

        if (_step != null)
        {
            try
            {
                _step.Leave(true);
            }
            catch (Exception exc)
            {
                SuperController.LogError($"Embody: Wizard {_step}.Leave failed: {exc}");
            }
            _step = null;
        }

        context.embody.activeJSON.val = false;
        context.trackers.previewTrackerOffsetJSON.val = false;
        context.snug.previewSnugOffsetJSON.val        = false;

        statusJSON.val = message ?? _wizardIntroMessage;
        _next          = false;
        _skip          = false;
        statusChanged.Invoke(false);
        enabledJSON.val = false;
        SuperController.singleton.worldScale = 1f;

        if (_poseJSON != null)
        {
            foreach (var storableJSON in _poseJSON.Childs)
            {
                var storableId = storableJSON["id"].Value;
                if (string.IsNullOrEmpty(storableId))
                {
                    continue;
                }
                var storable = containingAtom.GetStorableByID(storableId);
                storable.PreRestore();
                storable.RestoreFromJSON(storableJSON.AsObject);
                storable.PostRestore();
            }
            _poseJSON = null;
        }

        if (_navigationRigSnapshot != null)
        {
            _navigationRigSnapshot.Restore();
            _navigationRigSnapshot = null;
        }
    }
Ejemplo n.º 3
0
    private IEnumerator RestoreNavigationRig()
    {
        yield return(0);

        _navigationRigSnapshot?.Restore();
        _navigationRigSnapshot         = null;
        _restoreNavigationRigCoroutine = null;
    }
Ejemplo n.º 4
0
    private IEnumerator OnEnableCo(NavigationRigSnapshot rigSnapshot)
    {
        // Once bound, prevent vam from moving the head elsewhere due to world scale change
        yield return(new WaitForEndOfFrame());

        rigSnapshot.Restore();
        yield return(0f);

        rigSnapshot.Restore();
    }
Ejemplo n.º 5
0
 // ReSharper disable once UnusedMember.Local
 private void OnSceneSaved()
 {
     if (_activateAfterSaveComplete)
     {
         _activateAfterSaveComplete = false;
         var navigationRigSnapshot = _navigationRigSnapshot;
         Activate(_activatedManually);
         _navigationRigSnapshot = navigationRigSnapshot;
     }
 }
Ejemplo n.º 6
0
    private void Deactivate(bool defer)
    {
        activeJSON.valNoCallback = false;

        _context.automation.Reset();

        foreach (var module in _modules.GetComponents <IEmbodyModule>().Reverse())
        {
            if (module.skipChangeEnabledWhenActive)
            {
                continue;
            }
            module.enabledJSON.val = false;
        }

        foreach (var module in _enabledModules)
        {
            module.PostDeactivate();
        }

        _enabledModules.Clear();

        if (_poseJSON != null && _context.trackers?.restorePoseAfterPossessJSON.val == true)
        {
            foreach (var storableJSON in _poseJSON.Childs)
            {
                var storableId = storableJSON["id"].Value;
                if (string.IsNullOrEmpty(storableId))
                {
                    continue;
                }
                var storable = _context.containingAtom.GetStorableByID(storableId);
                if (storable == null)
                {
                    continue;
                }
                storable.PreRestore();
                storable.RestoreFromJSON(storableJSON.AsObject);
                storable.PostRestore();
            }
            _poseJSON = null;
        }

        _navigationRigSnapshot?.Restore();
        if (defer)
        {
            _restoreNavigationRigCoroutine = StartCoroutine(RestoreNavigationRig());
        }
        else
        {
            _navigationRigSnapshot = null;
        }
    }
Ejemplo n.º 7
0
 // ReSharper disable once UnusedMember.Local
 private void OnBeforeSceneSave()
 {
     if (activeJSON.val)
     {
         _activateAfterSaveComplete = true;
         var navigationRigSnapshot = _navigationRigSnapshot;
         var activatedManually     = _activatedManually;
         Deactivate(false);
         _navigationRigSnapshot = navigationRigSnapshot;
         _activatedManually     = activatedManually;
     }
 }
Ejemplo n.º 8
0
 public void TryBindTrackers()
 {
     if (Bind(headMotionControl))
     {
         StartCoroutine(OnEnableCo(NavigationRigSnapshot.Snap()));
     }
     Bind(leftHandMotionControl);
     Bind(rightHandMotionControl);
     BindFingers();
     foreach (var motionControl in viveTrackers)
     {
         Bind(motionControl);
     }
 }
Ejemplo n.º 9
0
    private void ActivatePreset(string presetVal)
    {
        var navigationRigSnapshot = _navigationRigSnapshot;

        if (activeJSON.val)
        {
            Deactivate(false);
        }

        presetsJSON.val = presetVal;

        ActivateManually();

        _navigationRigSnapshot = navigationRigSnapshot;
    }
Ejemplo n.º 10
0
    public override void OnEnable()
    {
        base.OnEnable();

        SuperController.singleton.ClearPossess();

        foreach (var motionControl in motionControls)
        {
            var controllerWithSnapshot = FindController(motionControl);
            if (controllerWithSnapshot == null)
            {
                continue;
            }
            var controller = controllerWithSnapshot.controller;
            if (restorePoseAfterPossessJSON.val)
            {
                controllerWithSnapshot.snapshot = FreeControllerV3Snapshot.Snap(controller);
            }

            if (motionControl.name == MotionControlNames.Head)
            {
                if (motionControl.currentMotionControl == SuperController.singleton.centerCameraTarget.transform)
                {
                    _navigationRigSnapshot = NavigationRigSnapshot.Snap();
                    AlignRigAndController(controller, motionControl);
                }
                else
                {
                    var controlRotation = controller.control.rotation;
                    motionControl.currentMotionControl.SetPositionAndRotation(
                        controller.control.position - controlRotation * motionControl.combinedOffset,
                        controlRotation
                        );
                }
            }
            else
            {
                controller.control.SetPositionAndRotation(motionControl.possessPointTransform.position, motionControl.possessPointTransform.rotation);
                if (controllerWithSnapshot.handControl != null)
                {
                    controllerWithSnapshot.handControl.possessed = true;
                }
            }

            Possess(motionControl, controllerWithSnapshot.controller);
        }
    }
Ejemplo n.º 11
0
    private IEnumerator ReinitializeIfActiveCo()
    {
        if (!activeJSON.val)
        {
            yield break;
        }

        var previousRigSnapshot     = _navigationRigSnapshot;
        var restorePoseAfterPossess = _context.trackers.restorePoseAfterPossessJSON.val;

        _context.trackers.restorePoseAfterPossessJSON.val = false;
        Deactivate(false);
        _context.trackers.restorePoseAfterPossessJSON.val = restorePoseAfterPossess;
        yield return(0);

        ActivateManually();
        _navigationRigSnapshot = previousRigSnapshot;
    }
Ejemplo n.º 12
0
    public override void OnDisable()
    {
        base.OnDisable();

        foreach (var c in controllers)
        {
            if (!c.controller.possessed)
            {
                continue;
            }

            c.controller.RestorePreLinkState();
            c.controller.possessed = false;

            var mac = c.controller.GetComponent <MotionAnimationControl>();
            if (mac != null)
            {
                mac.suspendPositionPlayback = false;
                mac.suspendRotationPlayback = false;
            }

            if (c.snapshot != null)
            {
                if (restorePoseAfterPossessJSON.val)
                {
                    c.snapshot.Restore();
                }
                c.snapshot = null;
            }

            if (c.handControl != null)
            {
                c.handControl.possessed = false;
            }
        }

        if (_navigationRigSnapshot != null)
        {
            _navigationRigSnapshot.Restore();
            _navigationRigSnapshot = null;
        }
    }
Ejemplo n.º 13
0
    public override void OnEnable()
    {
        base.OnEnable();

        _cameraCenter.localPosition = Vector3.zero;

        _headControlSnapshot         = FreeControllerV3Snapshot.Snap(_headControl);
        _headControl.canGrabPosition = false;
        _headControl.canGrabRotation = false;

        _navigationRigSnapshot = NavigationRigSnapshot.Snap();

        _previousInterpolation       = _headRigidbody.interpolation;
        _headRigidbody.interpolation = RigidbodyInterpolation.Interpolate;

        if (!allowPersonHeadRotationJSON.val)
        {
            GlobalSceneOptions.singleton.disableNavigation = true;
        }

        UpdateNavigationRig(true);
    }
Ejemplo n.º 14
0
    private void Activate()
    {
        if (!enabled)
        {
            activeJSON.valNoCallback = false;
            return;
        }

        SuperController.singleton.ClearPossess();

        try
        {
            foreach (var atom in SuperController.singleton.GetAtoms())
            {
                foreach (var storableId in atom.GetStorableIDs())
                {
                    if (!storableId.EndsWith("Embody"))
                    {
                        continue;
                    }
                    var storable = atom.GetStorableByID(storableId);
                    if (storable == null)
                    {
                        continue;
                    }
                    if (storable == this)
                    {
                        continue;
                    }
                    storable.SendMessage(nameof(EmbodyDeactivateImmediate), SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        catch (Exception e)
        {
            SuperController.LogError($"Embody: Failed deactivating other instances of Embody. {e}");
        }

        _enabledModules.Clear();

        foreach (var module in _modules.GetComponents <IEmbodyModule>())
        {
            if (module.skipChangeEnabledWhenActive)
            {
                continue;
            }
            if (!module.selectedJSON.val)
            {
                module.enabledJSON.val = false;
                continue;
            }

            if (module.Validate())
            {
                _enabledModules.Add(module);
            }
        }

        if (_restoreNavigationRigCoroutine != null)
        {
            StopCoroutine(_restoreNavigationRigCoroutine);
            _restoreNavigationRigCoroutine = null;
        }

        if (_navigationRigSnapshot == null && ((_context.trackers?.selectedJSON?.val ?? false) || (_context.passenger?.selectedJSON?.val ?? false)))
        {
            _navigationRigSnapshot = NavigationRigSnapshot.Snap();
        }

        if (_context.trackers?.restorePoseAfterPossessJSON.val == true)
        {
            _poseJSON = containingAtom.GetStorableIDs()
                        .Select(s => _context.containingAtom.GetStorableByID(s))
                        .Where(t => !t.exclude && t.gameObject.activeInHierarchy)
                        .Where(t => t is FreeControllerV3 || t is DAZBone)
                        .Select(t => t.GetJSON())
                        .Aggregate(new JSONArray(), (arrayJSON, storableJSON) =>
            {
                arrayJSON.Add(storableJSON);
                return(arrayJSON);
            });
        }

        foreach (var module in _enabledModules)
        {
            module.PreActivate();
        }

        foreach (var module in _enabledModules)
        {
            module.enabledJSON.val = true;
        }

        if (_context.automation?.autoArmForRecord.val ?? false)
        {
            Utilities.MarkForRecord(_context);
        }
    }
Ejemplo n.º 15
0
    private void Deactivate(bool asyncNavigationRigRestore)
    {
        if (!_active)
        {
            return;
        }
        _active = false;

        var wasActivatedManually = _activatedManually;

        _activatedManually       = false;
        activeJSON.valNoCallback = false;

        _context.automation.Reset();

        foreach (var module in _modulesList.AsEnumerable().Reverse())
        {
            if (module.skipChangeEnabledWhenActive)
            {
                continue;
            }
            module.enabledJSON.val = false;
        }

        foreach (var module in _enabledModules)
        {
            module.PostDeactivate();
        }

        _enabledModules.Clear();

        if (_poseJSON != null && _context.trackers?.restorePoseAfterPossessJSON.val == true)
        {
            foreach (var storableJSON in _poseJSON.Childs)
            {
                var storableId = storableJSON["id"].Value;
                if (string.IsNullOrEmpty(storableId))
                {
                    continue;
                }
                var storable = _context.containingAtom.GetStorableByID(storableId);
                if (storable == null)
                {
                    continue;
                }
                var controller = storable as FreeControllerV3;
                // NOTE: We use startedPossess to notify users of this (e.g. Timeline) that this is not a recordable movement
                if (controller != null)
                {
                    controller.startedPossess = true;
                }
                storable.PreRestore();
                storable.RestoreFromJSON(storableJSON.AsObject);
                storable.PostRestore();
                if (controller != null)
                {
                    controller.startedPossess = false;
                }
            }
            _poseJSON = null;
        }

        if (_restoreLeftHandEnabled != null)
        {
            SuperController.singleton.commonHandModelControl.leftHandEnabled = _restoreLeftHandEnabled.Value;
            _restoreLeftHandEnabled = null;
        }
        if (_restoreRightHandEnabled != null)
        {
            SuperController.singleton.commonHandModelControl.rightHandEnabled = _restoreRightHandEnabled.Value;
            _restoreRightHandEnabled = null;
        }

        if (!asyncNavigationRigRestore)
        {
            _navigationRigSnapshot?.Restore();
            _navigationRigSnapshot = null;
            return;
        }

        JSONStorableAction spawnAction;

        if (!wasActivatedManually && TryGetSpawnPoint(out spawnAction))
        {
            _navigationRigSnapshot?.Restore();
            _navigationRigSnapshot = null;
            if (spawnAction == null)
            {
                throw new NullReferenceException("Null spawn action");
            }
            spawnAction.actionCallback.Invoke();
            _restoreNavigationRigCoroutine = StartCoroutine(CallNextFrame(spawnAction.actionCallback.Invoke));
            return;
        }

        if (_navigationRigSnapshot != null)
        {
            _navigationRigSnapshot?.Restore();
            _restoreNavigationRigCoroutine = StartCoroutine(CallNextFrame(() =>
            {
                _navigationRigSnapshot?.Restore();
                _navigationRigSnapshot = null;
                if (_restoreNavigationRigCoroutine != null)
                {
                    StopCoroutine(_restoreNavigationRigCoroutine);
                    _restoreNavigationRigCoroutine = null;
                }
            }));
        }
    }
Ejemplo n.º 16
0
    private void Activate(bool activatedManually, bool force = false)
    {
        if (_active)
        {
            return;
        }

        if (!enabled || !containingAtom.on || (!force && activeToggle != null && !activeToggle.toggle.interactable))
        {
            SuperController.LogError("Embody: Cannot activate because the atom or plugin is currently disabled");
            activeJSON.valNoCallback = false;
            return;
        }

        try
        {
            foreach (var atom in SuperController.singleton.GetAtoms())
            {
                foreach (var storableId in atom.GetStorableIDs())
                {
                    if (!storableId.EndsWith("Embody"))
                    {
                        continue;
                    }
                    var storable = atom.GetStorableByID(storableId);
                    if (storable == null)
                    {
                        continue;
                    }
                    if (storable == this)
                    {
                        continue;
                    }
                    storable.SendMessage(nameof(EmbodyDeactivateImmediate), SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        catch (Exception e)
        {
            SuperController.LogError($"Embody: Failed deactivating other instances of Embody. {e}");
        }

        if (!TryInitializeModuleReferences())
        {
            activeJSON.valNoCallback = false;
            return;
        }

        _active = true;
        activeJSON.valNoCallback = true;
        _activatedManually       = activatedManually;

        SuperController.singleton.ClearPossess();

        if ((_context.trackers?.selectedJSON?.val ?? false) || (_context.passenger?.selectedJSON?.val ?? false))
        {
            _restoreLeftHandEnabled = SuperController.singleton.commonHandModelControl.leftHandEnabled;
            SuperController.singleton.commonHandModelControl.leftHandEnabled = false;
            _restoreRightHandEnabled = SuperController.singleton.commonHandModelControl.rightHandEnabled;
            SuperController.singleton.commonHandModelControl.rightHandEnabled = false;
        }

        _enabledModules.Clear();

        foreach (var module in _modulesList)
        {
            if (module.skipChangeEnabledWhenActive)
            {
                continue;
            }
            if (!module.selectedJSON.val)
            {
                module.enabledJSON.val = false;
                continue;
            }

            if (module.Validate())
            {
                _enabledModules.Add(module);
            }
        }

        if (_restoreNavigationRigCoroutine != null)
        {
            StopCoroutine(_restoreNavigationRigCoroutine);
            _restoreNavigationRigCoroutine = null;
        }

        if (_navigationRigSnapshot == null && ((_context.trackers?.selectedJSON?.val ?? false) || (_context.passenger?.selectedJSON?.val ?? false)))
        {
            _navigationRigSnapshot = NavigationRigSnapshot.Snap();
        }

        if ((_context.trackers?.selectedJSON?.val ?? false) && _context.trackers?.restorePoseAfterPossessJSON.val == true)
        {
            _poseJSON = containingAtom.GetStorableIDs()
                        .Select(s => _context.containingAtom.GetStorableByID(s))
                        .Where(t => !t.exclude && t.gameObject.activeInHierarchy)
                        .Where(t => t is FreeControllerV3 || t is DAZBone)
                        .Select(t => t.GetJSON())
                        .Aggregate(new JSONArray(), (arrayJSON, storableJSON) =>
            {
                arrayJSON.Add(storableJSON);
                return(arrayJSON);
            });
        }

        foreach (var module in _enabledModules)
        {
            module.PreActivate();
        }

        foreach (var module in _enabledModules)
        {
            module.enabledJSON.val = true;
        }

        if (_context.automation?.autoArmForRecord.val ?? false)
        {
            Utilities.MarkForRecord(_context);
        }
    }