using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.Video; public class TipPointCollider : MonoBehaviour { static List oldKeys = new List(); static List newKeys = new List(); public static TipPointCollider Instance; private void Awake() { Instance = this; } private void Start() { BaseController.StatusChanged += ControllerStatusChanged; ShowPointEx.ShowPointChanged += ControllerStatusChanged; } Data info; Dictionary> dicShows = new Dictionary>(); ShowBoxCollider tmpSBC; GameObject tmpObj; public void ControllerStatusChanged() { // Debug.Log(newKeys.Count); #region Spot¿ØÖÆ foreach (var key in newKeys) { if (oldKeys.Contains(key)) { continue; } else { GameObject obj = GameObject.Find(key); if (obj != null) { oldKeys.Add(key); if (DataLoader.DataDics.ContainsKey(key)) { info = DataLoader.DataDics[key]; AddShow(obj, info); } if (obj.transform.childCount != 0) { for (int i = 0; i < obj.transform.childCount; i++) { tmpObj = obj.transform.GetChild(i).gameObject; if (DataLoader.DataDics.ContainsKey(tmpObj.name)) { info = DataLoader.DataDics[tmpObj.name]; AddShow(tmpObj, info, key); } } } } } if (DataLoader.DataList != null) { var result = DataLoader.DataList.Where(data => data.ParentKey == key); if (result != null && result.Count() > 0) { foreach (var item in result) { GameObject obj = GameObject.Find(item.ObjectID); if (obj != null) { item.ShowHotTip = false; AddShow(obj, item, key); } } } } } foreach (var key in oldKeys) { if (newKeys.Contains(key)) { continue; } else { if (dicShows.ContainsKey(key)) { foreach (BaseShow bs in dicShows[key]) { if (bs.info.Clickable) { Destroy(bs.GetComponent()); } if (bs is VideoShow && bs.info.PlayVideoOnObject) { Destroy(bs.gameObject.GetComponent()); } Destroy(bs); } dicShows.Remove(key); } } } oldKeys.RemoveAll(tmp => !newKeys.Contains(tmp)); #endregion } public string GetImageShow(Data info, int index) { var result = DataLoader.DataDics.Values.FirstOrDefault(data => (data.ObjectID == info.ObjectID || data.ParentID == info.ParentID) && data.Type == DataType.MultiImage && data.Index == index ); if (result == null) return null; else return result.Title; } void AddShow(GameObject obj, Data info, string key = null) { if (key == null) { key = info.ObjectID; } info.ParentKey = key; if (info.IsType(DataType.Image) || info.IsType(DataType.MultiImage)) { AddShow(obj, info, key); if (info.IsType(DataType.MultiImage)) { Data dt = DataLoader.DataDics.Values.FirstOrDefault(data => data.ObjectID == info.ParentID); if (dt != null) { info.DataDetails = dt.DataDetails; } } } if (info.IsType(DataType.Video)) { AddShow(obj, info, key); } if (info.IsType(DataType.Game)) { AddShow(obj, info, key); } if (info.IsType(DataType.Url)) { AddShow(obj, info, key); } if (info.IsType(DataType.TipPoint)) { AddShow(obj, info, key); } if (info.IsType(DataType.Material)) { AddShow(obj, info, key); } if (info.IsType(DataType.Model)) { AddShow(obj, info, key); } if (info.IsType(DataType.Scene)) { AddShow(obj, info, key); } //else // obj.AddComponent().Test = true; // Debug.Log(info.ObjectID); if (info.Clickable) { tmpSBC = obj.AddComponent(); tmpSBC.showHotTip = info.ShowHotTip; tmpSBC.showBox = info.ShowBox; } } void AddShow(GameObject obj, Data info, string key) where T : BaseShow { BaseShow bs = obj.AddComponent(); bs.info = info; if (dicShows.ContainsKey(key)) { dicShows[key].Add(bs); } else { dicShows.Add(key, new List()); dicShows[key].Add(bs); } } void OnTriggerEnter(Collider other) { if (IsTipPoint(other)) { newKeys.Add(other.name.Substring(3)); // Debug.Log(other.name.Substring(3) + "Enter"); } } void OnTriggerStay(Collider other) { if (IsTipPoint(other)) { if (!newKeys.Contains(other.name.Substring(3))) { newKeys.Add(other.name.Substring(3)); // Debug.Log(other.name.Substring(3) + "Enter"); } } } void OnTriggerExit(Collider other) { if (IsTipPoint(other)) { newKeys.Remove(other.name.Substring(3)); // Debug.Log(other.name.Substring(3) + "Exit"); } } bool IsTipPoint(Collider other) { // return other.gameObject.layer == LayerMask.NameToLayer("TipPoint") && other.name.StartsWith("TP_"); return other.name.StartsWith("TP_"); } }