1.需要使用Rhibox Mr头盔开发Mr项目,支持头盔与平板的多人协同.官方提供一个案例,可以满足使用手柄移动物体,在头盔和平板上做同步,但官方的脚本要挂的有点多,不是很容易,编写一个脚本来一键设置.
2.使用的是2018版本的,
链接https://gitee.com/PolyEngine_Ent/RhinoX-SDK
3.像官方的一个物体上要挂4个脚本 ,还要改变物体的laye层级,如果要移动的物体多了就很不人性化.
3.
为了省力气,编写一个自动挂载脚本的工具:
先创建一个RhinoxSelectionGa脚本放到Editor文件夹下.添加一个入口,
其中 Selection.gameObjects获取在Hierachy窗口下选中的gameobject
[MenuItem("资源管理 /设置Rhinox移动Transform(官方脚本)")]
static void AddRhinoxMoveTransform()
{
List<GameObject> listGo = Selection.gameObjects.ToList<GameObject>();
for (int i = 0; i < listGo.Count; i++)
{
AddCompontent(listGo[i]);
}
}
最后是对 AddCompontent方法的实现:
里面都是一些简单的给物体添加脚本,
以及对Grabable脚本里面一些参数的修改. grabale.AlignMode选的是不跟手移动
对选中的gameobject设置层级
MeshCollider碰撞盒相对于其他类型的碰撞盒更消耗资源,可以看项目修改
private static void AddCompontent(GameObject gameObject)
{
if (gameObject.GetComponent<Outline>() == null)
gameObject.AddComponent<Outline>();
if (gameObject.GetComponent<OutlineOnTouch>() == null)
gameObject.AddComponent<OutlineOnTouch>();
if (gameObject.GetComponent<Grabable>() == null)
{
Grabable grabale = gameObject.AddComponent<Grabable>();
grabale.AlignMode = Grabable.AlignmentMode.DontAlign;
Transform Tran = gameObject.transform.Find("NullGa");
GameObject ga;
if (!Tran)
{
ga = new GameObject();
ga.name = "NullGa";
ga.transform.parent = gameObject.transform;
}
else
ga = Tran.gameObject;
grabale.m_AnchorTransform = ga.transform;
}
if (gameObject.GetComponent<MeshCollider>() == null)
gameObject.AddComponent<MeshCollider>();
gameObject.SetLayerRecursive(8,true);
}
最后:本来想连最后的网路同步SyncGameObjectRoot下的操作也添加到上面的方法里面,最后看的不是很懂,就这样吧,记录一下代码,省的瑕疵还要重新写,毕竟懒.能粘贴就不写