131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Common;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Utils;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
using Constants = Framework.Constants;
|
|
namespace Gameplay.Fight.Capture
|
|
{
|
|
public class CaptureInst
|
|
{
|
|
private static readonly int _Prop_Color1 = Shader.PropertyToID("_BaseColor");
|
|
|
|
public int cellIndex;
|
|
|
|
public int maxCaptureProgress = 10;
|
|
|
|
public List<GameUnit> inAreaUnits;
|
|
|
|
public float captureProgress;
|
|
|
|
private bool _lastIsInArea;
|
|
|
|
public bool isCaptured { get; private set; }
|
|
|
|
private GameObject _displayObj;
|
|
|
|
private Material _displayMat;
|
|
|
|
private Color _startColor;
|
|
private Color _endColor;
|
|
|
|
public CaptureInst(int cellIndex, int captureValue)
|
|
{
|
|
maxCaptureProgress = captureValue;
|
|
this.cellIndex = cellIndex;
|
|
inAreaUnits = new List<GameUnit>();
|
|
captureProgress = 0f;
|
|
isCaptured = false;
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(PathDefine.CapturePoint.CAPTURE_POINT_PATH);
|
|
_displayObj = Object.Instantiate(sampleObj);
|
|
var worldPos = AreaManager.instance.GetWorldPosByIndex(cellIndex);
|
|
_displayObj.transform.position = worldPos;
|
|
_lastIsInArea = false;
|
|
|
|
_startColor = ColorEx.FromStr("#FFFFFF");
|
|
_endColor = ColorEx.FromStr("#D4FF7E");
|
|
_SearchDisplayMat();
|
|
}
|
|
|
|
private void _SearchDisplayMat()
|
|
{
|
|
var findTrans = _displayObj.transform.GetChild(0);
|
|
var meshRender = findTrans.GetComponent<MeshRenderer>();
|
|
_displayMat = meshRender.material;
|
|
_displayMat.SetColor(_Prop_Color1, _startColor);
|
|
}
|
|
|
|
public void UpdateInAreaUnits(List<GameUnit> checkUnits)
|
|
{
|
|
if (isCaptured) return;
|
|
inAreaUnits.Clear();
|
|
for (int i = 0; i < checkUnits.Count; i++)
|
|
{
|
|
var unit = checkUnits[i];
|
|
var unitCellIndex = unit.transData.cellIndex;
|
|
if (unitCellIndex != cellIndex) continue;
|
|
inAreaUnits.Add(unit);
|
|
}
|
|
}
|
|
|
|
public void LogicUpdate(float dt)
|
|
{
|
|
if (isCaptured) return;
|
|
if (inAreaUnits.Count > 0)
|
|
{
|
|
captureProgress += dt * inAreaUnits.Count;
|
|
if (captureProgress >= maxCaptureProgress)
|
|
{
|
|
isCaptured = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, this);
|
|
|
|
_CreateNoticeOnGround();
|
|
}
|
|
else
|
|
{
|
|
var lerpValue = captureProgress / maxCaptureProgress;
|
|
var lerpColor = Color.Lerp(_startColor, _endColor, lerpValue);
|
|
_displayMat.SetColor(_Prop_Color1, lerpColor);
|
|
}
|
|
|
|
if (!_lastIsInArea)
|
|
{
|
|
_lastIsInArea = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_START, this);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_lastIsInArea)
|
|
{
|
|
_lastIsInArea = false;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_STOP, this);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void _CreateNoticeOnGround()
|
|
{
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(PathDefine.CapturePoint.CAPTURE_FINISHED_POINT_PATH);
|
|
var displayObj = Object.Instantiate(sampleObj);
|
|
var worldPos = _displayObj.transform.position;
|
|
displayObj.transform.position = worldPos;
|
|
_displayObj.Destroy();
|
|
_displayObj = displayObj;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_displayObj != null)
|
|
{
|
|
_displayObj.Destroy();
|
|
_displayObj = null;
|
|
}
|
|
}
|
|
}
|
|
}
|