1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651 |
- using LitJson;
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- /*
- * 半自动交付/自动交付
- * 景点、触发范围、水晶点应保持顺序对应
- * 当前场景下景点名称不应重复
- * 同一景点下素材名称不应重复
- * 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;
- public GameObject ernieBot;
- [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; }
- }
- private void Awake()
- {
-
- // Debug.unityLogger.logEnabled = false;
- }
- private void Start()
- {
- // 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 (OpenXRCamera.Instance.head != null && m_IsRuning)
- {
- m_SetBtn.transform.localEulerAngles = new Vector3(0, OpenXRCamera.Instance.head.localEulerAngles.y, 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();
- ernieBot.SetActive(true);
- }
- 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 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)
- {
- GetPosRotScale(); // 获取所有物体位置旋转缩放
- m_EditorCanvas.position = API_GSXR_Slam.GSXR_Get_Head().position + Player.transform.forward + new Vector3(0, 0.5f, 0);
- m_EditorCanvas.eulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_Head().eulerAngles.y, 0);
-
- }
- else
- {
- SetPosRotScale();// 设置所有物体位置旋转缩放
- m_EditorCanvas.position = API_GSXR_Slam.GSXR_Get_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;
- }
- }
- }
- public void OnSettingBtnValueChanged(bool ison)
- {
- m_SettingPanel.gameObject.SetActive(ison);
- if (ison)
- {
- Debug.Log(API_GSXR_Slam.GSXR_Get_Head().forward);
- m_SettingPanel.transform.position = API_GSXR_Slam.GSXR_Get_Head().position + Player.transform.forward;
- m_SettingPanel.transform.eulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_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 = API_GSXR_Slam.GSXR_Get_Head().position + Player.transform.forward + new Vector3(0, 0.5f, 0);
- m_UIAnchorsPanel.transform.eulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_Head().eulerAngles.y, 0);
- }
- else
- {
- m_UIAnchorsPanel.transform.position = API_GSXR_Slam.GSXR_Get_Head().position + new Vector3(0, 100, 0);
- }
- }
- 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);
- }
- }
- }
- }
- }
- 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++;
- }
- }
- }
- }
- }
- }
- #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);
- }
- }
- 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);
- 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);
- 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);
- 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);
- 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]);
- return;
- }
- }
- }
- /// <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;
- }
- }
- }
|