123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472 |
- using Blue;
- using Immersal.AR;
- using LitJson;
- using Newtonsoft.Json;
- using OpenCVForUnity.CoreModule;
- using OpenCVForUnity.ImgcodecsModule;
- using OpenCVForUnity.ImgprocModule;
- using OpenCVForUnity.UnityUtils;
- using SC.XR.Unity;
- using SC.XR.Unity.Module_InputSystem;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading;
- using TriLibCore;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- /*
- * 半自动交付/自动交付
- * 景点、触发范围、水晶点应保持顺序对应
- * 当前场景下景点名称不应重复
- * 同一景点下素材名称不应重复
- * ListShowObjs/ListColliderBoxs/ListCrystals半自动时在场景中推拽,全自动时全部由代码生成
- *
- * 新增锚点列表
- * 锚点识别图Vuforia XML和DAT文件
- * 各个锚点的位置信息
- *
- * 每次打开都下载vuforia文件
- * 自动加载生成ImageTarget
- *
- */
- public class GameManager : MonoSingleton<GameManager>
- {
- public LoadReference loadref;
- public GameObject armapObj;
- public ARMap armap;
- 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;
- public Dictionary<int, Vector3> spoitposDic = new Dictionary<int, Vector3>();
- public Dictionary<int, GameObject> spoitposObjDic = new Dictionary<int, GameObject>();
- [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 GameObject arcamre;
- public GameObject immser;
- 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>
- /// 2.0 场景数据
- /// </summary>
- public UserSceneItem m_scene;
- /// <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;
- private void Awake()
- {
- // Debug.unityLogger.logEnabled = false;
- }
- public Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>> allOldobjs = new Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>>();
- public Dictionary<string, Dictionary<string, Dictionary<string, GameObject>>> allobjs = new Dictionary<string, Dictionary<string, Dictionary<string, GameObject>>>();
- public Thread thread;
- private ThreadStart tstart;
- public Dictionary<long, GameObject> textureThread = new Dictionary<long, GameObject>();
- public Queue<Dictionary<string, Action>> TheadAcitons = new Queue<Dictionary<string, Action>>();
- public Queue<long> TheadAcitonsId = new Queue<long>();
- public Queue<Action> TheadBackAcitons = new Queue<Action>();
- List<long> removeLong = new List<long>();
- bool isBack;
- public long theadID;
- public long AddThead(Action a, Action b)
- {
- theadID++;
- Dictionary<string, Action> dic = new Dictionary<string, Action>();
- dic.Add("Thead", a);
- dic.Add("callBack", b);
- TheadAcitons.Enqueue(dic);
- TheadAcitonsId.Enqueue(theadID);
- return theadID;
- }
- private void subThread()
- {
- Dictionary<string, Action> dic;
- long id;
- while (true)
- {
- Thread.Sleep(100);
- try
- {
- if (TheadAcitons.Count > 0 && !isBack)
- {
- dic = TheadAcitons.Dequeue();
- id = TheadAcitonsId.Dequeue();
- if (!removeLong.Contains(id))
- {
- dic["Thead"].Invoke();
- if (dic["callBack"] != null && !removeLong.Contains(id))
- {
- isBack = true;
- TheadBackAcitons.Enqueue(dic["callBack"]);
- }
- }
- }
- else if (TheadAcitons.Count <= 0)
- {
- if (removeLong.Count > 0)
- removeLong = new List<long>();
- if (textureThread.Count > 0)
- textureThread = new Dictionary<long, GameObject>();
- }
- }
- catch
- {
- isBack = false;
- Debug.Log("22222222222");
- }
- }
- }
- public Text t;
- public void foundmap()
- {
- t.text = "发现地图";
- }
- public void lostmap()
- {
- t.text = "地图丢失";
- }
- public void destroyGo(UnityEngine.Object go)
- {
- if(go)
- {
- Debug.Log("destroyGo===>" + go.name);
- Destroy(go);
- }
- }
- public GameObject go20exit;
- public GameObject go21exit;
- public void show20exitpop(bool isshow)
- {
- go20exit.SetActive(isshow);
- }
- public void show21exitpop(bool isshow)
- {
- go21exit.SetActive(isshow);
- }
- public void exitscene2()
- {
- GameScene.Instance.o20.SetActive(false);
- //m_SetBtn.gameObject.SetActive(false);
- destroyGo(LoadManager.Instance.datFileObj);
- destroyGo(LoadManager.Instance.xmlFileDownObj);
- MsgHandler.ClearAllListeners();
- UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].Clear();
- GameScene.Instance.ShowScenes();
- UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().st.SetActive(false);
- UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().cs.SetActive(true);
- }
- public List<SceneValue> sucessvalues;
- public void exitscene()
- {
- Destroy(loadref.goRefrence);
- loadref.goRefrence = null;
- armapObj.transform.parent.position = Vector3.zero;
- armapObj.transform.parent.eulerAngles = Vector3.zero;
- t.text = "退出场景后";
- MoveChange.isCx = false;
- MoveChange.islixian = false;
- SetLocalTime.isFind = true;
- ARSpace.isFind=false;
- SettingPanel.dingweilist.Clear();
- allobjs.Clear();
- ARSpace.transformToSpace.Clear();
- ARSpace.spaceToTransform.Clear();
- ARSpace.mapIdToOffset.Clear();
- ARSpace.mapIdToMap.Clear();
-
- armap.FreeMap();
- Destroy(armap);
- armap = armapObj.AddComponent<ARMap>();
- armap.OnFirstLocalization = new MapLocalizedEvent();
- armap.OnFirstLocalization.AddListener(firstfound);
- XRLocalizer.Instance.Reset();
- m_IroBot.gameObject.SetActive(false);
- RouteCtr.CurrentPoints.Clear();
- m_SetBtn.gameObject.SetActive(false);
- // armap.FreeMap();
- m_MinMap.gameObject.SetActive(false);
- for (int i = 0; i < RouteCtr.list_route.Count; i++)
- {
- Destroy(RouteCtr.list_route[i].gameObject);
- }
- RouteCtr.list_route.Clear();
- for (int i = 0; i < m_MinMap.listAllPoint.Count; i++)
- {
- Destroy(m_MinMap.listAllPoint[i].gameObject);
- }
- m_MinMap.listAllPoint.Clear();
- for (int i = 0; i < m_MinMap.list_route.Count; i++)
- {
- Destroy(m_MinMap.list_route[i].gameObject);
- }
- m_MinMap.list_route.Clear();
- GameManager.Instance.IsRuning = false;
- ObjectValues.Clear();
- ColliderObjectValues.Clear();
- for (int i = 0; i < ListShowObjs.Count; i++)
- {
- Destroy(ListShowObjs[i].gameObject);
- }
- ListShowObjs.Clear();
- for (int i = 0; i < ListLocalShowObjs.Count; i++)
- {
- Destroy(ListLocalShowObjs[i].gameObject);
- }
- ListLocalShowObjs.Clear();
- for (int i = 0; i < ListColliderBoxs.Count; i++)
- {
- Destroy(ListColliderBoxs[i].gameObject);
- }
- ListColliderBoxs.Clear();
- for (int i = 0; i < ListColiderBoxs_Mesh.Count; i++)
- {
- Destroy(ListColiderBoxs_Mesh[i]);
- }
- ListColiderBoxs_Mesh.Clear();
- for (int i = 0; i < ListCrystals.Count; i++)
- {
- Destroy(ListCrystals[i].gameObject);
- }
- ListCrystals.Clear();
- for (int i = 0; i < UIAddMaterialPanel.pfablist.Count ; i++)
- {
- Destroy(UIAddMaterialPanel.pfablist[i]);
- }
- spoitposDic.Clear();
- foreach(var i in spoitposObjDic.Values)
- {
- Destroy(i);
- }
- spoitposObjDic.Clear();
- UIAddMaterialPanel.pfablist.Clear();
- UIManager.Instance.ShowUI(UINameConfig.SceneChoose, typeof(SceneChoose), sucessvalues);
- }
- public void firstfound(int arg0)
- {
- t.text = "第一次发现_"+ arg0;
- }
- public bool isShowDownTip;
- private void Start()
- {
- ARSpace.transformToSpace.Clear();
- ARSpace.spaceToTransform.Clear();
- ARSpace.mapIdToOffset.Clear();
- ARSpace.mapIdToMap.Clear();
- armap = armapObj.AddComponent<ARMap>();
- armap.OnFirstLocalization = new MapLocalizedEvent();
- armap.OnFirstLocalization.AddListener(firstfound);
- armapObj.transform.parent.position = Vector3.zero;
- armapObj.transform.parent.eulerAngles = Vector3.zero;
- // XRLocalizer.Instance.Reset();
- #if UNITY_EDITOR
- ArchitectureInitiator.Initiate();
- #endif
- ///神奇代码 但是不能删除 删除子线程使用opencv会闪退
- try
- {
- Texture2D texture2D = Resources.Load("touxiang") as Texture2D;
- Mat imgMat = new Mat(texture2D.height, texture2D.width, CvType.CV_8UC4);
- Utils.texture2DToMat(texture2D, imgMat);
- // Destroy(texture2D);
- imgMat.release();
- }
- catch { }
- 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);
- var t = TimerMgr.Instance.CreateTimer(()=> {
- if(isShowDownTip)
- {
- Debug.Log("HJJ 判断正在下载");
- if (downLoadCount == 0)
- {
- downLoadCount = COSDownLoad.showDownEndLoadCount;
- Debug.Log("HJJ 判断正在下载downLoadCount==0");
- }
- if (COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount)
- {
- Debug.Log("HJJ 判断正在下载COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount");
- string str = string.Format("{0}/{1}正在下载,{2}%", (COSDownLoad.showDownEndLoadCount - downLoadCount), COSDownLoad.showDownLoadCount - downLoadCount, COSDownLoad.showDownLoadPre.ToString("F2"));
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
- ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
- }
- else
- {
- Debug.Log("HJJ 判断正在下载downLoadCount != 0");
- TimerMgr.Instance.CreateTimer(()=> {
- if (COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount)
- {
- }else
- {
- // UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
- downLoadCount = 0;
- DownloadResManager.Instance.Save();
- isShowDownTip = false;
- }
- },1f);
- }
- if(COSDownLoad.showDownLoadCount==0&& downLoadCount ==0)
- {
- Debug.Log("HJJ 判断正在下载COSDownLoad.showDownLoadCount==0&& downLoadCount ==0");
- Debug.Log("DGJ updateEnd ");
- // UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
- isShowDownTip = false;
- }
- }
- },1,-1);
- tstart = new ThreadStart(subThread);
- thread = new Thread(tstart);
- thread.Start();
- StartCoroutine(startSendPos());
-
- }
- IEnumerator startSendPos()
- {
- while(true)
- {
- if (Player != null && GameManager.Instance.isStart)
- {
- float rot = Player.transform.localEulerAngles.y - 180;
- var pos = new Vector3(GameManager.Instance.MinMapSize.x - Math.Abs(Player.transform.localPosition.x) / GameManager.Instance.MapSize.x * GameManager.Instance.MinMapSize.x, -Math.Abs(Player.transform.localPosition.z) / GameManager.Instance.MapSize.y * GameManager.Instance.MinMapSize.y, 0);
- JsonData data = new JsonData();
- data["sn"] = SendSN.GetSN();
- data["position"] = new JsonData();
- data["position"]["x"] = 1-(pos.x / GameManager.Instance.MinMapSize.x);
- data["position"]["y"] = 1+(pos.y / GameManager.Instance.MinMapSize.y);
- //send.sn = API_GSXR_Slam.SlamManager.plugin.SN;
- ;
- MQTTClient.Instance.PublicPosScene(SceneChoose.Sid.ToString(), data.ToJson());
- }
- yield return new WaitForSeconds(3f);
- }
- }
- int downLoadCount = 0;
- private void LateUpdate()
- {
- if (TheadBackAcitons != null && TheadBackAcitons.Count > 0)
- {
- try
- {
- TheadBackAcitons.Dequeue().Invoke();
- }
- catch
- {
- }
- isBack = false;
- }
- // 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);
- // }
- if (avplayer && !avplayer.IsPlaying()&& !TemplateVideo.isPlayLock)
- {
- Debug.Log("HJJVideo 创建锁解开 并且播放完毕");
- TemplateVideo.isPlaying = false;
- avplayer = null;
- }
- if (TemplateVideo.temQueue.Count>0&&!TemplateVideo.isPlaying &&!TemplateVideo.isPlayLock)
- {
- Debug.Log("HJJVideo 开始播放");
- TemplateVideo.isPlaying = true;
- TimerMgr.Instance.CreateTimer(()=> {
- Debug.Log("HJJVideo 播放的创建锁 创建锁解开");
- TemplateVideo.isPlayLock = false;
- },3);
- TemplateVideo video = TemplateVideo.temQueue.Dequeue();
- #if !UNITY_EDITOR
- if (!video.localSavePath.Contains("file"))
- video.m_Video.SetUrl("file://" + video.localSavePath);
- #endif
- video.m_Video.transform.GetComponent<VideoPlayBtn>().m_IsPlaying = false;
- video.m_Video.transform.GetComponent<VideoPlayBtn>().PlayVideoAuto();
- avplayer = video.m_Video;
- }
- if(ModelItem.loadAB.Count>0&&!ModelItem.isLoad)
- {
- ModelItem mi = ModelItem.loadAB.Dequeue();
- if (IsAB(mi))
- {
- ModelItem.isLoad = true;
- AssetBundle assetBundle = AssetBundle.LoadFromMemory(mi.abByte);
- Debug.Log(mi.abByte.Length);
- mi.prefabModel.GetComponent<TemplateModel>().LoadModel(assetBundle);
- }else
- {
- Debug.Log("HJJ fileName==2=>" + mi.DownloadPath);
- mi.prefabModel.GetComponent<TemplateModel>().TriLibModel();
- }
- }
- }
- public bool IsAB(ModelItem mi)
- {
- bool finish = false;
- Debug.Log("HJJ fileName===>" + mi.DownloadPath);
- if (mi.DownloadPath.Contains(".ghb") || !mi.DownloadPath.Contains("."))
- {
- finish = true;
- }
- return finish;
- }
- float lockTime = 0;
- public AVProVideoPlayer avplayer;
- 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();
- if(!UserInfo.Instance.is20)
- MQTTClient.Instance.StartSendCameraPos();
- }
- public void saveOldData()
- {
- allOldobjs = new Dictionary<string, Dictionary<string, Dictionary<string, PosRotScalePatch>>>();
- foreach (var i in allobjs.Keys)
- {
- allOldobjs.Add(i, new Dictionary<string, Dictionary<string, PosRotScalePatch>>());
- foreach (var j in allobjs[i].Keys)
- {
- allOldobjs[i].Add(j, new Dictionary<string, PosRotScalePatch>());
- foreach (var k in allobjs[i][j].Keys)
- {
- PosRotScalePatch p = new PosRotScalePatch();
- p.PosPatch = allobjs[i][j][k].transform.localPosition;
- p.RotPatch = allobjs[i][j][k].transform.localEulerAngles;
- p.ScalePatch = allobjs[i][j][k].transform.localScale;
- allOldobjs[i][j].Add(k, p);
- }
- }
- }
- }
- public void refOldData()
- {
- foreach (var i in allobjs.Keys)
- {
- foreach (var j in allobjs[i].Keys)
- {
- foreach (var k in allobjs[i][j].Keys)
- {
- allobjs[i][j][k].transform.localPosition = allOldobjs[i][j][k].PosPatch;
- allobjs[i][j][k].transform.localEulerAngles = allOldobjs[i][j][k].RotPatch;
- allobjs[i][j][k].transform.localScale = allOldobjs[i][j][k].ScalePatch;
- }
- }
- }
- }
- 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();
- }
- 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
- {
- 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 SCToggleSwitch3D sc3D20zuJD;
- public SCToggleSwitch3D sc3D20zuEditor;
- public SCToggleSwitch3D sc3Dopen20zu;
- public static bool m_IsStartEditorJD;
- public void open20zuJD(bool ison)
- {
- m_IsStartEditorJD = ison;
- if (!ison)
- {
- // save20All();
- }else
- {
- sc3D20zuEditor.isOn = false;
- sc3Dopen20zu.isOn = false;
- }
- SaveButton.SetActive(ison);
- }
- public static bool m_IsStartEditorzu;
- public void open20zu(bool ison)
- {
- m_IsStartEditorzu = ison;
- if (!ison)
- {
- // save20All();
- }
- else
- {
- sc3D20zuJD.isOn = false;
- sc3D20zuEditor.isOn = false;
- }
- SaveButton.SetActive(ison);
- }
- public static bool m_IsStart20Editor;
- //2.0编辑模式 保存
- public void open20Editor(bool ison)
- {
- m_IsStart20Editor = ison;
- if(!ison)
- {
- // save20All();
- }
- else
- {
- // sc3D20zuJD.isOn = false;
- // sc3Dopen20zu.isOn = false;
- }
- SaveButton.SetActive(ison);
- }
- public GameObject SaveButton;
- public void save20All()
- {
- //if (!m_IsStartEditor)
- // {
- List<SendSaveDataNew> saveData = new List<SendSaveDataNew>();
- foreach (var i in UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].SpotsList.Keys)
- {
- SpotsItem sp = UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].SpotsList[i.ToString()];
- SendSaveDataNew data = new SendSaveDataNew();
- data.position = sp.position;
- data.triggerImageId = sp.triggerImageId;
- data.id = int.Parse(sp.id);
- data.name = sp.name;
- data.projectId = int.Parse(UserSceneManager.Instance.SceneList[UserSceneManager.Instance.nowId].id);
- List<MaterialOblNew> MaterialObllsit = new List<MaterialOblNew>();
- foreach (var z in sp.modelList.Keys)
- {
- ObjectTransform objt2 = new ObjectTransform();
- if(sp.isInitModel)
- {
- objt2.nowPos = sp.modelList[z].Model.transform.localPosition;
- objt2.nowRot = sp.modelList[z].Model.transform.localEulerAngles;
- objt2.nowScale = sp.modelList[z].Model.transform.localScale;
- }else
- {
- objt2 = sp.modelList[z].objectTransform;
- }
- sp.modelList[z].objectTransform = objt2;
- List<MaterialObjValueNew> materialList = new List<MaterialObjValueNew>();
- for (int j = 0; j < sp.modelList[z].materialList.Count; j++)
- {
- ObjectTransform objt3 = new ObjectTransform();
- if (sp.isInitModel)
- {
- objt3.nowPos = sp.modelList[z].materialList[j].prefabModel.transform.localPosition;
- objt3.nowRot = sp.modelList[z].materialList[j].prefabModel.transform.localEulerAngles;
- objt3.nowScale = sp.modelList[z].materialList[j].prefabModel.transform.localScale;
- }
- else
- {
- objt3 = sp.modelList[z].materialList[j].objectTransform;
- }
- sp.modelList[z].materialList[j].objectTransform = objt3;
- MaterialObjValueNew mov = new MaterialObjValueNew();
- mov.uid = sp.modelList[z].materialList[j].uid;
- mov.id = sp.modelList[z].materialList[j].id;
- mov.fileId = sp.modelList[z].materialList[j].fileId;
- mov.type = sp.modelList[z].materialList[j].type;
- mov.textContent = sp.modelList[z].materialList[j].textContent.ToString();
- mov.textPosition = sp.modelList[z].materialList[j].textPosition.ToString();
- mov.textBJ = sp.modelList[z].materialList[j].TextBJ.ToString();
- mov.downloadPath = sp.modelList[z].materialList[j].DownloadPath.ToString();
- mov.localSavePath = sp.modelList[z].materialList[j].localSavePath.ToString();
- mov.name = sp.modelList[z].materialList[j].name;
- mov.template = sp.modelList[z].materialList[j].template;
- mov.objectTransform = sp.modelList[z].materialList[j].objectTransform;
- materialList.Add(mov);
- }
- MaterialOblNew obj = new MaterialOblNew();
- obj.id = sp.modelList[z].id;
- obj.name = sp.modelList[z].name;
- obj.objectTransform = sp.modelList[z].objectTransform;
- obj.describe = sp.modelList[z].describe;
- obj.select = true;// sp.modelList[z].select;
- obj.type = sp.modelList[z].type;
- obj.materialList = materialList;
- MaterialObllsit.Add(obj);
- }
- data.material = MaterialObllsit;
- ObjectTransform objt = new ObjectTransform();
- objt.nowPos = sp.SpotsObj.transform.localPosition;
- objt.nowRot = sp.SpotsObj.transform.localEulerAngles;
- objt.nowScale = sp.SpotsObj.transform.localScale;
- data.spoittf = objt;
- //data.triggerRange = spoit.SpoitTransform[0];
- saveData.Add(data);
- }
- string sendData = JsonConvert.SerializeObject(saveData);
- //string sendData = JsonMapper.ToJson(saveData);
- Debug.Log("更新景点数据: " + sendData);
- HttpTool.Instance.PostTest(HttpAction.viewpoint_update, sendData, (string str) => {
- JsonData jd = JsonMapper.ToObject(str);
- if(jd["message"].ToString()=="success")
- {
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.SuccessText);
- CommandSystem.Instance.Send(Command);
- }else
- {
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.NetErrorText);
- CommandSystem.Instance.Send(Command);
- }
- Debug.Log("保存回调===》" + str);
- });
- // }
- }
- 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);
- }
- }
- public void GetPosRotScale()
- {
- saveOldData();
- return;
- 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 IEnumerator CreateScene(SceneValue scene)
- {
- SceneValue = scene;
- if (m_MinMap.Map.sprite == null)
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "正在获取地图信息");
- GetMinMap(scene ,null);
- }
- else
- {
- yield return StartCoroutine(StartCreateScene(scene));
- }
- yield return new WaitForSeconds(1f);
- MoveScenePatch();
- }
- private void MoveScenePatch()
- {
- Vector3 temp = ObjsParent.parent.localPosition;
- temp.z += MapSize.y;
- ObjsParent.parent.localPosition = temp;
- }
- private IEnumerator StartCreateScene(SceneValue scene)
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "正在初始化景点");
- if (scene.navLines != null && scene.navLines.Count > 0)
- SetRouteValue(scene.navLines);
- else
- Debug.LogError(" 当前场景未设置路径");
- Debug.Log("DGJ ====> " + JsonConvert.SerializeObject(scene));
- if (scene.listSpoit != null && scene.listSpoit.Count > 0)
- yield return StartCoroutine(SetSpoitValue(scene.listSpoit));
- else
- Debug.LogError(" 当前场景未创建景点");
- if (scene.listPicture != null && scene.listPicture.Count > 0)
- SetAnchor(scene.listPicture);
- else
- Debug.LogError(" 当前场景未创建锚点");
- //设置小地图景点
- // m_CalMap.SettingMapPoint(ListCrystals);
- yield return null;
- //UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
- // DownloadManager.Instance.UpdataData();
-
- UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
- IntoScene();
- }
- Action<bool> GetMinMapBack;
- /// <summary>
- /// 获取小地图
- /// </summary>
- public void GetMinMap( SceneValue scene ,Action<bool> getBack)
- {
- GetMinMapBack = getBack;
- //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("playerPos===>" + isStart);
- //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);
- }
- DownLoadMaterial downLoadMaterial = new DownLoadMaterial();
- downLoadMaterial.downLoadPath = MapPicUrl;
- downLoadMaterial.localLoadPath = Application.persistentDataPath + "/Material/" + MapPicUrl;
- downLoadMaterial.updataTime = scene.updateTime;
- downLoadMaterial.type = "-1";
- Debug.Log("Hjj 开始获取地图大小==》");
- MsgHandler.AddListener(downLoadMaterial.downLoadPath, HandleMsg);
- DownloadResManager.Instance.DownLoad(downLoadMaterial);
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "准备下载素材");
- GameManager.Instance.isShowDownTip = true;
- DownloadResManager.Instance.StartDownLoad();
- }
- public static MatOfByte filePathToMatByte(byte[] bytes)
- {
- Debug.Log("加載完成2222");
- MatOfByte matOfByte = new MatOfByte(bytes);
- Debug.Log("加載完成3333");
- //Imgcodecs.imdecode
- return matOfByte;
- }
- /// <summary>
- /// OpenCV生成图片缩略图
- /// </summary>
- /// <param name="path">文件路径</param>
- /// <param name="zoom">缩放值</param>
- /// <returns></returns>
- public static Mat zoomByteByOpenCV(byte[] path)
- {
- Debug.Log("加載完成2222");
- MatOfByte matbytes = filePathToMatByte(path);
- Debug.Log("加載完成3333");
- Mat mat = Imgcodecs.imdecode(matbytes, -1);
- Debug.Log("加載完成4444");
- float zoom = 1;
- float sint = 2048f;
- if (mat.cols() > sint)
- {
- zoom = (float)(sint / mat.cols());
- }
- if (mat.rows() * zoom > sint)
- {
- zoom = (float)(sint / (float)(mat.rows() * zoom));
- }
- Debug.Log("加載完成3333");
- //Debug.Log(mat.cols());
- //Debug.Log(mat.rows());
- //压缩图片
- Size size = new Size(mat.cols() * zoom, mat.rows() * zoom);
- Mat zoomMat = new Mat(size, CvType.CV_8UC4);
- Imgproc.resize(mat, zoomMat, size);
- ////BGR 转RGB
- Mat imgRGBMat = new Mat(zoomMat.cols(), zoomMat.rows(), CvType.CV_8UC4);
- Imgproc.cvtColor(zoomMat, imgRGBMat, Imgproc.COLOR_BGR2RGB);
- //RefreshEvent?.Invoke();
- zoomMat.release();
- mat.release();
- matbytes.release();
- Debug.Log("加載完成444");
- return imgRGBMat;
- //return mat;
- }
- public static Texture2D TextureByMat(Mat imgRGBMat)
- {
- //Debug.Log(imgRGBMat.cols());
- //Debug.Log(imgRGBMat.rows());
- Texture2D _tex = new Texture2D(imgRGBMat.cols(), imgRGBMat.rows(), TextureFormat.RGB24, false);
- Utils.fastMatToTexture2D(imgRGBMat, _tex);
- return _tex;
- }
- private void HandleMsg(Msg msg)
- {
- Debug.Log("Hjj 获取地图大小==》");
- // MsgHandler.RemoveListener()
- if(msg.Value!=null)
- {
- Texture2D tex = new Texture2D(1, 1);
- OpenCVForUnity.CoreModule.Mat _mat = null;
- Loom.RunAsync(() =>
- {
- Debug.Log("加載完成222222222222222222");
- _mat = zoomByteByOpenCV((byte[])msg.Value);
- Debug.Log("1111111");
- Loom.QueueOnMainThread(() =>
- {
- Debug.Log("加載完成111111111111");
- tex = TextureByMat(_mat);
- // Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
- Sprite sprite = Sprite.Create(tex, new UnityEngine.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);
- }
- Debug.Log("playerPos===>GetMinMapBack");
- GetMinMapBack?.Invoke(true);
- });
- });
-
- }else
- {
- GetMinMapBack?.Invoke(false);
- }
- }
- /// <summary>
- /// 设置景点素材信息
- /// </summary>
- /// <param name="spoits"></param>
- public IEnumerator 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);
- yield return StartCoroutine(CreateMaterial(spoit));
- spoits[i] = SV;
- }
- 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!=null&&spoit.SpoitTransform.Count > 0)
- {
- Debug.LogFormat("{0}{1}", spoit.name, " DGJ ===> 景点存在");
- SpoitPos trans = spoit.SpoitTransform[0];
-
- spoitPos = new Vector3((float)trans.pointRelativeX / WebMapSize.x * MapSize.x, -1f, MapSize.y - ((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, MapSize.y - (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);
- Debug.LogError($"名称:{spoit.name}+宽:{trans.areaRelativeW},长:{trans.areaRelativeH}");
- 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, "景点不存在");
- }
- }
- public float wutiH=1.5f;
- private GameObject CreateSpoit(SpoitValue spoit, Vector3 spoitPos)
- {
- //生成景点父物体
- GameObject spoitObj = new GameObject(spoit.name);
- spoitObj.transform.SetParent(ObjsParent.transform);
- spoitObj.AddComponent<EditorEventHandler>().IsClickEditor = false;
- spoitposObjDic.Add(spoit.id, spoitObj);
- /*
- //为景点位置信息赋值
- if (spoit.spoitTf.startPos == Vector3.zero && spoit.spoitTf.nowPos == Vector3.zero)
- {*/
- spoitposDic.Add(spoit.id, new Vector3(spoitPos.x, wutiH, spoitPos.z));
- spoitObj.transform.localPosition = new Vector3(spoitPos.x, wutiH, spoitPos.z)+ spoit.spoitTf.nowPos;
- Debug.Log("最新保存====》獲取的POS" + new Vector3(spoitPos.x, wutiH, spoitPos.z));
- Debug.Log("最新保存====》獲取的偏移POS" + spoit.spoitTf.nowPos);
- Debug.Log("最新保存====》獲取的物體Pos" + spoitObj.transform.localPosition);
- spoitObj.transform.localRotation = Quaternion.identity;
- spoitObj.transform.localEulerAngles = spoit.spoitTf.nowRot;
- spoitObj.transform.localScale = new Vector3(1, 1, 1);
- if(spoit.spoitTf.nowScale!=Vector3.zero)
- {
- spoitObj.transform.localScale = spoit.spoitTf.nowScale;
- }
- 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;
- }
- SpoitValue SV;
- /// <summary>
- /// 创建整体素材
- /// 一个景点下应只有一个父物体,其他素材都在父物体下
- /// </summary>
- private IEnumerator CreateMaterial(SpoitValue spoit)
- {
- MsgHandler.ClearAllListeners();
- if (!ObjectValues.ContainsKey(spoit.id))
- {
- SV = new SpoitValue();
- }
- else
- {
- var spoitValues = ObjectValues[spoit.id];
- var spoitObj = spoitValues.Object;
- Debug.Log("DGJ ===> 创建整体素材 "+ spoit.material.Count);
- SyncSpoit syncSpoit = new SyncSpoit();
- syncSpoit.spoitId = spoit.name;
- syncSpoit.spoitObj = spoitObj;
- if (MultiPlayerManager.Instance.dicSpoitValue.ContainsKey(spoit.name))
- {
- MultiPlayerManager.Instance.dicSpoitValue[spoit.name] =syncSpoit;
- }
- else
- MultiPlayerManager.Instance.dicSpoitValue.Add(spoit.name, syncSpoit);
- if(!UserInfo.Instance.is20)
- //生成素材组合
- 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);
- //素材组合对应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:
- Debug.Log("DGJ ===> LocalImage " + material.name);
- objsvalue = CreateSuCaiObj(spoit,material, matObj, out newmaterial);
- break;
- case (int)MaterialType.Image_Video_Text:
- Debug.Log("DGJ ===> Image_Video_Text " + material.name);
- objsvalue = CreateImage_Video_Text(spoit,material, matObj, out newmaterial);
- break;
- case (int)MaterialType.Model_Text:
- Debug.Log("DGJ ===> Model_Text " + material.name);
- objsvalue = CreateModel_Text(spoit,material, matObj, out newmaterial);
- break;
- default:
- break;
- }
-
- spoit.material[i] = newmaterial;
- spoitValue.ChildrenObj.AddRange(objsvalue);
- spoitValues.ChildrenObj.Add(spoitValue);
- Debug.Log("DGJ ===> 创建整体素材 " + spoitValues.ChildrenObj.Count);
- }
- SV = spoit;
- if (ObjectValues.ContainsKey(spoit.id))
- {
- ObjectValues[spoit.id] = spoitValues;
- }
- else
- {
- ObjectValues.Add(spoit.id, spoitValues);
- }
- spoitObj.gameObject.SetActive(false);
- }
- yield return null;
- }
- /// <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(spoit, newmaterial, matObj, out newmaterial);
- break;
- case (int)MaterialType.Image_Video_Text:
- objsvalue = CreateImage_Video_Text(spoit,newmaterial, matObj, out newmaterial);
- break;
- case (int)MaterialType.Model_Text:
- objsvalue = CreateModel_Text(spoit, 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(SpoitValue spoitjd, 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 (mat.type)
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Image:
- var pImage = ResMgr.Instance.Load<GameObject>("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>("Video");
- go = Instantiate(pVideo, spoit.transform);
- var videoitem = go.AddComponent<TemplateVideo>();
- videoitem.autoplay = material.autoplay;
- go.SetActive(true);
- videoitem.SetData(mat, material.updateTime);
-
- break;
- case (int)MaterialType.Model:
- var pModel = ResMgr.Instance.Load<GameObject>("Model");
- go = Instantiate(pModel, spoit.transform);
- var modelitem = go.AddComponent<TemplateModel>();
- go.SetActive(true);
- modelitem.SetData(mat, material.updateTime);
- Debug.Log(modelitem.Data.localLoadPath);
- break;
- case (int)MaterialType.Text:
- var pText = ResMgr.Instance.Load<GameObject>("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>("Image");
- go = Instantiate(pLocaImage, spoit.transform);
- var locaImageitem = go.AddComponent<TemplateImage>();
- go.SetActive(true);
- locaImageitem.SetLocaImageData(mat);
- break;
- default:
- break;
- }
- if (go != null)
- {
- if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString()))
- {
- GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary<string, Dictionary<string, GameObject>>());
- }
- if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(material.id.ToString()))
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(material.id.ToString(), new Dictionary<string, GameObject>());
- }
- if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].ContainsKey(mat.id.ToString()))
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].Add(mat.id.ToString(), go);
- }
- else
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()][mat.id.ToString()] = go;
- }
- go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
- mat.name = go.name;
- go.AddComponent<EditorEventHandler>().Type = (MaterialType)(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 (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(SpoitValue spoitjd, 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 (mat.type)
- {
- case (int)MaterialType.None:
- break;
- case (int)MaterialType.Model:
- var pModel = ResMgr.Instance.Load<GameObject>("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>("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)
- {
- if (!GameManager.Instance.allobjs.ContainsKey(spoitjd.id.ToString()))
- {
- GameManager.Instance.allobjs.Add(spoitjd.id.ToString(), new Dictionary<string, Dictionary<string, GameObject>>());
- }
- if (!GameManager.Instance.allobjs[spoitjd.id.ToString()].ContainsKey(material.id.ToString()))
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()].Add(material.id.ToString(), new Dictionary<string, GameObject>());
- }
- if (!GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].ContainsKey(mat.id.ToString()))
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()].Add(mat.id.ToString(), go);
- }
- else
- {
- GameManager.Instance.allobjs[spoitjd.id.ToString()][material.id.ToString()][mat.id.ToString()] = go;
- }
- go.name = string.IsNullOrWhiteSpace(mat.name) ? spoit.name + "-" + i.ToString() : mat.name;
- go.AddComponent<EditorEventHandler>().Type = (MaterialType)(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 (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);
- }
- Debug.LogError("Tyyyyyyyyyyyyyyyyyyt " + go.transform.localPosition);
- Debug.LogError("Tyyyyyyyyyyyyyyyyyyt " + mat.textContent);
- }
- 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(SpoitValue spoitjd,MaterialObl material, GameObject spoit, out MaterialObl newmaterial)
- {
- Debug.LogError("HJJmaterialObls.select DRFanLayout.CreateImage_Video_Text ");
- newmaterial = material;
- List<ObjectValue> objects = new List<ObjectValue>();
- SRTitleLayout.CalLayout(spoitjd,material, spoit, out newmaterial);
- Debug.LogError("HJJmaterialObls.select DRFanLayout.CalLayout default ");
- 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)(mat.type);
- Debug.LogError("Tyyyyyyyyyyyyyyyyyyt " + mat.ObjectTransform.nowPos);
- if (mat.type != (int)MaterialType.Text)
- {
- //为物体位置信息赋值
- 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);
-
- MQTTClient.Instance.sendActiveSp(ListShowObjs[i].name, true);
- Debug.Log(i);
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[i].gameObject.SetActive(true);
- // 进入景点通知后台
- for (int j = 0; j < SceneValue.listSpoit.Count; j++)
- {
- if(SceneValue.listSpoit[i].name == other.name)
- {
- HttpSocket.Instance.SendIpToPointTrigger(" ", SceneValue.listSpoit[i].id, CallBack);
- }
- }
- if (SpoitIndex == i)
- {
- return;
- }
- //进入新区域前关闭当前显示
- if (SpoitIndex >= 0 && IsStartEditor)
- {
- ListShowObjs[SpoitIndex].gameObject.SetActive(false);
- MQTTClient.Instance.sendActiveSp(ListShowObjs[SpoitIndex].name, 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]);
- m_SettingPanel.setMsg(SpoitValues[i]);
- return;
- }
- }
- }
- public void SetPosRotScale()
- {
- refOldData();
- }
- /// <summary>
- /// 当人物退出触发器范围
- /// </summary>
- public void OnColliderTriggerExit(Collider other)
- {
- IsTriggerExiting = false;
- if (IsStartEditor)
- {
- return;
- }
- else
- {
- ListShowObjs[SpoitIndex].gameObject.SetActive(false);
- MQTTClient.Instance.sendActiveSp(ListShowObjs[SpoitIndex].name, false);
- if (isShowLoacalShowObjs)
- ListLocalShowObjs[SpoitIndex].gameObject.SetActive(false);
- ListCrystals[SpoitIndex].gameObject.SetActive(true);
- m_EditorPanel.ClosePanel();
- SpoitIndex = -1;
- }
- m_SettingPanel.setMsg(null);
- }
- /// <summary>
- /// 更新景点信息
- /// </summary>
- public void UpdateSpoitValue()
- {
- if(SpoitValues!=null&& SpoitValues.Count> SpoitIndex&& SpoitIndex!=-1)
- {
- Debug.Log("SpoitValues====>"+SpoitValues.Count+" _ "+ SpoitIndex);
- 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);
- SpoitValues[SpoitIndex] = spoit;
- }
- return;
- /*
- 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;
- }
- }
- }
|