- :将需要进行描边的物体上加上VRTK_OutlineObjectCopyHighlighter组件。
- 创建射线监听脚本.
public VRTK_Pointer leftContrlPointer;//拿到pointe组件
//注册射线事件
protected virtual void OnEnable()
{
pointer = (pointer == null ? GetComponent<VRTK_DestinationMarker>() : pointer);
if (pointer != null)
{
pointer.DestinationMarkerEnter += DestinationMarkerEnter;
pointer.DestinationMarkerHover += DestinationMarkerHover;
pointer.DestinationMarkerExit += DestinationMarkerExit;
//当目标标记在场景中活动时发出,以确定最后的目的地位置(用于选择和传送)
pointer.DestinationMarkerSet += DestinationMarkerSet;
}
else
{
VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTKExample_PointerObjectHighlighterActivator", "VRTK_DestinationMarker", "the Controller Alias"));
}
}
//移除事件
protected virtual void OnDisable()
{
if (pointer != null)
{
pointer.DestinationMarkerEnter -= DestinationMarkerEnter;
pointer.DestinationMarkerHover -= DestinationMarkerHover;
pointer.DestinationMarkerExit -= DestinationMarkerExit;
pointer.DestinationMarkerSet -= DestinationMarkerSet;
}
}
设置模型高亮描边方法:
/// 模型高亮
/// </summary>
/// <param name="target"></param>
/// <param name="color"></param>
public void HighLight(Transform target,Color color)
{
VRTK_BaseHighlighter highlighter=target != null ? target.GetComponent<VRTK_BaseHighlighter>() : null;
if (highlighter!=null)
{
highlighter.Initialise();
if (color!=Color.clear)
{
highlighter.Highlight(color);
}
else
{
highlighter.Unhighlight();
}
}
}