This commit is contained in:
SepComet
2026-02-26 13:21:43 +08:00
parent a118803f1a
commit 4daefa17d5
1259 changed files with 290021 additions and 1 deletions
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 58efe0589d7e90f498c8bcbbf94c6be4
folderAsset: yes
timeCreated: 1528026151
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
using System;
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;
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;
}
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;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1b802c30cc274e04929b8659ec631e84
timeCreated: 1768890974
@@ -0,0 +1,62 @@
//------------------------------------------------------------
// 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 m_Id = 0;
[SerializeField]
private int m_TypeId = 0;
[SerializeField]
private Vector3 m_Position = Vector3.zero;
[SerializeField]
private Quaternion m_Rotation = Quaternion.identity;
public EntityDataBase(int entityId, int typeId)
{
m_Id = entityId;
m_TypeId = typeId;
}
/// <summary>
/// 实体编号。
/// </summary>
public int Id => m_Id;
/// <summary>
/// 实体类型编号。
/// </summary>
public int TypeId => m_TypeId;
/// <summary>
/// 实体位置。
/// </summary>
public Vector3 Position
{
get => m_Position;
set => m_Position = value;
}
/// <summary>
/// 实体朝向。
/// </summary>
public Quaternion Rotation
{
get => m_Rotation;
set => m_Rotation = value;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: afb91fe3ed8105e4a96b7bd5917ecc2b
timeCreated: 1528026152
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -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,3 @@
fileFormatVersion: 2
guid: b69d3168ac4f442994f8dc4d906daa60
timeCreated: 1768890638
@@ -0,0 +1,80 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.DataTable;
using System;
using GeometryTD.CustomUtility;
using GeometryTD.DataTable;
using GeometryTD.Entity;
using GeometryTD.Entity.EntityData;
using UnityGameFramework.Runtime;
namespace GeometryTD
{
public static class EntityExtension
{
private static int s_SerialId = 0;
public static EntityBase GetGameEntity(this EntityComponent entityComponent, int entityId)
{
UnityGameFramework.Runtime.Entity entity = entityComponent.GetEntity(entityId);
if (entity == null)
{
return null;
}
return (EntityBase)entity.Logic;
}
public static void HideEntity(this EntityComponent entityComponent, EntityBase entity)
{
entityComponent.HideEntity(entity.Entity);
}
public static void AttachEntity(this EntityComponent entityComponent, EntityBase entityBase, int ownerId,
string parentTransformPath = null, object userData = null)
{
entityComponent.AttachEntity(entityBase.Entity, ownerId, parentTransformPath, userData);
}
public static void ShowPlayer(this EntityComponent entityComponent, PlayerData data)
{
entityComponent.ShowEntity(typeof(Player), "Player", Constant.AssetPriority.PlayerAsset, data);
}
public static void ShowEnemy(this EntityComponent entityComponent, EnemyData data)
{
entityComponent.ShowEntity(typeof(Enemy), "Enemy", Constant.AssetPriority.EnemyAsset, data);
}
private static void ShowEntity(this EntityComponent entityComponent, Type logicType, string entityGroup,
int priority, EntityDataBase data)
{
if (data == null)
{
Log.Warning("Data is invalid.");
return;
}
IDataTable<DREntity> dtEntity = GameEntry.DataTable.GetDataTable<DREntity>();
DREntity drEntity = dtEntity.GetDataRow(data.TypeId);
if (drEntity == null)
{
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
return;
}
entityComponent.ShowEntity(data.Id, logicType, AssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup,
priority, data);
}
public static int GenerateSerialId(this EntityComponent entityComponent)
{
return --s_SerialId;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 626632079980ad34595c3b43a062a664
timeCreated: 1528026153
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 74fbdf043ed3bc141a0a0b09756bc7d2
folderAsset: yes
timeCreated: 1528026153
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
using Components;
using GeometryTD.Entity.EntityData;
using UnityEngine;
namespace GeometryTD.Entity
{
public class Enemy : EntityBase
{
private Transform _target;
private float _speed;
private MovementComponent _movementComponent;
private float _attackRange = 1f;
private float _attackRangeSquared;
protected override void OnInit(object userData)
{
base.OnInit(userData);
_movementComponent = GetComponent<MovementComponent>();
}
protected override void OnShow(object userData)
{
base.OnShow(userData);
if (userData is EnemyData enemyData)
{
_speed = enemyData.Speed;
_target = enemyData.Player;
}
_movementComponent.OnInit(_speed, this.CachedTransform);
_movementComponent.SetMove(true);
_attackRangeSquared = _attackRange * _attackRange;
}
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
float distanceSquared = (this.CachedTransform.position - _target.position).sqrMagnitude;
if (distanceSquared < _attackRangeSquared)
{
// 攻击
_movementComponent.SetMove(false);
}
else
{
_movementComponent.SetMove(true);
_movementComponent.SetDirection(GetTargetDirection());
}
_movementComponent.OnUpdate(elapseSeconds, realElapseSeconds);
}
protected override void OnHide(bool isShutdown, object userData)
{
_movementComponent.SetMove(false);
base.OnHide(isShutdown, userData);
}
private Vector3 GetTargetDirection()
{
return new Vector3(_target.position.x - this.CachedTransform.position.x, 0f,
_target.position.z - this.CachedTransform.position.z).normalized;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 112f2a17ab82438484782c9a763fdee1
timeCreated: 1768892870
@@ -0,0 +1,115 @@
using GeometryTD.Entity.EntityData;
using GameFramework;
using GeometryTD;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.Entity
{
public abstract class EntityBase : EntityLogic
{
[SerializeField] private EntityDataBase _entityData = null;
public int Id => Entity.Id;
public Animation CachedAnimation
{
get;
private set;
}
#if UNITY_2017_3_OR_NEWER
protected override void OnInit(object userData)
#else
protected internal override void OnInit(object userData)
#endif
{
base.OnInit(userData);
CachedAnimation = GetComponent<Animation>();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnRecycle()
#else
protected internal override void OnRecycle()
#endif
{
base.OnRecycle();
}
#if UNITY_2017_3_OR_NEWER
protected override void OnShow(object userData)
#else
protected internal override void OnShow(object userData)
#endif
{
base.OnShow(userData);
_entityData = userData as EntityDataBase;
if (_entityData == null)
{
Log.Error("Entity data is invalid.");
return;
}
Name = Utility.Text.Format("[Entity {0}]", Id);
CachedTransform.localPosition = _entityData.Position;
CachedTransform.localRotation = _entityData.Rotation;
CachedTransform.localScale = Vector3.one;
}
#if UNITY_2017_3_OR_NEWER
protected override void OnHide(bool isShutdown, object userData)
#else
protected internal override void OnHide(bool isShutdown, object userData)
#endif
{
base.OnHide(isShutdown, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
#else
protected internal override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
#endif
{
base.OnAttached(childEntity, parentTransform, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnDetached(EntityLogic childEntity, object userData)
#else
protected internal override void OnDetached(EntityLogic childEntity, object userData)
#endif
{
base.OnDetached(childEntity, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnAttachTo(EntityLogic parentEntity, Transform parentTransform, object userData)
#else
protected internal override void OnAttachTo(EntityLogic parentEntity, Transform parentTransform, object userData)
#endif
{
base.OnAttachTo(parentEntity, parentTransform, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnDetachFrom(EntityLogic parentEntity, object userData)
#else
protected internal override void OnDetachFrom(EntityLogic parentEntity, object userData)
#endif
{
base.OnDetachFrom(parentEntity, userData);
}
#if UNITY_2017_3_OR_NEWER
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
#else
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
#endif
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 878fbbe82b4bde944812bcb7c964cff8
timeCreated: 1528026154
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using Components;
using GeometryTD.Entity;
using GeometryTD.Entity.EntityData;
namespace GeometryTD.Entity
{
public class Player : EntityBase
{
private float _speed;
private InputComponent _inputComponent;
private MovementComponent _movementComponent;
protected override void OnInit(object userData)
{
base.OnInit(userData);
_inputComponent = GetComponent<InputComponent>();
_movementComponent = GetComponent<MovementComponent>();
}
protected override void OnShow(object userData)
{
base.OnShow(userData);
if (userData is PlayerData playerData)
{
_speed = playerData.Speed;
}
_inputComponent.OnInit();
_inputComponent.SetListening(true);
_movementComponent.OnInit(_speed, this.CachedTransform);
_movementComponent.SetMove(true);
}
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
_inputComponent.OnUpdate(elapseSeconds, realElapseSeconds);
_movementComponent.SetDirection(_inputComponent.Direction);
_movementComponent.OnUpdate(elapseSeconds, realElapseSeconds);
}
protected override void OnHide(bool isShutdown, object userData)
{
_inputComponent.SetListening(false);
_movementComponent.SetMove(false);
base.OnHide(isShutdown, userData);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3979cb10abff0944aad09de04ec7813a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: