Browse Source

Immersal按钮定位、与景点绑定

蓝色星空 1 year ago
parent
commit
2119037f8c

File diff suppressed because it is too large
+ 807 - 123
Assets/MRNavigatorPro.unity


+ 22 - 0
Assets/Scripts/Blue/Command/ImmersalSetLocalCommand.cs

@@ -0,0 +1,22 @@
+using Blue;
+
+/// <summary>
+/// Immersal设置命令
+/// 传入 id、projectId、location
+/// </summary>
+public class ImmersalSetLocalCommand : ICommand
+{
+    public int id;
+    public int projectId;
+    public bool location;
+    public ImmersalSetLocalCommand(int id,int projectId,bool location)
+    {
+        this.id = id;
+        this.projectId = projectId;
+        this.location = location;
+    }
+    public void OnExcute()
+    {
+        this.GetService<IImmersalLocationService>().Set(id,projectId,location);
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Command/ImmersalSetLocalCommand.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6119328f08587e948bd60d52611cd502
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 49 - 0
Assets/Scripts/Blue/Controller/ImmersalLocalControl.cs

@@ -0,0 +1,49 @@
+using Immersal.AR;
+using UnityEngine;
+using Blue;
+
+/// <summary>
+/// 打开景点后是否开启点云定位功能
+/// </summary>
+public class ImmersalLocalControl : AbstractController
+{
+    private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
+    private ImmersalLocalizerController ImmersalLocalizerController =>SceneIOCContainer.Instance.Pull("ImmersalLocalizerController")as ImmersalLocalizerController;
+    public int id;
+    public int projectId;
+    public bool isOn; // 是否开启
+
+    private bool firstOpen = true; // 第一次打开
+    private void OnEnable()
+    {
+        this.RegisterEvent<SetImmersalLocalEvent>(Unload);
+        if(firstOpen)
+        {
+            firstOpen = false;
+            return;
+        }
+
+        Debug.LogError("是否定位:"+isOn);
+        if(isOn)
+        {
+            // 启动脚本,开启定位
+            XRLocalizer.enabled = true;
+            ImmersalLocalizerController.enabled = true;
+        }
+        else
+        {
+            XRLocalizer.enabled = false;
+            ImmersalLocalizerController.enabled = false;
+        }
+    }
+    private void OnDisable()
+    {
+        this.UnRegisterEvent<SetImmersalLocalEvent>(Unload);
+    }
+
+    private void Unload(SetImmersalLocalEvent e)
+    {
+        isOn = e.isLocation;
+        this.SendCommand(new ImmersalSetLocalCommand(id,projectId,isOn));
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Controller/ImmersalLocalControl.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 10f791ca19fb19a4f8aaa6e500e0cf9e
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 4
Assets/Scripts/Blue/Controller/ImmersalLocalizerController.cs

@@ -7,7 +7,7 @@ using Blue;
 /// </summary>
 public class ImmersalLocalizerController: AbstractController
 {
-    [SerializeField] private XRLocalizer XRLocalizer;
+    private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
     [SerializeField] private float rateTime = 2f;
     private float time = 0f;
     private bool startLocalizer=false;
@@ -16,7 +16,6 @@ public class ImmersalLocalizerController: AbstractController
     {
         this.RegisterEvent<StartImmersalLocalizerEvent>(e=>
         {
-            XRLocalizer = GameObject.Find("ImmersalSDK").GetComponent<XRLocalizer>(); // 获取XRLocalizer
             this.enabled = true; // 开启脚本
             startLocalizer = true; // 开始定位
         }).UnRegisterWhenGameObjectDestroyed(gameObject);
@@ -27,7 +26,7 @@ public class ImmersalLocalizerController: AbstractController
                     InstantiateSystem.Instance.BlueObject.NormalPopUp,
                     "定位成功");
             this.SendCommand(Command);
-            SetSceneActive.Instance.ImmersalLocalizer = false;
+
             XRLocalizer.enabled = false;
             this.enabled = false;
         }).UnRegisterWhenGameObjectDestroyed(gameObject);
@@ -36,7 +35,7 @@ public class ImmersalLocalizerController: AbstractController
     {
         time += Time.deltaTime;
 
-        if(time > rateTime  && startLocalizer && !SetSceneActive.Instance.active && SetSceneActive.Instance.ImmersalLocalizer)
+        if(time > rateTime  && startLocalizer && !SetSceneActive.Instance.active)
         {
             XRLocalizer.Localize();
             time= 0;

+ 43 - 0
Assets/Scripts/Blue/Controller/IsLocation.cs

@@ -0,0 +1,43 @@
+using System.Collections;
+using System.Collections.Generic;
+using Immersal.AR;
+using Blue;
+using UnityEngine.UI;
+
+/// <summary>
+/// 是否定位功能
+/// </summary>
+public class IsLocation : AbstractController
+{
+    public Toggle Y_Location_Toggle;
+    public Toggle N_Location_Toggle;
+
+    private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
+    private ImmersalLocalizerController ImmersalLocalizerController =>SceneIOCContainer.Instance.Pull("ImmersalLocalizerController")as ImmersalLocalizerController;
+
+    private void Start()
+    {
+        Y_Location_Toggle.onValueChanged.AddListener(Y_IsLocationValueChange);
+        N_Location_Toggle.onValueChanged.AddListener(N_IsLocationValueChange);
+    }
+    private void Y_IsLocationValueChange(bool isOn)
+    {
+        if (isOn)
+        {
+            ImmersalLocalizerController.enabled = true;
+            XRLocalizer.enabled = true;
+
+            this.SendCommand(new SetImmersalLocalCommand(true));
+        }
+    }
+    private void N_IsLocationValueChange(bool isOn)
+    {
+        if (isOn)
+        {
+            ImmersalLocalizerController.enabled = false;
+            XRLocalizer.enabled = false;
+
+            this.SendCommand(new SetImmersalLocalCommand(false));
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Controller/IsLocation.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e11cf366d8ddd094a9f85d81ef73939c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 25 - 0
Assets/Scripts/Blue/Event/SetImmersalLocalEvent.cs

@@ -0,0 +1,25 @@
+using Blue;
+
+/// <summary>
+/// Immersal定位上传事件
+/// </summary>
+public class SetImmersalLocalEvent : IEvent
+{
+    public bool isLocation;
+}
+
+/// <summary>
+/// 设置Immersal定位上传命令
+/// </summary>
+public class SetImmersalLocalCommand : ICommand
+{
+    private bool isLocation;
+    public SetImmersalLocalCommand(bool isLocation)
+    {
+        this.isLocation = isLocation;
+    }
+    public void OnExcute()
+    {
+        this.SendEvent<SetImmersalLocalEvent>(new SetImmersalLocalEvent(){isLocation = this.isLocation});
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Event/SetImmersalLocalEvent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 78627c2cb69bc654f9ce1c242f040b03
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Assets/Scripts/Blue/MRNavigatorPro.cs

@@ -21,6 +21,7 @@ public class MRNavigatorPro : AbstractArchitecture<MRNavigatorPro>
         this.RegisterService<IPointService>(new PointService());
         this.RegisterService<IMQTTService>(new MQTTService());
         this.RegisterService<IMinMapService>(new MinMapService());
+        this.RegisterService<IImmersalLocationService>(new ImmersalLocationService());
     }
 
     private void RegisterUtility()

+ 0 - 2
Assets/Scripts/Blue/Model/SetSceneActive.cs

@@ -4,6 +4,4 @@ public class SetSceneActive : BlueSingleton<SetSceneActive>
 {
     public bool active = false;
     public float goReference_y;
-
-    public bool ImmersalLocalizer = true;
 }

+ 1 - 1
Assets/Scripts/Blue/Patch/Video/Patch_VideoController.cs

@@ -33,7 +33,7 @@ public class Patch_VideoController : AbstractController
             if (boundingBox != null)
             {
                 Destroy(boundingBox);
-                if (transform.Find("BoundingBox").gameObject != null)
+                if (transform.Find("BoundingBox") != null)
                     Destroy(transform.Find("BoundingBox").gameObject);
             }
         }

+ 65 - 0
Assets/Scripts/Blue/Service/IImmersalLocationService.cs

@@ -0,0 +1,65 @@
+using System.Collections;
+using UnityEngine;
+using Blue;
+using UnityEngine.Networking;
+using Newtonsoft.Json;
+using System.Text;
+
+/// <summary>
+/// Immersal 点云定位服务
+/// </summary>
+public interface IImmersalLocationService : IService
+{
+    void Set(int id,int projectId,bool location);
+}
+
+public class ImmersalLocationService : IImmersalLocationService
+{
+    private string userInfoSetUrl;
+    public void OnInit()
+    {
+        userInfoSetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/viewpoint/locationPoint";
+    }
+
+    public void Set(int id,int projectId,bool location)
+    {
+        CoroutineSystem.Instance.StartCoroutine(SetRequest(id,projectId,location));
+    }
+
+    private IEnumerator SetRequest(int id,int projectId,bool location)
+    {
+
+        using (UnityWebRequest webRequest = new UnityWebRequest(userInfoSetUrl, "POST"))
+        {
+            ImmersalLoaction ImmersalLoaction = new ImmersalLoaction();
+            ImmersalLoaction.id = id;
+            ImmersalLoaction.projectId = projectId;
+            ImmersalLoaction.location = location;
+            string jsonData = JsonConvert.SerializeObject(ImmersalLoaction);
+            Debug.LogError("JsonData"+jsonData);
+            byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
+
+            webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
+            webRequest.downloadHandler = new DownloadHandlerBuffer();
+
+            webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
+            webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
+
+            yield return webRequest.SendWebRequest();
+
+            if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
+                Debug.LogError("UnityWebRequest Error:"+webRequest.downloadHandler.text);
+            else
+            {
+                Debug.LogError("Immersal上传:"+webRequest.downloadHandler.text);
+            }
+        }
+    }
+}
+
+public class ImmersalLoaction
+{
+    public int id{ get; set; }
+    public int projectId{ get; set; }
+    public bool location{ get; set; }
+}

+ 11 - 0
Assets/Scripts/Blue/Service/IImmersalLocationService.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6c313cfd95f82d64b8370910e017747a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 14 - 0
Assets/Scripts/Blue/System/GetObjectSystem.cs

@@ -1,10 +1,16 @@
 using Blue;
+using Immersal.AR;
 using UnityEngine;
+using UnityEngine.UI;
 
 public class GetObjectSystem : SingletonMonobehaviour<GetObjectSystem>
 {
     [SerializeField] private GameObject mesh_test;
     [SerializeField] private GameObject ARSpaceForAll;
+    [SerializeField] private XRLocalizer mXRLocalizer;
+    [SerializeField] private ImmersalLocalizerController mImmersalLocalizerController;
+    [SerializeField] private Toggle ImmersalSetToggle;
+    [SerializeField] private Toggle AnchorBtnToggle;
     private void Awake()
     {
         GetObj();
@@ -15,11 +21,19 @@ public class GetObjectSystem : SingletonMonobehaviour<GetObjectSystem>
     {
         mesh_test = GameObject.Find("ARSpaceForAll/mesh_test");
         ARSpaceForAll = GameObject.Find("ARSpaceForAll");
+        mXRLocalizer = GameObject.Find("ImmersalSDK").GetComponent<XRLocalizer>();
+        mImmersalLocalizerController = GetComponentInChildren<ImmersalLocalizerController>();
+        //ImmersalSetToggle = GameObject.Find("SetBtn/Canvas/Parent/Test/Toggle").GetComponent<Toggle>();
+        AnchorBtnToggle = GameObject.Find("SetBtn/Canvas/Parent/AnchorBtn/Toggle").GetComponent<Toggle>();
     }
 
     private void PushIOC()
     {
         SceneIOCContainer.Instance.Push("mesh_test",mesh_test);
         SceneIOCContainer.Instance.Push("ARSpaceForAll",ARSpaceForAll);
+        SceneIOCContainer.Instance.Push("XRLocalizer",mXRLocalizer);
+        SceneIOCContainer.Instance.Push("ImmersalLocalizerController",mImmersalLocalizerController);
+        //SceneIOCContainer.Instance.Push("ImmersalSetToggle",ImmersalSetToggle);
+        SceneIOCContainer.Instance.Push("AnchorBtnToggle",AnchorBtnToggle);
     }
 }

+ 3 - 0
Assets/Scripts/Blue/Temp/MoveChange.cs

@@ -75,6 +75,7 @@ public class MoveChange : AbstractController
     }
 
     bool isCx;
+    private Toggle AnchorBtnToggle =>SceneIOCContainer.Instance.Pull("AnchorBtnToggle") as Toggle;
     void Update()
     {
         if (ARSpace.isFind)
@@ -91,12 +92,14 @@ public class MoveChange : AbstractController
             isCx = true;
             txtTip.SetActive(false);
             ARSpace.isFind = false;
+            AnchorBtnToggle.interactable = true;
             this.SendCommand(new SuccessImmersalLocalizerCommand());
         }
         else
         {
             if (!isCx)
             {
+                AnchorBtnToggle.interactable = false;
                 txtTip.SetActive(true);
                 txtTip.GetComponentInChildren<Text>().text = "请扫描周围环境以进行空间定位";
             }

+ 4 - 0
Assets/Scripts/Config/DataConfig.cs

@@ -301,6 +301,10 @@ public class SpoitValueDetail
     /// </summary>
     public string name { get; set; }
     /// <summary>
+    /// 是否需要开启点云定位
+    /// </summary>
+    public bool location;
+    /// <summary>
     /// 景点和触发范围信息
     /// </summary>
     public List<SpoitPos> position { get; set; }

+ 22 - 6
Assets/Scripts/UI/GameManager.cs

@@ -207,8 +207,8 @@ public class GameManager : MonoSingleton<GameManager>
     }
 
     public Toggle EditorToggle;
-    public ImmersalLocalizerController mImmersalLocalizerController;
-    public XRLocalizer XRLocalizer;
+
+    public GameObject ERNIEBot;
     private void Awake()
     {
         
@@ -332,6 +332,8 @@ public class GameManager : MonoSingleton<GameManager>
         m_SetBtn.gameObject.SetActive(true);
         InitCrystals();
         InitBoxColliders();
+
+        ERNIEBot.SetActive(true);
     }
 
 
@@ -490,13 +492,21 @@ public class GameManager : MonoSingleton<GameManager>
         }
 
     }
-    
+    /*
+    private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
+    private ImmersalLocalizerController ImmersalLocalizerController =>SceneIOCContainer.Instance.Pull("ImmersalLocalizerController")as ImmersalLocalizerController;
+    private Toggle ImmersalSetToggle =>SceneIOCContainer.Instance.Pull("ImmersalSetToggle") as Toggle;
     public void OnNYImmersalLocalizerBtnValueChange(bool ison)
     {
-        mImmersalLocalizerController.enabled = true;
-        XRLocalizer.enabled = true;
-        SetSceneActive.Instance.ImmersalLocalizer = true;
+        
+        if (ison)
+        {
+            ImmersalLocalizerController.enabled = true;
+            XRLocalizer.enabled = true;
+        }
+        
     }
+    */
     public void GetPosRotScale()
     {
         PosRotScale.PosRotScalePatchList.Clear();
@@ -783,6 +793,12 @@ public class GameManager : MonoSingleton<GameManager>
     {
         //生成景点父物体
         GameObject spoitObj = new GameObject(spoit.name);
+        // 添加Immersal是否定位脚本
+        ImmersalLocalControl mImmersalLocalControl = spoitObj.AddComponent<ImmersalLocalControl>();
+        mImmersalLocalControl.id = SpoitsValueDetail[spoit.id].id;
+        mImmersalLocalControl.projectId = SpoitsValueDetail[spoit.id].projectId;
+        mImmersalLocalControl.isOn = SpoitsValueDetail[spoit.id].location;
+
         spoitObj.transform.SetParent(ObjsParent.transform);
         spoitObj.AddComponent<EditorEventHandler>().IsClickEditor = false;
 

Some files were not shown because too many files changed in this diff