208 lines
6.6 KiB
C#
208 lines
6.6 KiB
C#
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Common;
|
|
using Gameplay.Effect;
|
|
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_BaseMap = Shader.PropertyToID("_BaseMap");
|
|
|
|
public int cellIndex;
|
|
private Vector3 _worldPos;
|
|
|
|
public int maxCaptureProgress = 10;
|
|
|
|
public List<GameUnit> inAreaUnits;
|
|
|
|
public float captureProgress;
|
|
|
|
private bool _lastIsInArea;
|
|
|
|
public bool isCaptured { get; private set; }
|
|
|
|
private Material _displayMat;
|
|
|
|
private GameObject _displayObj;
|
|
private GameObject _objGroundPoint;
|
|
private GameObject _objIcon;
|
|
|
|
private bool _isEntered;
|
|
|
|
public CaptureInst(int cellIndex,
|
|
int captureValue)
|
|
{
|
|
maxCaptureProgress = captureValue;
|
|
this.cellIndex = cellIndex;
|
|
inAreaUnits = new List<GameUnit>();
|
|
captureProgress = 0f;
|
|
isCaptured = false;
|
|
_isEntered = false;
|
|
|
|
_lastIsInArea = false;
|
|
|
|
_CreateObjs();
|
|
}
|
|
|
|
private void _CreateProgressObj(Vector3 worldPos)
|
|
{
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(PathDefine.CapturePoint.CAPTURE_POINT_PROGRESS_PATH);
|
|
_displayObj = Object.Instantiate(sampleObj);
|
|
_displayObj.transform.position = worldPos;
|
|
_SearchDisplayMat();
|
|
}
|
|
|
|
private void _CreateIcon()
|
|
{
|
|
// var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(PathDefine.CapturePoint.CAPTURE_EFFECT_ICON_PATH);
|
|
// _objIcon = Object.Instantiate(sampleObj);
|
|
// _objIcon.transform.position = _worldPos;
|
|
|
|
//UI创建Icon
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UI_ADD_GRID_OBJ,
|
|
new UIGridTypeData(cellIndex, UIGridTypeNode.GridType.Capture, this));
|
|
}
|
|
|
|
private void _CreateObjs()
|
|
{
|
|
_worldPos = AreaManager.instance.GetWorldPosByIndex(cellIndex);
|
|
{
|
|
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(PathDefine.CapturePoint.CAPTURE_POINT_GROUND_POINT_PATH);
|
|
_objGroundPoint = Object.Instantiate(sampleObj);
|
|
_objGroundPoint.transform.position = _worldPos;
|
|
}
|
|
_CreateIcon();
|
|
|
|
}
|
|
|
|
private void _DestroyObjs()
|
|
{
|
|
if (_objGroundPoint != null)
|
|
{
|
|
_objGroundPoint.Destroy();
|
|
_objGroundPoint = null;
|
|
}
|
|
_DestroyProgressObj();
|
|
_DestroyIcon();
|
|
}
|
|
|
|
private void _DestroyProgressObj()
|
|
{
|
|
if (_displayObj != null)
|
|
{
|
|
_displayObj.Destroy();
|
|
_displayObj = null;
|
|
}
|
|
}
|
|
|
|
private void _DestroyIcon()
|
|
{
|
|
// if (_objIcon != null)
|
|
// {
|
|
// _objIcon.Destroy();
|
|
// _objIcon = null;
|
|
// }
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UI_REMOVE_GRID_OBJ,
|
|
new UIGridTypeData(cellIndex, UIGridTypeNode.GridType.Capture, this));
|
|
}
|
|
|
|
private void _SearchDisplayMat()
|
|
{
|
|
var findTrans = _displayObj.transform.Find("lizi/liubian_dutiao");
|
|
var particleSystem = findTrans.GetComponent<ParticleSystemRenderer>();
|
|
_displayMat = particleSystem.material;
|
|
_displayMat.SetTextureOffset(_Prop_BaseMap, new Vector2(0, 0));
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (!_isEntered)
|
|
{
|
|
_isEntered = true;
|
|
_DestroyIcon();
|
|
_CreateProgressObj(_worldPos);
|
|
}
|
|
|
|
if (!_lastIsInArea)
|
|
{
|
|
_lastIsInArea = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_START, this);
|
|
|
|
EffectManager.instance.PlayEffectById(CodeDefine.Fight.CapturePoint.EFFECT_ID_EXIT, _worldPos);
|
|
}
|
|
|
|
captureProgress += dt;
|
|
if (captureProgress >= maxCaptureProgress)
|
|
{
|
|
isCaptured = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_FINSIHED, this);
|
|
EffectManager.instance.PlayEffectById(CodeDefine.Fight.CapturePoint.EFFECT_ID_FINISH, _worldPos);
|
|
_DestroyObjs();
|
|
return;
|
|
}
|
|
var lerpValue = captureProgress / maxCaptureProgress;
|
|
_displayMat.SetTextureOffset(_Prop_BaseMap, new Vector2(lerpValue, 0));
|
|
|
|
}
|
|
else
|
|
{
|
|
if (_lastIsInArea)
|
|
{
|
|
_lastIsInArea = false;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_CAPTURE_STOP, this);
|
|
|
|
EffectManager.instance.PlayEffectById(CodeDefine.Fight.CapturePoint.EFFECT_ID_EXIT, _worldPos);
|
|
}
|
|
|
|
captureProgress -= dt;
|
|
if (captureProgress <= 0)
|
|
{
|
|
captureProgress = 0;
|
|
|
|
if (_isEntered)
|
|
{
|
|
_isEntered = false;
|
|
_CreateIcon();
|
|
_DestroyProgressObj();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var lerpValue = captureProgress / maxCaptureProgress;
|
|
_displayMat.SetTextureOffset(_Prop_BaseMap, new Vector2(lerpValue, 0));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_DestroyObjs();
|
|
}
|
|
}
|
|
}
|