GameManager.cs 63 KB

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