GameManager.cs 61 KB

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