init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class BulletData : EntityDataBase
|
||||
{
|
||||
[SerializeField] private Transform _target = null;
|
||||
[SerializeField] private float _speed = 0f;
|
||||
[SerializeField] private float _maxLifetime = 3f;
|
||||
[SerializeField] private AttackPayload _attackPayload = new AttackPayload();
|
||||
|
||||
public BulletData(
|
||||
int entityId,
|
||||
int typeId,
|
||||
Vector3 position,
|
||||
Transform target,
|
||||
AttackPayload attackPayload,
|
||||
float speed,
|
||||
float maxLifetime = 3f) : base(entityId, typeId)
|
||||
{
|
||||
Position = position;
|
||||
|
||||
_target = target;
|
||||
_attackPayload = attackPayload?.Clone() ?? new AttackPayload();
|
||||
_speed = speed;
|
||||
_maxLifetime = maxLifetime;
|
||||
}
|
||||
|
||||
public Transform Target
|
||||
{
|
||||
get => _target;
|
||||
set => _target = value;
|
||||
}
|
||||
|
||||
public float Speed
|
||||
{
|
||||
get => _speed;
|
||||
set => _speed = value;
|
||||
}
|
||||
|
||||
public float MaxLifetime
|
||||
{
|
||||
get => _maxLifetime;
|
||||
set => _maxLifetime = value;
|
||||
}
|
||||
|
||||
public AttackPayload AttackPayload
|
||||
{
|
||||
get => _attackPayload;
|
||||
set => _attackPayload = value?.Clone() ?? new AttackPayload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class EnemyData : EntityDataBase
|
||||
{
|
||||
[SerializeField] private CampType _camp = CampType.Enemy;
|
||||
|
||||
[SerializeField] private int _maxHealth = 0;
|
||||
|
||||
[SerializeField] private float _speed = 0;
|
||||
|
||||
[SerializeField] private Transform _player = null;
|
||||
|
||||
[SerializeField] private List<Vector3> _pathPoints = new List<Vector3>();
|
||||
|
||||
public EnemyData(int entityId, int typeId, Transform player, Vector3 pos, int maxHp, float speed) : base(
|
||||
entityId, typeId)
|
||||
{
|
||||
_maxHealth = maxHp;
|
||||
_speed = speed;
|
||||
Position = pos;
|
||||
_player = player;
|
||||
_pathPoints.Clear();
|
||||
}
|
||||
|
||||
public EnemyData(int entityId, int typeId, Vector3 pos, int maxHp, float speed,
|
||||
IReadOnlyList<Vector3> pathPoints) : base(entityId, typeId)
|
||||
{
|
||||
_maxHealth = maxHp;
|
||||
_speed = speed;
|
||||
Position = pos;
|
||||
_player = null;
|
||||
SetPathPoints(pathPoints);
|
||||
}
|
||||
|
||||
public CampType Camp
|
||||
{
|
||||
get => _camp;
|
||||
set => _camp = value;
|
||||
}
|
||||
|
||||
public int MaxHealth
|
||||
{
|
||||
get => _maxHealth;
|
||||
set => _maxHealth = value;
|
||||
}
|
||||
|
||||
public float Speed
|
||||
{
|
||||
get => _speed;
|
||||
set => _speed = value;
|
||||
}
|
||||
|
||||
public Transform Player
|
||||
{
|
||||
get => _player;
|
||||
set => _player = value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Vector3> PathPoints => _pathPoints;
|
||||
|
||||
public bool HasPath => _pathPoints.Count > 0;
|
||||
|
||||
public void SetPathPoints(IReadOnlyList<Vector3> pathPoints)
|
||||
{
|
||||
_pathPoints.Clear();
|
||||
if (pathPoints == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pathPoints.Count; i++)
|
||||
{
|
||||
_pathPoints.Add(pathPoints[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public abstract class EntityDataBase
|
||||
{
|
||||
[SerializeField] private int _id = 0;
|
||||
|
||||
[SerializeField] private int _typeId = 0;
|
||||
|
||||
[SerializeField] private Vector3 _position = Vector3.zero;
|
||||
|
||||
[SerializeField] private Quaternion _rotation = Quaternion.identity;
|
||||
|
||||
public EntityDataBase(int entityId, int typeId)
|
||||
{
|
||||
_id = entityId;
|
||||
_typeId = typeId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成的实体编号。
|
||||
/// </summary>
|
||||
public int Id => _id;
|
||||
|
||||
/// <summary>
|
||||
/// 实体类型编号(外键)。
|
||||
/// </summary>
|
||||
public int TypeId => _typeId;
|
||||
|
||||
/// <summary>
|
||||
/// 实体位置。
|
||||
/// </summary>
|
||||
public Vector3 Position
|
||||
{
|
||||
get => _position;
|
||||
set => _position = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体朝向。
|
||||
/// </summary>
|
||||
public Quaternion Rotation
|
||||
{
|
||||
get => _rotation;
|
||||
set => _rotation = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.CustomUtility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class MapData : EntityDataBase
|
||||
{
|
||||
[SerializeField] private int _levelId = 0;
|
||||
[SerializeField] private int _initialCoin = 0;
|
||||
[SerializeField] private TowerStatsData[] _buildTowerStatsSnapshot = Array.Empty<TowerStatsData>();
|
||||
[SerializeField] private BackpackInventoryData _inventorySnapshot;
|
||||
[SerializeField] private TowerItemData[] _participantTowerSnapshot = Array.Empty<TowerItemData>();
|
||||
|
||||
public MapData(int entityId, int levelId, Vector3 position) : this(entityId, 0, levelId, position)
|
||||
{
|
||||
}
|
||||
|
||||
public MapData(int entityId, int typeId, int levelId, Vector3 position) : base(entityId, typeId)
|
||||
{
|
||||
_levelId = levelId;
|
||||
Position = position;
|
||||
}
|
||||
|
||||
public MapData(
|
||||
int entityId,
|
||||
int typeId,
|
||||
int levelId,
|
||||
Vector3 position,
|
||||
int initialCoin,
|
||||
IReadOnlyList<TowerStatsData> buildTowerStatsSnapshot,
|
||||
BackpackInventoryData inventorySnapshot,
|
||||
IReadOnlyList<TowerItemData> participantTowerSnapshot) : base(entityId, typeId)
|
||||
{
|
||||
_levelId = levelId;
|
||||
Position = position;
|
||||
_initialCoin = Mathf.Max(0, initialCoin);
|
||||
SetBuildTowerStatsSnapshot(buildTowerStatsSnapshot);
|
||||
_inventorySnapshot = inventorySnapshot != null
|
||||
? InventoryCloneUtility.CloneInventory(inventorySnapshot)
|
||||
: null;
|
||||
SetParticipantTowerSnapshot(participantTowerSnapshot);
|
||||
}
|
||||
|
||||
public int LevelId
|
||||
{
|
||||
get => _levelId;
|
||||
set => _levelId = value;
|
||||
}
|
||||
|
||||
public int InitialCoin
|
||||
{
|
||||
get => _initialCoin;
|
||||
set => _initialCoin = Mathf.Max(0, value);
|
||||
}
|
||||
|
||||
public int CurrentBuildTowerCount => _buildTowerStatsSnapshot != null ? _buildTowerStatsSnapshot.Length : 0;
|
||||
public BackpackInventoryData InventorySnapshot => _inventorySnapshot != null
|
||||
? InventoryCloneUtility.CloneInventory(_inventorySnapshot)
|
||||
: null;
|
||||
public IReadOnlyList<TowerItemData> ParticipantTowerSnapshot => _participantTowerSnapshot;
|
||||
|
||||
public bool TryGetBuildTowerStats(int buildIndex, out TowerStatsData stats)
|
||||
{
|
||||
stats = null;
|
||||
if (_buildTowerStatsSnapshot == null || buildIndex < 0 || buildIndex >= _buildTowerStatsSnapshot.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TowerStatsData sourceStats = _buildTowerStatsSnapshot[buildIndex];
|
||||
if (sourceStats == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
stats = InventoryCloneUtility.CloneTowerStats(sourceStats);
|
||||
return stats != null;
|
||||
}
|
||||
|
||||
public void SetBuildTowerStatsSnapshot(IReadOnlyList<TowerStatsData> buildTowerStatsSnapshot)
|
||||
{
|
||||
if (buildTowerStatsSnapshot == null || buildTowerStatsSnapshot.Count <= 0)
|
||||
{
|
||||
_buildTowerStatsSnapshot = Array.Empty<TowerStatsData>();
|
||||
return;
|
||||
}
|
||||
|
||||
_buildTowerStatsSnapshot = new TowerStatsData[buildTowerStatsSnapshot.Count];
|
||||
for (int i = 0; i < buildTowerStatsSnapshot.Count; i++)
|
||||
{
|
||||
_buildTowerStatsSnapshot[i] = InventoryCloneUtility.CloneTowerStats(buildTowerStatsSnapshot[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public MapData CloneForEntity(int entityId, Vector3 position)
|
||||
{
|
||||
return new MapData(
|
||||
entityId,
|
||||
TypeId,
|
||||
_levelId,
|
||||
position,
|
||||
_initialCoin,
|
||||
_buildTowerStatsSnapshot,
|
||||
_inventorySnapshot,
|
||||
_participantTowerSnapshot);
|
||||
}
|
||||
|
||||
public void SetParticipantTowerSnapshot(IReadOnlyList<TowerItemData> participantTowerSnapshot)
|
||||
{
|
||||
if (participantTowerSnapshot == null || participantTowerSnapshot.Count <= 0)
|
||||
{
|
||||
_participantTowerSnapshot = Array.Empty<TowerItemData>();
|
||||
return;
|
||||
}
|
||||
|
||||
_participantTowerSnapshot = new TowerItemData[participantTowerSnapshot.Count];
|
||||
for (int i = 0; i < participantTowerSnapshot.Count; i++)
|
||||
{
|
||||
_participantTowerSnapshot[i] = InventoryCloneUtility.CloneTower(participantTowerSnapshot[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
public sealed class MapEntityLoadContext
|
||||
{
|
||||
public MapEntityLoadContext(MapData initialMapData, Func<int, bool> tryConsumeCoin, Action<int> addCoin)
|
||||
{
|
||||
InitialMapData = initialMapData;
|
||||
TryConsumeCoin = tryConsumeCoin;
|
||||
AddCoin = addCoin;
|
||||
}
|
||||
|
||||
public MapData InitialMapData { get; }
|
||||
public Func<int, bool> TryConsumeCoin { get; }
|
||||
public Action<int> AddCoin { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class PlayerData : EntityDataBase
|
||||
{
|
||||
[SerializeField] private CampType _camp = CampType.Player;
|
||||
|
||||
[SerializeField] private int _maxHealth = 0;
|
||||
|
||||
[SerializeField] private float _speed = 0;
|
||||
|
||||
public PlayerData(int entityId, int typeId, int maxHp, float speed) : base(entityId, typeId)
|
||||
{
|
||||
_maxHealth = maxHp;
|
||||
_speed = speed;
|
||||
}
|
||||
|
||||
public CampType Camp
|
||||
{
|
||||
get => _camp;
|
||||
set => _camp = value;
|
||||
}
|
||||
|
||||
public int MaxHealth
|
||||
{
|
||||
get => _maxHealth;
|
||||
set => _maxHealth = value;
|
||||
}
|
||||
|
||||
public float Speed
|
||||
{
|
||||
get => _speed;
|
||||
set => _speed = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class TowerData : EntityDataBase
|
||||
{
|
||||
[SerializeField] private TowerStatsData _stats;
|
||||
[SerializeField] private int _towerLevel = 0;
|
||||
[SerializeField] private Color _muzzleColor;
|
||||
[SerializeField] private Color _bearingColor;
|
||||
[SerializeField] private Color _baseColor;
|
||||
|
||||
public TowerData(int entityId, int typeId, Vector3 position, Quaternion rotation,
|
||||
TowerStatsData stats, int towerLevel = 0, Color? muzzleColor = null, Color? bearingColor = null,
|
||||
Color? baseColor = null)
|
||||
: base(entityId, typeId)
|
||||
{
|
||||
Position = position;
|
||||
Rotation = rotation;
|
||||
_stats = stats ?? new TowerStatsData();
|
||||
_towerLevel = Mathf.Max(0, towerLevel);
|
||||
_muzzleColor = muzzleColor ?? Color.white;
|
||||
_bearingColor = bearingColor ?? Color.white;
|
||||
_baseColor = baseColor ?? Color.white;
|
||||
}
|
||||
|
||||
public TowerStatsData Stats
|
||||
{
|
||||
get => _stats;
|
||||
set => _stats = value ?? new TowerStatsData();
|
||||
}
|
||||
|
||||
public int TowerLevel
|
||||
{
|
||||
get => _towerLevel;
|
||||
set => _towerLevel = Mathf.Max(0, value);
|
||||
}
|
||||
|
||||
public Color MuzzleColor
|
||||
{
|
||||
get => _muzzleColor;
|
||||
set => _muzzleColor = value;
|
||||
}
|
||||
|
||||
public Color BearingColor
|
||||
{
|
||||
get => _bearingColor;
|
||||
set => _bearingColor = value;
|
||||
}
|
||||
|
||||
public Color BaseColor
|
||||
{
|
||||
get => _baseColor;
|
||||
set => _baseColor = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user