Пример #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);
    }
Пример #2
0
 public void TryBindTrackers()
 {
     if (Bind(headMotionControl))
     {
         StartCoroutine(OnEnableCo(NavigationRigSnapshot.Snap()));
     }
     Bind(leftHandMotionControl);
     Bind(rightHandMotionControl);
     BindFingers();
     foreach (var motionControl in viveTrackers)
     {
         Bind(motionControl);
     }
 }
Пример #3
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);
        }
    }
Пример #4
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);
    }
Пример #5
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);
        }
    }
Пример #6
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);
        }
    }