protected virtual void OnEnable() { if (head == null && NxrViewer.Instance.GetHead() != null) { head = NxrViewer.Instance.GetHead().transform; } nvrTrackedDevice = GetComponent <NxrTrackedDevice>(); UpdateTorsoDirection(true); OnControllerInputUpdated(); }
public GameObject GetControllerLaserDot() { if (trackedDevice == null) { trackedDevice = GetComponent <NxrTrackedDevice>(); } if (trackedDevice == null) { return(null); } if (trackedDevice.GetLaserPointer() == null) { return(null); } return(trackedDevice.GetLaserPointer().GetLosDot()); }
public NxrLaserPointer GetControllerLaser() { if (trackedDevice == null) { trackedDevice = GetComponent <NxrTrackedDevice>(); } if (trackedDevice == null) { return(null); } if (trackedDevice.GetLaserPointer() == null) { return(null); } return(trackedDevice.GetLaserPointer()); }
public void CreateControllerModel(string objName, InteractionManager.ControllerConfig mControllerConfig) { string objPath = mControllerConfig.objPath; if (objPath == null) { return; } DestroyChild(mTransform); GameObject go = new GameObject(objName); NxrLaserPointer mNxrLaserPointer = go.AddComponent <NxrLaserPointer>(); mNxrLaserPointer.deviceType = NxrInstantNativeApi.NibiruDeviceType.RightController; go.transform.SetParent(transform); go.transform.localScale = Vector3.one; go.transform.localPosition = new Vector3(0, 0, 0); go.transform.localRotation = new Quaternion(0, 0, 0, 1); GameObject modelGOParent = new GameObject("model_P"); modelGOParent.transform.SetParent(go.transform); modelGOParent.transform.localScale = new Vector3(-1, 1, 1); modelGOParent.transform.localPosition = new Vector3(0, 0, 0); modelGOParent.transform.localRotation = new Quaternion(0, 0, 0, 1); GameObject modelGO = new GameObject("model"); modelGO.transform.SetParent(modelGOParent.transform); modelGO.transform.localScale = new Vector3(mControllerConfig.modelScale[0] , mControllerConfig.modelScale[1], mControllerConfig.modelScale[2]); modelGO.transform.localRotation = Quaternion.Euler(mControllerConfig.modelRotation[0], mControllerConfig.modelRotation[1], mControllerConfig.modelRotation[2]); modelGO.transform.localPosition = new Vector3(mControllerConfig.modelPosition[0] , mControllerConfig.modelPosition[1], mControllerConfig.modelPosition[2]); // string objPath = "/system/etc/Objs/housing_bott.obj"; Debug.Log("objPath=" + objPath); ObjModelLoader mObjModelLoader = GetComponent <ObjModelLoader>(); if (mObjModelLoader == null) { gameObject.AddComponent <ObjMaterial>(); mObjModelLoader = gameObject.AddComponent <ObjModelLoader>(); } mObjModelLoader.LoadObjFile(objPath, modelGO.transform); GameObject powerGO = new GameObject("Power"); powerGO.transform.SetParent(go.transform); MeshRenderer powerMeshRenderer = powerGO.AddComponent <MeshRenderer>(); Mesh quadMesh = new Mesh(); quadMesh.name = "QUAD"; float quadSize = 0.5f; quadMesh.vertices = new Vector3[] { new Vector3(-1 * quadSize, -1 * quadSize, 0), new Vector3(-1 * quadSize, 1 * quadSize, 0), new Vector3(1 * quadSize, 1 * quadSize, 0), new Vector3(1 * quadSize, -1 * quadSize, 0) }; quadMesh.uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) }; int[] triangles = { 0, 1, 2, 0, 2, 3 }; quadMesh.triangles = triangles; powerGO.AddComponent <MeshFilter>().mesh = quadMesh; powerGO.AddComponent <MeshCollider>(); powerGO.AddComponent <NibiruControllerPower>(); powerGO.transform.localPosition = new Vector3(mControllerConfig.batteryPosition[0], mControllerConfig.batteryPosition[1] , mControllerConfig.batteryPosition[2]); powerGO.transform.localRotation = Quaternion.Euler(mControllerConfig.batteryRotation[0], mControllerConfig.batteryRotation[1] , mControllerConfig.batteryRotation[2]); powerGO.transform.localScale = new Vector3(mControllerConfig.batteryScale[0], mControllerConfig.batteryScale[1] , mControllerConfig.batteryScale[2]); // 射线起点 mNxrLaserPointer.SetHolderLocalPosition(new Vector3(mControllerConfig.rayStartPosition[0], mControllerConfig.rayStartPosition[1], mControllerConfig.rayStartPosition[2])); NxrTrackedDevice trackedDevice = GetComponent <NxrTrackedDevice>(); if (trackedDevice != null) { trackedDevice.ReloadLaserPointer(mNxrLaserPointer); } //close NxrViewer.Instance.SwitchControllerMode(true); Debug.Log("HideGaze.ForceUseReticle2"); CreateControllerTips(go.transform); }
//创建手柄 public void CreateControllerHandler() { #if UNITY_EDITOR DebugCtrlModelInEditor = true; #endif if (isNeedCustomModel) { if (string.IsNullOrEmpty(customModelPrefabName)) { Debug.LogError("The path of the custom handle model prefab is wrong"); } else { DestroyChild(mTransform); var customModelPrefab = Resources.Load <GameObject>(string.Concat("CustomModelPrefabs/", customModelPrefabName)); if (!customModelPrefab) { Debug.LogError("The prefab was not created successfully"); } else { var customModel = Instantiate(customModelPrefab); customModel.transform.parent = mTransform; var childTrans = customModel.transform.GetChild(0); var prefabTrackDevice = childTrans.GetComponent <NxrTrackedDevice>(); prefabTrackDevice.enabled = false; var nxrTrackedDevice = GetComponent <NxrTrackedDevice>(); if (nxrTrackedDevice != null) { nxrTrackedDevice.ReloadLaserPointer(childTrans.GetComponent <NxrLaserPointer>()); } NxrViewer.Instance.SwitchControllerMode(true); } return; } } if (DebugCtrlModelInEditor || (InteractionManager.IsInteractionSDKEnabled() && InteractionManager.IsSupportControllerModel())) { Debug.Log("CreateControllerModel.Controller3Dof..."); CreateControllerModel("Controller3Dof", InteractionManager.GetControllerConfig()); return; } string name = GetControllerName(); Debug.Log("CreateControllerHandler." + name); DestroyChild(mTransform); GameObject handlerPrefabs = Resources.Load <GameObject>(string.Concat("Controller/", name)); GameObject objHandler = Instantiate(handlerPrefabs); objHandler.transform.parent = mTransform; objHandler.transform.localPosition = new Vector3(0, 0, 0); objHandler.transform.localRotation = new Quaternion(0, 0, 0, 1); objHandler.transform.localScale = Vector3.one / 2; NxrTrackedDevice trackedDevice = GetComponent <NxrTrackedDevice>(); if (trackedDevice != null) { trackedDevice.ReloadLaserPointer(objHandler.GetComponent <NxrLaserPointer>()); } //close NxrViewer.Instance.SwitchControllerMode(true); Debug.Log("HideGaze.ForceUseReticle"); }