Esempio n. 1
0
 public void ReloadLaserPointer(NxrLaserPointer laserPointerIn)
 {
     this.laserPointer = laserPointerIn;
     if (laserPointer != null)
     {
         laserPointer.PointerIn  += PointerInEventHandler;
         laserPointer.PointerOut += PointerOutEventHandler;
     }
 }
Esempio n. 2
0
        private void Start()
        {
            isGamePad    = gameObject.name.Contains("Gamepad");
            laserPointer = GetComponent <NxrLaserPointer>();
            if (laserPointer != null)
            {
                laserPointer.PointerIn  += PointerInEventHandler;
                laserPointer.PointerOut += PointerOutEventHandler;
            }

            if (!isGamePad)
            {
                controllerModel = GetComponentInChildren <NxrControllerModel>();
                controllerPower = GetComponentInChildren <NibiruControllerPower>();

                if (controllerModel != null)
                {
                    controllerModel.gameObject.SetActive(false);
                }
                if (controllerPower != null)
                {
                    controllerPower.gameObject.SetActive(false);
                }
            }
#if UNITY_ANDROID
            NibiruTaskApi.deviceConnectState += OnDeviceConnectState;
            _currentStates = new NxrInstantNativeApi.Nibiru_ControllerStates();
            _prevStates    = new NxrInstantNativeApi.Nibiru_ControllerStates();
            _currentStates.connectStatus = 0;
            _prevStates.connectStatus    = 0;

            _currentStates.buttons = 0;
            _currentStates.touches = 0;
            _prevStates.buttons    = 0;
            _prevStates.touches    = 0;
#endif
        }
Esempio n. 3
0
        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");
        }