Jtro的技术分享:关于Htc_vive开发中的问题解决方案——
这个问题是挺常见的,我当时开发产品被测试的时候。场景中的某个物体由于种种原因拿起之后会掉下来,接着又有地面不对齐等一系列问题,所以我就想着把这个问题解决了。
然后通过各种修改源码,最后的效果仍是不是乐观。后来求助一位做了许久的VR 的朋友,给了我一个脚本。然后通过拖拽方法的方法,解决了问题。在这里要好好感谢这位朋友,帮了我大忙。
、、、
using UnityEngine;
using System.Collections;
using VRTK;
using UnityEngine.Events;
public class VRTK_ObjCallBack : MonoBehaviour
{
VRTK_InteractableObject IO;
[System.Serializable]
public class ButtonEvents
{
public UnityEvent InteractableObjectGrabbed;
public UnityEvent InteractableObjectUngrabbed;
public UnityEvent InteractableObjectUsed;
public UnityEvent InteractableObjectUnused;
}
public ButtonEvents events;
// Use this for initialization
void Start()
{
IO = GetComponent();
IO.InteractableObjectGrabbed += IO_InteractableObjectGrabbed;
IO.InteractableObjectUngrabbed += IO_InteractableObjectUngrabbed;
IO.InteractableObjectUsed += IO_InteractableObjectUsed;
IO.InteractableObjectUnused+= IO_InteractableObjectUnused;
}
void IO_InteractableObjectUsed(object sender, InteractableObjectEventArgs e)
{
if (events.InteractableObjectUsed != null)
events.InteractableObjectUsed.Invoke();
}
void IO_InteractableObjectGrabbed(object sender, InteractableObjectEventArgs e)
{
if (events.InteractableObjectGrabbed != null)
events.InteractableObjectGrabbed.Invoke();
}
void IO_InteractableObjectUngrabbed(object sender, InteractableObjectEventArgs e)
{
if (events.InteractableObjectUngrabbed != null)
events.InteractableObjectUngrabbed.Invoke();
}
void IO_InteractableObjectUnused(object sender, InteractableObjectEventArgs e)
{
if (events.InteractableObjectUnused!= null)
events.InteractableObjectUnused.Invoke();
}
#if UNITY_EDITOR
void OnMouseDown()
{
if (events.InteractableObjectUsed != null)
events.InteractableObjectUsed.Invoke();
}
#endif
}
、、、