NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/PlaneShadow/PlaneShadowManager.cs

84 lines
2.4 KiB
C#

using System.Collections.Generic;
using Gameplay.Character;
using Gameplay.Common;
using Gameplay.Performance;
using Gameplay.Unit;
using Gameplay.Vehicle.Impl;
using PhxhSDK;
using UnityEngine;
namespace Code.Scripts.Gameplay.PlaneShadow
{
public class PlaneShadowManager
{
private static PlaneShadowManager _instance;
public static PlaneShadowManager instance
{
get
{
if (_instance == null)
{
_instance = new PlaneShadowManager();
}
return _instance;
}
}
private List<ViewPlaneShadow> _viewPlaneShadows = new List<ViewPlaneShadow>();
private Transform _rootTrans;
public void Init()
{
var rootObj = new GameObject("[PlaneShadowRoot]");
_rootTrans = rootObj.transform;
}
public void AddUnit(GameUnit unit)
{
if (!PerformanceManager.instance.data.usePanelShadow) return;
if (unit is Character unitCharacter)
{
var shadowPath = PathDefine.PlaneShadow.PLANE_SHADOW_CHARACTER_PATH;
var view = new ViewPlaneShadow(unitCharacter);
view.CreateView(shadowPath, _rootTrans);
_viewPlaneShadows.Add(view);
}
else if (unit is NormalVehicle unitVehicle)
{
var shadowPath = PathDefine.PlaneShadow.PLANE_SHADOW_VEHICLE_PATH;
var view = new ViewPlaneShadow(unitVehicle);
view.CreateView(shadowPath, _rootTrans);
_viewPlaneShadows.Add(view);
}
}
public void ViewUpdate()
{
for (int i = 0; i < _viewPlaneShadows.Count; i++)
{
var view = _viewPlaneShadows[i];
view.ViewUpdate();
if (view.needRemove)
{
view.Dispose();
_viewPlaneShadows.RemoveAt(i);
i--;
}
}
}
public void Dispose()
{
for (int i = 0; i < _viewPlaneShadows.Count; i++)
{
var view = _viewPlaneShadows[i];
view.Dispose();
}
_viewPlaneShadows.Clear();
Object.Destroy(_rootTrans.gameObject);
_instance = null;
}
}
}