【战争黑夜】增加部分黑夜代码
parent
8abe1058ab
commit
ea16c7d14f
|
|
@ -60,6 +60,8 @@ namespace Framework
|
|||
|
||||
public const string STORY_HEAD_CAMERA_PATH = "Assets/Art/Other/head_camera_neck.prefab";
|
||||
|
||||
public const string FIGHT_LIGHT_AREA_PATH = "Assets/Art/Other/light_point.prefab";
|
||||
|
||||
|
||||
// public const string UI_HEAD_PATH = "Assets/Art/UI/SplitTexture/Icon/HeadPic/Alive/";
|
||||
// public const string UI_DEAD_HEAD_PATH = "Assets/Art/UI/Texture/Icon/HeadPic/Death/";
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@
|
|||
|
||||
INFIGHT_BLACK_SCREEN_START, // 黑屏开始
|
||||
INFIGHT_BLACK_SCREEN_END, // 黑屏结束
|
||||
|
||||
INFIGHT_UNIT_VISIBLE_CHANGE, // 单位可见性改变
|
||||
|
||||
//--------- AI ------------
|
||||
INFIGHT_CHARACTER_AI_CHAIN, //连锁 AI索敌时发送
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ namespace Gameplay.Level
|
|||
AssetManager.Instance.Unload(Constants.FLAG_PICK_PATH);
|
||||
AssetManager.Instance.Unload(Constants.FLAG_RETURN_PATH);
|
||||
AssetManager.Instance.Unload(Constants.PROTECT_TARGET_POINT_PATH);
|
||||
AssetManager.Instance.Unload(Constants.FIGHT_LIGHT_AREA_PATH);
|
||||
|
||||
_UnloadOutlinePost();
|
||||
|
||||
|
|
@ -361,7 +362,8 @@ namespace Gameplay.Level
|
|||
_stateMachine.ChangeState(new PrepareState(this));
|
||||
SelecterView.Instance.Init();
|
||||
|
||||
BlackAreaManager.instance.Init(false);
|
||||
// todo: 这里后续修改为从关卡配置读取
|
||||
BlackAreaManager.instance.Init(true);
|
||||
}
|
||||
|
||||
private void _CreateCapturePoints()
|
||||
|
|
@ -427,6 +429,7 @@ namespace Gameplay.Level
|
|||
AssetManager.Instance.PostPreload(Constants.FLAG_PICK_PATH);
|
||||
AssetManager.Instance.PostPreload(Constants.FLAG_RETURN_PATH);
|
||||
AssetManager.Instance.PostPreload(Constants.PROTECT_TARGET_POINT_PATH);
|
||||
AssetManager.Instance.PostPreload(Constants.FIGHT_LIGHT_AREA_PATH);
|
||||
|
||||
await AssetManager.Instance.WaitAllPreloads();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ namespace Gameplay.Level
|
|||
PauseManager.instance.LogicUpdate(deltaTime);
|
||||
TireMarkManager.instance.LogicUpdate(deltaTime);
|
||||
CaptureManager.instance.LogicUpdate(deltaTime);
|
||||
BlackAreaManager.instance.LogicUpdate(deltaTime);
|
||||
EventManager.Instance.Send(EventManager.EventName.LevelTimeIncrease,deltaTime);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Framework;
|
|||
using Gameplay.Area;
|
||||
using Gameplay.Character;
|
||||
using Gameplay.Guide;
|
||||
using Gameplay.PostProcess.BlackArea;
|
||||
using Gameplay.Unit;
|
||||
using Gameplay.Unit.Data;
|
||||
using Gameplay.Vehicle;
|
||||
|
|
@ -29,8 +30,12 @@ namespace Gameplay.Level
|
|||
|
||||
protected override void _OnUpdate(float deltaTime)
|
||||
{
|
||||
if (BlackAreaManager.instance.enableBlackArea)
|
||||
{
|
||||
BlackAreaManager.instance.AutoLightUpReadyArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void _OnExit()
|
||||
{
|
||||
EventManager.Instance.Unregister(EventManager.EventName.ToFightModelDragEnd, (Action<Vector2>)_OnModelDragEnd);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using Gameplay.Area;
|
||||
using Gameplay.Character;
|
||||
using Gameplay.Level;
|
||||
using Gameplay.Unit;
|
||||
using Gameplay.Unit.Data;
|
||||
using Gameplay.Vehicle.Impl;
|
||||
using PhxhSDK;
|
||||
using UnityEngine;
|
||||
using Constants = Framework.Constants;
|
||||
namespace Gameplay.PostProcess.BlackArea
|
||||
{
|
||||
public class BlackAreaManager
|
||||
|
|
@ -24,21 +32,109 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
}
|
||||
|
||||
private List<LightPoint> _pointList;
|
||||
private Dictionary<int, LightPoint> _pointDic;
|
||||
private GameObject _rootObj;
|
||||
|
||||
public void Init(bool enable)
|
||||
{
|
||||
enableBlackArea = enable;
|
||||
if (!enableBlackArea) return;
|
||||
_pointList = new List<LightPoint>();
|
||||
_pointDic = new Dictionary<int, LightPoint>();
|
||||
_InitLightMap();
|
||||
}
|
||||
|
||||
private void _InitLightMap()
|
||||
{
|
||||
_rootObj = new GameObject("[BlackAreaRoot]");
|
||||
var allCells = LevelManager.Instance.CurrentLevel.Map.TerrainGridSystem.cells;
|
||||
var sampleObj = AssetManager.Instance.GetPreLoadResult<GameObject>(Constants.FIGHT_LIGHT_AREA_PATH);
|
||||
for (int i = 0; i < allCells.Count; i++)
|
||||
{
|
||||
var cell = allCells[i];
|
||||
var cellIndex = cell.index;
|
||||
var cellWorldPos = AreaManager.instance.GetCellPosByIndex(cellIndex);
|
||||
var instObj = Object.Instantiate(sampleObj, cellWorldPos, Quaternion.identity, _rootObj.transform);
|
||||
|
||||
var lightPoint = new LightPoint(cellIndex, instObj);
|
||||
lightPoint.LightOff();
|
||||
_pointList.Add(lightPoint);
|
||||
_pointDic.Add(cellIndex, lightPoint);
|
||||
}
|
||||
}
|
||||
|
||||
public void AutoLightUpReadyArea()
|
||||
{
|
||||
var readyArea = AreaManager.instance.readyAreaManager.mapReadyCellIndexs;
|
||||
for (int i = 0; i < readyArea.Count; i++)
|
||||
{
|
||||
LightUpCell(readyArea[i], 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
public void LightUpCell(int cellIndex, float during)
|
||||
{
|
||||
if (_pointDic.TryGetValue(cellIndex, out var lightPoint))
|
||||
{
|
||||
lightPoint.MarkLight(during);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtil.LogError("LightUpCell failed, cellIndex:{0} is invalid!", cellIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void _AutoLightCharacterArea()
|
||||
{
|
||||
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
||||
for (int i = 0; i < allUnits.Count; i++)
|
||||
{
|
||||
var unit = allUnits[i];
|
||||
if (!unit.isReady) continue;
|
||||
if (unit.statusData.isDead) continue;
|
||||
if (unit.commonData.troopId != ETroopsId.Self) continue;
|
||||
var lightUpDistance = unit.fightData.lightUpArea;
|
||||
var cellIndexs = AreaManager.instance.GetCellIndexsAround(unit.transData.cellIndex, lightUpDistance);
|
||||
for (int j = 0; j < cellIndexs.Count; j++)
|
||||
{
|
||||
LightUpCell(cellIndexs[j], 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckIsInLightArea(int cellIndex)
|
||||
{
|
||||
if (!enableBlackArea)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (_pointDic.TryGetValue(cellIndex, out var lightPoint))
|
||||
{
|
||||
return lightPoint.isLight;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LogicUpdate(float dt)
|
||||
{
|
||||
|
||||
if (!enableBlackArea)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_AutoLightCharacterArea();
|
||||
for (int i = 0; i < _pointList.Count; i++)
|
||||
{
|
||||
_pointList[i].LogicUpdate(dt);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_rootObj != null)
|
||||
{
|
||||
Object.Destroy(_rootObj);
|
||||
_rootObj = null;
|
||||
}
|
||||
enableBlackArea = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
//渲染发生的阶段,具体信息可以在枚举类RenderPassEvent中查看
|
||||
public RenderPassEvent renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
|
||||
public LayerMask layerMask;
|
||||
public Material drawMaterial;
|
||||
public Material blitMaterial;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +70,6 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
renderingData.cameraData.camera);
|
||||
renderListDesc.renderQueueRange = RenderQueueRange.all;
|
||||
renderListDesc.layerMask = _settings.layerMask;
|
||||
renderListDesc.overrideMaterial = _settings.drawMaterial;
|
||||
var renderList = context.CreateRendererList(renderListDesc);
|
||||
cmd.DrawRendererList(renderList);
|
||||
|
||||
|
|
@ -81,7 +79,7 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
// 把这张图渲染到屏幕上
|
||||
cmd = CommandBufferPool.Get("BlackArea-DrawMaskToScreen");
|
||||
var cameraRt = renderingData.cameraData.renderer.cameraColorTargetHandle.nameID;
|
||||
_blitMaterial.SetTexture("_MaskTex", _cachedTarget);
|
||||
_blitMaterial.SetTexture(MaskTex, _cachedTarget);
|
||||
cmd.Blit(cameraRt, cameraRt, _blitMaterial);
|
||||
context.ExecuteCommandBuffer(cmd);
|
||||
CommandBufferPool.Release(cmd);
|
||||
|
|
@ -91,6 +89,7 @@ namespace Gameplay.PostProcess.BlackArea
|
|||
public Settings settings;
|
||||
private CustomRenderPass _scriptablePass;
|
||||
private static readonly int MainTex = Shader.PropertyToID("_MainTex");
|
||||
private static readonly int MaskTex = Shader.PropertyToID("_MaskTex");
|
||||
|
||||
public override void Create()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,57 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Gameplay.PostProcess.BlackArea
|
||||
{
|
||||
public class LightPoint
|
||||
{
|
||||
public Vector3 position;
|
||||
public float lightStrength;
|
||||
public bool isLight;
|
||||
public int cellIndex;
|
||||
public float remainTime;
|
||||
|
||||
private MeshRenderer _meshRenderer;
|
||||
private readonly GameObject _lightObj;
|
||||
|
||||
public LightPoint(int cellIndex, GameObject lightObj)
|
||||
{
|
||||
this.cellIndex = cellIndex;
|
||||
_lightObj = lightObj;
|
||||
isLight = false;
|
||||
remainTime = 0f;
|
||||
|
||||
_meshRenderer = _lightObj.GetComponentInChildren<MeshRenderer>();
|
||||
}
|
||||
|
||||
public void LightUp()
|
||||
{
|
||||
isLight = true;
|
||||
_lightObj.SetActive(true);
|
||||
}
|
||||
|
||||
public void LightOff()
|
||||
{
|
||||
isLight = false;
|
||||
_lightObj.SetActive(false);
|
||||
}
|
||||
|
||||
public void MarkLight(float duringTime)
|
||||
{
|
||||
remainTime = Mathf.Max(duringTime, remainTime);
|
||||
if (!isLight)
|
||||
{
|
||||
LightUp();
|
||||
}
|
||||
}
|
||||
|
||||
public void LogicUpdate(float dt)
|
||||
{
|
||||
if (isLight)
|
||||
{
|
||||
remainTime -= dt;
|
||||
if (remainTime < 0)
|
||||
{
|
||||
LightOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ namespace Gameplay.Unit.Data
|
|||
|
||||
public GameUnit owner;
|
||||
|
||||
/// <summary>
|
||||
/// 照亮区域
|
||||
/// </summary>
|
||||
public ObscuredInt lightUpArea = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 特殊普通逻辑id
|
||||
/// 为0表示没有特殊逻辑
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Gameplay.Character;
|
||||
using Gameplay.PostProcess.BlackArea;
|
||||
namespace Gameplay.Unit.Data
|
||||
{
|
||||
public class UnitStatusData
|
||||
|
|
@ -118,6 +119,13 @@ namespace Gameplay.Unit.Data
|
|||
if (isDead) return false;
|
||||
if (isOnVehicle) return false;
|
||||
if (isPretend) return false;
|
||||
if (owner.commonData.troopId != ETroopsId.Self)
|
||||
{
|
||||
if (!BlackAreaManager.instance.CheckIsInLightArea(owner.transData.cellIndex))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
using System.Collections.Generic;
|
||||
using Framework;
|
||||
using UnityEngine;
|
||||
namespace Gameplay.Unit.Data
|
||||
{
|
||||
public class UnitViewData
|
||||
{
|
||||
|
||||
public GameUnit owner;
|
||||
|
||||
private List<Renderer> _renderers;
|
||||
|
||||
public bool isShow;
|
||||
|
||||
public UnitViewData(GameUnit owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
_renderers = new List<Renderer>();
|
||||
var renderers = owner.Node.GameObject.GetComponentsInChildren<Renderer>();
|
||||
foreach (var renderer in renderers)
|
||||
{
|
||||
_renderers.Add(renderer);
|
||||
}
|
||||
isShow = true;
|
||||
}
|
||||
|
||||
public void SetShow(bool setShow)
|
||||
{
|
||||
if (isShow == setShow) return;
|
||||
isShow = setShow;
|
||||
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UNIT_VISIBLE_CHANGE, owner);
|
||||
foreach (var renderer in _renderers)
|
||||
{
|
||||
renderer.enabled = isShow;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89e18a060e934f368192fcc39eb72e6b
|
||||
timeCreated: 1720611550
|
||||
|
|
@ -13,6 +13,7 @@ using Gameplay.Common.Attri;
|
|||
using Gameplay.Fight.Flag;
|
||||
using Gameplay.Performance;
|
||||
using Gameplay.Pool;
|
||||
using Gameplay.PostProcess.BlackArea;
|
||||
using Gameplay.Skill;
|
||||
using Gameplay.Unit.AI;
|
||||
using Gameplay.Unit.Data;
|
||||
|
|
@ -43,6 +44,8 @@ namespace Gameplay.Unit
|
|||
}
|
||||
}
|
||||
|
||||
public UnitViewData viewData;
|
||||
|
||||
/// <summary>
|
||||
/// 公用数据,或者其他一些不知道放哪的数据
|
||||
/// </summary>
|
||||
|
|
@ -150,6 +153,8 @@ namespace Gameplay.Unit
|
|||
/// </summary>
|
||||
public void EnterBattle()
|
||||
{
|
||||
viewData = new UnitViewData(this);
|
||||
|
||||
_OnEnterBattle();
|
||||
|
||||
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UNIT_READY, this);
|
||||
|
|
@ -202,6 +207,17 @@ namespace Gameplay.Unit
|
|||
{
|
||||
aiManager.LogicUpdate(dt);
|
||||
}
|
||||
_UpdateBlackArea();
|
||||
}
|
||||
|
||||
private void _UpdateBlackArea()
|
||||
{
|
||||
if (commonData.troopId == ETroopsId.Self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var isInLightArea = BlackAreaManager.instance.CheckIsInLightArea(transData.cellIndex);
|
||||
viewData.SetShow(isInLightArea);
|
||||
}
|
||||
|
||||
protected virtual void _OnLogicUpdate(float dt)
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ namespace Gameplay.Unit
|
|||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_DEAD, (Action<GameUnit>)_OnCharacterDead);
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_READY, (Action<GameUnit>)_OnUnitEnterBattle);
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_VEHICLE_DESTROY, (Action<NormalVehicle>)_OnVehicleDestroyed);
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_VISIBLE_CHANGE, (Action<GameUnit>)_OnUnitVisibleChange);
|
||||
}
|
||||
|
||||
private void _UnRegistEvents()
|
||||
|
|
@ -100,8 +101,14 @@ namespace Gameplay.Unit
|
|||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UP_VEHICLE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
||||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_DOWN_VEHICLE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
||||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_DEAD, (Action<GameUnit>)_OnCharacterDead);
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_READY, (Action<GameUnit>)_OnUnitEnterBattle);
|
||||
EventManager.Instance.Register(EventManager.EventName.INFIGHT_VEHICLE_DESTROY, (Action<NormalVehicle>)_OnVehicleDestroyed);
|
||||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_READY, (Action<GameUnit>)_OnUnitEnterBattle);
|
||||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_VEHICLE_DESTROY, (Action<NormalVehicle>)_OnVehicleDestroyed);
|
||||
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_VISIBLE_CHANGE, (Action<GameUnit>)_OnUnitVisibleChange);
|
||||
}
|
||||
|
||||
private void _OnUnitVisibleChange(GameUnit unit)
|
||||
{
|
||||
_needUpdateTargets = true;
|
||||
}
|
||||
|
||||
private void _OnVehicleDestroyed(NormalVehicle unit)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using Cysharp.Threading.Tasks;
|
||||
using Gameplay.Performance;
|
||||
using Gameplay.Pool;
|
||||
using Gameplay.PostProcess.BlackArea;
|
||||
using Gameplay.Unit;
|
||||
using Gameplay.Unit.Data;
|
||||
|
||||
|
|
@ -77,6 +78,11 @@ namespace Gameplay.Weapon
|
|||
|
||||
public void OpenFire(GameUnit enemy)
|
||||
{
|
||||
if (owner.commonData.troopId != ETroopsId.Self)
|
||||
{
|
||||
BlackAreaManager.instance.LightUpCell(owner.transData.cellIndex, 1f);
|
||||
}
|
||||
|
||||
var groundEffectId = GLConfig.Inst.data.GroundFireEffectId;
|
||||
if (groundEffectId > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,13 +53,15 @@ Shader "Unlit/BlackAreaBlit"
|
|||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
fixed4 mask = tex2D(_MaskTex, i.uv);
|
||||
fixed4 black = fixed4(0, 0, 0, 1);
|
||||
if (mask.r > 0.01)
|
||||
float minAlpha = 0.02;
|
||||
if (mask.r > minAlpha)
|
||||
{
|
||||
float scale = mask.r * 1;
|
||||
scale = min(scale, 1);
|
||||
scale = max(scale, minAlpha);
|
||||
return col * scale;
|
||||
}
|
||||
return col * 0.01;
|
||||
return col * minAlpha;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ Shader "Unlit/LightArea"
|
|||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Alpha ("Alpha", Range(0, 1)) = 1
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
|
|
@ -55,6 +56,8 @@ Shader "Unlit/LightArea"
|
|||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
float _Alpha;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
|
@ -69,6 +72,7 @@ Shader "Unlit/LightArea"
|
|||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
col *= _Alpha;
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
|
|
|
|||
Loading…
Reference in New Issue