985 lines
41 KiB
C#
985 lines
41 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using RuntimeData;
|
||
using Animancer;
|
||
using Logic;
|
||
using NUnit.Framework;
|
||
using TMPro.Examples;
|
||
using Unity.IO.LowLevel.Unsafe;
|
||
using Object = UnityEngine.Object;
|
||
using Random = UnityEngine.Random;
|
||
using TMPro;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1Renderer
|
||
{
|
||
|
||
public class GridRenderer
|
||
{
|
||
private MapData _mapData;
|
||
private Main _main;
|
||
private GameObject _ROGrid;
|
||
private uint _gridId;
|
||
private bool _cityWallMark = false;
|
||
|
||
//-------- 表现层数据Rdata --------//
|
||
public bool IsSelectHighlight = false;
|
||
public bool IsMoveHighlight = false;
|
||
|
||
//-------- Update缓存数据 --------//
|
||
private GridData _gridData;
|
||
private bool _freeland;
|
||
private CityData _cityData;
|
||
private PlayerData _playerData;
|
||
|
||
private GameObject _land,
|
||
_mountain,
|
||
_forest,
|
||
_road,
|
||
_resource,
|
||
_cityBuilding,
|
||
_cityWall,
|
||
_fog,
|
||
_borderUpLeft,
|
||
_borderUpRight,
|
||
_borderDownLeft,
|
||
_borderDownRight,
|
||
_cityBorderUpLeft,
|
||
_cityBorderUpRight,
|
||
_cityBorderDownLeft,
|
||
_cityBorderDownRight,
|
||
_selectHighlight,
|
||
_moveHighlight,
|
||
_effect,
|
||
_RODebugText;
|
||
private TextMeshPro _debugText;
|
||
|
||
public int x, y;
|
||
string forcesName, civName;
|
||
bool needBounce = false, isBounceDown = true;
|
||
Vector3 bounceUpPos, bounceDownPos;
|
||
|
||
private float _bounceWaitTime = 0f;
|
||
float bounceTime = 0f;
|
||
float bounceDownFullTime = 0.07f;
|
||
float bounceUpFullTime = 0.2f;
|
||
|
||
|
||
|
||
|
||
//------- VFX相关参数 --------//
|
||
public AnimationClip FogEffectAnim;
|
||
public float RandomWait; //播放fog前的随机等待参数
|
||
bool _playFogEffect = false;
|
||
bool _isPlayingFog = false;
|
||
//TODO 把下面这些零散的rendermark全部整合到VFXManagerDict里去
|
||
public AnimationClip HurtVFXAnim;
|
||
private bool _playHurtVFX;
|
||
private bool _isPlayingHurtVFX;
|
||
public AnimationClip DieVFXAnim;
|
||
private bool _playDieVFX;
|
||
private bool _isPlayingDieVFX;
|
||
public AnimationClip DieHintVFXAnim;
|
||
private bool _playDieHintVFX;
|
||
public bool _isPlayingDieHintVFX;
|
||
private bool _stopDieHintVFX;
|
||
public AnimationClip TreasureVFXAnim;
|
||
private bool _playTreasureVFX;
|
||
private bool _isPlayingTreasureVFX;
|
||
public AnimationClip HealVFXAnim;
|
||
private bool _playHealVFX;
|
||
private bool _isPlayingHealVFX;
|
||
private Sprite _dieHint;
|
||
private Sprite _counterDieHint;
|
||
|
||
|
||
public Dictionary<GridVFXType, GridVFXRenderer> VFXManagerDict;
|
||
|
||
bool renderVeteran = false;
|
||
|
||
// Start is called before the first frame update
|
||
public GridRenderer(GameObject prefab,Transform father, uint gridId, MapData mapData, Main main)
|
||
{
|
||
_mapData = mapData;
|
||
_main = main;
|
||
_gridId = gridId;
|
||
mapData.GridMap.GetGridDataByGid(_gridId,out _gridData);
|
||
_freeland = !_mapData.GetCityDataByTerritoryGid(_gridId,out _cityData);
|
||
if(!_freeland)
|
||
_mapData.GetPlayerDataByCityId(_cityData.Id,out _playerData);
|
||
if (!(_cityData == null) && !(_playerData == null))
|
||
{
|
||
_mapData.GridMap.GetGridDataByGid(gridId, out var g1);
|
||
}
|
||
Vector3 tpos = Table.Instance.GridToWorld(_gridData);
|
||
_ROGrid = GameObject.Instantiate(prefab,tpos, Quaternion.identity, father);
|
||
Init(_gridData);
|
||
|
||
}
|
||
|
||
public GameObject GetROGrid() { return _ROGrid; }
|
||
|
||
|
||
//判断各自是否要bounce 并处理bounce动画
|
||
public void UpdateBounceAnim()
|
||
{
|
||
if (needBounce)
|
||
{
|
||
if (_bounceWaitTime > 0)
|
||
_bounceWaitTime -= Time.deltaTime;
|
||
else
|
||
{
|
||
if (isBounceDown)
|
||
{
|
||
bounceTime += Time.deltaTime / bounceDownFullTime;
|
||
_ROGrid.transform.position = Vector3.Lerp(bounceUpPos, bounceDownPos, bounceTime);
|
||
if (bounceTime >= 1f)
|
||
{
|
||
isBounceDown = false;
|
||
bounceTime = 0f;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bounceTime += Time.deltaTime / bounceUpFullTime;
|
||
_ROGrid.transform.position = Vector3.Lerp(bounceDownPos, bounceUpPos, bounceTime);
|
||
if (bounceTime >= 1f)
|
||
needBounce = false;
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
//读取gridData的VFXRendermark
|
||
public void ChangeVFXRenderMarkToVFXSignal()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
|
||
//遍历gridData的rendermarkVFXDict,看看有没有什么VFX的rendermark是true,那么就需要出发特效播放
|
||
if(_gridData.RenderMarkVFXDict != null )
|
||
foreach (var vfxPair in _gridData.RenderMarkVFXDict)
|
||
{
|
||
if (vfxPair.Value.RenderMark)
|
||
{
|
||
if (VFXManagerDict.TryGetValue(vfxPair.Key, out var vfxRenderer))
|
||
{
|
||
if (vfxPair.Value.PlayOrStop)
|
||
{
|
||
//更新vfrenderer的特殊参数,比如civId或者damage之类的,就是有些特殊参数的VFX需要先设置一下参数
|
||
var t = new GridVFXParams(vfxPair.Value);
|
||
vfxRenderer.UpdateSpecialParam(t);
|
||
vfxRenderer.SetPlay();
|
||
}
|
||
else
|
||
vfxRenderer.SetStop();
|
||
}
|
||
|
||
vfxPair.Value.RenderMark = false;
|
||
}
|
||
}
|
||
if (_gridData.VFXRenderMarkHurt)
|
||
{
|
||
_gridData.VFXRenderMarkHurt = false;
|
||
SetHurtVFXAnim();
|
||
}
|
||
if (_gridData.VFXRenderMarkDie)
|
||
{
|
||
_gridData.VFXRenderMarkDie = false;
|
||
SetDieVFXAnim();
|
||
}
|
||
if (_gridData.VFXRenderMarkDieHintStart)
|
||
{
|
||
_gridData.VFXRenderMarkDieHintStart = false;
|
||
//用param传递是普通死亡hint还是反击死亡hint
|
||
if(_gridData.VFXRenderMarkDieHintStartParam == 0)
|
||
SetDieHintVFXAnim();
|
||
else if(_gridData.VFXRenderMarkDieHintStartParam == 1)
|
||
SetDieHintVFXAnim(true);
|
||
}
|
||
if (_gridData.VFXRenderMarkDieHintEnd)
|
||
{
|
||
_gridData.VFXRenderMarkDieHintEnd = false;
|
||
SetStopDieHintVFXAnim();
|
||
}
|
||
if (_gridData.VFXRenderMarkTreasure)
|
||
{
|
||
_gridData.VFXRenderMarkTreasure = false;
|
||
SetTreasureVFXAnim();
|
||
}
|
||
if (_gridData.VFXRenderMarkFog)
|
||
{
|
||
_gridData.VFXRenderMarkFog = false;
|
||
SetFogAnim(false);
|
||
}
|
||
if (_gridData.VFXRenderMarkHeal)
|
||
{
|
||
_gridData.VFXRenderMarkHeal = false;
|
||
SetHealVFXAnim();
|
||
}
|
||
|
||
_ROGrid.transform.Find("Effect/Fire").gameObject.SetActive(false);
|
||
//判断是否着火
|
||
if (_mapData.GetCityDataByGid(_gridId,out var city) && _mapData.GetUnitDataByGid(_gridId,out var unit))
|
||
if (_mapData.GetPlayerDataByCityId(city.Id, out var player1) &&
|
||
_mapData.GetPlayerDataByUnitId(unit.Id, out var player2))
|
||
if(player1.Id != player2.Id)
|
||
_ROGrid.transform.Find("Effect/Fire").gameObject.SetActive(true);
|
||
|
||
}
|
||
|
||
//处理VFXManagerDict下每个Effect的Update
|
||
public void UpdateVFX()
|
||
{
|
||
foreach (var vfxPair in VFXManagerDict)
|
||
vfxPair.Value.Update();
|
||
//TODO 把下面的结构都转化为ManagerDict内的结构
|
||
if (_playHurtVFX)
|
||
{
|
||
_playHurtVFX = false;
|
||
PlayHurtVFX();
|
||
}
|
||
if (_playDieVFX)
|
||
{
|
||
_playDieVFX = false;
|
||
PlayDieVFX();
|
||
}
|
||
if (_playDieHintVFX)
|
||
{
|
||
_playDieHintVFX = false;
|
||
PlayDieHintVFX();
|
||
}
|
||
if (_stopDieHintVFX)
|
||
{
|
||
_stopDieHintVFX = false;
|
||
StopDieHintVFX();
|
||
}
|
||
|
||
if (_playTreasureVFX)
|
||
{
|
||
_playTreasureVFX = false;
|
||
PlayTreasureVFX();
|
||
}
|
||
if (_playHealVFX)
|
||
{
|
||
_playHealVFX = false;
|
||
PlayHealVFX();
|
||
}
|
||
|
||
if (_playFogEffect)
|
||
{
|
||
if (RandomWait > 0)
|
||
{
|
||
RandomWait -= Time.deltaTime;
|
||
}
|
||
else
|
||
{
|
||
_playFogEffect = false;
|
||
PlayFogEffect();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
if (_gridData.RenderMark)
|
||
{
|
||
_gridData.RenderMark = false;
|
||
RenderUpdateGridWithoutCityBuilding();
|
||
}
|
||
|
||
if (_gridData.CityBuildingRenderMark)
|
||
{
|
||
_gridData.CityBuildingRenderMark = false;
|
||
RenderUpdateCityBuilding(_cityData.Id);
|
||
}
|
||
}
|
||
public void Update()
|
||
{
|
||
_mapData.GridMap.GetGridDataByGid(_gridId, out _gridData);
|
||
_freeland = !_mapData.GetCityDataByTerritoryGid(_gridId, out _cityData);
|
||
if (!_freeland)
|
||
_mapData.GetPlayerDataByCityId(_cityData.Id, out _playerData);
|
||
|
||
//读取gridData的VFXRendermark
|
||
//这里有个潜规则,就是如果有视野(也就是没有fog),才会判断gridData的VFXRendermark
|
||
ChangeVFXRenderMarkToVFXSignal();
|
||
|
||
//查看城市边界的更新情况,这个没有视野也会显示的
|
||
UpdateCityBorder();
|
||
|
||
//判断各自是否要bounce
|
||
UpdateBounceAnim();
|
||
|
||
//处理VFXManagerDict下每个Effect的Update
|
||
UpdateVFX();
|
||
}
|
||
|
||
public void RenderUpdateDebug()
|
||
{
|
||
if (DebugCenter.Instance.DebugMode)
|
||
{
|
||
if(!_RODebugText.activeSelf)
|
||
_RODebugText.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
_RODebugText.SetActive(false);
|
||
return;
|
||
}
|
||
_debugText.text = "";
|
||
_debugText.text += $"ID={_gridId}";
|
||
_debugText.text += $" pos={_gridData.Pos.X} {_gridData.Pos.Y}\n";
|
||
if(_gridData.buildingLevel > 0)
|
||
_debugText.text += $"lv = {_gridData.buildingLevel}\n";
|
||
if(_gridData.Feature == TerrainFeature.Road)
|
||
_debugText.text += $"road\n";
|
||
|
||
}
|
||
|
||
public void Init(GridData t)
|
||
{
|
||
x = (int)t.Pos.X;
|
||
y = (int)t.Pos.Y;
|
||
//Vector3 pos = transform.position;
|
||
//pos.z = GridData.pos.x + GridData.pos.y;
|
||
//transform.position = pos;
|
||
_land = _ROGrid.transform.Find("Land").gameObject;
|
||
_road = _ROGrid.transform.Find("Road").gameObject;
|
||
_mountain = _ROGrid.transform.Find("Mountain").gameObject;
|
||
_forest = _ROGrid.transform.Find("Forest").gameObject;
|
||
_resource = _ROGrid.transform.Find("Resource").gameObject;
|
||
_cityBuilding = _ROGrid.transform.Find("cityBuilding").gameObject;
|
||
_cityWall = _ROGrid.transform.Find("cityWall").gameObject;
|
||
_fog = _ROGrid.transform.Find("Fog").gameObject;
|
||
_borderUpLeft = _ROGrid.transform.Find("BorderUpLeft").gameObject;
|
||
_borderUpRight = _ROGrid.transform.Find("BorderUpRight").gameObject;
|
||
_borderDownLeft = _ROGrid.transform.Find("BorderDownLeft").gameObject;
|
||
_borderDownRight = _ROGrid.transform.Find("BorderDownRight").gameObject;
|
||
_cityBorderUpLeft = _ROGrid.transform.Find("CityBorderUpLeft").gameObject;
|
||
_cityBorderUpRight = _ROGrid.transform.Find("CityBorderUpRight").gameObject;
|
||
_cityBorderDownLeft = _ROGrid.transform.Find("CityBorderDownLeft").gameObject;
|
||
_cityBorderDownRight = _ROGrid.transform.Find("CityBorderDownRight").gameObject;
|
||
_selectHighlight = _ROGrid.transform.Find("SelectHighlight").gameObject;
|
||
_moveHighlight = _ROGrid.transform.Find("MoveHighlight").gameObject;
|
||
_effect = _ROGrid.transform.Find("Effect").gameObject;
|
||
|
||
_RODebugText = _ROGrid.transform.Find("DebugText").gameObject;
|
||
_debugText = _RODebugText.GetComponent<TextMeshPro>();
|
||
|
||
|
||
foreach(Transform child in _effect.transform)
|
||
child.gameObject.SetActive(false);
|
||
civName = Table.Instance.QueryCivsName(_gridData.CivId);
|
||
UpdateLand();
|
||
UpdateRoad();
|
||
UpdateForest();
|
||
UpdateMountain();
|
||
UpdateResource();
|
||
UpdateCityWall();
|
||
UpdateCityBorder();
|
||
UpdateFog();
|
||
RenderUpdateDebug();
|
||
//UpdateBorder();fog自带updateborder
|
||
|
||
//初始化VFXManagerDict
|
||
FogEffectAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayFog");
|
||
HurtVFXAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayAttack");
|
||
DieVFXAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayDie");
|
||
DieHintVFXAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayDieHint");
|
||
TreasureVFXAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayTreasure");
|
||
HealVFXAnim = Resources.Load<AnimationClip>("Animations/VFX/PlayHeal");
|
||
_dieHint = Resources.Load<Sprite>("ArtResources/TH1VFX/TH1VFX_Die");
|
||
_counterDieHint = Resources.Load<Sprite>("ArtResources/TH1VFX/TH1VFX_CounterDie");
|
||
VFXManagerDict = new Dictionary<GridVFXType, GridVFXRenderer>();
|
||
GridVFXParams flagParam = new GridVFXParams(GridVFXType.Flag,Resources.Load<AnimationClip>("Animations/VFX/PlayHeal"),null,_effect.transform.Find("Flag")?.gameObject);
|
||
VFXManagerDict[GridVFXType.Flag] = GridVFXRendererFactory.Create(flagParam);
|
||
GridVFXParams damageParam = new GridVFXParams(GridVFXType.Damage,Resources.Load<AnimationClip>("Animations/VFX/PlayDamage"),null,_effect.transform.Find("Damage")?.gameObject);
|
||
VFXManagerDict[GridVFXType.Damage] = GridVFXRendererFactory.Create(damageParam);
|
||
Sprite ROYALFLAMESSprite = Resources.Load<Sprite>("ArtResources/TH1UI/Common/SkillIcon/Skill_ROYALFLAMES");
|
||
GridVFXParams ROYALFLAMESParam = new GridVFXParams(GridVFXType.ROYALFLAMES,Resources.Load<AnimationClip>("Animations/VFX/PlayHeal"),ROYALFLAMESSprite,_effect.transform.Find("Skill")?.gameObject);
|
||
VFXManagerDict[GridVFXType.ROYALFLAMES] = GridVFXRendererFactory.Create(ROYALFLAMESParam);
|
||
|
||
|
||
}
|
||
|
||
public void RenderUpdateGridWithoutCityBuilding()
|
||
{
|
||
UpdateLand();
|
||
UpdateRoad();
|
||
UpdateMountain();
|
||
UpdateForest();
|
||
UpdateResource();
|
||
UpdateCityWall();
|
||
UpdateCityBorder();
|
||
UpdateFog();
|
||
if (DebugCenter.Instance.DebugMode)
|
||
RenderUpdateDebug();
|
||
//UpdateBorder();fog自带updateborder
|
||
}
|
||
public void RenderUpdateCityBuilding(uint cityId)
|
||
{
|
||
_mapData.CityMap.GetCityById(cityId,out CityData cityData);
|
||
_mapData.GetPlayerDataByCityId(cityId, out PlayerData playerData);
|
||
uint civId = playerData.PlayerCivId;
|
||
int citylevel = cityData.Level;
|
||
int houseEdge = Table.Instance.cityLevel2HouseEdge[citylevel];
|
||
int houseSize = houseEdge * houseEdge;
|
||
int houseCount = Table.Instance.cityLevel2HouseNumber[citylevel];
|
||
int houseHeight = Table.Instance.cityLevel2HouseHeight[citylevel];
|
||
int[] housePosHeight = new int[houseSize];
|
||
int[,] textureType = new int[houseHeight, houseCount];
|
||
|
||
for (int k = 0; k < houseSize; k++)
|
||
{
|
||
for (int l = 0; l < houseHeight; l++)
|
||
textureType[l, k] = 0; //初始化
|
||
housePosHeight[k] = 1;
|
||
textureType[0, k] = Random.Range(0, Table.Instance.cityLevel2HouseType[citylevel]);
|
||
}
|
||
for (int k = houseSize; k < houseCount; k++)
|
||
{
|
||
int randPos = Random.Range(0, houseSize);
|
||
if (housePosHeight[randPos] >= houseHeight)
|
||
for (randPos = houseSize - 1; randPos >= 0; randPos--)
|
||
if (housePosHeight[randPos] < houseHeight)
|
||
break;
|
||
textureType[housePosHeight[randPos]++, randPos] = Random.Range(0, Table.Instance.cityLevel2HouseType[citylevel]);
|
||
}
|
||
|
||
//清空原来的城市图像
|
||
foreach (UnityEngine.Transform child in _cityBuilding.transform)
|
||
Object.Destroy(child.gameObject);
|
||
|
||
//开始设置城市图像
|
||
for (int x = 0; x < houseEdge; x++)
|
||
for (int y = 0; y < houseEdge; y++)
|
||
for (int z = 0; z < housePosHeight[x * houseEdge + y]; z++)
|
||
{
|
||
GameObject house = new GameObject($"house{x}_{y}_{z}");
|
||
SpriteRenderer sr = house.AddComponent<SpriteRenderer>();
|
||
string forcesName = Table.Instance.QueryForcesName(playerData.PlayerForceId);
|
||
string civName = Table.Instance.QueryCivsName(playerData.PlayerCivId);
|
||
//Debug.Log($"ArtResources/TH1Buildings/TH1Buildings{forcesName}/{civName}/{forcesName}_{civName}_House_{z + 1}");
|
||
sr.sprite = Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1Buildings{forcesName}/{civName}/{forcesName}_{civName}_House_{textureType[z,x*houseEdge +y] + 1}");
|
||
house.transform.parent = _cityBuilding.transform;
|
||
Vector3 tpos = _ROGrid.transform.position;
|
||
//每层的层高
|
||
float levelHeight = 1.2f;
|
||
tpos = new Vector3(tpos.x + 1.22f * (x - y),
|
||
tpos.y + 0.7f * (x + y) + z * levelHeight - 7.5f + 0.7f * (4 - houseEdge),
|
||
tpos.z + 0.9f - (30 + z - x - y) * 0.001f);
|
||
house.transform.position = tpos;
|
||
}
|
||
|
||
}
|
||
|
||
public void RenderUpdataHighlight()
|
||
{
|
||
_moveHighlight.SetActive(IsMoveHighlight);
|
||
_selectHighlight.SetActive(IsSelectHighlight);
|
||
}
|
||
|
||
public void SetSelectHighlight(bool v)
|
||
{
|
||
if (IsSelectHighlight == v)
|
||
return;
|
||
IsSelectHighlight = v;
|
||
MapRenderer.Instance.HighlightGridIdSet.Add(_gridId);
|
||
MapRenderer.Instance.HighlightGridIdSetRenderMark = true;
|
||
}
|
||
|
||
public void SetMoveHighlight(bool v)
|
||
{
|
||
if (IsMoveHighlight == v)
|
||
return;
|
||
IsMoveHighlight = v;
|
||
MapRenderer.Instance.HighlightGridIdSet.Add(_gridId);
|
||
MapRenderer.Instance.HighlightGridIdSetRenderMark = true;
|
||
}
|
||
public void UpdateLand()
|
||
{
|
||
if (_gridData.Terrain == TerrainType.Land)
|
||
_land.GetComponent<SpriteRenderer>().sprite =
|
||
Resources.Load<Sprite>($"ArtResources/TH1Grounds/TH1Ground_{civName}");
|
||
else
|
||
{
|
||
if (_gridData.Terrain == TerrainType.ShallowSea)
|
||
_land.GetComponent<SpriteRenderer>().sprite =
|
||
Resources.Load<Sprite>($"ArtResources/TH1Waters/TH1Water_Water");
|
||
else
|
||
_land.GetComponent<SpriteRenderer>().sprite =
|
||
Resources.Load<Sprite>($"ArtResources/TH1Waters/TH1Water_Ocean");
|
||
}
|
||
}
|
||
|
||
public void UpdateRoad()
|
||
{
|
||
//如果当前的feature没有road
|
||
if (_gridData.Feature != TerrainFeature.Road)
|
||
{
|
||
for (int i = 1; i <= 9; i++)
|
||
{
|
||
int dirForHuman = i;
|
||
int dirForComputer = dirForHuman - 1;
|
||
var t = _road.transform.Find($"Road{dirForHuman}");
|
||
if (t != null)
|
||
GameObject.Destroy(t.gameObject);
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
|
||
//TODO 最好把dir做成enum
|
||
for (int i = 1; i <= 9; i++)
|
||
{
|
||
int dirForHuman = i;
|
||
int dirForComputer = dirForHuman - 1;
|
||
var t = _road.transform.Find($"Road{dirForHuman}");
|
||
if (!_mapData.CheckIfNearByGridRoadCanConnenct(_gridData, dirForComputer))
|
||
{
|
||
if (t != null)
|
||
GameObject.Destroy(t.gameObject);
|
||
continue;
|
||
}
|
||
|
||
if (t == null)
|
||
{
|
||
GameObject road = new GameObject($"Road{dirForHuman}");
|
||
SpriteRenderer sr = road.AddComponent<SpriteRenderer>();
|
||
MapRenderer.Instance.ResourceCache.SpriteCache.Roads.TryGetValue((_gridData.Terrain == TerrainType.Land ? "Road" : "WaterRoad") + dirForComputer,out var tmpSprite);
|
||
sr.sprite = tmpSprite;
|
||
road.transform.parent = _road.transform;
|
||
road.transform.localPosition = new Vector3(0, 0, 0);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
public void UpdateMountain()
|
||
{
|
||
_mountain.GetComponent<SpriteRenderer>().sprite = _gridData.Feature == TerrainFeature.Mountain
|
||
? Resources.Load<Sprite>($"ArtResources/TH1Mountains/TH1Mountain_{civName}")
|
||
: null;
|
||
}
|
||
|
||
public void UpdateForest()
|
||
{
|
||
_forest.GetComponent<SpriteRenderer>().sprite = _gridData.Vegetation == Vegetation.Trees
|
||
? Resources.Load<Sprite>($"ArtResources/TH1Forests/TH1Forest_{civName}")
|
||
: null;
|
||
}
|
||
|
||
|
||
public void UpdateResource( bool bridgeMirror = false)
|
||
{
|
||
if(!_freeland)
|
||
forcesName = Table.Instance.QueryForcesName(_playerData.PlayerForceId);
|
||
|
||
|
||
//处理glow
|
||
string needGlow = "";
|
||
if (!_freeland && _playerData.Id == _mapData.PlayerMap.SelfPlayerData.Id
|
||
&& (_gridData.Resource == ResourceType.Fruit &&
|
||
_playerData.TechTree.CheckIfHasTech(TechType.Organization)
|
||
|| (_gridData.Resource == ResourceType.Animal &&
|
||
_playerData.TechTree.CheckIfHasTech(TechType.Hunting))
|
||
|| (_gridData.Resource == ResourceType.Fish &&
|
||
_playerData.TechTree.CheckIfHasTech(TechType.Fishing))
|
||
|| (_gridData.Resource == ResourceType.Crop &&
|
||
_playerData.TechTree.CheckIfHasTech(TechType.Farming))
|
||
|| (_gridData.Resource == ResourceType.Metal &&
|
||
_playerData.TechTree.CheckIfHasTech(TechType.Mining))))
|
||
needGlow = "_glow";
|
||
if (_gridData.Resource == ResourceType.Starfish && _mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Navigation))
|
||
needGlow = "_glow";
|
||
|
||
bool hasCity = _mapData.GetCityDataByTerritoryGid(_gridId, out var cityData);
|
||
|
||
//处理隐藏没有科技情况下 metal、starfish、crop的情况
|
||
bool skip = false;
|
||
if (_gridData.Resource == ResourceType.Crop)
|
||
if (!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Organization) &&
|
||
!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Farming))
|
||
skip = true;
|
||
if (_gridData.Resource == ResourceType.Metal)
|
||
if (!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Mining) &&
|
||
!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Climbing))
|
||
skip = true;
|
||
if (_gridData.Resource == ResourceType.Starfish)
|
||
if (!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Navigation) &&
|
||
!_mapData.PlayerMap.SelfPlayerData.TechTree.CheckIfHasTech(TechType.Sailing))
|
||
skip = true;
|
||
|
||
|
||
if (skip)
|
||
{
|
||
_resource.GetComponent<SpriteRenderer>().sprite = null;
|
||
return;
|
||
}
|
||
|
||
|
||
var res = _gridData.Resource switch
|
||
{
|
||
ResourceType.Crop => Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Crop{needGlow}"),
|
||
ResourceType.Metal => Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Metal{needGlow}"),
|
||
ResourceType.Fish => Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Fish{needGlow}"),
|
||
ResourceType.Animal => Resources.Load<Sprite>($"ArtResources/TH1Animals/TH1Animal_{civName}{needGlow}"),
|
||
ResourceType.Fruit => Resources.Load<Sprite>($"ArtResources/TH1Fruits/TH1Fruit_{civName}{needGlow}"),
|
||
ResourceType.CityCenter => hasCity ? null : Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Tribe"),
|
||
ResourceType.Treasure => Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Treasure"),
|
||
ResourceType.Starfish => Resources.Load<Sprite>($"ArtResources/TH1Miscs/TH1Misc_Starfish{needGlow}"),
|
||
ResourceType.Temple => Table.Instance.GridAndResourceDataAssets.GetResourceSprite(ResourceType.Temple,_playerData,_gridData),//.Load<Sprite>($"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Temple"),
|
||
ResourceType.ForestTemple => Table.Instance.GridAndResourceDataAssets.GetResourceSprite(ResourceType.ForestTemple,_playerData,_gridData),
|
||
ResourceType.MountainTemple => Table.Instance.GridAndResourceDataAssets.GetResourceSprite(ResourceType.MountainTemple,_playerData,_gridData),
|
||
ResourceType.WaterTemple => Table.Instance.GridAndResourceDataAssets.GetResourceSprite(ResourceType.WaterTemple,_playerData,_gridData),
|
||
ResourceType.Farm => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Farm"),
|
||
ResourceType.Mine => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Mine"),
|
||
ResourceType.LumberHut => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_LumberHut"),
|
||
ResourceType.Port => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Port"),
|
||
ResourceType.Bridge => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Bridge{(bridgeMirror ? ("Mirror") : (""))}"),
|
||
ResourceType.Windmill => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Windmill_{Mathf.Min(_gridData.buildingLevel, 8)}"),
|
||
ResourceType.Forge => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Forge_{Mathf.Min(_gridData.buildingLevel, 8)}"),
|
||
ResourceType.Sawmill => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Sawmill_{Mathf.Min(_gridData.buildingLevel, 8)}"),
|
||
ResourceType.Market => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Market_{Mathf.Min(_gridData.buildingLevel, 8)}"),
|
||
ResourceType.Wonder => Table.Instance.GridAndResourceDataAssets.GetWonderSprite(_gridData.Wonder,_playerData),
|
||
ResourceType.Tower => Resources.Load<Sprite>(
|
||
$"ArtResources/TH1Buildings/TH1BuildingsCommon/TH1Building_Tower"),
|
||
_ => null
|
||
};
|
||
|
||
if (_resource.GetComponent<SpriteRenderer>().sprite != res)
|
||
_resource.GetComponent<SpriteRenderer>().sprite = res;
|
||
|
||
|
||
//处理建设建筑的时候播放fog的效果
|
||
/*if (_resource.GetComponent<SpriteRenderer>().sprite != res)
|
||
{
|
||
_resource.GetComponent<SpriteRenderer>().sprite = res;
|
||
if(needGlow != "_glow")
|
||
PlayFogEffect();
|
||
}*/
|
||
}
|
||
|
||
public void UpdateCityWall()
|
||
{
|
||
if (_cityWall.activeSelf)
|
||
return;
|
||
if (!_mapData.GetCityDataByGid(_gridId, out var cityData))
|
||
return;
|
||
if (!cityData.CityWall)
|
||
return;
|
||
_cityWallMark = true;
|
||
_cityWall.SetActive(true);
|
||
}
|
||
|
||
public void UpdateBorder()
|
||
{
|
||
//如果不是城市领土,不需要生成border
|
||
if (_freeland)
|
||
{
|
||
_borderDownLeft.SetActive(false);
|
||
_borderDownRight.SetActive(false);
|
||
_borderUpLeft.SetActive(false);
|
||
_borderUpRight.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
if (Table.Instance.PlayerDataAssets.GetPlayerInfo(_playerData, out var playerInfo))
|
||
{
|
||
var c = playerInfo.Color;
|
||
//c.a = 0.8f;
|
||
_borderDownLeft.GetComponent<SpriteRenderer>().color = c;
|
||
_borderDownRight.GetComponent<SpriteRenderer>().color = c;
|
||
_borderUpRight.GetComponent<SpriteRenderer>().color = c;
|
||
_borderUpLeft.GetComponent<SpriteRenderer>().color = c;
|
||
}
|
||
_borderDownLeft.SetActive(!_mapData.CheckIfNearByGridSamePlayer(_gridData,4));
|
||
_borderDownRight.SetActive(!_mapData.CheckIfNearByGridSamePlayer(_gridData,2));
|
||
_borderUpRight.SetActive(!_mapData.CheckIfNearByGridSamePlayer(_gridData,6));
|
||
_borderUpLeft.SetActive(!_mapData.CheckIfNearByGridSamePlayer(_gridData,8));
|
||
}
|
||
|
||
public void UpdateCityBorder()
|
||
{
|
||
//如果没有rendermark 直接return
|
||
if (!_gridData.CityBorderRenderMark)
|
||
{
|
||
_cityBorderDownLeft.SetActive(false);
|
||
_cityBorderDownRight.SetActive(false);
|
||
_cityBorderUpLeft.SetActive(false);
|
||
_cityBorderUpRight.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
if (!_mapData.GetPlayerDataByTerritoryGridId(_gridData.Id, out var player))
|
||
return;
|
||
var color = Color.red;
|
||
if(player.Id == _mapData.PlayerMap.SelfPlayerId)
|
||
color = Color.green;
|
||
_cityBorderDownLeft.GetComponent<SpriteRenderer>().color = color;
|
||
_cityBorderDownRight.GetComponent<SpriteRenderer>().color = color;
|
||
_cityBorderUpRight.GetComponent<SpriteRenderer>().color = color;
|
||
_cityBorderUpLeft.GetComponent<SpriteRenderer>().color = color;
|
||
_cityBorderDownLeft.SetActive(!_mapData.CheckIfNearByGridSameCity(_gridData,4));
|
||
_cityBorderDownRight.SetActive(!_mapData.CheckIfNearByGridSameCity(_gridData,2));
|
||
_cityBorderUpRight.SetActive(!_mapData.CheckIfNearByGridSameCity(_gridData,6));
|
||
_cityBorderUpLeft.SetActive(!_mapData.CheckIfNearByGridSameCity(_gridData,8));
|
||
}
|
||
|
||
public void UpdateFog()
|
||
{
|
||
bool isFog = !_mapData.PlayerMap.SelfPlayerData.Sight.CheckIsInSight(_gridData.Id);
|
||
if (_fog.activeSelf != isFog)
|
||
{
|
||
if (isFog)
|
||
{
|
||
_fog.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
SetFogAnim();
|
||
Timer.Instance.TimerRegister(this, () =>
|
||
{
|
||
_fog.SetActive(false);
|
||
if(_gridData.Resource == ResourceType.CityCenter || _gridData.Resource == ResourceType.Treasure)
|
||
SetTreasureVFXAnim();
|
||
},RandomWait);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
_land.SetActive(!isFog);
|
||
_road.SetActive(!isFog);
|
||
_mountain.SetActive(!isFog);
|
||
_forest.SetActive(!isFog);
|
||
_cityWall.SetActive(!isFog&&_cityWallMark);
|
||
_cityBuilding.SetActive(!isFog);
|
||
_resource.SetActive(!isFog);
|
||
if (isFog)
|
||
{
|
||
_borderDownLeft.SetActive(false);
|
||
_borderDownRight.SetActive(false);
|
||
_borderUpLeft.SetActive(false);
|
||
_borderUpRight.SetActive(false);
|
||
}
|
||
else
|
||
UpdateBorder();
|
||
}
|
||
|
||
|
||
public void SetBounceAnim(bool NeedRandomWait=false)
|
||
{
|
||
if (needBounce) return;
|
||
if(!NeedRandomWait)
|
||
_bounceWaitTime = 0f;
|
||
else
|
||
{
|
||
|
||
_bounceWaitTime = Random.Range(0,0.3f);
|
||
Debug.Log(_bounceWaitTime);
|
||
}
|
||
needBounce = true;
|
||
isBounceDown = true;
|
||
bounceTime = 0f;
|
||
bounceUpPos = _ROGrid.transform.position;
|
||
bounceDownPos = new Vector3(_ROGrid.transform.position.x, _ROGrid.transform.position.y - 0.8f, _ROGrid.transform.position.z);
|
||
}
|
||
|
||
public void SetFogAnim(bool needRandomWait = true)
|
||
{
|
||
RandomWait = 0f;
|
||
if (needRandomWait)
|
||
RandomWait = Random.Range(0,50) * 0.002f;
|
||
|
||
if (_isPlayingFog) return;
|
||
_playFogEffect = true;
|
||
}
|
||
|
||
public void PlayFogEffect()
|
||
{
|
||
//给preview模块打的补丁
|
||
if (_ROGrid.transform.parent.name == "Grid") return;
|
||
|
||
var fogObj = _ROGrid.transform.Find("Effect/Fog").gameObject;
|
||
fogObj.SetActive(true);
|
||
var animancer = _ROGrid.transform.Find("Effect/Fog").GetComponent<AnimancerComponent>();
|
||
if (FogEffectAnim != null)
|
||
{
|
||
_isPlayingFog = true;
|
||
animancer.Play(FogEffectAnim);
|
||
Timer.Instance.TimerRegister(fogObj, () =>
|
||
{
|
||
fogObj.SetActive(false);
|
||
_isPlayingFog = false;
|
||
}, FogEffectAnim.length);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public void SetHurtVFXAnim()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (_isPlayingHurtVFX) return;
|
||
_playHurtVFX = true;
|
||
}
|
||
|
||
public void PlayHurtVFX()
|
||
{
|
||
var VFX = _ROGrid.transform.Find("Effect/Hurt").gameObject;
|
||
VFX.SetActive(true);
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (HurtVFXAnim != null)
|
||
{
|
||
_isPlayingHurtVFX = true;
|
||
animancer.Play(HurtVFXAnim);
|
||
Timer.Instance.TimerRegister(VFX, () =>
|
||
{
|
||
VFX.SetActive(false);
|
||
_isPlayingHurtVFX = false;
|
||
}, HurtVFXAnim.length);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public void SetDieVFXAnim()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (_isPlayingDieVFX) return;
|
||
_playDieVFX = true;
|
||
}
|
||
|
||
public void PlayDieVFX()
|
||
{
|
||
var VFX = _ROGrid.transform.Find("Effect/Die").gameObject;
|
||
VFX.SetActive(true);
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (DieVFXAnim != null)
|
||
{
|
||
_isPlayingDieVFX = true;
|
||
animancer.Play(DieVFXAnim);
|
||
Timer.Instance.TimerRegister(VFX, () =>
|
||
{
|
||
VFX.SetActive(false);
|
||
_isPlayingDieVFX = false;
|
||
}, DieVFXAnim.length);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public void SetDieHintVFXAnim(bool isCounter = false)
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (_isPlayingDieHintVFX) return;
|
||
//根据是否是反击提示,更换图像
|
||
_ROGrid.transform.Find("Effect/Die").GetComponent<SpriteRenderer>().sprite = isCounter ? _counterDieHint : _dieHint;
|
||
_playDieHintVFX = true;
|
||
}
|
||
|
||
//isCounter用来判断是杀死对方的提示,还是被提房杀死的反击提示
|
||
public void PlayDieHintVFX()
|
||
{
|
||
var VFX = _ROGrid.transform.Find("Effect/Die").gameObject;
|
||
VFX.SetActive(true);
|
||
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (DieVFXAnim != null)
|
||
{
|
||
_isPlayingDieHintVFX = true;
|
||
animancer.Play(DieHintVFXAnim);
|
||
}
|
||
|
||
}
|
||
|
||
public void SetStopDieHintVFXAnim()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (!_isPlayingDieHintVFX) return;
|
||
_stopDieHintVFX = true;
|
||
}
|
||
|
||
public void StopDieHintVFX()
|
||
{
|
||
var VFX = _ROGrid.transform.Find("Effect/Die").gameObject;
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (DieVFXAnim != null)
|
||
{
|
||
_isPlayingDieHintVFX = false;
|
||
animancer.Stop(DieHintVFXAnim);
|
||
}
|
||
VFX.SetActive(false);
|
||
|
||
}
|
||
|
||
|
||
public void SetTreasureVFXAnim()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (_isPlayingTreasureVFX) return;
|
||
_playTreasureVFX = true;
|
||
}
|
||
|
||
public void PlayTreasureVFX()
|
||
{
|
||
var VFX = _ROGrid.transform.Find("Effect/Treasure").gameObject;
|
||
VFX.SetActive(true);
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (TreasureVFXAnim != null)
|
||
{
|
||
_isPlayingTreasureVFX = true;
|
||
animancer.Play(TreasureVFXAnim);
|
||
Timer.Instance.TimerRegister(VFX, () =>
|
||
{
|
||
VFX.SetActive(false);
|
||
_isPlayingTreasureVFX = false;
|
||
}, TreasureVFXAnim.length);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public void SetHealVFXAnim()
|
||
{
|
||
if (_fog.activeSelf) return;
|
||
if (_isPlayingHealVFX) return;
|
||
_playHealVFX = true;
|
||
}
|
||
|
||
public void PlayHealVFX()
|
||
{
|
||
|
||
var VFX = _ROGrid.transform.Find("Effect/Heal").gameObject;
|
||
VFX.SetActive(true);
|
||
var animancer = VFX.GetComponent<AnimancerComponent>();
|
||
if (HealVFXAnim != null)
|
||
{
|
||
_isPlayingHealVFX = true;
|
||
animancer.Play(HealVFXAnim);
|
||
Timer.Instance.TimerRegister(VFX, () =>
|
||
{
|
||
VFX.SetActive(false);
|
||
_isPlayingHealVFX = false;
|
||
}, HealVFXAnim.length);
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
} |