GameManager.cs 87 KB

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