报错修改
This commit is contained in:
181
Assets/Domain/Main/HotUpdate/ZoneController.cs
Normal file
181
Assets/Domain/Main/HotUpdate/ZoneController.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Stary.Evo;
|
||||
using Stary.Evo.AudioCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using YooAsset;
|
||||
|
||||
namespace Main
|
||||
{
|
||||
public class ZoneController : MonoBehaviour, IController
|
||||
{
|
||||
public ZoneType zoneType;
|
||||
/// <summary>
|
||||
/// 区域包围盒
|
||||
/// </summary>
|
||||
public BoxCollider ZoneCollider { get; set; }
|
||||
/// <summary>
|
||||
/// 区域中心点碰撞盒
|
||||
/// </summary>
|
||||
public SphereCollider ZoneColliderPoint { get; set; }
|
||||
public PointController[] PointControllerEntities { get; set; }
|
||||
|
||||
private IUnRegister _onTriggerEnterUnRegister;
|
||||
private IUnRegister _onTriggerExitUnRegister;
|
||||
private Image _image;
|
||||
private Transform ipTransform;
|
||||
public async void Init(ZoneData zoneData)
|
||||
{
|
||||
|
||||
name = zoneData.name;
|
||||
zoneType = Enum.Parse<ZoneType>(name);
|
||||
_image=transform.Find("Canvas/Image").GetComponent<Image>();
|
||||
ipTransform = transform.Find("IPPosition");
|
||||
//根据数据设置zone 碰撞盒
|
||||
transform.localPosition = zoneData.position;
|
||||
transform.localRotation = Quaternion.Euler(zoneData.rotation);
|
||||
transform.localScale = zoneData.scale;
|
||||
ZoneCollider = this.transform.Find("BoxBounding").GetComponent<BoxCollider>();
|
||||
|
||||
ZoneCollider.center = zoneData.boundingBoxCenter;
|
||||
ZoneCollider.size = zoneData.boundingBoxSize;
|
||||
ZoneCollider.gameObject.SetActive(false);
|
||||
|
||||
ZoneColliderPoint = this.transform.Find("GuideBall_Point").GetComponent<SphereCollider>();
|
||||
ZoneColliderPoint.transform.localPosition = zoneData.ColliderPosition;
|
||||
ZoneColliderPoint.transform.localRotation = Quaternion.Euler(zoneData.ColliderRotation);
|
||||
ZoneColliderPoint.transform.localScale = zoneData.ColliderScale;
|
||||
ZoneColliderPoint.GetComponentInChildren<TextMesh>().text = zoneData.desc;
|
||||
|
||||
|
||||
|
||||
PointControllerEntities = new PointController[zoneData.pointDatas.Count];
|
||||
|
||||
var package = YooAssets.TryGetPackage("Main");
|
||||
|
||||
var spriteHandle = package.LoadAssetAsync<Sprite>($"Sprites_{zoneData.spriteName}" );
|
||||
await spriteHandle.Task;
|
||||
_image.sprite = spriteHandle.GetAssetObject<Sprite>();
|
||||
_image.SetNativeSize();
|
||||
_image.gameObject.SetActive(false);
|
||||
|
||||
var pointHandle = package.LoadAssetAsync<GameObject>(R.Res.Main.prefabs.guideball_point_prefab);
|
||||
await pointHandle.Task;
|
||||
for (int i = 0; i < zoneData.pointDatas.Count; i++)
|
||||
{
|
||||
|
||||
PointData currentPointData = zoneData.pointDatas[i];
|
||||
var pointGo = pointHandle.InstantiateSync(this.transform);
|
||||
PointController pointController = pointGo.GetOrAddComponent<PointController>();
|
||||
PointControllerEntities[i] = pointController;
|
||||
pointController.Init(this, currentPointData);
|
||||
|
||||
|
||||
this.GetSystem<IDigitalHuman>().AddPointData(new DigitalHumanPointData()
|
||||
{
|
||||
pointName = zoneData.pointDatas[i].name,
|
||||
boundName = zoneData.name,
|
||||
pointTransform = pointGo.transform,
|
||||
boundTransform = ipTransform,
|
||||
});
|
||||
}
|
||||
// this.RegisterEvent(zoneType, OpenPoint);
|
||||
_onTriggerEnterUnRegister = ZoneColliderPoint.OnTriggerEnterEvent(OnZoneTriggerEnterEvent);
|
||||
}
|
||||
|
||||
|
||||
public async void OnZoneTriggerEnterEvent(Collider collider)
|
||||
{
|
||||
Debug.Log($"【{transform.name}】OnZoneTriggerEnterEvent");
|
||||
if (collider.gameObject.CompareTag("MainCamera"))
|
||||
{
|
||||
_onTriggerEnterUnRegister.UnRegister();
|
||||
ZoneColliderPoint.gameObject.SetActive(false);
|
||||
PointActive(true);
|
||||
this.GetSystem<IZoneSystem>().OpenCurrentZone(this);
|
||||
ZoneCollider.gameObject.SetActive(true);
|
||||
_onTriggerExitUnRegister = ZoneCollider.OnTriggerExitEvent(OnZoneTriggerExitEvent);
|
||||
var package=YooAssets.TryGetPackage("Main");
|
||||
var handle=package.LoadAssetAsync<AudioClip>(R.Res.Main.audios.au_effect_element_pop_mp3);
|
||||
await handle.WithCancellation(this.GetCancellationTokenOnDestroy());
|
||||
AudioCoreManager.PlaySFX(new AudioData()
|
||||
{
|
||||
clip = handle.GetAssetObject<AudioClip>()
|
||||
});
|
||||
BoundingEvent();
|
||||
}
|
||||
}
|
||||
public void OnZoneTriggerExitEvent(Collider collider)
|
||||
{
|
||||
|
||||
if (collider.gameObject.CompareTag("MainCamera"))
|
||||
{
|
||||
Debug.Log($"【{transform.name}】OnZoneTriggerExitEvent");
|
||||
_onTriggerExitUnRegister.UnRegister();
|
||||
ZoneCollider.gameObject.SetActive(false);
|
||||
PointActive(false);
|
||||
HybridClREntrance entrance= FindObjectOfType<HybridClREntrance>();
|
||||
if (entrance != null)
|
||||
{
|
||||
entrance.CloseDomain();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("UnityEvo:HybridClREntrance is null");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PointActive(bool force = true)
|
||||
{
|
||||
foreach (var controller in PointControllerEntities)
|
||||
{
|
||||
controller.gameObject.SetActive(force);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenPoint(PointController controller)
|
||||
{
|
||||
foreach (var controllerEntity in PointControllerEntities)
|
||||
{
|
||||
if (controllerEntity == controller)
|
||||
{
|
||||
controller.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
controllerEntity.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void ColsePoint()
|
||||
{
|
||||
foreach (var controller in PointControllerEntities)
|
||||
{
|
||||
controller.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void BoundingEvent(bool isShow = true)
|
||||
{
|
||||
//显示ip相关
|
||||
if (isShow)
|
||||
{
|
||||
_image.gameObject.SetActive(true);
|
||||
this.GetSystem<IDigitalHuman>().SetPositionOfBound(this.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_image.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
public IArchitecture GetArchitecture()
|
||||
{
|
||||
return MainArchitecture.Interface;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user