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,62 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using GeometryTD.Definition;
using GeometryTD.UI;
using UnityEngine;
using UnityEngine.Serialization;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
public class BuiltinDataComponent : GameFrameworkComponent
{
[FormerlySerializedAs("m_BuildInfoTextAsset")] [SerializeField] private TextAsset _buildInfoTextAsset = null;
[FormerlySerializedAs("m_DefaultDictionaryTextAsset")] [SerializeField] private TextAsset _defaultDictionaryTextAsset = null;
[FormerlySerializedAs("m_UpdateResourceFormTemplate")] [SerializeField] private UpdateResourceForm _updateResourceFormTemplate = null;
private BuildInfo _buildInfo = null;
public BuildInfo BuildInfo => _buildInfo;
public UpdateResourceForm UpdateResourceFormTemplate => _updateResourceFormTemplate;
public void InitBuildInfo()
{
if (_buildInfoTextAsset == null || string.IsNullOrEmpty(_buildInfoTextAsset.text))
{
Log.Info("Build info can not be found or empty.");
return;
}
_buildInfo = Utility.Json.ToObject<BuildInfo>(_buildInfoTextAsset.text);
if (_buildInfo == null)
{
Log.Warning("Parse build info failure.");
return;
}
}
public void InitDefaultDictionary()
{
if (_defaultDictionaryTextAsset == null || string.IsNullOrEmpty(_defaultDictionaryTextAsset.text))
{
Log.Info("Default dictionary can not be found or empty.");
return;
}
if (!GameEntry.Localization.ParseData(_defaultDictionaryTextAsset.text))
{
Log.Warning("Parse default dictionary failure.");
return;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cfb0b001fcb30fe45ac95ddb8c28ba57
timeCreated: 1528026146
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 259253e364fe32a4195e182f78b8cc54
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
using GeometryTD.Entity;
using GeometryTD.Entity.EntityData;
using GameFramework.Event;
using GeometryTD;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
public class EnemyManagerComponent : GameFrameworkComponent
{
private EntityComponent _entity;
private float _spawnEnemyInterval = 5f;
private float _spawnEnemyTimer;
private float _spawnEnemyAccelerate = 0.5f;
private int _spawnEnemyCount = 5;
private int _spawnEnemyMaxCount = 5000;
private int _currentEnemyCount;
private int _spawnDistanceFromPlayer = 10;
private int _currentSpawnEnemyId = 0;
private Transform _player;
public void OnInit()
{
_entity = GameEntry.Entity;
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
GameEntry.Event.Subscribe(ShowEntityFailureEventArgs.EventId, OnShowEntityFailure);
GameEntry.Event.Subscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
}
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
_spawnEnemyTimer += elapseSeconds;
if (_spawnEnemyTimer < _spawnEnemyInterval) return;
SpawnEnemy();
_spawnEnemyTimer = 0;
_spawnEnemyInterval = Mathf.Max(0.1f, _spawnEnemyInterval - _spawnEnemyAccelerate);
}
public void OnDestroy()
{
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
GameEntry.Event.Unsubscribe(ShowEntityFailureEventArgs.EventId, OnShowEntityFailure);
GameEntry.Event.Unsubscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
}
private void SpawnEnemy()
{
if (_player == null) return;
for (int i = 0; i < _spawnEnemyCount; i++)
{
if (_currentEnemyCount >= _spawnEnemyMaxCount) break;
_entity.ShowEnemy(new EnemyData(_currentSpawnEnemyId % _spawnEnemyMaxCount, 1001, _player,
GetRandomPosition(), 10, 2));
_currentSpawnEnemyId++;
}
}
private Vector3 GetRandomPosition()
{
float x = Random.Range(-1f, 1f);
float z = Random.Range(-1f, 1f);
Vector3 dir = new Vector3(x, 0, z).normalized;
return _player.position + dir * _spawnDistanceFromPlayer;
}
private void OnShowEntitySuccess(object sender, GameEventArgs e)
{
if (e is ShowEntitySuccessEventArgs ne)
{
if (ne.EntityLogicType == typeof(Enemy))
{
_currentEnemyCount++;
}
if (ne.EntityLogicType == typeof(Player))
{
_player = ne.Entity.transform;
}
}
}
private void OnShowEntityFailure(object sender, GameEventArgs e)
{
}
private void OnHideEntityComplete(object sender, GameEventArgs e)
{
if (e is HideEntityCompleteEventArgs ne)
{
if (ne.EntityGroup.Name == "Enemy")
{
_currentEnemyCount--;
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d840df1b53db744cb522b82426f2cd5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f75cb14d28565904e89eb5765829c210
folderAsset: yes
timeCreated: 1528026155
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,123 @@
using GameFramework.ObjectPool;
using System.Collections.Generic;
using GeometryTD.Entity;
using GeometryTD;
using GeometryTD.PoolObjectBase;
using GeometryTD.UI;
using UnityEngine;
using UnityEngine.Serialization;
using UnityGameFramework.Runtime;
namespace GeometryTD.CustomComponent
{
public class HPBarComponent : GameFrameworkComponent
{
[FormerlySerializedAs("m_HPBarItemTemplate")] [SerializeField]
private HPBarItem _hpBarItemTemplate = null;
[FormerlySerializedAs("m_HPBarInstanceRoot")] [SerializeField]
private Transform _hpBarInstanceRoot = null;
[FormerlySerializedAs("m_InstancePoolCapacity")] [SerializeField]
private int _instancePoolCapacity = 16;
private IObjectPool<HPBarItemObject> _hpBarItemObjectPool = null;
private List<HPBarItem> _activeHPBarItems = null;
private Canvas _cachedCanvas = null;
private void Start()
{
if (_hpBarInstanceRoot == null)
{
Log.Error("You must set HP bar instance root first.");
return;
}
_cachedCanvas = _hpBarInstanceRoot.GetComponent<Canvas>();
_hpBarItemObjectPool =
GameEntry.ObjectPool.CreateSingleSpawnObjectPool<HPBarItemObject>("HPBarItem", _instancePoolCapacity);
_activeHPBarItems = new List<HPBarItem>();
}
private void OnDestroy()
{
}
private void Update()
{
for (int i = _activeHPBarItems.Count - 1; i >= 0; i--)
{
HPBarItem hpBarItem = _activeHPBarItems[i];
if (hpBarItem.Refresh())
{
continue;
}
HideHPBar(hpBarItem);
}
}
public void ShowHPBar(EntityBase entity, float fromHPRatio, float toHPRatio)
{
if (entity == null)
{
Log.Warning("Entity is invalid.");
return;
}
HPBarItem hpBarItem = GetActiveHPBarItem(entity);
if (hpBarItem == null)
{
hpBarItem = CreateHPBarItem(entity);
_activeHPBarItems.Add(hpBarItem);
}
hpBarItem.Init(entity, _cachedCanvas, fromHPRatio, toHPRatio);
}
private void HideHPBar(HPBarItem hpBarItem)
{
hpBarItem.Reset();
_activeHPBarItems.Remove(hpBarItem);
_hpBarItemObjectPool.Unspawn(hpBarItem);
}
private HPBarItem GetActiveHPBarItem(EntityBase entity)
{
if (entity == null)
{
return null;
}
for (int i = 0; i < _activeHPBarItems.Count; i++)
{
if (_activeHPBarItems[i].Owner == entity)
{
return _activeHPBarItems[i];
}
}
return null;
}
private HPBarItem CreateHPBarItem(EntityBase entity)
{
HPBarItem hpBarItem = null;
HPBarItemObject hpBarItemObject = _hpBarItemObjectPool.Spawn();
if (hpBarItemObject != null)
{
hpBarItem = (HPBarItem)hpBarItemObject.Target;
}
else
{
hpBarItem = Instantiate(_hpBarItemTemplate);
Transform transform = hpBarItem.GetComponent<Transform>();
transform.SetParent(_hpBarInstanceRoot);
transform.localScale = Vector3.one;
_hpBarItemObjectPool.Register(HPBarItemObject.Create(hpBarItem), true);
}
return hpBarItem;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 879e921586721514f9f85de777050af4
timeCreated: 1528026155
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
using GeometryTD.UI;
namespace CustomComponent
{
public class UIRouterComponent : GameFrameworkComponent
{
private readonly Dictionary<UIFormType, IUIFormController> _routeControllers = new();
public void BindUIUseCase(UIFormType uiFormType, IUIUseCase useCase)
{
IUIFormController controller = GetOrCreateController(uiFormType);
controller.BindUseCase(useCase);
}
public int? OpenUI(UIFormType uiFormType, object userData = null)
{
IUIFormController controller = GetOrCreateController(uiFormType);
return controller.OpenUI(userData);
}
public void CloseUI(UIFormType uiFormType)
{
IUIFormController controller = GetOrCreateController(uiFormType);
controller.CloseUI();
}
private IUIFormController GetOrCreateController(UIFormType uiFormType)
{
if (_routeControllers.TryGetValue(uiFormType, out IUIFormController controller))
{
return controller;
}
string typename = $"UI.{uiFormType}Controller";
Type controllerType = Type.GetType(typename);
if (controllerType == null)
{
controller = new DefaultUIFormController(uiFormType);
}
else
{
controller = (IUIFormController)Activator.CreateInstance(controllerType);
}
_routeControllers.Add(uiFormType, controller);
return controller;
}
private void OnDestroy()
{
foreach (KeyValuePair<UIFormType, IUIFormController> pair in _routeControllers)
{
pair.Value.CloseUI();
}
_routeControllers.Clear();
}
private class DefaultUIFormController : IUIFormController
{
private readonly UIFormType _uiFormType;
private int? _lastSerialId;
public DefaultUIFormController(UIFormType uiFormType)
{
_uiFormType = uiFormType;
}
public int? OpenUI(object userData = null)
{
_lastSerialId = GameEntry.UI.OpenUIForm(_uiFormType, userData);
return _lastSerialId;
}
public void CloseUI()
{
if (_lastSerialId.HasValue)
{
GameEntry.UI.CloseUIForm(_lastSerialId.Value);
_lastSerialId = null;
return;
}
UGuiForm uiForm = GameEntry.UI.GetUIForm(_uiFormType);
if (uiForm != null)
{
GameEntry.UI.CloseUIForm(uiForm);
}
}
public void BindUseCase(IUIUseCase useCase)
{
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c27ab66e930c72847aef7dd05aff8953
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: