private void LoadControllerModel(NxrInstantNativeApi.HoloeverDeviceType holoeverDeviceType, string objName)
        {
            if (InteractionManager.IsSupportControllerModel())
            {
                if (NxrPlayerCtrl.Instance.isNeedCustomModel)
                {
                    if (string.IsNullOrEmpty(NxrPlayerCtrl.Instance.customModelPrefabName))
                    {
                        Debug.LogError("The path of the custom handle model prefab is wrong");
                    }
                    else
                    {
                        LoadDefaultCtrl(NxrPlayerCtrl.Instance.customModelPrefabName);
                        return;
                    }
                }

                InteractionManager.ControllerConfig mControllerConfig = InteractionManager.GetControllerConfig();
                CreateControllerModel(holoeverDeviceType, objName, mControllerConfig);
            }
            else
            {
                LoadDefaultCtrl("CustomModel");
            }
        }
Example #2
0
        /// <summary>
        /// Get and Cache Controller Prompt UI.
        /// </summary>
        private void RefreshSprites()
        {
            InteractionManager.ControllerConfig controllerConfig = InteractionManager.GetControllerConfig();
            var controllerKeyInfoList = controllerConfig.KeyInfoList;

            if (controllerKeyInfoList == null)
            {
                Debug.LogError("----------KeyInfoList is null----------");
                return;
            }
            var imgsPath = new string[controllerKeyInfoList.Count];

            if (NxrSDKApi.Instance.Last3DofModelPath == null)
            {
                NxrSDKApi.Instance.Last3DofModelPath = controllerConfig.modelPath;
            }
            else
            {
                var currentModelPath = controllerConfig.modelPath;
                if (currentModelPath != NxrSDKApi.Instance.Last3DofModelPath)
                {
                    NxrSDKApi.Instance.Is3DofSpriteFirstLoad = false;
                }
            }

            if (!NxrSDKApi.Instance.Is3DofSpriteFirstLoad)
            {
                NxrSDKApi.Instance.ClearCachSpriteDict();
                for (var i = 0; i < controllerKeyInfoList.Count; i++)
                {
                    var tipList = controllerKeyInfoList[i].tipList;
                    imgsPath[i] = tipList[(int)NxrSDKApi.Instance.GetTipLanguage()].picPath;
                }

                var spriteLoader = tipsGo.AddComponent <SpriteLoader>();
                spriteLoader.LoadSpriteFile(imgsPath);
            }

            isTipsCreated = false;
        }
        private void Update()
        {
            if (IsDebugInEditor)
            {
                IsDebugInEditor = false;
                NxrSDKApi.Instance.ExecuteControllerStatusChangeEvent(InteractionManager.NACTION_HAND_TYPE.HAND_LEFT,
                                                                      true, true);
                NxrSDKApi.Instance.ExecuteControllerStatusChangeEvent(InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT,
                                                                      true, true);
            }

            if (InteractionManager.IsInteractionSDKEnabled() && InteractionManager.IsSixDofController &&
                DualCtrlDeviceDict.Count != 2)
            {
                if (InteractionManager.IsSixDofControllerConnected((int)InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) &&
                    !DualCtrlDeviceDict.ContainsKey(InteractionManager.NACTION_HAND_TYPE.HAND_LEFT))
                {
                    OnControllerStatusChangeEvent(InteractionManager.NACTION_HAND_TYPE.HAND_LEFT, true,
                                                  InteractionManager.IsSixDofController);
                }

                if (InteractionManager.IsSixDofControllerConnected(
                        (int)InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT) &&
                    !DualCtrlDeviceDict.ContainsKey(InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
                {
                    OnControllerStatusChangeEvent(InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT, true,
                                                  InteractionManager.IsSixDofController);
                }
            }

            if (leftObj || rightObj)
            {
                InteractionManager.ControllerConfig controllerConfig = InteractionManager.GetControllerConfig();
                if (NxrSDKApi.Instance.Last6DofModelPath == null)
                {
                    NxrSDKApi.Instance.Last6DofModelPath = controllerConfig.modelPath;
                }
                else
                {
                    var currentModelPath = controllerConfig.modelPath;
                    if (currentModelPath != NxrSDKApi.Instance.Last6DofModelPath)
                    {
                        isLeftTipsGoGreated  = false;
                        isRightTipsGoGreated = false;
                        NxrSDKApi.Instance.Is6DofSpriteFirstLoad = false;
                        isLoadSprites      = false;
                        isLeftTipsCreated  = false;
                        isRightTipsCreated = false;
                    }
                }

                if (leftObj && !isLeftTipsGoGreated)
                {
                    isLeftTipsGoGreated = true;
                    CreateControllerTips(leftObj);
                }

                if (rightObj && !isRightTipsGoGreated)
                {
                    isRightTipsGoGreated = true;
                    CreateControllerTips(rightObj);
                }

                if (leftTipsGo && !isLeftTipsCreated)
                {
                    CreateTipImgs(leftTipsGo);
                }
                if (rightTipsGo && !isRightTipsCreated)
                {
                    CreateTipImgs(rightTipsGo);
                }
                if (leftTipsGo && isLeftTipsCreated)
                {
                    ChangeTipAlpha(leftTipsGo);
                }
                if (rightTipsGo && isRightTipsCreated)
                {
                    ChangeTipAlpha(rightTipsGo);
                }
                if (leftModelGo && leftTipsGo)
                {
                    leftTipsGo.SetActive(leftModelGo.activeSelf);
                }
                if (rightModelGo && rightTipsGo)
                {
                    rightTipsGo.SetActive(rightModelGo.activeSelf);
                }
            }
        }
        private void CreateControllerModel(NxrInstantNativeApi.HoloeverDeviceType deviceType, string objName,
                                           InteractionManager.ControllerConfig mControllerConfig)
        {
            string objPath = mControllerConfig.objPath;

            if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
            {
                objPath = mControllerConfig.leftCtrlObjPath;
            }
            else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
            {
                objPath = mControllerConfig.rightCtrlObjPath;
            }

            if (objPath == null)
            {
                Debug.LogError("CreateControllerModel failed, objPath is null......" + objName);
                return;
            }

            GameObject      go = new GameObject(objName);
            NxrLaserPointer mNxrLaserPointer = go.AddComponent <NxrLaserPointer>();

            mNxrLaserPointer.deviceType = deviceType;
            go.transform.SetParent(transformCache);
            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.localScale    = new Vector3(-1, 1, 1);
            modelGOParent.transform.localPosition = new Vector3(0, 0, 0);
            modelGOParent.transform.localRotation = new Quaternion(0, 0, 0, 1);
            modelGOParent.transform.SetParent(go.transform);

            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]);
            modelGO.AddComponent <NxrControllerModel>();

            //  string objPath = "/system/etc/Objs/housing_bott.obj";
            Debug.Log("objPath=" + objPath);

            ObjModelLoader mObjModelLoader = go.GetComponent <ObjModelLoader>();

            if (mObjModelLoader == null)
            {
                go.AddComponent <ObjMaterial>();
                mObjModelLoader = go.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 <HoloeverControllerPower>();

            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 = go.AddComponent <NxrTrackedDevice>();

            if (trackedDevice != null)
            {
                trackedDevice.ReloadLaserPointer(mNxrLaserPointer);
                trackedDevice.deviceType = deviceType;
                InteractionManager.NACTION_HAND_TYPE mHandType =
                    deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController
                        ? InteractionManager.NACTION_HAND_TYPE.HAND_LEFT
                        : InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT;

                if (!DualCtrlDeviceDict.ContainsKey(mHandType))
                {
                    DualCtrlDeviceDict.Add(mHandType, trackedDevice);
                }
                else
                {
                    DualCtrlDeviceDict[mHandType] = trackedDevice;
                }
            }

            if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
            {
                leftObj     = go;
                leftModelGo = modelGO;
            }
            else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
            {
                rightObj     = go;
                rightModelGo = modelGO;
            }

            //close
            NxrViewer.Instance.SwitchControllerMode(true);
            Debug.Log("HideGaze.ForceUseReticle3");
        }
Example #5
0
        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);
        }