GameManager.cs 56 KB

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