Files
TaiWan/Assets/Roaming/Scripts/Controller/Camera/ShowController.cs
2025-10-31 15:20:38 +08:00

141 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class ShowControllerXX : MonoBehaviour
{
public static ShowControllerXX Instance;
List<BaseShow> lstShow;
// Start is called before the first frame update
void Start()
{
Instance = this;
lstShow = new List<BaseShow>();
}
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<Transform>().Min(tran => Vector3.Distance(CommonData.MainCamera.transform.position, tran.position));
// Debug.Log(show.name);
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>õľ<C3B5><C4BE><EFBFBD>
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);
// <20>ɵ<EFBFBD><C9B5><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>ı<C4B1><E4A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>
if (show.CanClick != canClickNewStatus)
{
show.CanClick = canClickNewStatus;
if (show.info.Clickable)
{
if (show.CanClick)
{
tmpSBC = show.gameObject.AddComponent<ShowBoxCollider>();
tmpSBC.showHotTip = show.info.ShowHotTip;
tmpSBC.showBox = show.info.ShowBox;
}
else
{
Destroy(show.gameObject.GetComponent<ShowBoxCollider>());
}
}
show.OnStatusChange();
// <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (show.sbc != null)
{
if (show.CanClick)
{
show.sbc.enabled = true;
}
else
{
show.sbc.enabled = false;
}
}
}
distance = 0f;
}
}
}
}