Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
public class AutoMoveTowardsTargetProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
[SerializeField]
|
||||
private PoseTravelData _travellingData = PoseTravelData.DEFAULT;
|
||||
public PoseTravelData TravellingData
|
||||
{
|
||||
get
|
||||
{
|
||||
return _travellingData;
|
||||
}
|
||||
set
|
||||
{
|
||||
_travellingData = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField, Interface(typeof(IPointableElement))]
|
||||
private UnityEngine.Object _pointableElement;
|
||||
public IPointableElement PointableElement { get; private set; }
|
||||
|
||||
private bool _started;
|
||||
|
||||
public List<AutoMoveTowardsTarget> _movers = new List<AutoMoveTowardsTarget>();
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
PointableElement = _pointableElement as IPointableElement;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.BeginStart(ref _started);
|
||||
this.AssertField(_pointableElement, nameof(_pointableElement));
|
||||
this.EndStart(ref _started);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
for (int i = _movers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
AutoMoveTowardsTarget mover = _movers[i];
|
||||
if (mover.Aborting)
|
||||
{
|
||||
mover.Tick();
|
||||
if (mover.Stopped)
|
||||
{
|
||||
_movers.Remove(mover);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
AutoMoveTowardsTarget mover = new AutoMoveTowardsTarget(_travellingData, PointableElement);
|
||||
mover.WhenAborted += HandleAborted;
|
||||
return mover;
|
||||
}
|
||||
|
||||
private void HandleAborted(AutoMoveTowardsTarget mover)
|
||||
{
|
||||
mover.WhenAborted -= HandleAborted;
|
||||
_movers.Add(mover);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllAutoMoveTowardsTargetProvider(IPointableElement pointableElement)
|
||||
{
|
||||
InjectPointableElement(pointableElement);
|
||||
}
|
||||
|
||||
public void InjectPointableElement(IPointableElement pointableElement)
|
||||
{
|
||||
PointableElement = pointableElement;
|
||||
_pointableElement = pointableElement as UnityEngine.Object;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This IMovement stores the initial Pose, and in case
|
||||
/// of an aborted movement it will finish it itself.
|
||||
/// </summary>
|
||||
public class AutoMoveTowardsTarget : IMovement
|
||||
{
|
||||
private PoseTravelData _travellingData;
|
||||
private IPointableElement _pointableElement;
|
||||
|
||||
public Pose Pose => _tween.Pose;
|
||||
public bool Stopped => _tween == null || _tween.Stopped;
|
||||
public bool Aborting { get; private set; }
|
||||
|
||||
public Action<AutoMoveTowardsTarget> WhenAborted = delegate { };
|
||||
|
||||
private UniqueIdentifier _identifier;
|
||||
public int Identifier => _identifier.ID;
|
||||
|
||||
private Tween _tween;
|
||||
private Pose _target;
|
||||
private Pose _source;
|
||||
private bool _eventRegistered;
|
||||
|
||||
public AutoMoveTowardsTarget(PoseTravelData travellingData, IPointableElement pointableElement)
|
||||
{
|
||||
_identifier = UniqueIdentifier.Generate();
|
||||
_travellingData = travellingData;
|
||||
_pointableElement = pointableElement;
|
||||
}
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
AbortSelfAligment();
|
||||
_target = target;
|
||||
_tween = _travellingData.CreateTween(_source, target);
|
||||
if (!_eventRegistered)
|
||||
{
|
||||
_pointableElement.WhenPointerEventRaised += HandlePointerEventRaised;
|
||||
_eventRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
_target = target;
|
||||
_tween.UpdateTarget(_target);
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose pose)
|
||||
{
|
||||
if (_eventRegistered)
|
||||
{
|
||||
_pointableElement.WhenPointerEventRaised -= HandlePointerEventRaised;
|
||||
_eventRegistered = false;
|
||||
}
|
||||
|
||||
_source = pose;
|
||||
if (_tween != null && !_tween.Stopped)
|
||||
{
|
||||
GeneratePointerEvent(PointerEventType.Hover);
|
||||
GeneratePointerEvent(PointerEventType.Select);
|
||||
Aborting = true;
|
||||
WhenAborted.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
_tween.Tick();
|
||||
if (Aborting)
|
||||
{
|
||||
GeneratePointerEvent(PointerEventType.Move);
|
||||
if (_tween.Stopped)
|
||||
{
|
||||
AbortSelfAligment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePointerEventRaised(PointerEvent evt)
|
||||
{
|
||||
if (evt.Type == PointerEventType.Select || evt.Type == PointerEventType.Unselect)
|
||||
{
|
||||
AbortSelfAligment();
|
||||
}
|
||||
}
|
||||
|
||||
private void AbortSelfAligment()
|
||||
{
|
||||
if (Aborting)
|
||||
{
|
||||
Aborting = false;
|
||||
|
||||
GeneratePointerEvent(PointerEventType.Unselect);
|
||||
GeneratePointerEvent(PointerEventType.Unhover);
|
||||
}
|
||||
}
|
||||
|
||||
private void GeneratePointerEvent(PointerEventType pointerEventType)
|
||||
{
|
||||
PointerEvent evt = new PointerEvent(Identifier, pointerEventType, Pose);
|
||||
_pointableElement.ProcessPointerEvent(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4c6cba82e9f3c84f80041e0d2741ef6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
/// <summary>
|
||||
/// This IPoseMovement constantly moves the pose at a fixed rate
|
||||
/// towards the target.
|
||||
/// </summary>
|
||||
public class FollowTargetProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
[SerializeField]
|
||||
private float _speed = 5f;
|
||||
|
||||
private Transform _space;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_space = this.transform;
|
||||
}
|
||||
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
return new FollowTarget(_speed, _space);
|
||||
}
|
||||
}
|
||||
|
||||
public class FollowTarget : IMovement
|
||||
{
|
||||
private float _speed;
|
||||
private Transform _space;
|
||||
|
||||
public Pose Pose => ToWorld(_localPose);
|
||||
public bool Stopped => false;
|
||||
|
||||
private Pose _localTarget;
|
||||
private Pose _localPose;
|
||||
|
||||
private float _startTime;
|
||||
|
||||
private const float ROTATION_SPEED_FACTOR = 50f;
|
||||
|
||||
public FollowTarget(float speed, Transform space)
|
||||
{
|
||||
_speed = speed;
|
||||
_space = space;
|
||||
}
|
||||
|
||||
private Pose ToLocal(in Pose pose)
|
||||
{
|
||||
Vector3 localPos = _space.InverseTransformPoint(pose.position);
|
||||
Quaternion localRot = Quaternion.Inverse(_space.rotation) * pose.rotation;
|
||||
|
||||
return new Pose(localPos, localRot);
|
||||
}
|
||||
|
||||
private Pose ToWorld(in Pose pose)
|
||||
{
|
||||
Vector3 worldPos = _space.TransformPoint(pose.position);
|
||||
Quaternion worldRot = _space.rotation * pose.rotation;
|
||||
return new Pose(worldPos, worldRot);
|
||||
}
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
_startTime = Time.time;
|
||||
_localTarget = ToLocal(target);
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
_localTarget = ToLocal(target);
|
||||
Tick();
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose source)
|
||||
{
|
||||
_localPose = ToLocal(source);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
|
||||
float now = Time.time;
|
||||
float delta = (now - _startTime) * _speed;
|
||||
_startTime = now;
|
||||
|
||||
_localPose.position = Vector3.MoveTowards(_localPose.position, _localTarget.position, delta);
|
||||
_localPose.rotation = Quaternion.RotateTowards(_localPose.rotation, _localTarget.rotation, delta * ROTATION_SPEED_FACTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4120d88f4ba2a3f48989ce4b2ff1e317
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
public interface IMovement
|
||||
{
|
||||
Pose Pose { get; }
|
||||
bool Stopped { get; }
|
||||
|
||||
void MoveTo(Pose target);
|
||||
void UpdateTarget(Pose target);
|
||||
void StopAndSetPose(Pose pose);
|
||||
void Tick();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d0a5c95721146547bbb1d653e6b66b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
public interface IMovementProvider
|
||||
{
|
||||
IMovement CreateMovement();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 788e7bf9a580f7945ba725de5a4bdc91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
public class MoveAtSourceProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
return new MoveRelativeToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public class MoveRelativeToTarget : IMovement
|
||||
{
|
||||
public Pose Pose => _current;
|
||||
public bool Stopped => true;
|
||||
|
||||
private Pose _current = Pose.identity;
|
||||
private Pose _originalTarget;
|
||||
private Pose _originalSource;
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
_originalTarget = target;
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
Pose grabberDelta = PoseUtils.Delta(_originalTarget, target);
|
||||
PoseUtils.Multiply(_originalSource, grabberDelta, ref _current);
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose source)
|
||||
{
|
||||
_current = _originalSource = source;
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8894220c202ef0c46a4446465edae43d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
public class MoveFromTargetProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
return new MoveFromTarget();
|
||||
}
|
||||
}
|
||||
|
||||
public class MoveFromTarget : IMovement
|
||||
{
|
||||
public Pose Pose { get; private set; } = Pose.identity;
|
||||
public bool Stopped => true;
|
||||
|
||||
public void StopMovement()
|
||||
{
|
||||
}
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
Pose = target;
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
Pose = target;
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose source)
|
||||
{
|
||||
Pose = source;
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 953054d108799b942815afb3405983ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
public class MoveTowardsTargetProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
[SerializeField]
|
||||
private PoseTravelData _travellingData = PoseTravelData.FAST;
|
||||
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
return new MoveTowardsTarget(_travellingData);
|
||||
}
|
||||
|
||||
#region Inject
|
||||
public void InjectAllMoveTowardsTargetProvider(PoseTravelData travellingData)
|
||||
{
|
||||
InjectTravellingData(travellingData);
|
||||
}
|
||||
|
||||
public void InjectTravellingData(PoseTravelData travellingData)
|
||||
{
|
||||
_travellingData = travellingData;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MoveTowardsTarget : IMovement
|
||||
{
|
||||
private PoseTravelData _travellingData;
|
||||
|
||||
public Pose Pose => _tween.Pose;
|
||||
public bool Stopped => _tween != null && _tween.Stopped;
|
||||
|
||||
private Tween _tween;
|
||||
private Pose _source;
|
||||
private Pose _target;
|
||||
|
||||
public MoveTowardsTarget(PoseTravelData travellingData)
|
||||
{
|
||||
_travellingData = travellingData;
|
||||
}
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
_target = target;
|
||||
_tween = _travellingData.CreateTween(_source, target);
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
if (_target != target)
|
||||
{
|
||||
_target = target;
|
||||
_tween.UpdateTarget(_target);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose pose)
|
||||
{
|
||||
_source = pose;
|
||||
_tween?.StopAndSetPose(_source);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
_tween.Tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b04d39d26e3b7804e9963f738ef7bfe1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction.HandGrab
|
||||
{
|
||||
public class ObjectPullProvider : MonoBehaviour, IMovementProvider
|
||||
{
|
||||
[SerializeField]
|
||||
[Min(0f)]
|
||||
private float _speed = 1f;
|
||||
public float Speed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _speed;
|
||||
}
|
||||
set
|
||||
{
|
||||
_speed = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Min(0f)]
|
||||
private float _deadZone = 0.02f;
|
||||
public float DeadZone
|
||||
{
|
||||
get
|
||||
{
|
||||
return _deadZone;
|
||||
}
|
||||
set
|
||||
{
|
||||
_deadZone = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IMovement CreateMovement()
|
||||
{
|
||||
return new ObjectPull(_speed, _deadZone);
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectPull : IMovement
|
||||
{
|
||||
private float _speed = 1f;
|
||||
private float _deadZone = 0f;
|
||||
|
||||
public Pose Pose => _current;
|
||||
public bool Stopped => _reachedGrabber;
|
||||
|
||||
private Pose _current = Pose.identity;
|
||||
private Pose _grabberStartPose;
|
||||
private Pose _grabbableStartPose;
|
||||
private Pose _target;
|
||||
|
||||
private Plane _pullingPlane;
|
||||
|
||||
private Vector3 _translationDelta = Vector3.zero;
|
||||
|
||||
private float _lastTime;
|
||||
private float _originalDistance;
|
||||
|
||||
private bool _reachedGrabber = false;
|
||||
|
||||
public ObjectPull(float speed, float deadZone)
|
||||
{
|
||||
_speed = speed;
|
||||
_deadZone = deadZone;
|
||||
}
|
||||
|
||||
public void MoveTo(Pose target)
|
||||
{
|
||||
_target = _grabberStartPose = target;
|
||||
_current = _grabbableStartPose;
|
||||
_lastTime = Time.time;
|
||||
_reachedGrabber = false;
|
||||
Vector3 grabDir = (_grabbableStartPose.position - _grabberStartPose.position);
|
||||
_originalDistance = grabDir.magnitude;
|
||||
_pullingPlane = new Plane(grabDir.normalized, _grabberStartPose.position);
|
||||
}
|
||||
|
||||
public void UpdateTarget(Pose target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public void StopAndSetPose(Pose source)
|
||||
{
|
||||
_grabbableStartPose = source;
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (_reachedGrabber)
|
||||
{
|
||||
_current = _target;
|
||||
return;
|
||||
}
|
||||
|
||||
float timeDelta = (Time.time - _lastTime);
|
||||
_lastTime = Time.time;
|
||||
float posDelta = _pullingPlane.GetDistanceToPoint(_target.position);
|
||||
if (Mathf.Abs(posDelta) < _deadZone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 direction = (_current.position - _target.position).normalized;
|
||||
_translationDelta = direction * posDelta * _speed * timeDelta;
|
||||
float remainingDistance = Vector3.Distance(_current.position, _target.position);
|
||||
if (remainingDistance < _translationDelta.magnitude)
|
||||
{
|
||||
_reachedGrabber = true;
|
||||
_current = _target;
|
||||
}
|
||||
else
|
||||
{
|
||||
_current.position += _translationDelta;
|
||||
float currentDistance = Vector3.Distance(_current.position, _target.position);
|
||||
float progress = 1f - Mathf.Clamp01(currentDistance / _originalDistance);
|
||||
_current.rotation = Quaternion.Slerp(_grabbableStartPose.rotation, _target.rotation, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c42b92a6b90197042be7c25c2a319e55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user