using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; public class ShowControllerXX : MonoBehaviour { public static ShowControllerXX Instance; List lstShow; // Start is called before the first frame update void Start() { Instance = this; lstShow = new List(); } public void AddShow(BaseShow bs) { lstShow.Add(bs); } public void RemoveShow(BaseShow bs) { lstShow.Remove(bs); } public string GetImageShow(Data info, int index) { var result = lstShow.FirstOrDefault(show => (show.info.ObjectID == info.ObjectID || show.info.ParentID == info.ParentID) && show.info.Type == DataType.MultiImage && show.info.Index == index ); if (result == null) { int count = lstShow.Count(show => show.info.ParentID == info.ObjectID); if (result == null) { return info.Title; } else { return null; } } else { ImageShow isResult = (result as ImageShow); if (isResult == null) { return null; } else { return isResult.info.Title; } } } float distance; bool canClickNewStatus; ShowBoxCollider tmpSBC; // Update is called once per frame void FixedUpdate() { //if ( // BaseController.IsJoyStickOnControl // || BaseController.IsKeyOnControl // || BaseController.IsMouseOnControl // || BaseController.IsNavOnControl // ) if(BaseController.CanControl && !BaseController.IsKeyOnControl && !BaseController.IsNavOnControl && !BaseController.IsJoyStickOnControl) { foreach (BaseShow show in lstShow) { if(show.transform.childCount > 0) { distance = show.GetComponentsInChildren().Min(tran => Vector3.Distance(CommonData.MainCamera.transform.position, tran.position)); // Debug.Log(show.name); } // 获取摄像机与中心位置的距离 if (distance == 0) distance = Vector3.Distance(CommonData.MainCamera.transform.position, show.transform.position); else distance = Mathf.Min( distance, Vector3.Distance(CommonData.MainCamera.transform.position, show.transform.position) ); canClickNewStatus = (distance <= CommonData.ClickDistance); // 可单击状态发生改变(靠近或远离) if (show.CanClick != canClickNewStatus) { show.CanClick = canClickNewStatus; if (show.info.Clickable) { if (show.CanClick) { tmpSBC = show.gameObject.AddComponent(); tmpSBC.showHotTip = show.info.ShowHotTip; tmpSBC.showBox = show.info.ShowBox; } else { Destroy(show.gameObject.GetComponent()); } } show.OnStatusChange(); // 启用或禁用选中控制组件 if (show.sbc != null) { if (show.CanClick) { show.sbc.enabled = true; } else { show.sbc.enabled = false; } } } distance = 0f; } } } }