修改
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Rokid.UXR.Interaction;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.RKTools
|
||||
@@ -19,7 +17,6 @@ namespace Stary.Evo.RKTools
|
||||
float TouchScale = 1.2f)
|
||||
{
|
||||
Collider ObjectCollider = Touchedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
@@ -27,15 +24,33 @@ namespace Stary.Evo.RKTools
|
||||
ObjectCollider = Touchedobject.AddComponent<BoxCollider>();
|
||||
ObjectCollider.isTrigger = true;
|
||||
}
|
||||
#if Evo_Rokid
|
||||
var GrabInteractable = Touchedobject.GetComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable = Touchedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable = Touchedobject.AddComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
GrabInteractable.rate = TouchScale;
|
||||
}
|
||||
GrabInteractable.OnHoverBegin.AddListener(() => TouchEvent?.Invoke(Touchedobject));
|
||||
#elif Evo_Xreal
|
||||
var GrabInteractable =
|
||||
Touchedobject.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable =
|
||||
Touchedobject.AddComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
GrabInteractable.smoothScale = true;
|
||||
GrabInteractable.smoothScaleAmount = TouchScale; // 低数值 = 高惯性
|
||||
GrabInteractable.tightenScale = 0.1f; // 强平滑效果
|
||||
}
|
||||
GrabInteractable.throwOnDetach = false;
|
||||
GrabInteractable.GetComponent<Rigidbody>().useGravity = false;
|
||||
GrabInteractable.hoverEntered.AddListener((a) => TouchEvent?.Invoke(Touchedobject));
|
||||
|
||||
ObjectCollider.enabled = true;
|
||||
GrabInteractable.OnHoverBegin.AddListener(() => TouchEvent?.Invoke(Touchedobject));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,13 +85,25 @@ namespace Stary.Evo.RKTools
|
||||
/// <param name="Touchedobject">被触碰物体</param>
|
||||
public static void ObjectRemoveTouchEvent(this GameObject Touchedobject)
|
||||
{
|
||||
GrabInteractable GrabInteractable = Touchedobject.GetComponent<GrabInteractable>();
|
||||
#if Evo_Rokid
|
||||
Rokid.UXR.Interaction.GrabInteractable GrabInteractable =
|
||||
Touchedobject.GetComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHoverBegin.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
#elif Evo_Xreal
|
||||
var GrabInteractable =
|
||||
Touchedobject.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.hoverEntered.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -91,10 +118,12 @@ namespace Stary.Evo.RKTools
|
||||
public static void objectAddDrag(this GameObject Dragedobject, System.Action<GameObject> DragingEvent = null,
|
||||
float DragScale = 1.2f)
|
||||
{
|
||||
#if Evo_Rokid
|
||||
Collider ObjectCollider = Dragedobject.GetComponent<Collider>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
Rokid.UXR.Interaction.GrabInteractable GrabInteractable =
|
||||
Dragedobject.GetComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
Rigidbody Rigidbody = Dragedobject.GetComponent<Rigidbody>();
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
Rokid.UXR.Interaction.Throwable Throwable = Dragedobject.GetComponent<Rokid.UXR.Interaction.Throwable>();
|
||||
|
||||
// 原有的组件设置优先级最高
|
||||
if (ObjectCollider == null)
|
||||
@@ -105,7 +134,7 @@ namespace Stary.Evo.RKTools
|
||||
|
||||
if (GrabInteractable == null)
|
||||
{
|
||||
GrabInteractable = Dragedobject.AddComponent<GrabInteractable>();
|
||||
GrabInteractable = Dragedobject.AddComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
GrabInteractable.rate = DragScale;
|
||||
}
|
||||
|
||||
@@ -117,10 +146,27 @@ namespace Stary.Evo.RKTools
|
||||
|
||||
if (Throwable == null)
|
||||
{
|
||||
Throwable = Dragedobject.AddComponent<Throwable>();
|
||||
Throwable = Dragedobject.AddComponent<Rokid.UXR.Interaction.Throwable>();
|
||||
}
|
||||
|
||||
GrabInteractable.OnHeldUpdate.AddListener(() => DragingEvent?.Invoke(Dragedobject));
|
||||
#elif Evo_Xreal
|
||||
var Throwable =
|
||||
Dragedobject.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
|
||||
if (Throwable == null)
|
||||
{
|
||||
Throwable =
|
||||
Dragedobject.AddComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
Throwable.throwOnDetach = true;
|
||||
Throwable.throwVelocityScale = DragScale; // 低数值 = 高惯性
|
||||
}
|
||||
|
||||
Throwable.GetComponent<Rigidbody>().useGravity = false;
|
||||
Throwable.selectEntered.AddListener((a) => DragingEvent?.Invoke(Dragedobject));
|
||||
|
||||
Throwable.enabled = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,14 +191,26 @@ namespace Stary.Evo.RKTools
|
||||
|
||||
public static void objectRemoveDrag(this GameObject Dragedobject)
|
||||
{
|
||||
Throwable Throwable = Dragedobject.GetComponent<Throwable>();
|
||||
GrabInteractable GrabInteractable = Dragedobject.GetComponent<GrabInteractable>();
|
||||
#if Evo_Rokid
|
||||
Rokid.UXR.Interaction.Throwable Throwable = Dragedobject.GetComponent<Rokid.UXR.Interaction.Throwable>();
|
||||
Rokid.UXR.Interaction.GrabInteractable GrabInteractable =
|
||||
Dragedobject.GetComponent<Rokid.UXR.Interaction.GrabInteractable>();
|
||||
if (Throwable != null) Object.Destroy(Throwable);
|
||||
if (GrabInteractable != null)
|
||||
{
|
||||
GrabInteractable.OnHeldUpdate.RemoveAllListeners();
|
||||
Object.Destroy(GrabInteractable);
|
||||
}
|
||||
#elif Evo_Xreal
|
||||
var Throwable =
|
||||
Dragedobject.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactables.XRGrabInteractable>();
|
||||
|
||||
if (Throwable != null)
|
||||
{
|
||||
Throwable.selectEntered.RemoveAllListeners();
|
||||
Object.Destroy(Throwable);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user