GameManager.cs 58 KB

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