Exemplo n.º 1
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();
    }
Exemplo n.º 2
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;
        }
    }
Exemplo n.º 3
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;
        }
    }
Exemplo n.º 4
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;
        }
    }
Exemplo n.º 5
0
    public override void OnDisable()
    {
        base.OnDisable();

        GlobalSceneOptions.singleton.disableNavigation = false;

        _navigationRigSnapshot?.Restore();

        if (_headRigidbody != null)
        {
            _headRigidbody.interpolation = _previousInterpolation;
        }

        if (_headControlSnapshot != null)
        {
            _headControlSnapshot.Restore();
            _headControlSnapshot = null;
        }

        _currentPositionVelocity = Vector3.zero;
        _currentRotationVelocity = Quaternion.identity;
    }
Exemplo n.º 6
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;
                }
            }));
        }
    }