12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706 |
- using Immersal.AR;
- using LitJson;
- using Newtonsoft.Json;
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- /*
- * 半自动交付/自动交付
- * 景点、触发范围、水晶点应保持顺序对应
- * 当前场景下景点名称不应重复
- * 同一景点下素材名称不应重复
- * ListShowObjs/ListColliderBoxs/ListCrystals半自动时在场景中推拽,全自动时全部由代码生成
- *
- * 新增锚点列表
- * 锚点识别图Vuforia XML和DAT文件
- * 各个锚点的位置信息
- *
- * 每次打开都下载vuforia文件
- * 自动加载生成ImageTarget
- *
- */
- public class GameManager : MonoSingleton<GameManager>
- {
- public Text text;
- public GameObject Map;
- /// <summary>
- /// 景点ID与对应的素材组合
- /// </summary>
- [SerializeField, Tooltip("景点对应的物体及景点下的素材")]
- private Dictionary<int, ObjectValue> ObjectValues = new Dictionary<int, ObjectValue>();
- public List<ObjectValue> ColliderObjectValues = new List<ObjectValue>();
- [Header("Spoit")]
- [Tooltip("景点对应的显示物体")]
- public List<Transform> ListShowObjs;
- [Tooltip("景点对应的显示物体,本地添加物体")]
- public List<Transform> ListLocalShowObjs;
- public bool isShowLoacalShowObjs = false;
- [Tooltip("景点对应的物体触发范围")]
- public List<Transform> ListColliderBoxs;
- private List<MeshRenderer> ListColiderBoxs_Mesh;
- [Tooltip("景点对应的水晶点")]
- public List<Transform> ListCrystals;
- [Tooltip("景点对应的显示物体父物体")]
- public Transform ObjsParent;
- [Tooltip("触发器父物体")]
- public Transform CollidersParent;
- [Tooltip("水晶点父物体")]
- public Transform CrystalsParent;
- [Tooltip("锚点父物体")]
- public Transform AnchorsParent;
- public GameObject ColliderItem;
- public GameObject CrystalItem;
- [Space(20)]
- [Tooltip("是否显示路径")]
- public bool IsShowLuJIng = true;
- [Tooltip("是否为编辑模式")]
- public bool IsEditor = true;
- [Tooltip("是否是全自动显示景点")]
- public bool IsAuto = true;
- [SerializeField, Tooltip("路径控制器")]
- private RouteCtr RouteCtr;
- [SerializeField, Tooltip("素材编辑器")]
- private EditorPanel m_EditorPanel;
- [SerializeField, Tooltip("计算人物在地图上的位置")]
- [Header("MinMap")]
- private CalMap m_CalMap;
- [SerializeField, Tooltip("小地图信息")]
- private MinMap m_MinMap;
- [Header("Setting")]
- [SerializeField, Tooltip("设置面板")]
- private SettingPanel m_SettingPanel;
- [SerializeField, Tooltip("编辑器面板")]
- private Transform m_EditorCanvas;
- [SerializeField, Tooltip("设置按钮")]
- private Transform m_SetBtn;
- [Header("地图比例")]
- public Transform PointA;
- public Transform PointB;
- public Transform PointC;
- public Transform PointD;
- public bool isStart; // 场景四个点已经确定
- public Vector2 WebMapSize;
- public Vector2 MapSize;
- public Vector2 MinMapSize = new Vector2(320, 135);
- public string MapPicUrl;
- [Header("展厅")]
- public GameObject MRZhanTing;
- public bool isPlayMRZhanTing;
- public IrobotMove m_IroBot;
- [Header("Player")]
- public PlayerTrigger Player;
- [Header("Head")]
- public Transform m_head;
- [Header("虚拟导游")]
- public List<IrobotMove> Irobots;
- /// <summary>
- /// 是否在触发区域内
- /// </summary>
- private bool m_IsTriggerExiting;
- /// <summary>
- /// 是否在触发区域内
- /// </summary>
- public bool IsTriggerExiting
- {
- get { return m_IsTriggerExiting; }
- set { m_IsTriggerExiting = value; }
- }
- /// <summary>
- /// 是否可以开始编辑素材
- /// </summary>
- private bool m_IsStartEditor;
- /// <summary>
- /// 是否可以开始编辑素材
- /// </summary>
- public bool IsStartEditor
- {
- get { return m_IsStartEditor; }
- set { m_IsStartEditor = value; }
- }
- /// <summary>
- /// 素材加载完成,素材prefab生成完成,开始进入运行状态
- /// </summary>
- public bool m_IsRuning;
- /// <summary>
- /// 素材加载完成,素材prefab生成完成,开始进入运行状态
- /// </summary>
- public bool IsRuning
- {
- get { return m_IsRuning; }
- set { m_IsRuning = value; }
- }
- /// <summary>
- /// 当前触发物体的下标
- /// </summary>
- private int m_SpoitIndex;
- /// <summary>
- /// 当前触发物体的下标
- /// </summary>
- public int SpoitIndex
- {
- get { return m_SpoitIndex; }
- set { m_SpoitIndex = value; }
- }
- /// <summary>
- /// 当前场景数据
- /// </summary>
- public SceneValue m_SceneValue;
- /// <summary>
- /// 当前场景数据
- /// </summary>
- public SceneValue SceneValue
- {
- get { return m_SceneValue; }
- set { m_SceneValue = value; }
- }
- /// <summary>
- /// 当前场景中的景点信息
- /// </summary>
- private List<SpoitValue> m_SpoitValues;
- /// <summary>
- /// 当前场景中的景点信息
- /// </summary>
- public List<SpoitValue> SpoitValues
- {
- get { return m_SpoitValues; }
- set { m_SpoitValues = value; }
- }
- /// <summary>
- /// 景点详情数据
- /// </summary>
- private Dictionary<int, SpoitValueDetail> m_SpoitsValueDetail;
- /// <summary>
- /// 景点详情数据
- /// </summary>
- public Dictionary<int, SpoitValueDetail> SpoitsValueDetail
- {
- get { return m_SpoitsValueDetail; }
- set { m_SpoitsValueDetail = value; }
- }
- public UIAnchorsPanel m_UIAnchorsPanel;
- private Dictionary<Anchor, MeshRenderer> m_AnchorValue;
- public Dictionary<Anchor, MeshRenderer> AnchorValue
- {
- get { return m_AnchorValue; }
- set { m_AnchorValue = value; }
- }
- private Dictionary<Anchor, GameObject> m_AnchorChild;
- public Dictionary<Anchor,GameObject> AnchorChild
- {
- get { return m_AnchorChild; }
- set { m_AnchorChild = value; }
- }
- public Toggle EditorToggle;
- public GameObject ERNIEBot;
- private void Awake()
- {
-
- // Debug.unityLogger.logEnabled = false;
- }
- private void Start()
- {
- this.gameObject.AddComponent<TimerMgr>();
- // PlayerPrefs.DeleteAll();
- isStart = false;
- m_SpoitsValueDetail = new Dictionary<int, SpoitValueDetail>();
- m_AnchorValue = new Dictionary<Anchor, MeshRenderer>();
- m_AnchorChild = new Dictionary<Anchor, GameObject>();
- SceneValue = null;
- m_IsStartEditor = false;
- m_IsRuning = false;
- m_SetBtn.gameObject.SetActive(false);
- //CalMapSize();
- SpoitIndex = -1;
- SpoitValues = new List<SpoitValue>();
- if (m_EditorPanel == null)
- {
- m_EditorPanel = GameObject.FindObjectOfType<EditorPanel>();
- }
-
- if (!IsAuto)
- {
- //GetObjectValue();
- //CreateSpoitValue();
- }
- else
- {
- ListShowObjs = new List<Transform>();
- ListColliderBoxs = new List<Transform>();
- ListColiderBoxs_Mesh = new List<MeshRenderer>();
- ListCrystals = new List<Transform>();
- // ListLocalShowObjs = new List<Transform>();
- }
- m_MinMap.gameObject.SetActive(false);
- Map.SetActive(false);
- }
- private void LateUpdate()
- {
- // if (API_GSXR_Slam.GSXR_Get_Head() != null && m_IsRuning)
- // {
- m_SetBtn.transform.LookAt(OpenXRCamera.Instance.head);
- m_SetBtn.transform.localEulerAngles = new Vector3(0, m_SetBtn.transform.localEulerAngles.y+180, 0);
- //m_SetBtn.transform.position = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f+ new Vector3(0, 1f, 0);
- //m_SetBtn.transform.localPosition = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f + new Vector3(0, 1f, 0);
- m_SetBtn.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward * 1.3f + new Vector3(-0.2f, 1f, 0);
- // }
- }
- public void Init()
- {
- }
- private void InitCrystals()
- {
- for (int i = 0; i < ListCrystals.Count; i++)
- {
- ListCrystals[i].gameObject.SetActive(true);
- }
- }
- private void InitBoxColliders()
- {
- for (int i = 0; i < ListColliderBoxs.Count; i++)
- {
- ListColliderBoxs[i].gameObject.SetActive(true);
- }
- }
- public void IntoScene()
- {
- Map.SetActive(true);
- //GameObject.Instantiate(Resources.Load<GameObject>("ARCamera"));
- //ImageTargetManager.Instance.LoadVuforiaDat();
- //API_GSXR_Slam.GSXR_Get_Head().localPosition = new Vector3(23.57f, 2.5f, 16.74f);
- //API_GSXR_Slam.GSXR_Get_Head().localEulerAngles = new Vector3(0, -35.9f, 0);
- StartCoroutine(StartScene(isPlayMRZhanTing));
- HttpSocket.Instance.SendIpToElectric();
- }
- IEnumerator StartScene( bool isPlayMRZhanTing)
- {
- yield return new WaitForSeconds(0.5f);
- if(isPlayMRZhanTing)
- {
-
- //if (!string.IsNullOrWhiteSpace(DataManager.Instance.CurrentScene.sandTable))
- //{
- MRZhanTing.gameObject.SetActive(true);
- MRZhanTing.transform.position = API_GSXR_Slam.GSXR_Get_Head().position + API_GSXR_Slam.GSXR_Get_Head().forward + new Vector3(0, -0.7f, 0);
- MRZhanTing.transform.localEulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_Head().eulerAngles.y, 0);
- yield return new WaitForSeconds(18f);
- MRZhanTing.gameObject.SetActive(false);
- //}
- }
- m_SettingPanel.gameObject.SetActive(true);
- m_EditorPanel.Init();
- m_SettingPanel.Init();
- if (RouteCtr.CurrentPoints.Count > 0)
- {
- Player.MovePoints = RouteCtr.CurrentPoints;
- //判断选择那个虚拟导游
- //int id = ChooseIroBot();
- //if (id < 3)
- //{
- //m_IroBot = Irobots[id - 1];
- m_IroBot.gameObject.SetActive(true);
- m_IroBot.Points = RouteCtr.CurrentPoints;
- yield return new WaitForSeconds(5f);
- //}
- }
- IsRuning = true;
- m_SetBtn.gameObject.SetActive(true);
- InitCrystals();
- InitBoxColliders();
- if (AutoERNIEBot.ERNIEBot)
- ERNIEBot.SetActive(true);
- CommandSystem.Instance.Send(new LoadMapFileCommand());
- }
- private int ChooseIroBot()
- {
- int id = 3;
- var navlines = DataManager.Instance.CurrentScene.navLines;
- if (navlines.Count > 0)
- {
- id = navlines[0].guideMod;
- }
- return id;
- }
- /// <summary>
- /// 若为半自动显示素材,需要获取景点物体来为ObjectValues赋值
- /// </summary>
- private void GetObjectValue()
- {
- //for (int i = 0; i < ListShowObjs.Count; i++)
- //{
- // var spoit = ListShowObjs[i];
- // List<ObjectValue> values = new List<ObjectValue>();
- // ObjectValue objectValue = new ObjectValue(i, -1, spoit.name, spoit.gameObject, spoit.localPosition, spoit.localEulerAngles, spoit.localScale);
- // var editors = spoit.GetComponentsInChildren<EditorEventHandler>();
- // for (int j = 1; j < editors.Length; j++)
- // {
- // var obj = editors[j];
- // ObjectValue value = new ObjectValue(j, i, obj.name, obj.gameObject, obj.transform.localPosition, obj.transform.localEulerAngles, obj.transform.localScale);
- // objectValue.ChildrenObj.Add(value);
- // }
- // values.Add(objectValue);
- // ObjectValues.Add(i, values);
- //}
- }
- /// <summary>
- /// 半自动时创建景点信息
- /// </summary>
- //private void CreateSpoitValue()
- //{
- // if (SpoitValues == null)
- // {
- // SpoitValues = new List<SpoitValue>();
- // }
- // SpoitValues.Clear();
- // foreach (int id in ObjectValues.Keys)
- // {
- // var item = ObjectValues[id];
- // SpoitValue spoit = new SpoitValue();
- // spoit.id = item[0].ID;
- // spoit.name = item[0].matName;
- // for (int i = 0; i < item.Count; i++)
- // {
- // var objs = item[i];
- // MaterialObl materialObl = new MaterialObl();
- // materialObl.id = objs.ID;
- // materialObl.name = objs.matName;
- // materialObl.type = 0;
- // OjectTransform ojectTransform = new OjectTransform(objs.Object.transform.localPosition, objs.Object.transform.localEulerAngles, objs.Object.transform.localScale);
- // for (int m = 0; m < objs.ChildrenObj.Count; m++)
- // {
- // var obj = objs.ChildrenObj[i];
- // MaterialObjValue mat = new MaterialObjValue();
- // mat.name = obj.matName;
- // mat.type = 0;
- // mat.objectTransform = new OjectTransform(obj.Object.transform.localPosition, obj.Object.transform.localEulerAngles, obj.Object.transform.localScale);
- // materialObl.materialList.Add(mat);
- // }
- // spoit.material.Add(materialObl);
- // SpoitValues.Add(spoit);
- // }
- // }
- //}
- #region 设置功能
- public bool needSavePosRotScale = true;
- public void OnEditorBtnValueChanged(bool ison)
- {
- m_EditorCanvas.gameObject.SetActive(ison);
- m_IsStartEditor = ison;
- for (int i = 0; i < ListColiderBoxs_Mesh.Count; i++)
- {
- ListColiderBoxs_Mesh[i].enabled = ison;
- }
- if (ison)
- {
- if (needSavePosRotScale)
- {
- GetPosRotScale(); // 获取所有物体位置旋转缩放
- needSavePosRotScale = false;
- }
- m_EditorCanvas.position = OpenXRCamera.Instance.head.position + Player.transform.forward + new Vector3(0, 0.5f, 0);
- m_EditorCanvas.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
- CommandSystem.Instance.Send( new EditorSettingCommand(true){ } );
- CommandSystem.Instance.Send( new Patch_VideoCommand(true){ } );
- }
- else
- {
- //SetPosRotScale();// 设置所有物体位置旋转缩放
- m_EditorCanvas.position = OpenXRCamera.Instance.head.position + new Vector3(0, 100, 0);
- if (SpoitIndex >= 0 && !IsTriggerExiting)
- {
- ListShowObjs[SpoitIndex].gameObject.SetActive(false);
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
- ListCrystals[SpoitIndex].gameObject.SetActive(true);
- m_EditorPanel.ClosePanel();
- SpoitIndex = -1;
- }
- CommandSystem.Instance.Send( new EditorSettingCommand(false){ } );
- CommandSystem.Instance.Send( new Patch_VideoCommand(false){ } );
- }
- }
- public void OnSettingBtnValueChanged(bool ison)
- {
- m_SettingPanel.gameObject.SetActive(ison);
- if (ison)
- {
- Debug.Log(OpenXRCamera.Instance.head.forward);
- m_SettingPanel.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward;
- m_SettingPanel.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
- }
- }
- public void OnAnchorBtnValueChanged(bool ison)
- {
- foreach (var item in m_AnchorValue)
- {
- item.Value.enabled = ison;
- }
- //foreach (var item in m_AnchorChild)
- //{
- // item.Value.SetActive(ison);
- //}
- if(ison)
- {
- m_UIAnchorsPanel.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward + new Vector3(0, 0.5f, 0);
- m_UIAnchorsPanel.transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0);
- }
- else
- {
- m_UIAnchorsPanel.transform.position = OpenXRCamera.Instance.head.position + new Vector3(0, 100, 0);
- }
- }
- /*
- private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
- private ImmersalLocalizerController ImmersalLocalizerController =>SceneIOCContainer.Instance.Pull("ImmersalLocalizerController")as ImmersalLocalizerController;
- private Toggle ImmersalSetToggle =>SceneIOCContainer.Instance.Pull("ImmersalSetToggle") as Toggle;
- public void OnNYImmersalLocalizerBtnValueChange(bool ison)
- {
-
- if (ison)
- {
- ImmersalLocalizerController.enabled = true;
- XRLocalizer.enabled = true;
- }
-
- }
- */
- public void GetPosRotScale()
- {
- PosRotScale.PosRotScalePatchList.Clear();
- for (int i = 0; i < GameManager.Instance.ObjsParent.childCount; i++)
- {
- if (i != 0)
- {
- for (int j = 0; j < GameManager.Instance.ObjsParent.GetChild(i).childCount; j++)
- {
- for (int k = 0; k < GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).childCount; k++)
- {
- PosRotScalePatch PosRotScalePatch = new PosRotScalePatch();
- PosRotScalePatch.PosPatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localPosition;
- PosRotScalePatch.RotPatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localEulerAngles;
- PosRotScalePatch.ScalePatch = GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localScale;
- PosRotScale.PosRotScalePatchList.Add(PosRotScalePatch);
- }
- }
- }
- }
- }
- #endregion
- #region 获取景点信息--素材编辑模式下
- /// <summary>
- /// 获取当前景点对应的物体信息
- /// </summary>
- /// <param name="spoitID"></param>
- /// <returns></returns>
- public ObjectValue GetSpoitObjs(int spoitID)
- {
- if (ObjectValues.ContainsKey(spoitID))
- {
- return ObjectValues[spoitID];
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 初始化数据
- /// 素材编辑模式下
- /// </summary>
- /// <param name="matObjs"></param>
- public void InitSpoitObjs()
- {
- m_EditorPanel.InitObjTransForm();
- }
- /// <summary>
- /// 保存数据
- /// 素材编辑模式下
- /// </summary>
- /// <param name="matObjs"></param>
- public void SaveSpoitObjs()
- {
- m_EditorPanel.SaveObjTransForm();
- }
- public void SaveAnchorObjs( string name)
- {
- foreach (var item in AnchorValue) // 保存所有锚点
- {
- item.Key.objectTransform.SavePos(item.Value.transform.localPosition, item.Value.transform.localEulerAngles, item.Value.transform.localScale);
- }
- // 锚点发送后台
- m_UIAnchorsPanel.SaveAnchors(name);
- }
- #endregion
- #region 创建水晶点、触发器范围、显示物体
- public void CreateScene(SceneValue scene)
- {
- SceneValue = scene;
- if (m_MinMap.Map.sprite == null)
- {
- GetMinMap(scene );
- }
- else
- {
- StartCreateScene(scene);
- }
- Invoke("MoveScenePatch",1);
- }
- private void MoveScenePatch()
- {
- Vector3 temp = ObjsParent.parent.localPosition;
- temp.z += MapSize.y;
- ObjsParent.parent.localPosition = temp;
- }
- private void StartCreateScene(SceneValue scene)
- {
- if (scene.navLines != null && scene.navLines.Count > 0)
- SetRouteValue(scene.navLines);
- else
- Debug.LogError(" 当前场景未设置路径");
- if (scene.listSpoit != null && scene.listSpoit.Count > 0)
- SetSpoitValue(scene.listSpoit);
- else
- Debug.LogError(" 当前场景未创建景点");
- if (scene.listPicture != null && scene.listPicture.Count > 0)
- SetAnchor(scene.listPicture);
- else
- Debug.LogError(" 当前场景未创建锚点");
- //设置小地图景点
- // m_CalMap.SettingMapPoint(ListCrystals);
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
- DownloadManager.Instance.UpdataData();
- }
- /// <summary>
- /// 获取小地图
- /// </summary>
- public void GetMinMap( SceneValue scene )
- {
- DownloadData data1 = new DownloadData();
- string filename = Path.GetFileName(MapPicUrl);
- data1.name = filename;
- data1.type = 1;
- data1.downloadPath = MapPicUrl;
- //data1.updateTime = (int)SceneValue.updateTime;
- data1.localSavePath = DownloadManager.Instance.LocaDataPath + "/map/" + filename;
- if(scene.width>0 &&scene.length>0)
- {
- //Debug.Log(scene.width + " " + scene.length);
- isStart = true;
- PointB.position = Vector3.zero;
- PointB.eulerAngles = Vector3.zero;
- PointA.position = PointB.position + new Vector3(0, 0, scene.width);
- PointA.eulerAngles = Vector3.zero;
- PointC.position = PointB.position + new Vector3(scene.length, 0, 0);
- PointC.eulerAngles = Vector3.zero;
- PointD.position = PointB.position + new Vector3(scene.length, 0, scene.width);
- PointD.eulerAngles = Vector3.zero;
- m_CalMap.SettingMapPoint(ListCrystals);
- }
- DownloadManager.Instance.GetMapImage(data1, m_MinMap.Map, (b, tex) =>
- {
- if (b)
- {
- Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
- m_MinMap.Map.sprite = sprite;
- //m_MinMap.Map.SetNativeSize();
- float width = tex.width;
- float height = tex.height;
- if(width>height)
- {
- width = width / height;
- height = 1;
- }
- else
- {
- height = height / width;
- width = 1;
- }
- MinMapSize = new Vector2(width * 150, height * 150);
- CalMapSize();
- m_MinMap.Map.GetComponent<RectTransform>().sizeDelta = new Vector2( width*150,height*150 );
- //获取网页端
- WebMapSize = new Vector2((float)tex.width, (float)tex.height);
- if (SceneValue != null)
- {
- StartCreateScene(SceneValue);
- }
- }
- });
- }
- /// <summary>
- /// 设置景点素材信息
- /// </summary>
- /// <param name="spoits"></param>
- public void SetSpoitValue(List<SpoitValue> spoits)
- {
- SpoitValue spoitValue;
- for (int i = 0; i < spoits.Count-1; i++)
- {
- spoitValue = null;
- for (int j = 0; j < spoits.Count-1-i; j++)
- {
- if(spoits[j].id>spoits[j+1].id)
- {
- spoitValue = spoits[j];
- spoits[j] = spoits[j+1];
- spoits[j+1] = spoitValue;
- }
- }
- }
- SpoitValues.Clear();
- for (int i = 0; i < spoits.Count; i++)
- {
- var spoit = spoits[i];
- SpoitValue spoit1 = spoit;
- CreateCrystalAndTrigger(spoit);
- CreateMaterial(spoit, out spoit1);
- spoits[i] = spoit1;
- }
- for (int i = 0; i < ListColiderBoxs_Mesh.Count; i++)
- {
- ListColiderBoxs_Mesh[i].enabled = false;
- }
- SpoitValues.AddRange(spoits);
- SceneValue.listSpoit = SpoitValues;
- DataManager.Instance.Spoits = SpoitValues;
- }
- /// <summary>
- /// 创建水晶点和触发器
- /// </summary>
- private void CreateCrystalAndTrigger(SpoitValue spoit)
- {
- var spoitPos = Vector3.zero;
- if (spoit.SpoitTransform.Count > 0)
- {
- //Debug.LogFormat("{0}{1}", spoit.name, "景点存在");
- SpoitPos trans = spoit.SpoitTransform[0];
- spoitPos = new Vector3((float)trans.pointRelativeX / WebMapSize.x * MapSize.x, -1f, -(float)trans.pointRelativeY / WebMapSize.y * MapSize.y);
- //创建水晶点
- var obj = Instantiate(CrystalItem, CrystalsParent);
- CommandSystem.Instance.Send(
- new InstantiateGOCommand(InstantiateSystem.Instance.BlueObject.SpoitName, obj.gameObject)
- );
- obj.name = spoit.name;
- obj.transform.localPosition = spoitPos;
- ListCrystals.Add(obj.transform);
- var spoitobj = CreateSpoit(spoit, spoitPos);
- ListShowObjs.Add(spoitobj.transform);
- ObjectValue spoitvalue = new ObjectValue(spoit.id, -1, spoitobj.name, spoitobj);
- ObjectValues.Add(spoit.id, spoitvalue);
- ////创建触发器
- //if (SpoitsValueDetail.ContainsKey(spoit.id))
- //{
- // var spoitdetail = SpoitsValueDetail[spoit.id];
- // var range = spoitdetail.triggerRange;
- // if (range.areaRelativeH == 0 && range.areaRelativeW == 0 && range.areaRelativeX == 0 && range.areaRelativeY == 0)
- // {
- // }
- // else
- // {
- // trans = range;
- // }
- //}
- //var tiggerpos = new Vector3((float)trans.areaRelativeX / WebMapSize.x * MapSize.x, -0.5f, -(float)trans.areaRelativeY / WebMapSize.y * MapSize.y);
- 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);
- var tiggerRange = new Vector3((float)trans.areaRelativeW / WebMapSize.x * MapSize.x, 0.1f, (float)trans.areaRelativeH / WebMapSize.y * MapSize.y);
- var triggerobj = Instantiate(ColliderItem, CollidersParent);
- triggerobj.name = spoit.name;
- triggerobj.transform.localPosition = tiggerpos;
- triggerobj.transform.localScale = tiggerRange;
- //triggerobj.AddComponent<EditorEventHandler>().IsClickEditor = true;
- ObjectValue boxvalue = new ObjectValue(spoit.id, -1, triggerobj.name, triggerobj);
- ColliderObjectValues.Add(boxvalue);
- ListColliderBoxs.Add(triggerobj.transform);
- ListColiderBoxs_Mesh.Add(triggerobj.GetComponent<MeshRenderer>());
- }
- else
- {
- Debug.LogFormat("{0}{1}", spoit.name, "景点不存在");
- }
- }
- private GameObject CreateSpoit(SpoitValue spoit, Vector3 spoitPos)
- {
- //生成景点父物体
- GameObject spoitObj = new GameObject(spoit.name);
- // 添加Immersal是否定位脚本
- ImmersalLocalControl mImmersalLocalControl = spoitObj.AddComponent<ImmersalLocalControl>();
- mImmersalLocalControl.id = SpoitsValueDetail[spoit.id].id;
- mImmersalLocalControl.projectId = SpoitsValueDetail[spoit.id].projectId;
- mImmersalLocalControl.isOn = SpoitsValueDetail[spoit.id].location;
- spoitObj.transform.SetParent(ObjsParent.transform);
- spoitObj.AddComponent<EditorEventHandler>().IsClickEditor = false;
- //为景点位置信息赋值
- if (spoit.spoitTf.startPos == Vector3.zero && spoit.spoitTf.nowPos == Vector3.zero)
- {
- spoitObj.transform.localPosition = new Vector3(spoitPos.x, 0.5f, spoitPos.z);
- spoitObj.transform.localRotation = Quaternion.identity;
- spoitObj.transform.localScale = new Vector3(1, 1, 1);
- spoit.spoitTf.SetStartValue(spoitObj.transform.localPosition, spoitObj.transform.localEulerAngles, spoitObj.transform.localScale);
- }
- else
- {
- spoitObj.transform.localPosition = spoit.spoitTf.nowPos;
- spoitObj.transform.localEulerAngles = spoit.spoitTf.nowRot;
- spoitObj.transform.localScale = spoit.spoitTf.nowScale;
- }
- return spoitObj;
- }
- /// <summary>
- /// 创建整体素材
- /// 一个景点下应只有一个父物体,其他素材都在父物体下
- /// </summary>
- private void CreateMaterial(SpoitValue spoit, out SpoitValue newspoit)
- {
- var spoitValues = ObjectValues[spoit.id];
- var spoitObj = spoitValues.Object;
- //生成素材组合
- for (int i = 0; i < spoit.material.Count; i++)
- {
- //素材整体
- MaterialObl material = spoit.material[i];
- //Debug.Log(spoit.material[i].name);
- //素材组物体
- GameObject matObj = new GameObject(material.name);
- matObj.transform.SetParent(spoitValues.Object.transform);
- matObj.transform.localPosition = Vector3.zero;
- matObj.transform.localEulerAngles = Vector3.zero;
- matObj.transform.localScale = new Vector3(1, 1, 1);
- material.objectTransform.SetStartValue(matObj.transform.localPosition, matObj.transform.localEulerAngles, matObj.transform.localScale);
- /*
- if (!material.select)
- {
- matObj.transform.localPosition = Vector3.zero;
- matObj.transform.localEulerAngles = Vector3.zero;
- matObj.transform.localScale = new Vector3(1, 1, 1);
- material.objectTransform.SetStartValue(matObj.transform.localPosition, matObj.transform.localEulerAngles, matObj.transform.localScale);
- }
- else
- {
- matObj.transform.localPosition = material.objectTransform.nowPos;
- matObj.transform.localEulerAngles = material.objectTransform.nowRot;
- matObj.transform.localScale = material.objectTransform.nowScale;
- }
- */
- //素材组合对应ObjectValue的
- ObjectValue spoitValue = new ObjectValue(i, spoit.id, material.name, matObj);
- //素材组合下的单个素材ObjectValue
- List<ObjectValue> objsvalue = null;
- MaterialObl newmaterial = material;
- //生成素材组合的ObjectValue,是对应景点的
- switch (material.type)
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Image:
- case (int)MaterialType.Video:
- case (int)MaterialType.Model:
- case (int)MaterialType.Text:
- case (int)MaterialType.LocaImage:
- objsvalue = CreateSuCaiObj(material, matObj, out newmaterial);
- break;
- case (int)MaterialType.Image_Video_Text:
- objsvalue = CreateImage_Video_Text(material, matObj, out newmaterial);
- break;
- case (int)MaterialType.Model_Text:
- objsvalue = CreateModel_Text(material, matObj, out newmaterial);
- break;
- default:
- break;
- }
- spoit.material[i] = newmaterial;
- spoitValue.ChildrenObj.AddRange(objsvalue);
- spoitValues.ChildrenObj.Add(spoitValue);
- }
- newspoit = spoit;
- if (ObjectValues.ContainsKey(spoit.id))
- {
- ObjectValues[spoit.id] = spoitValues;
- }
- else
- {
- ObjectValues.Add(spoit.id, spoitValues);
- }
- spoitObj.gameObject.SetActive(false);
- }
- /// <summary>
- /// 编辑面板添加素材
- /// </summary>
- /// <param name="material"></param>
- public void AddMaterial(MaterialObl material)
- {
- if (SpoitIndex < 0)
- {
- return;
- }
- MaterialObl newmaterial = new MaterialObl();
- newmaterial = material;
- var spoit = SpoitValues[SpoitIndex];
- var spoitValues = ObjectValues[spoit.id];
- var spoitObj = spoitValues.Object;
- //素材组物体
- GameObject matObj = new GameObject(newmaterial.name + "-" + spoit.material.Count.ToString());
- newmaterial.name = matObj.name;
- matObj.transform.SetParent(spoitValues.Object.transform);
- if (!material.select)
- {
- matObj.transform.localPosition = Vector3.zero;
- matObj.transform.localEulerAngles = Vector3.zero;
- matObj.transform.localScale = new Vector3(1, 1, 1);
- newmaterial.objectTransform.SetStartValue(matObj.transform.localPosition, matObj.transform.localEulerAngles, matObj.transform.localScale);
- }
- else
- {
- matObj.transform.localPosition = newmaterial.objectTransform.nowPos;
- matObj.transform.localEulerAngles = newmaterial.objectTransform.nowRot;
- matObj.transform.localScale = newmaterial.objectTransform.nowScale;
- }
- //素材组合对应ObjectValue的
- ObjectValue spoitValue = new ObjectValue(spoit.material.Count, spoit.id, newmaterial.name, matObj);
- //素材组合下的单个素材ObjectValue
- List<ObjectValue> objsvalue = null;
- //生成素材组合的ObjectValue,是对应景点的
- switch (material.type)
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Image:
- case (int)MaterialType.Video:
- case (int)MaterialType.Model:
- case (int)MaterialType.Text:
- case (int)MaterialType.LocaImage:
- objsvalue = CreateSuCaiObj(newmaterial, matObj, out newmaterial);
- break;
- case (int)MaterialType.Image_Video_Text:
- objsvalue = CreateImage_Video_Text(newmaterial, matObj, out newmaterial);
- break;
- case (int)MaterialType.Model_Text:
- objsvalue = CreateModel_Text(newmaterial, matObj, out newmaterial);
- break;
- default:
- break;
- }
- newmaterial.select = true;
- spoit.material.Add(newmaterial);
- spoitValue.ChildrenObj.AddRange(objsvalue);
- spoitValues.ChildrenObj.Add(spoitValue);
- if (ObjectValues.ContainsKey(spoit.id))
- {
- ObjectValues[spoit.id] = spoitValues;
- }
- else
- {
- ObjectValues.Add(spoit.id, spoitValues);
- }
- SpoitValues[SpoitIndex] = spoit;
- //更新编辑面板Ui
- UpdateEditorUI();
- }
- /// <summary>
- /// 创建 1图片 2视频 3模型 4文字
- /// </summary>
- /// <param name="type">素材类型</param>
- /// <param name="material">素材数据</param>
- /// <param name="spoit">景点</param>
- /// <returns></returns>
- private List<ObjectValue> CreateSuCaiObj(MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
- {
- List<ObjectValue> objects = new List<ObjectValue>();
- List<MaterialObjValue> objs = material.materialList;
- newmaterial = material;
- //for (int i = 0; i < objs.Count; i++)
- //{
- // Debug.Log(objs[i].localSavePath);
- //}
- for (int i = 0; i < objs.Count; i++)
- {
- var mat = objs[i];
- GameObject go = null;
- switch (int.Parse(mat.type))
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Image:
- var pImage = ResMgr.Instance.Load<GameObject>("Template/Prefab/Image");
- go = Instantiate(pImage, spoit.transform);
- var imageitem = go.AddComponent<TemplateImage>();
- go.SetActive(true);
- imageitem.SetData(mat, material.updateTime);
- break;
- case (int)MaterialType.Video:
- var pVideo = ResMgr.Instance.Load<GameObject>("Template/Prefab/Video");
- go = Instantiate(pVideo, spoit.transform);
- var videoitem = go.AddComponent<TemplateVideo>();
- go.SetActive(true);
- videoitem.SetData(mat, material.updateTime);
- break;
- case (int)MaterialType.Model:
- var pModel = ResMgr.Instance.Load<GameObject>("Template/Prefab/Model");
- go = Instantiate(pModel, spoit.transform);
- var modelitem = go.AddComponent<TemplateModel>();
- go.SetActive(true);
- modelitem.SetData(mat, material.updateTime);
- Debug.Log(modelitem.Data.localSavePath);
- break;
- case (int)MaterialType.Text:
- var pText = ResMgr.Instance.Load<GameObject>("Template/Prefab/Text");
- go = Instantiate(pText, spoit.transform);
- var textitem = go.AddComponent<TemplateText>();
- go.SetActive(true);
- textitem.SetData(mat, material.updateTime);
- break;
- case (int)MaterialType.LocaImage:
- var pLocaImage = ResMgr.Instance.Load<GameObject>("Template/Prefab/Image");
- go = Instantiate(pLocaImage, spoit.transform);
- var locaImageitem = go.AddComponent<TemplateImage>();
- go.SetActive(true);
- locaImageitem.SetLocaImageData(mat);
- break;
- default:
- break;
- }
- if (go != null)
- {
- go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
- mat.name = go.name;
- go.AddComponent<EditorEventHandler>().Type = (MaterialType)(int.Parse(mat.type));
- if (material.select)
- {
- go.transform.localPosition = mat.ObjectTransform.nowPos;
- go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
- go.transform.localScale = mat.ObjectTransform.nowScale;
- }
- else
- {
- go.transform.localEulerAngles = Vector3.zero;
- go.transform.localScale = new Vector3(1, 1, 1);
- if (int.Parse(mat.type) != (int)MaterialType.Text)
- {
- go.transform.localPosition = Vector3.zero;
- }
- else
- {
- //Set text position
- if (mat.textPosition == "top")
- {
- go.transform.localPosition = new Vector3(0, 0.3f, 0);
- }
- else if (mat.textPosition == "bottom")
- {
- go.transform.localPosition = new Vector3(0, -0.3f, 0);
- }
- }
- mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
- }
- ObjectValue objectValue = new ObjectValue(i, material.id, mat.name, go);
- objects.Add(objectValue);
- }
- newmaterial.materialList[i] = mat;
- }
- return objects;
- }
- /// <summary>
- /// 创建 6模型+文字
- /// </summary>
- /// <param name="material"></param>
- /// <param name="spoit"></param>
- /// <returns></returns>
- private List<ObjectValue> CreateModel_Text(MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
- {
- List<ObjectValue> objects = new List<ObjectValue>();
- List<MaterialObjValue> objs = material.materialList;
- newmaterial = material;
- for (int i = 0; i < objs.Count; i++)
- {
- var mat = objs[i];
- GameObject go = null;
- switch (int.Parse(mat.type))
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Model:
- var pModel = ResMgr.Instance.Load<GameObject>("Template/Prefab/Model");
- go = Instantiate(pModel, spoit.transform);
- var modelitem = go.AddComponent<TemplateModel>();
- go.SetActive(true);
- modelitem.SetData(mat, material.updateTime);
- break;
- case (int)MaterialType.Text:
- var pText = ResMgr.Instance.Load<GameObject>("Template/Prefab/Text");
- go = Instantiate(pText, spoit.transform);
- var textitem = go.AddComponent<TemplateText>();
- go.SetActive(true);
- textitem.SetData(mat, material.updateTime);
- break;
- default:
- break;
- }
- if (go != null)
- {
- go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
- go.AddComponent<EditorEventHandler>().Type = (MaterialType)(int.Parse(mat.type));
- if (material.select)
- {
- go.transform.localPosition = mat.ObjectTransform.nowPos;
- go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
- go.transform.localScale = mat.ObjectTransform.nowScale;
- }
- else
- {
- go.transform.localEulerAngles = Vector3.zero;
- go.transform.localScale = new Vector3(1, 1, 1);
- if (int.Parse(mat.type) != (int)MaterialType.Text)
- {
- go.transform.localPosition = Vector3.zero;
- }
- else
- {
- //Set text position
- if (mat.textPosition == "top")
- {
- go.transform.localPosition = new Vector3(0, 0.3f, 0);
- }
- else if (mat.textPosition == "bottom")
- {
- go.transform.localPosition = new Vector3(0, -0.3f, 0);
- }
- else if (mat.textPosition == "left")
- {
- go.transform.localPosition = new Vector3(-0.3f, 0, 0);
- }
- else if (mat.textPosition == "right")
- {
- go.transform.localPosition = new Vector3(0.3f, 0f, 0);
- }
- }
- mat.ObjectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
- }
- ObjectValue objectValue = CreateMatObjectValue(i, material.id, go, mat);
- objects.Add(objectValue);
- }
- newmaterial.materialList[i] = mat;
- }
- return objects;
- }
- /// <summary>
- /// 创建 5图片+文字/视频+文字
- /// </summary>
- private List<ObjectValue> CreateImage_Video_Text(MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
- {
- newmaterial = material;
- List<ObjectValue> objects = new List<ObjectValue>();
- switch (material.typesetting)
- {
- case "1":
- objects = SRTitleLayout.CalLayout(material, spoit, out newmaterial);
- break;
- case "2":
- objects = SRSectorLayout.CalLayout(material, spoit, out newmaterial);
- break;
- case "3":
- objects = DRTitleLayout.CalLayout(material, spoit, out newmaterial);
- break;
- case "4":
- objects = DRFanLayout.CalLayout(material, spoit, out newmaterial);
- break;
- case "5":
- objects = SRTitleLayout.CalLayout(material, spoit, out newmaterial,"5");
- break;
- case "自定义":
- break;
- default:
- break;
- }
- return objects;
- }
- /// <summary>
- /// 创建物体ObjectValue,并赋值位置信息
- /// </summary>
- /// <param name="id"></param>
- /// <param name="parentid"></param>
- /// <param name="go"></param>
- /// <param name="mat"></param>
- /// <returns></returns>
- private ObjectValue CreateMatObjectValue(int id, int parentid, GameObject go, MaterialObjValue mat)
- {
- go.name = string.IsNullOrWhiteSpace(mat.name) ? go.name : mat.name;
- go.AddComponent<EditorEventHandler>().Type = (MaterialType)(int.Parse(mat.type));
- //为物体位置信息赋值
- if (mat.ObjectTransform != null)
- {
- go.transform.localPosition = mat.ObjectTransform.nowPos;
- go.transform.localEulerAngles = mat.ObjectTransform.nowRot;
- go.transform.localScale = mat.ObjectTransform.nowScale;
- }
- else
- {
- go.transform.localPosition = Vector3.zero;
- go.transform.localEulerAngles = Vector3.zero;
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- ObjectValue objectValue = new ObjectValue(id, parentid, mat.name, go, go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
- return objectValue;
- }
- #endregion
- #region 路径
- /// <summary>
- /// 设置路线数据
- /// </summary>
- /// <param name="navLines"></param>
- public void SetRouteValue(List<NavLinesItem> navLines)
- {
- if (navLines == null || navLines.Count <= 0)
- {
- Debug.Log("当前景点未绘制路线");
- return;
- }
- RouteCtr.SetRouteValue(navLines);
- }
- #endregion
- #region 锚点
- /// <summary>
- /// 设置场景锚点
- /// </summary>
- /// <param name="listAnchor"></param>
- public void SetAnchor(List<Anchor> listAnchor)
- {
- if (listAnchor == null)
- return;
- Anchor anchor;
- for (int i = 0; i < listAnchor.Count - 1; i++)
- {
- for (int j = 0; j < listAnchor.Count - 1 - i; j++)
- {
- if (listAnchor[j].id > listAnchor[j + 1].id)
- {
- anchor = listAnchor[j];
- listAnchor[j] = listAnchor[j + 1];
- listAnchor[j + 1] = anchor;
- }
- }
- }
-
- for (int i = 0; i < listAnchor.Count; i++)
- {
-
- // 创建锚点
- GameManager.Instance.AnchorValue.Add(listAnchor[i], CreateAnchor(listAnchor[i]));
- GameManager.Instance.AnchorChild.Add(listAnchor[i], AnchorValue[listAnchor[i]].transform.GetChild(0).gameObject);
- }
- m_UIAnchorsPanel.SetAnchor(AnchorValue);
- }
- private MeshRenderer CreateAnchor(Anchor anchor)
- {
- // 创建锚点 给锚点赋值
- GameObject anchorObj = GameObject.Instantiate(Resources.Load<GameObject>("Template/Prefab/Anchor"),AnchorsParent);
- anchorObj.name = "Anchor" + anchor.id;
- /*
- VuforiaAnchor vuforiaAnchor = anchorObj.GetComponent<VuforiaAnchor>();
- vuforiaAnchor.player = GameManager.Instance.m_head.transform;
- if (VuforiaManager.Instance.list_Anchor == null)
- VuforiaManager.Instance.list_Anchor = new List<VuforiaAnchor>();
- VuforiaManager.Instance.list_Anchor.Add(vuforiaAnchor);*/
- var anchorPos = Vector3.zero;
- Debug.Log(anchor.picturePosition.pointRelativeX+" "+ WebMapSize.x);
- anchorPos = new Vector3((float)anchor.picturePosition.pointRelativeX / WebMapSize.x * MapSize.x, -1f, -(float)anchor.picturePosition.pointRelativeY / WebMapSize.y * MapSize.y);
- anchorObj.transform.localPosition = anchorPos;
- anchorObj.transform.GetChild(0).gameObject.SetActive(false);
- var mesh = anchorObj.GetComponent<MeshRenderer>();
- mesh.enabled = false;
- //if(anchor.objectTransform!=null)
- //{
- // anchorObj.transform.localPosition = anchor.objectTransform.nowPos;
- // anchorObj.transform.localEulerAngles = anchor.objectTransform.nowRot;
- //}
- if(anchor.objectTransform!=null && anchor.objectTransform.nowScale!=Vector3.zero)
- {
- anchorObj.transform.localEulerAngles = anchor.objectTransform.nowRot;
- anchorObj.transform.localPosition = anchor.objectTransform.nowPos;
- }
- return mesh;
- }
- #endregion
- #region 触发器判定
- /// <summary>
- /// 当人物进入触发器范围
- /// </summary>
- public void OnColliderTriggerEnter(Collider other)
- {
- IsTriggerExiting = true;
- for (int i = 0; i < ListColliderBoxs.Count; i++)
- {
- if (other.name == ListColliderBoxs[i].name)
- {
- ListShowObjs[i].gameObject.SetActive(true);
- Debug.Log(i);
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[i].gameObject.SetActive(true);
- // 进入景点通知后台
- HttpSocket.Instance.SendIpToPointTrigger(" ",other.name, CallBack);
- if (SpoitIndex == i)
- {
- return;
- }
- //进入新区域前关闭当前显示
- if (SpoitIndex >= 0 && IsStartEditor)
- {
- ListShowObjs[SpoitIndex].gameObject.SetActive(false);
-
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
- ListCrystals[SpoitIndex].gameObject.SetActive(true);
- m_EditorPanel.ClosePanel();
- }
- //进入新的出发区域
- SpoitIndex = i;
- ListCrystals[SpoitIndex].gameObject.SetActive(false);
- m_EditorPanel.SetSpoit(SpoitValues[i]);
- //StartCoroutine(SetPosRotScale());
- return;
- }
- }
- //StartCoroutine(SetPosRotScale());
- }
- public void SetPosRotScale()
- {
- if (PosRotScale.PosRotScalePatchList.Count != 0)
- {
- int temp = 0;
- for (int i = 0; i < GameManager.Instance.ObjsParent.childCount; i++)
- {
- if (i != 0)
- {
- for (int j = 0; j < GameManager.Instance.ObjsParent.GetChild(i).childCount; j++)
- {
- for (int k = 0; k < GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).childCount; k++)
- {
- GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localPosition = PosRotScale.PosRotScalePatchList[temp].PosPatch;
- GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localEulerAngles = PosRotScale.PosRotScalePatchList[temp].RotPatch;
- GameManager.Instance.ObjsParent.GetChild(i).GetChild(j).GetChild(k).localScale = PosRotScale.PosRotScalePatchList[temp].ScalePatch;
- temp++;
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 当人物退出触发器范围
- /// </summary>
- public void OnColliderTriggerExit(Collider other)
- {
- IsTriggerExiting = false;
- if (IsStartEditor)
- {
- return;
- }
- else
- {
- ListShowObjs[SpoitIndex].gameObject.SetActive(false);
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
- ListCrystals[SpoitIndex].gameObject.SetActive(true);
- m_EditorPanel.ClosePanel();
- SpoitIndex = -1;
- }
- }
- /// <summary>
- /// 更新景点信息
- /// </summary>
- public void UpdateSpoitValue()
- {
- var spoit = SpoitValues[SpoitIndex];
- var objvalues = ObjectValues[spoit.id];
- spoit.spoitTf.SavePos(objvalues.nowPos, objvalues.nowRot, objvalues.nowScale);
- //X\Y\W\H
- var collidervalue = ColliderObjectValues[SpoitIndex];
- var collider = collidervalue.Object;
- var pos = collidervalue.nowPos;
- var w = collidervalue.nowScale.x;
- var h = collidervalue.nowScale.z;
- var webpos = new Vector3(Math.Abs(pos.x) / MapSize.x * WebMapSize.x, 0, Math.Abs(pos.z) / MapSize.y * WebMapSize.y);
- var webw = w / MapSize.x * WebMapSize.x;
- var webh = h / MapSize.y * WebMapSize.y;
- spoit.SpoitTransform[0].areaRelativeX = webpos.x;
- spoit.SpoitTransform[0].areaRelativeY = webpos.z;
- spoit.SpoitTransform[0].areaRelativeW = webw;
- spoit.SpoitTransform[0].areaRelativeH = webh;
- spoit.spoitTf.SavePos(objvalues.nowPos, objvalues.nowRot, objvalues.nowScale);
- if (objvalues.Object == null)
- {
- RemoveSpoitObjectValue(spoit.id);
- spoit.material = new List<MaterialObl>();
- }
- else
- {
- var mats = spoit.material;
- var objvalue = objvalues.ChildrenObj;
- for (int j = 0; j < mats.Count; j++)
- {
- var matobj = mats[j];
- var obis = objvalue[j];
- matobj.objectTransform.SavePos(obis.nowPos, obis.nowRot, obis.nowScale);
- for (int m = 0; m < matobj.materialList.Count; m++)
- {
- var childrenobj = obis.ChildrenObj[m];
- var mat = matobj.materialList[m];
- if (childrenobj.Object == null)
- {
- obis.ChildrenObj.RemoveAt(m);
- matobj.materialList.RemoveAt(m);
- break;
- }
- mat.ObjectTransform.SavePos(childrenobj.nowPos, childrenobj.nowRot, childrenobj.nowScale);
- }
- matobj.select = true;
- if (obis.ChildrenObj.Count <= 0)
- {
- mats.RemoveAt(j);
- objvalue.RemoveAt(j);
- Destroy(obis.Object);
- break;
- }
- }
- }
- SpoitValues[SpoitIndex] = spoit;
- }
- public void UpdateEditorUI()
- {
- m_EditorPanel.SetSpoit(SpoitValues[SpoitIndex]);
- }
-
- #endregion
- public ObjectValue GetCurrentColliderValue()
- {
- return ColliderObjectValues[SpoitIndex];
- }
- public void SaveSpoitObjectValue(ObjectValue value)
- {
- if (ObjectValues.ContainsKey(SpoitValues[SpoitIndex].id))
- {
- ObjectValues[SpoitValues[SpoitIndex].id] = value;
- }
- }
- public void RemoveSpoitObjectValue(int id)
- {
- if (ObjectValues.ContainsKey(id))
- {
- ObjectValues.Remove(id);
- }
- }
- public void SaveCurrentColliderValue(ObjectValue value)
- {
- if (ColliderObjectValues.Contains(value))
- {
- ColliderObjectValues[SpoitIndex] = value;
- }
- }
- //计算场景中点云地图比例
- public void CalMapSize()
- {
-
-
- //场景地图比例
- var disX = Vector3.Distance(PointA.localPosition, PointD.localPosition);
- var disZ = Vector3.Distance(PointA.localPosition, PointB.localPosition);
- MapSize = new Vector2(disX, disZ);
- //Debug.LogFormat("{0}:{1}", "AB", Vector3.Distance(PointA.localPosition, PointB.localPosition));
- //Debug.LogFormat("{0}:{1}", "CD", Vector3.Distance(PointC.localPosition, PointD.localPosition));
- //Debug.LogFormat("{0}:{1}", "AD", Vector3.Distance(PointA.localPosition, PointD.localPosition));
- //Debug.LogFormat("{0}:{1}", "BC", Vector3.Distance(PointB.localPosition, PointC.localPosition));
- }
- public void CallBack(string message)
- {
- }
- }
- [Serializable]
- public class ObjectValue
- {
- /// <summary>
- /// 景点ID
- /// </summary>
- [SerializeField]
- public int ID;
- /// <summary>
- /// 当前物体名称
- /// </summary>
- [SerializeField]
- public string matName;
- /// <summary>
- /// 父物体ID
- /// -1表示当期物体为景点
- /// </summary>
- [SerializeField]
- public int parentID;
- /// <summary>
- /// 对应的物体
- /// </summary>
- [SerializeField]
- public GameObject Object;
- /// <summary>
- /// 子物体
- /// </summary>
- [SerializeField]
- public List<ObjectValue> ChildrenObj;
- public Vector3 startPos { get; set; }
- public Vector3 startRot { get; set; }
- public Vector3 startScale { get; set; }
- public Vector3 nowPos { get; set; }
- public Vector3 nowRot { get; set; }
- public Vector3 nowScale { get; set; }
- public ObjectValue()
- {
- ChildrenObj = new List<ObjectValue>();
- parentID = -1;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="id">景点对应的index</param>
- /// <param name="parentid">景点ID</param>
- /// <param name="name"></param>
- /// <param name="object"></param>
- /// <param name="pos"></param>
- /// <param name="Rot"></param>
- /// <param name="Scale"></param>
- public ObjectValue(int id, int parentid, string name, GameObject @object, Vector3 pos, Vector3 Rot, Vector3 Scale)
- {
- ID = id;
- parentID = parentid;
- matName = name;
- Object = @object;
- ChildrenObj = new List<ObjectValue>();
- startPos = pos;
- nowPos = pos;
- startRot = Rot;
- nowRot = Rot;
- startScale = Scale;
- nowScale = Scale;
- }
- public ObjectValue(int id, int parentid, string name, GameObject @object)
- {
- ID = id;
- parentID = parentid;
- matName = name;
- Object = @object;
- ChildrenObj = new List<ObjectValue>();
- startPos = @object.transform.localPosition;
- nowPos = startPos;
- startRot = @object.transform.localEulerAngles;
- nowRot = startRot;
- startScale = @object.transform.localScale;
- nowScale = startScale;
- }
- /// <summary>
- /// 初始化时当前位置和初始位置
- /// 此方法只在组合素材时使用
- /// </summary>
- public void InitTransform()
- {
- if (Object != null)
- {
- startPos = Object.transform.localPosition;
- nowPos = Object.transform.localPosition;
- startRot = Object.transform.localEulerAngles;
- nowRot = Object.transform.localEulerAngles;
- startScale = Object.transform.localScale;
- nowScale = Object.transform.localScale;
- }
- }
- /// <summary>
- /// 编辑物体坐标时初始化坐标
- /// </summary>
- public void InitObjTransform()
- {
- Object.transform.localPosition = startPos;
- Object.transform.localEulerAngles = startRot;
- Object.transform.localScale = startScale;
- nowPos = startPos;
- nowRot = startRot;
- nowScale = startScale;
- }
- /// <summary>
- /// 编辑物体坐标时保存坐标信息
- /// </summary>
- public void SaveObjTransfoem()
- {
- if (Object != null)
- {
- nowPos = Object.transform.localPosition;
- nowRot = Object.transform.localEulerAngles;
- nowScale = Object.transform.localScale;
- }
- }
- }
|