GameManager.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. using LitJson;
  2. using Newtonsoft.Json;
  3. using SC.XR.Unity;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using XRTool.Util;
  11. /*
  12. * 半自动交付/自动交付
  13. * 景点、触发范围、水晶点应保持顺序对应
  14. * 当前场景下景点名称不应重复
  15. * 同一景点下素材名称不应重复
  16. * ListShowObjs/ListColliderBoxs/ListCrystals半自动时在场景中推拽,全自动时全部由代码生成
  17. *
  18. * 新增锚点列表
  19. * 锚点识别图Vuforia XML和DAT文件
  20. * 各个锚点的位置信息
  21. *
  22. * 每次打开都下载vuforia文件
  23. * 自动加载生成ImageTarget
  24. *
  25. */
  26. public class GameManager : MonoSingleton<GameManager>
  27. {
  28. public Text text;
  29. public GameObject Map;
  30. /// <summary>
  31. /// 景点ID与对应的素材组合
  32. /// </summary>
  33. [SerializeField, Tooltip("景点对应的物体及景点下的素材")]
  34. private Dictionary<int, ObjectValue> ObjectValues = new Dictionary<int, ObjectValue>();
  35. public List<ObjectValue> ColliderObjectValues = new List<ObjectValue>();
  36. [Header("Spoit")]
  37. [Tooltip("景点对应的显示物体")]
  38. public List<Transform> ListShowObjs;
  39. [Tooltip("景点对应的显示物体,本地添加物体")]
  40. public List<Transform> ListLocalShowObjs;
  41. public bool isShowLoacalShowObjs = false;
  42. [Tooltip("景点对应的物体触发范围")]
  43. public List<Transform> ListColliderBoxs;
  44. private List<MeshRenderer> ListColiderBoxs_Mesh;
  45. [Tooltip("景点对应的水晶点")]
  46. public List<Transform> ListCrystals;
  47. [Tooltip("景点对应的显示物体父物体")]
  48. public Transform ObjsParent;
  49. [Tooltip("触发器父物体")]
  50. public Transform CollidersParent;
  51. [Tooltip("水晶点父物体")]
  52. public Transform CrystalsParent;
  53. [Tooltip("锚点父物体")]
  54. public Transform AnchorsParent;
  55. public GameObject ColliderItem;
  56. public GameObject CrystalItem;
  57. [Space(20)]
  58. [Tooltip("是否显示路径")]
  59. public bool IsShowLuJIng = true;
  60. [Tooltip("是否为编辑模式")]
  61. public bool IsEditor = true;
  62. [Tooltip("是否是全自动显示景点")]
  63. public bool IsAuto = true;
  64. [SerializeField, Tooltip("路径控制器")]
  65. private RouteCtr RouteCtr;
  66. [SerializeField, Tooltip("素材编辑器")]
  67. private EditorPanel m_EditorPanel;
  68. [SerializeField, Tooltip("计算人物在地图上的位置")]
  69. [Header("MinMap")]
  70. private CalMap m_CalMap;
  71. [SerializeField, Tooltip("小地图信息")]
  72. private MinMap m_MinMap;
  73. [Header("Setting")]
  74. [SerializeField, Tooltip("设置面板")]
  75. private SettingPanel m_SettingPanel;
  76. [SerializeField, Tooltip("编辑器面板")]
  77. private Transform m_EditorCanvas;
  78. [SerializeField, Tooltip("设置按钮")]
  79. private Transform m_SetBtn;
  80. [Header("地图比例")]
  81. public Transform PointA;
  82. public Transform PointB;
  83. public Transform PointC;
  84. public Transform PointD;
  85. public bool isStart; // 场景四个点已经确定
  86. public Vector2 WebMapSize;
  87. public Vector2 MapSize;
  88. public Vector2 MinMapSize = new Vector2(320, 135);
  89. public string MapPicUrl;
  90. [Header("展厅")]
  91. public GameObject MRZhanTing;
  92. public bool isPlayMRZhanTing;
  93. public IrobotMove m_IroBot;
  94. [Header("Player")]
  95. public PlayerTrigger Player;
  96. [Header("Head")]
  97. public Transform m_head;
  98. [Header("虚拟导游")]
  99. public List<IrobotMove> Irobots;
  100. /// <summary>
  101. /// 是否在触发区域内
  102. /// </summary>
  103. private bool m_IsTriggerExiting;
  104. /// <summary>
  105. /// 是否在触发区域内
  106. /// </summary>
  107. ///
  108. public GameObject arcamre;
  109. public GameObject immser;
  110. public bool IsTriggerExiting
  111. {
  112. get { return m_IsTriggerExiting; }
  113. set { m_IsTriggerExiting = value; }
  114. }
  115. /// <summary>
  116. /// 是否可以开始编辑素材
  117. /// </summary>
  118. private bool m_IsStartEditor;
  119. /// <summary>
  120. /// 是否可以开始编辑素材
  121. /// </summary>
  122. public bool IsStartEditor
  123. {
  124. get { return m_IsStartEditor; }
  125. set { m_IsStartEditor = value; }
  126. }
  127. /// <summary>
  128. /// 素材加载完成,素材prefab生成完成,开始进入运行状态
  129. /// </summary>
  130. public bool m_IsRuning;
  131. /// <summary>
  132. /// 素材加载完成,素材prefab生成完成,开始进入运行状态
  133. /// </summary>
  134. public bool IsRuning
  135. {
  136. get { return m_IsRuning; }
  137. set { m_IsRuning = value; }
  138. }
  139. /// <summary>
  140. /// 当前触发物体的下标
  141. /// </summary>
  142. private int m_SpoitIndex;
  143. /// <summary>
  144. /// 当前触发物体的下标
  145. /// </summary>
  146. public int SpoitIndex
  147. {
  148. get { return m_SpoitIndex; }
  149. set { m_SpoitIndex = value; }
  150. }
  151. /// <summary>
  152. /// 2.0 场景数据
  153. /// </summary>
  154. public UserSceneItem m_scene;
  155. /// <summary>
  156. /// 当前场景数据
  157. /// </summary>
  158. public SceneValue m_SceneValue;
  159. /// <summary>
  160. /// 当前场景数据
  161. /// </summary>
  162. public SceneValue SceneValue
  163. {
  164. get { return m_SceneValue; }
  165. set { m_SceneValue = value; }
  166. }
  167. /// <summary>
  168. /// 当前场景中的景点信息
  169. /// </summary>
  170. private List<SpoitValue> m_SpoitValues;
  171. /// <summary>
  172. /// 当前场景中的景点信息
  173. /// </summary>
  174. public List<SpoitValue> SpoitValues
  175. {
  176. get { return m_SpoitValues; }
  177. set { m_SpoitValues = value; }
  178. }
  179. /// <summary>
  180. /// 景点详情数据
  181. /// </summary>
  182. private Dictionary<int, SpoitValueDetail> m_SpoitsValueDetail;
  183. /// <summary>
  184. /// 景点详情数据
  185. /// </summary>
  186. public Dictionary<int, SpoitValueDetail> SpoitsValueDetail
  187. {
  188. get { return m_SpoitsValueDetail; }
  189. set { m_SpoitsValueDetail = value; }
  190. }
  191. public UIAnchorsPanel m_UIAnchorsPanel;
  192. private Dictionary<Anchor, MeshRenderer> m_AnchorValue;
  193. public Dictionary<Anchor, MeshRenderer> AnchorValue
  194. {
  195. get { return m_AnchorValue; }
  196. set { m_AnchorValue = value; }
  197. }
  198. private Dictionary<Anchor, GameObject> m_AnchorChild;
  199. public Dictionary<Anchor,GameObject> AnchorChild
  200. {
  201. get { return m_AnchorChild; }
  202. set { m_AnchorChild = value; }
  203. }
  204. public Toggle EditorToggle;
  205. private void Awake()
  206. {
  207. // Debug.unityLogger.logEnabled = false;
  208. }
  209. public Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>> allOldobjs = new Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>>();
  210. public Dictionary<string, Dictionary<string, Dictionary<string, GameObject>>> allobjs = new Dictionary<string, Dictionary<string, Dictionary<string, GameObject>>>();
  211. public bool isShowDownTip;
  212. private void Start()
  213. {
  214. this.gameObject.AddComponent<TimerMgr>();
  215. // PlayerPrefs.DeleteAll();
  216. isStart = false;
  217. m_SpoitsValueDetail = new Dictionary<int, SpoitValueDetail>();
  218. m_AnchorValue = new Dictionary<Anchor, MeshRenderer>();
  219. m_AnchorChild = new Dictionary<Anchor, GameObject>();
  220. SceneValue = null;
  221. m_IsStartEditor = false;
  222. m_IsRuning = false;
  223. m_SetBtn.gameObject.SetActive(false);
  224. //CalMapSize();
  225. SpoitIndex = -1;
  226. SpoitValues = new List<SpoitValue>();
  227. if (m_EditorPanel == null)
  228. {
  229. m_EditorPanel = GameObject.FindObjectOfType<EditorPanel>();
  230. }
  231. if (!IsAuto)
  232. {
  233. //GetObjectValue();
  234. //CreateSpoitValue();
  235. }
  236. else
  237. {
  238. ListShowObjs = new List<Transform>();
  239. ListColliderBoxs = new List<Transform>();
  240. ListColiderBoxs_Mesh = new List<MeshRenderer>();
  241. ListCrystals = new List<Transform>();
  242. // ListLocalShowObjs = new List<Transform>();
  243. }
  244. m_MinMap.gameObject.SetActive(false);
  245. Map.SetActive(false);
  246. var t = TimerMgr.Instance.CreateTimer(()=> {
  247. if(isShowDownTip)
  248. {
  249. Debug.Log("HJJ 判断正在下载");
  250. if (downLoadCount == 0)
  251. {
  252. downLoadCount = COSDownLoad.showDownEndLoadCount;
  253. Debug.Log("HJJ 判断正在下载downLoadCount==0");
  254. }
  255. if (COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount)
  256. {
  257. Debug.Log("HJJ 判断正在下载COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount");
  258. string str = string.Format("{0}/{1}正在下载,{2}%", (COSDownLoad.showDownEndLoadCount - downLoadCount), COSDownLoad.showDownLoadCount - downLoadCount, COSDownLoad.showDownLoadPre.ToString("F2"));
  259. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
  260. ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
  261. }
  262. else
  263. {
  264. Debug.Log("HJJ 判断正在下载downLoadCount != 0");
  265. UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
  266. downLoadCount = 0;
  267. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.updateEnd);
  268. isShowDownTip = false;
  269. }
  270. if(COSDownLoad.showDownLoadCount==0&& downLoadCount ==0)
  271. {
  272. Debug.Log("HJJ 判断正在下载COSDownLoad.showDownLoadCount==0&& downLoadCount ==0");
  273. Debug.Log("DGJ updateEnd ");
  274. UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.updateEnd);
  275. isShowDownTip = false;
  276. // TimerMgr.Instance.DestroyTimer(t);
  277. }
  278. }
  279. },1,-1);
  280. }
  281. int downLoadCount = 0;
  282. private void LateUpdate()
  283. {
  284. // if (API_GSXR_Slam.GSXR_Get_Head() != null && m_IsRuning)
  285. // {
  286. m_SetBtn.transform.LookAt(OpenXRCamera.Instance.head);
  287. m_SetBtn.transform.localEulerAngles = new Vector3(0, m_SetBtn.transform.localEulerAngles.y+180, 0);
  288. //m_SetBtn.transform.position = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f+ new Vector3(0, 1f, 0);
  289. //m_SetBtn.transform.localPosition = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f + new Vector3(0, 1f, 0);
  290. m_SetBtn.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward * 1.3f + new Vector3(-0.2f, 1f, 0);
  291. // }
  292. if (avplayer && !avplayer.IsPlaying()&& !TemplateVideo.isPlayLock)
  293. {
  294. Debug.Log("HJJVideo 创建锁解开 并且播放完毕");
  295. TemplateVideo.isPlaying = false;
  296. avplayer = null;
  297. }
  298. if (TemplateVideo.temQueue.Count>0&&!TemplateVideo.isPlaying &&!TemplateVideo.isPlayLock)
  299. {
  300. Debug.Log("HJJVideo 开始播放");
  301. TemplateVideo.isPlaying = true;
  302. TimerMgr.Instance.CreateTimer(()=> {
  303. Debug.Log("HJJVideo 播放的创建锁 创建锁解开");
  304. TemplateVideo.isPlayLock = false;
  305. },3);
  306. TemplateVideo video = TemplateVideo.temQueue.Dequeue();
  307. #if !UNITY_EDITOR
  308. if (!video.localSavePath.Contains("file"))
  309. video.m_Video.SetUrl("file://" + video.localSavePath);
  310. #endif
  311. video.m_Video.transform.GetComponent<VideoPlayBtn>().m_IsPlaying = false;
  312. video.m_Video.transform.GetComponent<VideoPlayBtn>().PlayVideoAuto();
  313. avplayer = video.m_Video;
  314. }
  315. }
  316. float lockTime = 0;
  317. public AVProVideoPlayer avplayer;
  318. public void Init()
  319. {
  320. }
  321. private void InitCrystals()
  322. {
  323. for (int i = 0; i < ListCrystals.Count; i++)
  324. {
  325. ListCrystals[i].gameObject.SetActive(true);
  326. }
  327. }
  328. private void InitBoxColliders()
  329. {
  330. for (int i = 0; i < ListColliderBoxs.Count; i++)
  331. {
  332. ListColliderBoxs[i].gameObject.SetActive(true);
  333. }
  334. }
  335. public void IntoScene()
  336. {
  337. Map.SetActive(true);
  338. //GameObject.Instantiate(Resources.Load<GameObject>("ARCamera"));
  339. //ImageTargetManager.Instance.LoadVuforiaDat();
  340. //API_GSXR_Slam.GSXR_Get_Head().localPosition = new Vector3(23.57f, 2.5f, 16.74f);
  341. //API_GSXR_Slam.GSXR_Get_Head().localEulerAngles = new Vector3(0, -35.9f, 0);
  342. StartCoroutine(StartScene(isPlayMRZhanTing));
  343. HttpSocket.Instance.SendIpToElectric();
  344. if(!UserInfo.Instance.is20)
  345. MQTTClient.Instance.StartSendCameraPos();
  346. }
  347. public void saveOldData()
  348. {
  349. allOldobjs = new Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>>();
  350. foreach (var i in allobjs.Keys)
  351. {
  352. allOldobjs.Add(i, new Dictionary<string, Dictionary<string, PosRotScalePatch>>());
  353. foreach (var j in allobjs[i].Keys)
  354. {
  355. allOldobjs[i].Add(j, new Dictionary<string, PosRotScalePatch>());
  356. foreach (var k in allobjs[i][j].Keys)
  357. {
  358. PosRotScalePatch p = new PosRotScalePatch();
  359. p.PosPatch = allobjs[i][j][k].transform.localPosition;
  360. p.RotPatch = allobjs[i][j][k].transform.localEulerAngles;
  361. p.ScalePatch = allobjs[i][j][k].transform.localScale;
  362. allOldobjs[i][j].Add(k, p);
  363. }
  364. }
  365. }
  366. }
  367. public void refOldData()
  368. {
  369. foreach (var i in allobjs.Keys)
  370. {
  371. foreach (var j in allobjs[i].Keys)
  372. {
  373. foreach (var k in allobjs[i][j].Keys)
  374. {
  375. allobjs[i][j][k].transform.localPosition = allOldobjs[i][j][k].PosPatch;
  376. allobjs[i][j][k].transform.localEulerAngles = allOldobjs[i][j][k].RotPatch;
  377. allobjs[i][j][k].transform.localScale = allOldobjs[i][j][k].ScalePatch;
  378. }
  379. }
  380. }
  381. }
  382. IEnumerator StartScene( bool isPlayMRZhanTing)
  383. {
  384. yield return new WaitForSeconds(0.5f);
  385. if(isPlayMRZhanTing)
  386. {
  387. //if (!string.IsNullOrWhiteSpace(DataManager.Instance.CurrentScene.sandTable))
  388. //{
  389. MRZhanTing.gameObject.SetActive(true);
  390. MRZhanTing.transform.position = API_GSXR_Slam.GSXR_Get_Head().position + API_GSXR_Slam.GSXR_Get_Head().forward + new Vector3(0, -0.7f, 0);
  391. MRZhanTing.transform.localEulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_Head().eulerAngles.y, 0);
  392. yield return new WaitForSeconds(18f);
  393. MRZhanTing.gameObject.SetActive(false);
  394. //}
  395. }
  396. m_SettingPanel.gameObject.SetActive(true);
  397. m_EditorPanel.Init();
  398. m_SettingPanel.Init();
  399. if (RouteCtr.CurrentPoints.Count > 0)
  400. {
  401. Player.MovePoints = RouteCtr.CurrentPoints;
  402. //判断选择那个虚拟导游
  403. //int id = ChooseIroBot();
  404. //if (id < 3)
  405. //{
  406. //m_IroBot = Irobots[id - 1];
  407. m_IroBot.gameObject.SetActive(true);
  408. m_IroBot.Points = RouteCtr.CurrentPoints;
  409. yield return new WaitForSeconds(5f);
  410. //}
  411. }
  412. IsRuning = true;
  413. m_SetBtn.gameObject.SetActive(true);
  414. InitCrystals();
  415. InitBoxColliders();
  416. }
  417. private int ChooseIroBot()
  418. {
  419. int id = 3;
  420. var navlines = DataManager.Instance.CurrentScene.navLines;
  421. if (navlines.Count > 0)
  422. {
  423. id = navlines[0].guideMod;
  424. }
  425. return id;
  426. }
  427. /// <summary>
  428. /// 若为半自动显示素材,需要获取景点物体来为ObjectValues赋值
  429. /// </summary>
  430. private void GetObjectValue()
  431. {
  432. //for (int i = 0; i < ListShowObjs.Count; i++)
  433. //{
  434. // var spoit = ListShowObjs[i];
  435. // List<ObjectValue> values = new List<ObjectValue>();
  436. // ObjectValue objectValue = new ObjectValue(i, -1, spoit.name, spoit.gameObject, spoit.localPosition, spoit.localEulerAngles, spoit.localScale);
  437. // var editors = spoit.GetComponentsInChildren<EditorEventHandler>();
  438. // for (int j = 1; j < editors.Length; j++)
  439. // {
  440. // var obj = editors[j];
  441. // ObjectValue value = new ObjectValue(j, i, obj.name, obj.gameObject, obj.transform.localPosition, obj.transform.localEulerAngles, obj.transform.localScale);
  442. // objectValue.ChildrenObj.Add(value);
  443. // }
  444. // values.Add(objectValue);
  445. // ObjectValues.Add(i, values);
  446. //}
  447. }
  448. /// <summary>
  449. /// 半自动时创建景点信息
  450. /// </summary>
  451. //private void CreateSpoitValue()
  452. //{
  453. // if (SpoitValues == null)
  454. // {
  455. // SpoitValues = new List<SpoitValue>();
  456. // }
  457. // SpoitValues.Clear();
  458. // foreach (int id in ObjectValues.Keys)
  459. // {
  460. // var item = ObjectValues[id];
  461. // SpoitValue spoit = new SpoitValue();
  462. // spoit.id = item[0].ID;
  463. // spoit.name = item[0].matName;
  464. // for (int i = 0; i < item.Count; i++)
  465. // {
  466. // var objs = item[i];
  467. // MaterialObl materialObl = new MaterialObl();
  468. // materialObl.id = objs.ID;
  469. // materialObl.name = objs.matName;
  470. // materialObl.type = 0;
  471. // OjectTransform ojectTransform = new OjectTransform(objs.Object.transform.localPosition, objs.Object.transform.localEulerAngles, objs.Object.transform.localScale);
  472. // for (int m = 0; m < objs.ChildrenObj.Count; m++)
  473. // {
  474. // var obj = objs.ChildrenObj[i];
  475. // MaterialObjValue mat = new MaterialObjValue();
  476. // mat.name = obj.matName;
  477. // mat.type = 0;
  478. // mat.objectTransform = new OjectTransform(obj.Object.transform.localPosition, obj.Object.transform.localEulerAngles, obj.Object.transform.localScale);
  479. // materialObl.materialList.Add(mat);
  480. // }
  481. // spoit.material.Add(materialObl);
  482. // SpoitValues.Add(spoit);
  483. // }
  484. // }
  485. //}
  486. #region 设置功能
  487. public bool needSavePosRotScale = true;
  488. public void OnEditorBtnValueChanged(bool ison)
  489. {
  490. m_EditorCanvas.gameObject.SetActive(ison);
  491. m_IsStartEditor = ison;
  492. for (int i = 0; i < ListColiderBoxs_Mesh.Count; i++)
  493. {
  494. ListColiderBoxs_Mesh[i].enabled = ison;
  495. }
  496. if (ison)
  497. {
  498. if (needSavePosRotScale)
  499. {
  500. GetPosRotScale(); // 获取所有物体位置旋转缩放
  501. needSavePosRotScale = false;
  502. }
  503. m_EditorCanvas.position = OpenXRCamera.Instance.head.position + Player.transform.forward + new Vector3(0, 0.5f, 0);
  504. m_EditorCanvas.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
  505. CommandSystem.Instance.Send( new EditorSettingCommand(true){ } );
  506. CommandSystem.Instance.Send( new Patch_VideoCommand(true){ } );
  507. }
  508. else
  509. {
  510. m_EditorCanvas.position = OpenXRCamera.Instance.head.position + new Vector3(0, 100, 0);
  511. if (SpoitIndex >= 0 && !IsTriggerExiting)
  512. {
  513. ListShowObjs[SpoitIndex].gameObject.SetActive(false);
  514. if (isShowLoacalShowObjs)
  515. ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
  516. ListCrystals[SpoitIndex].gameObject.SetActive(true);
  517. m_EditorPanel.ClosePanel();
  518. SpoitIndex = -1;
  519. }
  520. CommandSystem.Instance.Send( new EditorSettingCommand(false){ } );
  521. CommandSystem.Instance.Send( new Patch_VideoCommand(false){ } );
  522. }
  523. }
  524. public static bool m_IsStartEditorJD;
  525. public void open20zuJD(bool ison)
  526. {
  527. m_IsStartEditorJD = ison;
  528. if (!ison)
  529. {
  530. // save20All();
  531. }
  532. SaveButton.SetActive(ison);
  533. }
  534. public static bool m_IsStartEditorzu;
  535. public void open20zu(bool ison)
  536. {
  537. m_IsStartEditorzu = ison;
  538. if (!ison)
  539. {
  540. // save20All();
  541. }
  542. SaveButton.SetActive(ison);
  543. }
  544. //2.0编辑模式 保存
  545. public void open20Editor(bool ison)
  546. {
  547. m_IsStartEditor = ison;
  548. if(!ison)
  549. {
  550. // save20All();
  551. }
  552. SaveButton.SetActive(ison);
  553. }
  554. public GameObject SaveButton;
  555. public void save20All()
  556. {
  557. if (!m_IsStartEditor)
  558. {
  559. List<SendSaveDataNew> saveData = new List<SendSaveDataNew>();
  560. foreach (var i in UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].SpotsList.Keys)
  561. {
  562. SpotsItem sp = UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].SpotsList[i.ToString()];
  563. SendSaveDataNew data = new SendSaveDataNew();
  564. data.position = sp.position;
  565. data.id = int.Parse(sp.id);
  566. data.name = sp.name;
  567. data.projectId = int.Parse(UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].id);
  568. List<MaterialOblNew> MaterialObllsit = new List<MaterialOblNew>();
  569. foreach (var z in sp.modelList.Keys)
  570. {
  571. ObjectTransform objt2 = new ObjectTransform();
  572. objt2.nowPos = sp.modelList[z].Model.transform.localPosition;
  573. objt2.nowRot = sp.modelList[z].Model.transform.localEulerAngles;
  574. objt2.nowScale = sp.modelList[z].Model.transform.localScale;
  575. sp.modelList[z].objectTransform = objt2;
  576. List<MaterialObjValueNew> materialList = new List<MaterialObjValueNew>();
  577. for (int j = 0; j < sp.modelList[z].materialList.Count; j++)
  578. {
  579. ObjectTransform objt3 = new ObjectTransform();
  580. objt3.nowPos = sp.modelList[z].materialList[j].prefabModel.transform.localPosition;
  581. objt3.nowRot = sp.modelList[z].materialList[j].prefabModel.transform.localEulerAngles;
  582. objt3.nowScale = sp.modelList[z].materialList[j].prefabModel.transform.localScale;
  583. sp.modelList[z].materialList[j].objectTransform = objt3;
  584. MaterialObjValueNew mov = new MaterialObjValueNew();
  585. mov.uid = sp.modelList[z].materialList[j].uid;
  586. mov.id = sp.modelList[z].materialList[j].id;
  587. mov.fileId = sp.modelList[z].materialList[j].fileId;
  588. mov.type = sp.modelList[z].materialList[j].type;
  589. mov.textContent = sp.modelList[z].materialList[j].textContent.ToString();
  590. mov.textPosition = sp.modelList[z].materialList[j].textPosition.ToString();
  591. mov.textBJ = sp.modelList[z].materialList[j].TextBJ.ToString();
  592. mov.downloadPath = sp.modelList[z].materialList[j].DownloadPath.ToString();
  593. mov.localSavePath = sp.modelList[z].materialList[j].localSavePath.ToString();
  594. mov.name = sp.modelList[z].materialList[j].name;
  595. mov.template = sp.modelList[z].materialList[j].template;
  596. mov.objectTransform = sp.modelList[z].materialList[j].objectTransform;
  597. materialList.Add(mov);
  598. }
  599. MaterialOblNew obj = new MaterialOblNew();
  600. obj.id = sp.modelList[z].id;
  601. obj.name = sp.modelList[z].name;
  602. obj.objectTransform = sp.modelList[z].objectTransform;
  603. obj.describe = sp.modelList[z].describe;
  604. obj.select = sp.modelList[z].select;
  605. obj.type = sp.modelList[z].type;
  606. obj.materialList = materialList;
  607. MaterialObllsit.Add(obj);
  608. }
  609. data.material = MaterialObllsit;
  610. ObjectTransform objt = new ObjectTransform();
  611. objt.nowPos = sp.SpotsObj.transform.localPosition;
  612. objt.nowRot = sp.SpotsObj.transform.localEulerAngles;
  613. objt.nowScale = sp.SpotsObj.transform.localScale;
  614. data.spoittf = objt;
  615. //data.triggerRange = spoit.SpoitTransform[0];
  616. saveData.Add(data);
  617. }
  618. string sendData = JsonConvert.SerializeObject(saveData);
  619. //string sendData = JsonMapper.ToJson(saveData);
  620. Debug.Log("更新景点数据: " + sendData);
  621. HttpTool.Instance.PostTest(HttpAction.viewpoint_update, sendData, (string str) => {
  622. JsonData jd = JsonMapper.ToObject(str);
  623. if(jd["message"].ToString()=="success")
  624. {
  625. InstantiateCommand Command = new InstantiateCommand(
  626. InstantiateSystem.Instance.BlueObject.WarningPopUp,
  627. InstantiateSystem.Instance.BlueObject.SuccessText);
  628. CommandSystem.Instance.Send(Command);
  629. }else
  630. {
  631. InstantiateCommand Command = new InstantiateCommand(
  632. InstantiateSystem.Instance.BlueObject.WarningPopUp,
  633. InstantiateSystem.Instance.BlueObject.NetErrorText);
  634. CommandSystem.Instance.Send(Command);
  635. }
  636. Debug.Log("保存回调===》" + str);
  637. });
  638. }
  639. }
  640. public void OnSettingBtnValueChanged(bool ison)
  641. {
  642. m_SettingPanel.gameObject.SetActive(ison);
  643. if (ison)
  644. {
  645. Debug.Log(OpenXRCamera.Instance.head.forward);
  646. m_SettingPanel.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward;
  647. m_SettingPanel.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
  648. }
  649. }
  650. public void OnAnchorBtnValueChanged(bool ison)
  651. {
  652. foreach (var item in m_AnchorValue)
  653. {
  654. item.Value.enabled = ison;
  655. }
  656. //foreach (var item in m_AnchorChild)
  657. //{
  658. // item.Value.SetActive(ison);
  659. //}
  660. if(ison)
  661. {
  662. m_UIAnchorsPanel.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward + new Vector3(0, 0.5f, 0);
  663. m_UIAnchorsPanel.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
  664. }
  665. else
  666. {
  667. m_UIAnchorsPanel.transform.position = OpenXRCamera.Instance.head.position + new Vector3(0, 100, 0);
  668. }
  669. }
  670. public void GetPosRotScale()
  671. {
  672. saveOldData();
  673. return;
  674. PosRotScale.PosRotScalePatchList.Clear();
  675. for (int i = 0; i < GameManager.Instance.ObjsParent.childCount; i++)
  676. {
  677. if (i != 0)
  678. {
  679. for (int j = 0; j < GameManager.Instance.ObjsParent.GetChild(i).childCount; j++)
  680. {
  681. for (int k = 0; k < GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).childCount; k++)
  682. {
  683. PosRotScalePatch PosRotScalePatch = new PosRotScalePatch();
  684. PosRotScalePatch.PosPatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localPosition;
  685. PosRotScalePatch.RotPatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localEulerAngles;
  686. PosRotScalePatch.ScalePatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localScale;
  687. PosRotScale.PosRotScalePatchList.Add(PosRotScalePatch);
  688. }
  689. }
  690. }
  691. }
  692. }
  693. #endregion
  694. #region 获取景点信息--素材编辑模式下
  695. /// <summary>
  696. /// 获取当前景点对应的物体信息
  697. /// </summary>
  698. /// <param name="spoitID"></param>
  699. /// <returns></returns>
  700. public ObjectValue GetSpoitObjs(int spoitID)
  701. {
  702. if (ObjectValues.ContainsKey(spoitID))
  703. {
  704. return ObjectValues[spoitID];
  705. }
  706. else
  707. {
  708. return null;
  709. }
  710. }
  711. /// <summary>
  712. /// 初始化数据
  713. /// 素材编辑模式下
  714. /// </summary>
  715. /// <param name="matObjs"></param>
  716. public void InitSpoitObjs()
  717. {
  718. m_EditorPanel.InitObjTransForm();
  719. }
  720. /// <summary>
  721. /// 保存数据
  722. /// 素材编辑模式下
  723. /// </summary>
  724. /// <param name="matObjs"></param>
  725. public void SaveSpoitObjs()
  726. {
  727. m_EditorPanel.SaveObjTransForm();
  728. }
  729. public void SaveAnchorObjs( string name)
  730. {
  731. foreach (var item in AnchorValue) // 保存所有锚点
  732. {
  733. item.Key.objectTransform.SavePos(item.Value.transform.localPosition, item.Value.transform.localEulerAngles, item.Value.transform.localScale);
  734. }
  735. // 锚点发送后台
  736. m_UIAnchorsPanel.SaveAnchors(name);
  737. }
  738. #endregion
  739. #region 创建水晶点、触发器范围、显示物体
  740. public IEnumerator CreateScene(SceneValue scene)
  741. {
  742. SceneValue = scene;
  743. if (m_MinMap.Map.sprite == null)
  744. {
  745. GetMinMap(scene ,null);
  746. }
  747. else
  748. {
  749. yield return StartCoroutine(StartCreateScene(scene));
  750. }
  751. yield return new WaitForSeconds(1f);
  752. MoveScenePatch();
  753. }
  754. private void MoveScenePatch()
  755. {
  756. Vector3 temp = ObjsParent.parent.localPosition;
  757. temp.z += MapSize.y;
  758. ObjsParent.parent.localPosition = temp;
  759. }
  760. private IEnumerator StartCreateScene(SceneValue scene)
  761. {
  762. if (scene.navLines != null && scene.navLines.Count > 0)
  763. SetRouteValue(scene.navLines);
  764. else
  765. Debug.LogError(" 当前场景未设置路径");
  766. Debug.Log("DGJ ====> " + JsonConvert.SerializeObject(scene));
  767. if (scene.listSpoit != null && scene.listSpoit.Count > 0)
  768. yield return StartCoroutine(SetSpoitValue(scene.listSpoit));
  769. else
  770. Debug.LogError(" 当前场景未创建景点");
  771. if (scene.listPicture != null && scene.listPicture.Count > 0)
  772. SetAnchor(scene.listPicture);
  773. else
  774. Debug.LogError(" 当前场景未创建锚点");
  775. //设置小地图景点
  776. // m_CalMap.SettingMapPoint(ListCrystals);
  777. yield return null;
  778. //UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
  779. // DownloadManager.Instance.UpdataData();
  780. }
  781. Action<bool> GetMinMapBack;
  782. /// <summary>
  783. /// 获取小地图
  784. /// </summary>
  785. public void GetMinMap( SceneValue scene ,Action<bool> getBack)
  786. {
  787. GetMinMapBack = getBack;
  788. //DownloadData data1 = new DownloadData();
  789. //string filename = Path.GetFileName(MapPicUrl);
  790. //data1.name = filename;
  791. //data1.type = 1;
  792. //data1.downloadPath = MapPicUrl;
  793. ////data1.updateTime = (int)SceneValue.updateTime;
  794. //data1.localSavePath = DownloadManager.Instance.LocaDataPath + "/map/" + filename;
  795. if(scene.width>0 &&scene.length>0)
  796. {
  797. //Debug.Log(scene.width + " " + scene.length);
  798. isStart = true;
  799. PointB.position = Vector3.zero;
  800. PointB.eulerAngles = Vector3.zero;
  801. PointA.position = PointB.position + new Vector3(0, 0, scene.width);
  802. PointA.eulerAngles = Vector3.zero;
  803. PointC.position = PointB.position + new Vector3(scene.length, 0, 0);
  804. PointC.eulerAngles = Vector3.zero;
  805. PointD.position = PointB.position + new Vector3(scene.length, 0, scene.width);
  806. PointD.eulerAngles = Vector3.zero;
  807. m_CalMap.SettingMapPoint(ListCrystals);
  808. }
  809. DownLoadMaterial downLoadMaterial = new DownLoadMaterial();
  810. downLoadMaterial.downLoadPath = MapPicUrl;
  811. downLoadMaterial.localLoadPath = Application.persistentDataPath + "/Material/" + MapPicUrl;
  812. downLoadMaterial.updataTime = scene.updateTime;
  813. downLoadMaterial.type = "-1";
  814. Debug.Log("Hjj 开始获取地图大小==》");
  815. MsgHandler.AddListener(downLoadMaterial.downLoadPath, HandleMsg);
  816. DownloadResManager.Instance.DownLoad(downLoadMaterial);
  817. ////DownloadManager.Instance.GetMapImage(data1, m_MinMap.Map, (b, tex) =>
  818. //{
  819. // if (b)
  820. // {
  821. // Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
  822. // m_MinMap.Map.sprite = sprite;
  823. // //m_MinMap.Map.SetNativeSize();
  824. // float width = tex.width;
  825. // float height = tex.height;
  826. // if(width>height)
  827. // {
  828. // width = width / height;
  829. // height = 1;
  830. // }
  831. // else
  832. // {
  833. // height = height / width;
  834. // width = 1;
  835. // }
  836. // MinMapSize = new Vector2(width * 150, height * 150);
  837. // CalMapSize();
  838. // m_MinMap.Map.GetComponent<RectTransform>().sizeDelta = new Vector2( width*150,height*150 );
  839. // //获取网页端
  840. // WebMapSize = new Vector2((float)tex.width, (float)tex.height);
  841. // if (SceneValue != null)
  842. // {
  843. // StartCreateScene(SceneValue);
  844. // }
  845. // }
  846. //});
  847. GameManager.Instance.isShowDownTip = true;
  848. DownloadResManager.Instance.StartDownLoad();
  849. }
  850. private void HandleMsg(Msg msg)
  851. {
  852. Debug.Log("Hjj 获取地图大小==》");
  853. // MsgHandler.RemoveListener()
  854. if(msg.Value!=null)
  855. {
  856. Texture2D tex = new Texture2D(1, 1);
  857. tex.LoadImage((byte[])msg.Value);
  858. // Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
  859. Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
  860. m_MinMap.Map.sprite = sprite;
  861. //m_MinMap.Map.SetNativeSize();
  862. float width = tex.width;
  863. float height = tex.height;
  864. if (width > height)
  865. {
  866. width = width / height;
  867. height = 1;
  868. }
  869. else
  870. {
  871. height = height / width;
  872. width = 1;
  873. }
  874. MinMapSize = new Vector2(width * 150, height * 150);
  875. CalMapSize();
  876. m_MinMap.Map.GetComponent<RectTransform>().sizeDelta = new Vector2(width * 150, height * 150);
  877. //获取网页端
  878. WebMapSize = new Vector2((float)tex.width, (float)tex.height);
  879. if (SceneValue != null)
  880. {
  881. StartCreateScene(SceneValue);
  882. }
  883. GetMinMapBack?.Invoke(true);
  884. }else
  885. {
  886. GetMinMapBack?.Invoke(false);
  887. }
  888. }
  889. /// <summary>
  890. /// 设置景点素材信息
  891. /// </summary>
  892. /// <param name="spoits"></param>
  893. public IEnumerator SetSpoitValue(List<SpoitValue> spoits)
  894. {
  895. SpoitValue spoitValue;
  896. for (int i = 0; i < spoits.Count-1; i++)
  897. {
  898. spoitValue = null;
  899. for (int j = 0; j < spoits.Count-1-i; j++)
  900. {
  901. if(spoits[j].id>spoits[j+1].id)
  902. {
  903. spoitValue = spoits[j];
  904. spoits[j] = spoits[j+1];
  905. spoits[j+1] = spoitValue;
  906. }
  907. }
  908. }
  909. SpoitValues.Clear();
  910. for (int i = 0; i < spoits.Count; i++)
  911. {
  912. var spoit = spoits[i];
  913. SpoitValue spoit1 = spoit;
  914. CreateCrystalAndTrigger(spoit);
  915. yield return StartCoroutine(CreateMaterial(spoit));
  916. spoits[i] = SV;
  917. }
  918. for (int i = 0; i < ListColiderBoxs_Mesh.Count; i++)
  919. {
  920. ListColiderBoxs_Mesh[i].enabled = false;
  921. }
  922. SpoitValues.AddRange(spoits);
  923. SceneValue.listSpoit = SpoitValues;
  924. DataManager.Instance.Spoits = SpoitValues;
  925. }
  926. /// <summary>
  927. /// 创建水晶点和触发器
  928. /// </summary>
  929. private void CreateCrystalAndTrigger(SpoitValue spoit)
  930. {
  931. var spoitPos = Vector3.zero;
  932. if (spoit.SpoitTransform!=null&&spoit.SpoitTransform.Count > 0)
  933. {
  934. Debug.LogFormat("{0}{1}", spoit.name, " DGJ ===> 景点存在");
  935. SpoitPos trans = spoit.SpoitTransform[0];
  936. spoitPos = new Vector3((float)trans.pointRelativeX / WebMapSize.x * MapSize.x, -1f, -(float)trans.pointRelativeY / WebMapSize.y * MapSize.y);
  937. //创建水晶点
  938. var obj = Instantiate(CrystalItem, CrystalsParent);
  939. CommandSystem.Instance.Send(
  940. new InstantiateGOCommand(InstantiateSystem.Instance.BlueObject.SpoitName, obj.gameObject)
  941. );
  942. obj.name = spoit.name;
  943. obj.transform.localPosition = spoitPos;
  944. ListCrystals.Add(obj.transform);
  945. var spoitobj = CreateSpoit(spoit, spoitPos);
  946. ListShowObjs.Add(spoitobj.transform);
  947. ObjectValue spoitvalue = new ObjectValue(spoit.id, -1, spoitobj.name, spoitobj);
  948. ObjectValues.Add(spoit.id, spoitvalue);
  949. ////创建触发器
  950. //if (SpoitsValueDetail.ContainsKey(spoit.id))
  951. //{
  952. // var spoitdetail = SpoitsValueDetail[spoit.id];
  953. // var range = spoitdetail.triggerRange;
  954. // if (range.areaRelativeH == 0 && range.areaRelativeW == 0 && range.areaRelativeX == 0 && range.areaRelativeY == 0)
  955. // {
  956. // }
  957. // else
  958. // {
  959. // trans = range;
  960. // }
  961. //}
  962. //var tiggerpos = new Vector3((float)trans.areaRelativeX / WebMapSize.x * MapSize.x, -0.5f, -(float)trans.areaRelativeY / WebMapSize.y * MapSize.y);
  963. var tiggerpos = new Vector3((float)(trans.areaRelativeX + trans.areaRelativeW / 2) / WebMapSize.x * MapSize.x, -0.5f, -(float)(trans.areaRelativeY + trans.areaRelativeH / 2) / WebMapSize.y * MapSize.y);
  964. var tiggerRange = new Vector3((float)trans.areaRelativeW / WebMapSize.x * MapSize.x, 0.1f, (float)trans.areaRelativeH / WebMapSize.y * MapSize.y);
  965. var triggerobj = Instantiate(ColliderItem, CollidersParent);
  966. triggerobj.name = spoit.name;
  967. triggerobj.transform.localPosition = tiggerpos;
  968. triggerobj.transform.localScale = tiggerRange;
  969. //triggerobj.AddComponent<EditorEventHandler>().IsClickEditor = true;
  970. ObjectValue boxvalue = new ObjectValue(spoit.id, -1, triggerobj.name, triggerobj);
  971. ColliderObjectValues.Add(boxvalue);
  972. ListColliderBoxs.Add(triggerobj.transform);
  973. ListColiderBoxs_Mesh.Add(triggerobj.GetComponent<MeshRenderer>());
  974. }
  975. else
  976. {
  977. Debug.LogFormat("{0}{1}", spoit.name, "景点不存在");
  978. }
  979. }
  980. private GameObject CreateSpoit(SpoitValue spoit, Vector3 spoitPos)
  981. {
  982. //生成景点父物体
  983. GameObject spoitObj = new GameObject(spoit.name);
  984. spoitObj.transform.SetParent(ObjsParent.transform);
  985. spoitObj.AddComponent<EditorEventHandler>().IsClickEditor = false;
  986. //为景点位置信息赋值
  987. if (spoit.spoitTf.startPos == Vector3.zero && spoit.spoitTf.nowPos == Vector3.zero)
  988. {
  989. spoitObj.transform.localPosition = new Vector3(spoitPos.x, 0.5f, spoitPos.z);
  990. spoitObj.transform.localRotation = Quaternion.identity;
  991. spoitObj.transform.localScale = new Vector3(1, 1, 1);
  992. spoit.spoitTf.SetStartValue(spoitObj.transform.localPosition, spoitObj.transform.localEulerAngles, spoitObj.transform.localScale);
  993. }
  994. else
  995. {
  996. spoitObj.transform.localPosition = spoit.spoitTf.nowPos;
  997. spoitObj.transform.localEulerAngles = spoit.spoitTf.nowRot;
  998. spoitObj.transform.localScale = spoit.spoitTf.nowScale;
  999. }
  1000. return spoitObj;
  1001. }
  1002. SpoitValue SV;
  1003. /// <summary>
  1004. /// 创建整体素材
  1005. /// 一个景点下应只有一个父物体,其他素材都在父物体下
  1006. /// </summary>
  1007. private IEnumerator CreateMaterial(SpoitValue spoit)
  1008. {
  1009. if(!ObjectValues.ContainsKey(spoit.id))
  1010. {
  1011. SV = new SpoitValue();
  1012. }
  1013. else
  1014. {
  1015. var spoitValues = ObjectValues[spoit.id];
  1016. var spoitObj = spoitValues.Object;
  1017. Debug.Log("DGJ ===> 创建整体素材 "+ spoit.material.Count);
  1018. SyncSpoit syncSpoit = new SyncSpoit();
  1019. syncSpoit.spoitId = spoit.name;
  1020. syncSpoit.spoitObj = spoitObj;
  1021. MultiPlayerManager.Instance.dicSpoitValue.Add(spoit.name, syncSpoit);
  1022. if(!UserInfo.Instance.is20)
  1023. //生成素材组合
  1024. for (int i = 0; i < spoit.material.Count; i++)
  1025. {
  1026. //素材整体
  1027. MaterialObl material = spoit.material[i];
  1028. //Debug.Log(spoit.material[i].name);
  1029. //素材组物体
  1030. GameObject matObj = new GameObject(material.name);
  1031. matObj.transform.SetParent(spoitValues.Object.transform);
  1032. matObj.transform.localPosition = Vector3.zero;
  1033. matObj.transform.localEulerAngles = Vector3.zero;
  1034. matObj.transform.localScale = new Vector3(1, 1, 1);
  1035. material.objectTransform.SetStartValue(matObj.transform.localPosition, matObj.transform.localEulerAngles, matObj.transform.localScale);
  1036. //素材组合对应ObjectValue的
  1037. ObjectValue spoitValue = new ObjectValue(i, spoit.id, material.name, matObj);
  1038. //素材组合下的单个素材ObjectValue
  1039. List<ObjectValue> objsvalue = null;
  1040. MaterialObl newmaterial = material;
  1041. //生成素材组合的ObjectValue,是对应景点的
  1042. switch (material.type)
  1043. {
  1044. case (int)MaterialType.None:
  1045. break;
  1046. case (int)MaterialType.Image:
  1047. case (int)MaterialType.Video:
  1048. case (int)MaterialType.Model:
  1049. case (int)MaterialType.Text:
  1050. case (int)MaterialType.LocaImage:
  1051. Debug.Log("DGJ ===> LocalImage " + material.name);
  1052. objsvalue = CreateSuCaiObj(spoit,material, matObj, out newmaterial);
  1053. break;
  1054. case (int)MaterialType.Image_Video_Text:
  1055. Debug.Log("DGJ ===> Image_Video_Text " + material.name);
  1056. objsvalue = CreateImage_Video_Text(spoit,material, matObj, out newmaterial);
  1057. break;
  1058. case (int)MaterialType.Model_Text:
  1059. Debug.Log("DGJ ===> Model_Text " + material.name);
  1060. objsvalue = CreateModel_Text(spoit,material, matObj, out newmaterial);
  1061. break;
  1062. default:
  1063. break;
  1064. }
  1065. spoit.material[i] = newmaterial;
  1066. spoitValue.ChildrenObj.AddRange(objsvalue);
  1067. spoitValues.ChildrenObj.Add(spoitValue);
  1068. }
  1069. SV = spoit;
  1070. if (ObjectValues.ContainsKey(spoit.id))
  1071. {
  1072. ObjectValues[spoit.id] = spoitValues;
  1073. }
  1074. else
  1075. {
  1076. ObjectValues.Add(spoit.id, spoitValues);
  1077. }
  1078. spoitObj.gameObject.SetActive(false);
  1079. }
  1080. yield return null;
  1081. }
  1082. /// <summary>
  1083. /// 编辑面板添加素材
  1084. /// </summary>
  1085. /// <param name="material"></param>
  1086. public void AddMaterial(MaterialObl material)
  1087. {
  1088. if (SpoitIndex < 0)
  1089. {
  1090. return;
  1091. }
  1092. MaterialObl newmaterial = new MaterialObl();
  1093. newmaterial = material;
  1094. var spoit = SpoitValues[SpoitIndex];
  1095. var spoitValues = ObjectValues[spoit.id];
  1096. var spoitObj = spoitValues.Object;
  1097. //素材组物体
  1098. GameObject matObj = new GameObject(newmaterial.name + "-" + spoit.material.Count.ToString());
  1099. newmaterial.name = matObj.name;
  1100. matObj.transform.SetParent(spoitValues.Object.transform);
  1101. if (!material.select)
  1102. {
  1103. matObj.transform.localPosition = Vector3.zero;
  1104. matObj.transform.localEulerAngles = Vector3.zero;
  1105. matObj.transform.localScale = new Vector3(1, 1, 1);
  1106. newmaterial.objectTransform.SetStartValue(matObj.transform.localPosition, matObj.transform.localEulerAngles, matObj.transform.localScale);
  1107. }
  1108. else
  1109. {
  1110. matObj.transform.localPosition = newmaterial.objectTransform.nowPos;
  1111. matObj.transform.localEulerAngles = newmaterial.objectTransform.nowRot;
  1112. matObj.transform.localScale = newmaterial.objectTransform.nowScale;
  1113. }
  1114. //素材组合对应ObjectValue的
  1115. ObjectValue spoitValue = new ObjectValue(spoit.material.Count, spoit.id, newmaterial.name, matObj);
  1116. //素材组合下的单个素材ObjectValue
  1117. List<ObjectValue> objsvalue = null;
  1118. //生成素材组合的ObjectValue,是对应景点的
  1119. switch (material.type)
  1120. {
  1121. case (int)MaterialType.None:
  1122. break;
  1123. case (int)MaterialType.Image:
  1124. case (int)MaterialType.Video:
  1125. case (int)MaterialType.Model:
  1126. case (int)MaterialType.Text:
  1127. case (int)MaterialType.LocaImage:
  1128. objsvalue = CreateSuCaiObj(spoit, newmaterial, matObj, out newmaterial);
  1129. break;
  1130. case (int)MaterialType.Image_Video_Text:
  1131. objsvalue = CreateImage_Video_Text(spoit,newmaterial, matObj, out newmaterial);
  1132. break;
  1133. case (int)MaterialType.Model_Text:
  1134. objsvalue = CreateModel_Text(spoit, newmaterial, matObj, out newmaterial);
  1135. break;
  1136. default:
  1137. break;
  1138. }
  1139. newmaterial.select = true;
  1140. spoit.material.Add(newmaterial);
  1141. spoitValue.ChildrenObj.AddRange(objsvalue);
  1142. spoitValues.ChildrenObj.Add(spoitValue);
  1143. if (ObjectValues.ContainsKey(spoit.id))
  1144. {
  1145. ObjectValues[spoit.id] = spoitValues;
  1146. }
  1147. else
  1148. {
  1149. ObjectValues.Add(spoit.id, spoitValues);
  1150. }
  1151. SpoitValues[SpoitIndex] = spoit;
  1152. //更新编辑面板Ui
  1153. UpdateEditorUI();
  1154. }
  1155. /// <summary>
  1156. /// 创建 1图片 2视频 3模型 4文字
  1157. /// </summary>
  1158. /// <param name="type">素材类型</param>
  1159. /// <param name="material">素材数据</param>
  1160. /// <param name="spoit">景点</param>
  1161. /// <returns></returns>
  1162. private List<ObjectValue> CreateSuCaiObj(SpoitValue spoitjd, MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
  1163. {
  1164. List<ObjectValue> objects = new List<ObjectValue>();
  1165. List<MaterialObjValue> objs = material.materialList;
  1166. newmaterial = material;
  1167. //for (int i = 0; i < objs.Count; i++)
  1168. //{
  1169. // Debug.Log(objs[i].localSavePath);
  1170. //}
  1171. for (int i = 0; i < objs.Count; i++)
  1172. {
  1173. var mat = objs[i];
  1174. GameObject go = null;
  1175. switch (mat.type)
  1176. {
  1177. case (int)MaterialType.None:
  1178. break;
  1179. case (int)MaterialType.Image:
  1180. var pImage = ResMgr.Instance.Load<GameObject>("Template/Prefab/Image");
  1181. go = Instantiate(pImage, spoit.transform);
  1182. var imageitem = go.AddComponent<TemplateImage>();
  1183. go.SetActive(true);
  1184. imageitem.SetData(mat, material.updateTime);
  1185. break;
  1186. case (int)MaterialType.Video:
  1187. var pVideo = ResMgr.Instance.Load<GameObject>("Template/Prefab/Video");
  1188. go = Instantiate(pVideo, spoit.transform);
  1189. var videoitem = go.AddComponent<TemplateVideo>();
  1190. videoitem.autoplay = material.autoplay;
  1191. go.SetActive(true);
  1192. videoitem.SetData(mat, material.updateTime);
  1193. break;
  1194. case (int)MaterialType.Model:
  1195. var pModel = ResMgr.Instance.Load<GameObject>("Template/Prefab/Model");
  1196. go = Instantiate(pModel, spoit.transform);
  1197. var modelitem = go.AddComponent<TemplateModel>();
  1198. go.SetActive(true);
  1199. modelitem.SetData(mat, material.updateTime);
  1200. Debug.Log(modelitem.Data.localLoadPath);
  1201. break;
  1202. case (int)MaterialType.Text:
  1203. var pText = ResMgr.Instance.Load<GameObject>("Template/Prefab/Text");
  1204. go = Instantiate(pText, spoit.transform);
  1205. var textitem = go.AddComponent<TemplateText>();
  1206. go.SetActive(true);
  1207. textitem.SetData(mat, material.updateTime);
  1208. break;
  1209. case (int)MaterialType.LocaImage:
  1210. var pLocaImage = ResMgr.Instance.Load<GameObject>("Template/Prefab/Image");
  1211. go = Instantiate(pLocaImage, spoit.transform);
  1212. var locaImageitem = go.AddComponent<TemplateImage>();
  1213. go.SetActive(true);
  1214. locaImageitem.SetLocaImageData(mat);
  1215. break;
  1216. default:
  1217. break;
  1218. }
  1219. if (go != null)
  1220. {
  1221. if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString()))
  1222. {
  1223. GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary<string, Dictionary<string, GameObject>>());
  1224. }
  1225. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(material.id.ToString()))
  1226. {
  1227. GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(material.id.ToString(), new Dictionary<string, GameObject>());
  1228. }
  1229. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].ContainsKey(mat.id.ToString()))
  1230. {
  1231. GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].Add(mat.id.ToString(), go);
  1232. }
  1233. else
  1234. {
  1235. GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()][mat.id.ToString()] = go;
  1236. }
  1237. go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
  1238. mat.name = go.name;
  1239. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  1240. if (material.select)
  1241. {
  1242. go.transform.localPosition = mat.ObjectTransform.nowPos;
  1243. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  1244. go.transform.localScale = mat.ObjectTransform.nowScale;
  1245. }
  1246. else
  1247. {
  1248. go.transform.localEulerAngles = Vector3.zero;
  1249. go.transform.localScale = new Vector3(1, 1, 1);
  1250. if (mat.type != (int)MaterialType.Text)
  1251. {
  1252. go.transform.localPosition = Vector3.zero;
  1253. }
  1254. else
  1255. {
  1256. //Set text position
  1257. if (mat.textPosition == "top")
  1258. {
  1259. go.transform.localPosition = new Vector3(0, 0.3f, 0);
  1260. }
  1261. else if (mat.textPosition == "bottom")
  1262. {
  1263. go.transform.localPosition = new Vector3(0, -0.3f, 0);
  1264. }
  1265. }
  1266. mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  1267. }
  1268. ObjectValue objectValue = new ObjectValue(i, material.id, mat.name, go);
  1269. objects.Add(objectValue);
  1270. }
  1271. newmaterial.materialList[i] = mat;
  1272. }
  1273. return objects;
  1274. }
  1275. /// <summary>
  1276. /// 创建 6模型+文字
  1277. /// </summary>
  1278. /// <param name="material"></param>
  1279. /// <param name="spoit"></param>
  1280. /// <returns></returns>
  1281. private List<ObjectValue> CreateModel_Text(SpoitValue spoitjd, MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
  1282. {
  1283. List<ObjectValue> objects = new List<ObjectValue>();
  1284. List<MaterialObjValue> objs = material.materialList;
  1285. newmaterial = material;
  1286. for (int i = 0; i < objs.Count; i++)
  1287. {
  1288. var mat = objs[i];
  1289. GameObject go = null;
  1290. switch (mat.type)
  1291. {
  1292. case (int)MaterialType.None:
  1293. break;
  1294. case (int)MaterialType.Model:
  1295. var pModel = ResMgr.Instance.Load<GameObject>("Template/Prefab/Model");
  1296. go = Instantiate(pModel, spoit.transform);
  1297. var modelitem = go.AddComponent<TemplateModel>();
  1298. go.SetActive(true);
  1299. modelitem.SetData(mat, material.updateTime);
  1300. break;
  1301. case (int)MaterialType.Text:
  1302. var pText = ResMgr.Instance.Load<GameObject>("Template/Prefab/Text");
  1303. go = Instantiate(pText, spoit.transform);
  1304. var textitem = go.AddComponent<TemplateText>();
  1305. go.SetActive(true);
  1306. textitem.SetData(mat, material.updateTime);
  1307. break;
  1308. default:
  1309. break;
  1310. }
  1311. if (go != null)
  1312. {
  1313. if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString()))
  1314. {
  1315. GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary<string, Dictionary<string, GameObject>>());
  1316. }
  1317. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(material.id.ToString()))
  1318. {
  1319. GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(material.id.ToString(), new Dictionary<string, GameObject>());
  1320. }
  1321. if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].ContainsKey(mat.id.ToString()))
  1322. {
  1323. GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].Add(mat.id.ToString(), go);
  1324. }
  1325. else
  1326. {
  1327. GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()][mat.id.ToString()] = go;
  1328. }
  1329. go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
  1330. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  1331. if (material.select)
  1332. {
  1333. go.transform.localPosition = mat.ObjectTransform.nowPos;
  1334. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  1335. go.transform.localScale = mat.ObjectTransform.nowScale;
  1336. }
  1337. else
  1338. {
  1339. go.transform.localEulerAngles = Vector3.zero;
  1340. go.transform.localScale = new Vector3(1, 1, 1);
  1341. if (mat.type != (int)MaterialType.Text)
  1342. {
  1343. go.transform.localPosition = Vector3.zero;
  1344. }
  1345. else
  1346. {
  1347. //Set text position
  1348. if (mat.textPosition == "top")
  1349. {
  1350. go.transform.localPosition = new Vector3(0, 0.3f, 0);
  1351. }
  1352. else if (mat.textPosition == "bottom")
  1353. {
  1354. go.transform.localPosition = new Vector3(0, -0.3f, 0);
  1355. }
  1356. else if (mat.textPosition == "left")
  1357. {
  1358. go.transform.localPosition = new Vector3(-0.3f, 0, 0);
  1359. }
  1360. else if (mat.textPosition == "right")
  1361. {
  1362. go.transform.localPosition = new Vector3(0.3f, 0f, 0);
  1363. }
  1364. }
  1365. mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  1366. }
  1367. ObjectValue objectValue = CreateMatObjectValue(i, material.id, go, mat);
  1368. objects.Add(objectValue);
  1369. }
  1370. newmaterial.materialList[i] = mat;
  1371. }
  1372. return objects;
  1373. }
  1374. /// <summary>
  1375. /// 创建 5图片+文字/视频+文字
  1376. /// </summary>
  1377. private List<ObjectValue> CreateImage_Video_Text(SpoitValue spoitjd,MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
  1378. {
  1379. Debug.LogError("HJJmaterialObls.select DRFanLayout.CreateImage_Video_Text ");
  1380. newmaterial = material;
  1381. List<ObjectValue> objects = new List<ObjectValue>();
  1382. SRTitleLayout.CalLayout(spoitjd,material, spoit, out newmaterial);
  1383. Debug.LogError("HJJmaterialObls.select DRFanLayout.CalLayout default ");
  1384. return objects;
  1385. }
  1386. /// <summary>
  1387. /// 创建物体ObjectValue,并赋值位置信息
  1388. /// </summary>
  1389. /// <param name="id"></param>
  1390. /// <param name="parentid"></param>
  1391. /// <param name="go"></param>
  1392. /// <param name="mat"></param>
  1393. /// <returns></returns>
  1394. private ObjectValue CreateMatObjectValue(int id, int parentid, GameObject go, MaterialObjValue mat)
  1395. {
  1396. go.name = string.IsNullOrWhiteSpace(mat.name) ? go.name : mat.name;
  1397. go.AddComponent<EditorEventHandler>().Type = (MaterialType)(mat.type);
  1398. //为物体位置信息赋值
  1399. if (mat.ObjectTransform != null)
  1400. {
  1401. go.transform.localPosition = mat.ObjectTransform.nowPos;
  1402. go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
  1403. go.transform.localScale = mat.ObjectTransform.nowScale;
  1404. }
  1405. else
  1406. {
  1407. go.transform.localPosition = Vector3.zero;
  1408. go.transform.localEulerAngles = Vector3.zero;
  1409. go.transform.localScale = new Vector3(1, 1, 1);
  1410. }
  1411. ObjectValue objectValue = new ObjectValue(id, parentid, mat.name, go, go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
  1412. return objectValue;
  1413. }
  1414. #endregion
  1415. #region 路径
  1416. /// <summary>
  1417. /// 设置路线数据
  1418. /// </summary>
  1419. /// <param name="navLines"></param>
  1420. public void SetRouteValue(List<NavLinesItem> navLines)
  1421. {
  1422. if (navLines == null || navLines.Count <= 0)
  1423. {
  1424. Debug.Log("当前景点未绘制路线");
  1425. return;
  1426. }
  1427. RouteCtr.SetRouteValue(navLines);
  1428. }
  1429. #endregion
  1430. #region 锚点
  1431. /// <summary>
  1432. /// 设置场景锚点
  1433. /// </summary>
  1434. /// <param name="listAnchor"></param>
  1435. public void SetAnchor(List<Anchor> listAnchor)
  1436. {
  1437. if (listAnchor == null)
  1438. return;
  1439. Anchor anchor;
  1440. for (int i = 0; i < listAnchor.Count - 1; i++)
  1441. {
  1442. for (int j = 0; j < listAnchor.Count - 1 - i; j++)
  1443. {
  1444. if (listAnchor[j].id > listAnchor[j + 1].id)
  1445. {
  1446. anchor = listAnchor[j];
  1447. listAnchor[j] = listAnchor[j + 1];
  1448. listAnchor[j + 1] = anchor;
  1449. }
  1450. }
  1451. }
  1452. for (int i = 0; i < listAnchor.Count; i++)
  1453. {
  1454. // 创建锚点
  1455. GameManager.Instance.AnchorValue.Add(listAnchor[i], CreateAnchor(listAnchor[i]));
  1456. GameManager.Instance.AnchorChild.Add(listAnchor[i], AnchorValue[listAnchor[i]].transform.GetChild(0).gameObject);
  1457. }
  1458. m_UIAnchorsPanel.SetAnchor(AnchorValue);
  1459. }
  1460. private MeshRenderer CreateAnchor(Anchor anchor)
  1461. {
  1462. // 创建锚点 给锚点赋值
  1463. GameObject anchorObj = GameObject.Instantiate(Resources.Load<GameObject>("Template/Prefab/Anchor"),AnchorsParent);
  1464. anchorObj.name = "Anchor" + anchor.id;
  1465. /*
  1466. VuforiaAnchor vuforiaAnchor = anchorObj.GetComponent<VuforiaAnchor>();
  1467. vuforiaAnchor.player = GameManager.Instance.m_head.transform;
  1468. if (VuforiaManager.Instance.list_Anchor == null)
  1469. VuforiaManager.Instance.list_Anchor = new List<VuforiaAnchor>();
  1470. VuforiaManager.Instance.list_Anchor.Add(vuforiaAnchor);*/
  1471. var anchorPos = Vector3.zero;
  1472. Debug.Log(anchor.picturePosition.pointRelativeX+" "+ WebMapSize.x);
  1473. anchorPos = new Vector3((float)anchor.picturePosition.pointRelativeX / WebMapSize.x * MapSize.x, -1f, -(float)anchor.picturePosition.pointRelativeY / WebMapSize.y * MapSize.y);
  1474. anchorObj.transform.localPosition = anchorPos;
  1475. anchorObj.transform.GetChild(0).gameObject.SetActive(false);
  1476. var mesh = anchorObj.GetComponent<MeshRenderer>();
  1477. mesh.enabled = false;
  1478. //if(anchor.objectTransform!=null)
  1479. //{
  1480. // anchorObj.transform.localPosition = anchor.objectTransform.nowPos;
  1481. // anchorObj.transform.localEulerAngles = anchor.objectTransform.nowRot;
  1482. //}
  1483. if(anchor.objectTransform!=null && anchor.objectTransform.nowScale!=Vector3.zero)
  1484. {
  1485. anchorObj.transform.localEulerAngles = anchor.objectTransform.nowRot;
  1486. anchorObj.transform.localPosition = anchor.objectTransform.nowPos;
  1487. }
  1488. return mesh;
  1489. }
  1490. #endregion
  1491. #region 触发器判定
  1492. /// <summary>
  1493. /// 当人物进入触发器范围
  1494. /// </summary>
  1495. public void OnColliderTriggerEnter(Collider other)
  1496. {
  1497. IsTriggerExiting = true;
  1498. for (int i = 0; i < ListColliderBoxs.Count; i++)
  1499. {
  1500. if (other.name == ListColliderBoxs[i].name)
  1501. {
  1502. ListShowObjs[i].gameObject.SetActive(true);
  1503. MQTTClient.Instance.sendActiveSp(ListShowObjs[i].name, true);
  1504. Debug.Log(i);
  1505. if (isShowLoacalShowObjs)
  1506. ListLocalShowObjs[i].gameObject.SetActive(true);
  1507. // 进入景点通知后台
  1508. for (int j = 0; j < SceneValue.listSpoit.Count; j++)
  1509. {
  1510. if(SceneValue.listSpoit[i].name == other.name)
  1511. {
  1512. HttpSocket.Instance.SendIpToPointTrigger(" ", SceneValue.listSpoit[i].id, CallBack);
  1513. }
  1514. }
  1515. if (SpoitIndex == i)
  1516. {
  1517. return;
  1518. }
  1519. //进入新区域前关闭当前显示
  1520. if (SpoitIndex >= 0 && IsStartEditor)
  1521. {
  1522. ListShowObjs[SpoitIndex].gameObject.SetActive(false);
  1523. MQTTClient.Instance.sendActiveSp(ListShowObjs[SpoitIndex].name, false);
  1524. if (isShowLoacalShowObjs)
  1525. ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
  1526. ListCrystals[SpoitIndex].gameObject.SetActive(true);
  1527. m_EditorPanel.ClosePanel();
  1528. }
  1529. //进入新的出发区域
  1530. SpoitIndex = i;
  1531. ListCrystals[SpoitIndex].gameObject.SetActive(false);
  1532. m_EditorPanel.SetSpoit(SpoitValues[i]);
  1533. return;
  1534. }
  1535. }
  1536. }
  1537. public void SetPosRotScale()
  1538. {
  1539. refOldData();
  1540. }
  1541. /// <summary>
  1542. /// 当人物退出触发器范围
  1543. /// </summary>
  1544. public void OnColliderTriggerExit(Collider other)
  1545. {
  1546. IsTriggerExiting = false;
  1547. if (IsStartEditor)
  1548. {
  1549. return;
  1550. }
  1551. else
  1552. {
  1553. ListShowObjs[SpoitIndex].gameObject.SetActive(false);
  1554. MQTTClient.Instance.sendActiveSp(ListShowObjs[SpoitIndex].name, false);
  1555. if (isShowLoacalShowObjs)
  1556. ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
  1557. ListCrystals[SpoitIndex].gameObject.SetActive(true);
  1558. m_EditorPanel.ClosePanel();
  1559. SpoitIndex = -1;
  1560. }
  1561. }
  1562. /// <summary>
  1563. /// 更新景点信息
  1564. /// </summary>
  1565. public void UpdateSpoitValue()
  1566. {
  1567. var spoit = SpoitValues[SpoitIndex];
  1568. var objvalues = ObjectValues[spoit.id];
  1569. spoit.spoitTf.SavePos(objvalues.nowPos, objvalues.nowRot, objvalues.nowScale);
  1570. //X\Y\W\H
  1571. var collidervalue = ColliderObjectValues[SpoitIndex];
  1572. var collider = collidervalue.Object;
  1573. var pos = collidervalue.nowPos;
  1574. var w = collidervalue.nowScale.x;
  1575. var h = collidervalue.nowScale.z;
  1576. var webpos = new Vector3(Math.Abs(pos.x) / MapSize.x * WebMapSize.x, 0, Math.Abs(pos.z) / MapSize.y * WebMapSize.y);
  1577. var webw = w / MapSize.x * WebMapSize.x;
  1578. var webh = h / MapSize.y * WebMapSize.y;
  1579. spoit.SpoitTransform[0].areaRelativeX = webpos.x;
  1580. spoit.SpoitTransform[0].areaRelativeY = webpos.z;
  1581. spoit.SpoitTransform[0].areaRelativeW = webw;
  1582. spoit.SpoitTransform[0].areaRelativeH = webh;
  1583. spoit.spoitTf.SavePos(objvalues.nowPos, objvalues.nowRot, objvalues.nowScale);
  1584. if (objvalues.Object == null)
  1585. {
  1586. RemoveSpoitObjectValue(spoit.id);
  1587. spoit.material = new List<MaterialObl>();
  1588. }
  1589. else
  1590. {
  1591. var mats = spoit.material;
  1592. var objvalue = objvalues.ChildrenObj;
  1593. for (int j = 0; j < mats.Count; j++)
  1594. {
  1595. var matobj = mats[j];
  1596. var obis = objvalue[j];
  1597. matobj.objectTransform.SavePos(obis.nowPos, obis.nowRot, obis.nowScale);
  1598. for (int m = 0; m < matobj.materialList.Count; m++)
  1599. {
  1600. var childrenobj = obis.ChildrenObj[m];
  1601. var mat = matobj.materialList[m];
  1602. if (childrenobj.Object == null)
  1603. {
  1604. obis.ChildrenObj.RemoveAt(m);
  1605. matobj.materialList.RemoveAt(m);
  1606. break;
  1607. }
  1608. mat.ObjectTransform.SavePos(childrenobj.nowPos, childrenobj.nowRot, childrenobj.nowScale);
  1609. }
  1610. matobj.select = true;
  1611. if (obis.ChildrenObj.Count <= 0)
  1612. {
  1613. mats.RemoveAt(j);
  1614. objvalue.RemoveAt(j);
  1615. Destroy(obis.Object);
  1616. break;
  1617. }
  1618. }
  1619. }
  1620. SpoitValues[SpoitIndex] = spoit;
  1621. }
  1622. public void UpdateEditorUI()
  1623. {
  1624. m_EditorPanel.SetSpoit(SpoitValues[SpoitIndex]);
  1625. }
  1626. #endregion
  1627. public ObjectValue GetCurrentColliderValue()
  1628. {
  1629. return ColliderObjectValues[SpoitIndex];
  1630. }
  1631. public void SaveSpoitObjectValue(ObjectValue value)
  1632. {
  1633. if (ObjectValues.ContainsKey(SpoitValues[SpoitIndex].id))
  1634. {
  1635. ObjectValues[SpoitValues[SpoitIndex].id] = value;
  1636. }
  1637. }
  1638. public void RemoveSpoitObjectValue(int id)
  1639. {
  1640. if (ObjectValues.ContainsKey(id))
  1641. {
  1642. ObjectValues.Remove(id);
  1643. }
  1644. }
  1645. public void SaveCurrentColliderValue(ObjectValue value)
  1646. {
  1647. if (ColliderObjectValues.Contains(value))
  1648. {
  1649. ColliderObjectValues[SpoitIndex] = value;
  1650. }
  1651. }
  1652. //计算场景中点云地图比例
  1653. public void CalMapSize()
  1654. {
  1655. //场景地图比例
  1656. var disX = Vector3.Distance(PointA.localPosition, PointD.localPosition);
  1657. var disZ = Vector3.Distance(PointA.localPosition, PointB.localPosition);
  1658. MapSize = new Vector2(disX, disZ);
  1659. //Debug.LogFormat("{0}:{1}", "AB", Vector3.Distance(PointA.localPosition, PointB.localPosition));
  1660. //Debug.LogFormat("{0}:{1}", "CD", Vector3.Distance(PointC.localPosition, PointD.localPosition));
  1661. //Debug.LogFormat("{0}:{1}", "AD", Vector3.Distance(PointA.localPosition, PointD.localPosition));
  1662. //Debug.LogFormat("{0}:{1}", "BC", Vector3.Distance(PointB.localPosition, PointC.localPosition));
  1663. }
  1664. public void CallBack(string message)
  1665. {
  1666. }
  1667. }
  1668. [Serializable]
  1669. public class ObjectValue
  1670. {
  1671. /// <summary>
  1672. /// 景点ID
  1673. /// </summary>
  1674. [SerializeField]
  1675. public int ID;
  1676. /// <summary>
  1677. /// 当前物体名称
  1678. /// </summary>
  1679. [SerializeField]
  1680. public string matName;
  1681. /// <summary>
  1682. /// 父物体ID
  1683. /// -1表示当期物体为景点
  1684. /// </summary>
  1685. [SerializeField]
  1686. public int parentID;
  1687. /// <summary>
  1688. /// 对应的物体
  1689. /// </summary>
  1690. [SerializeField]
  1691. public GameObject Object;
  1692. /// <summary>
  1693. /// 子物体
  1694. /// </summary>
  1695. [SerializeField]
  1696. public List<ObjectValue> ChildrenObj;
  1697. public Vector3 startPos { get; set; }
  1698. public Vector3 startRot { get; set; }
  1699. public Vector3 startScale { get; set; }
  1700. public Vector3 nowPos { get; set; }
  1701. public Vector3 nowRot { get; set; }
  1702. public Vector3 nowScale { get; set; }
  1703. public ObjectValue()
  1704. {
  1705. ChildrenObj = new List<ObjectValue>();
  1706. parentID = -1;
  1707. }
  1708. /// <summary>
  1709. ///
  1710. /// </summary>
  1711. /// <param name="id">景点对应的index</param>
  1712. /// <param name="parentid">景点ID</param>
  1713. /// <param name="name"></param>
  1714. /// <param name="object"></param>
  1715. /// <param name="pos"></param>
  1716. /// <param name="Rot"></param>
  1717. /// <param name="Scale"></param>
  1718. public ObjectValue(int id, int parentid, string name, GameObject @object, Vector3 pos, Vector3 Rot, Vector3 Scale)
  1719. {
  1720. ID = id;
  1721. parentID = parentid;
  1722. matName = name;
  1723. Object = @object;
  1724. ChildrenObj = new List<ObjectValue>();
  1725. startPos = pos;
  1726. nowPos = pos;
  1727. startRot = Rot;
  1728. nowRot = Rot;
  1729. startScale = Scale;
  1730. nowScale = Scale;
  1731. }
  1732. public ObjectValue(int id, int parentid, string name, GameObject @object)
  1733. {
  1734. ID = id;
  1735. parentID = parentid;
  1736. matName = name;
  1737. Object = @object;
  1738. ChildrenObj = new List<ObjectValue>();
  1739. startPos = @object.transform.localPosition;
  1740. nowPos = startPos;
  1741. startRot = @object.transform.localEulerAngles;
  1742. nowRot = startRot;
  1743. startScale = @object.transform.localScale;
  1744. nowScale = startScale;
  1745. }
  1746. /// <summary>
  1747. /// 初始化时当前位置和初始位置
  1748. /// 此方法只在组合素材时使用
  1749. /// </summary>
  1750. public void InitTransform()
  1751. {
  1752. if (Object != null)
  1753. {
  1754. startPos = Object.transform.localPosition;
  1755. nowPos = Object.transform.localPosition;
  1756. startRot = Object.transform.localEulerAngles;
  1757. nowRot = Object.transform.localEulerAngles;
  1758. startScale = Object.transform.localScale;
  1759. nowScale = Object.transform.localScale;
  1760. }
  1761. }
  1762. /// <summary>
  1763. /// 编辑物体坐标时初始化坐标
  1764. /// </summary>
  1765. public void InitObjTransform()
  1766. {
  1767. Object.transform.localPosition = startPos;
  1768. Object.transform.localEulerAngles = startRot;
  1769. Object.transform.localScale = startScale;
  1770. nowPos = startPos;
  1771. nowRot = startRot;
  1772. nowScale = startScale;
  1773. }
  1774. /// <summary>
  1775. /// 编辑物体坐标时保存坐标信息
  1776. /// </summary>
  1777. public void SaveObjTransfoem()
  1778. {
  1779. if (Object != null)
  1780. {
  1781. nowPos = Object.transform.localPosition;
  1782. nowRot = Object.transform.localEulerAngles;
  1783. nowScale = Object.transform.localScale;
  1784. }
  1785. }
  1786. }