Skip to content

Commit

Permalink
首次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
TippingGame committed Feb 20, 2024
1 parent c7234aa commit c49b0f1
Show file tree
Hide file tree
Showing 19 changed files with 1,048 additions and 974 deletions.
16 changes: 12 additions & 4 deletions ConfigData/F8DataManager/F8DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using F8Framework.F8ExcelDataClass;
using F8Framework.Core;

namespace F8Framework.F8DataManager
namespace F8Framework.ConfigData
{
public class F8DataManager : Singleton<F8DataManager>
{
Expand All @@ -25,7 +25,7 @@ public Sheet1Item GetSheet1ByID(Int32 id)
{
Sheet1Item t = null;
p_Sheet1.Dict.TryGetValue(id, out t);
if (t == null) LogF8.LogError("can't find the id " + id + " in Sheet1");
if (t == null) LogF8.LogError("找不到id: " + id + " ,配置表: Sheet1");
return t;
}

Expand All @@ -38,7 +38,7 @@ public Sheet2Item GetSheet2ByID(Int32 id)
{
Sheet2Item t = null;
p_Sheet2.Dict.TryGetValue(id, out t);
if (t == null) LogF8.LogError("can't find the id " + id + " in Sheet2");
if (t == null) LogF8.LogError("找不到id: " + id + " ,配置表: Sheet2");
return t;
}

Expand All @@ -51,7 +51,7 @@ public LocalizedStringsItem GetLocalizedStringsByID(Int32 id)
{
LocalizedStringsItem t = null;
p_LocalizedStrings.Dict.TryGetValue(id, out t);
if (t == null) LogF8.LogError("can't find the id " + id + " in LocalizedStrings");
if (t == null) LogF8.LogError("找不到id: " + id + " ,配置表: LocalizedStrings");
return t;
}

Expand Down Expand Up @@ -81,6 +81,14 @@ public IEnumerable LoadAllAsync()
yield return LoadAsync("LocalizedStrings", result => p_LocalizedStrings = result as LocalizedStrings);
}

public IEnumerator LoadAllAsync(Action onLoadComplete)
{
yield return LoadAsync("Sheet1", result => p_Sheet1 = result as Sheet1);
yield return LoadAsync("Sheet2", result => p_Sheet2 = result as Sheet2);
yield return LoadAsync("LocalizedStrings", result => p_LocalizedStrings = result as LocalizedStrings);
onLoadComplete?.Invoke();
}

private System.Object Load(string name)
{
IFormatter f = new BinaryFormatter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "F8Framework.F8DataManager",
"name": "F8Framework.ConfigData",
"references": ["F8Framework.Core"],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
32 changes: 25 additions & 7 deletions Editor/AssetManager/ABBuildTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void GenerateAssetNames()
string[] allPaths = filePaths.Concat(folderPaths).ToArray();

List<string> tempNames = new List<string>();
Dictionary<string, string> tempNamesDirectory = new Dictionary<string, string>();
Dictionary<string, List<string>> tempNamesDirectory = new Dictionary<string, List<string>>();

// 创建文本文件
StringBuilder codeStr = new StringBuilder(
Expand Down Expand Up @@ -213,18 +213,36 @@ public static void GenerateAssetNames()
}
tempNames.Add(fileNameWithoutExtension);

codeStr.Append(string.Format(" {{\"{0}\", new AssetMapping(\"{1}\", new []{{\"{2}\"}})}},\n", fileNameWithoutExtension, abName.ToLower(), assetPath));

// 修改同一AB名的assetPath
if (!tempNamesDirectory.ContainsKey(fileNameWithoutExtension))
List<string> assetPathsForAbName;
string _temp = null;
if (!tempNamesDirectory.TryGetValue(abName.ToLower(), out assetPathsForAbName))
{
tempNamesDirectory.TryAdd(fileNameWithoutExtension, assetPath);
// 如果该 AssetBundle 名称还没有对应的资源路径列表,就创建一个新的列表
assetPathsForAbName = new List<string>();
tempNamesDirectory.Add(abName.ToLower(), assetPathsForAbName);
}
else
{
codeStr.Replace(tempNamesDirectory[fileNameWithoutExtension], tempNamesDirectory[fileNameWithoutExtension] + ", " + assetPath);
tempNamesDirectory[fileNameWithoutExtension] = tempNamesDirectory[fileNameWithoutExtension] + ", " + assetPath;
_temp = string.Join(", ", assetPathsForAbName.Select(p => "\"" + p + "\""));
}

// 将当前资源路径添加到列表中,但是只添加一次,确保每个资源路径只出现一次
if (!assetPathsForAbName.Contains(assetPath))
{
assetPathsForAbName.Add(assetPath);
}

if (_temp != null)
{
codeStr.Replace(_temp, string.Join(", ", assetPathsForAbName.Select(p => "\"" + p + "\"")));
}

string mappingLine = string.Format(" {{\"{0}\", new AssetMapping(\"{1}\", new []{{", fileNameWithoutExtension, abName.ToLower());
mappingLine += string.Join(", ", assetPathsForAbName.Select(p => "\"" + p + "\"")); // 添加所有资源路径
mappingLine += "})},\n";

codeStr.Append(mappingLine);
}
else if (Directory.Exists(filePath)) // 文件夹
{
Expand Down
4 changes: 2 additions & 2 deletions Editor/ExcelTool/ExcelDataTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ private static string GetScriptPath()
private static void CreateAsmdefFile()
{
// 创建.asmdef文件的路径
string asmdefPath = Application.dataPath + DataManagerFolder + "/F8Framework.F8DataManager.asmdef";
string asmdefPath = Application.dataPath + DataManagerFolder + "/F8Framework.ConfigData.asmdef";

FileTools.CheckFileAndCreateDirWhenNeeded(asmdefPath);
// 创建一个新的.asmdef文件
string asmdefContent = @"{
""name"": ""F8Framework.F8DataManager"",
""name"": ""F8Framework.ConfigData"",
""references"": [""F8Framework.Core""],
""includePlatforms"": [],
""excludePlatforms"": [],
Expand Down
16 changes: 13 additions & 3 deletions Editor/ExcelTool/SupportType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static void CreateDataManager(Assembly assembly)
source.Append("using System.IO;\n");
source.Append("using " + ExcelDataTool.CODE_NAMESPACE + ";\n");
source.Append("using F8Framework.Core;\n\n");
source.Append("namespace F8Framework.F8DataManager\n");
source.Append("namespace F8Framework.ConfigData\n");
source.Append("{\n");
source.Append("\tpublic class F8DataManager : Singleton<F8DataManager>\n");
source.Append("\t{\n");
Expand All @@ -230,9 +230,9 @@ public static void CreateDataManager(Assembly assembly)
source.Append("\t\t{\n");
source.Append("\t\t\t" + typeName + " t = null;\n");
source.Append("\t\t\tp_" + t.Name + ".Dict.TryGetValue(id, out t);\n");
source.Append("\t\t\tif (t == null) LogF8.LogError(" + '"' + "can't find the id " + '"' + " + id " +
source.Append("\t\t\tif (t == null) LogF8.LogError(" + '"' + "找不到id: " + '"' + " + id " +
"+ " +
'"' + " in " + t.Name + '"' + ");\n");
'"' + " ,配置表: " + t.Name + '"' + ");\n");
source.Append("\t\t\treturn t;\n");
source.Append("\t\t}\n\n");

Expand Down Expand Up @@ -272,6 +272,16 @@ public static void CreateDataManager(Assembly assembly)

source.Append("\t\t}\n\n");

//异步加载所有配置表
source.Append("\t\tpublic IEnumerator LoadAllAsync(Action onLoadComplete)\n");
source.Append("\t\t{\n");
foreach (Type t in types)
{
source.Append("\t\t\tyield return LoadAsync("+ '"' + t.Name + '"' + ", result => " + "p_" + t.Name + " = result" + " as " + t.Name + ");\n");
}
source.Append("\t\t\tonLoadComplete?.Invoke();\n");
source.Append("\t\t}\n\n");

//反序列化
source.Append("\t\tprivate System.Object Load(string name)\n");
source.Append("\t\t{\n");
Expand Down
1 change: 0 additions & 1 deletion Runtime/ExcelTool/ReadExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using System.Text.RegularExpressions;
using Excel;
using UnityEngine;
using Assembly = System.Reflection.Assembly;

namespace F8Framework.Core
Expand Down
16 changes: 8 additions & 8 deletions Runtime/GameObjectPool/Components/F8GameObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private readonly F8PoolList<Poolable> _despawnedPoolables
/// <summary>
/// Has this pool registered as persistent?
/// </summary>
public bool HasRegisteredAsPersistent => FF8.GameObjectPool.HasPoolRegisteredAsPersistent(this);
public bool HasRegisteredAsPersistent => GameObjectPool.Instance.HasPoolRegisteredAsPersistent(this);

/// <summary>
/// The actions will be performed on a game object spawned by this pool.
Expand Down Expand Up @@ -218,7 +218,7 @@ private void Start()
private void OnDestroy()
{
Clear();
FF8.GameObjectPool.UnregisterPool(this);
GameObjectPool.Instance.UnregisterPool(this);
}

/// <summary>
Expand Down Expand Up @@ -506,7 +506,7 @@ public void DespawnAllClones()

for (int i = 0; i < _poolablesTemp._count; i++)
{
FF8.GameObjectPool.DespawnImmediate(_poolablesTemp._components[i]);
GameObjectPool.Instance.DespawnImmediate(_poolablesTemp._components[i]);
}

if (_poolablesTemp._count > 0)
Expand All @@ -528,7 +528,7 @@ internal bool TrySetup(GameObject prefab)
return false;
}

if (FF8.GameObjectPool.s_checkForPrefab)
if (GameObjectPool.s_checkForPrefab)
{
if (CheckForPrefab(prefab) == false)
{
Expand Down Expand Up @@ -556,7 +556,7 @@ internal bool TrySetup(GameObject prefab)
SetupPreloadedClones();
}

FF8.GameObjectPool.RegisterPool(this);
GameObjectPool.Instance.RegisterPool(this);

_isSetup = true;
return true;
Expand Down Expand Up @@ -825,7 +825,7 @@ private void DisposePoolablesInList(F8PoolList<Poolable> f8PoolList, ref int cou

private bool TryRegisterPoolAsPersistent()
{
if (FF8.GameObjectPool.HasPoolRegisteredAsPersistent(this) == false)
if (GameObjectPool.Instance.HasPoolRegisteredAsPersistent(this) == false)
{
#if DEBUG
if (_cachedTransform.parent != null)
Expand All @@ -838,7 +838,7 @@ private bool TryRegisterPoolAsPersistent()
#endif
_dontDestroyOnLoad = true;
DontDestroyOnLoad(gameObject);
FF8.GameObjectPool.RegisterPersistentPool(this);
GameObjectPool.Instance.RegisterPersistentPool(this);
return true;
}

Expand Down Expand Up @@ -1001,7 +1001,7 @@ private Poolable InstantiateAndSetupPoolable(bool isPopulatingPool)
poolable._transform.SetParent(_isSetup ? _cachedTransform : transform, false);
}

FF8.GameObjectPool.GameObjectInstantiated.RaiseEvent(newGameObject);
GameObjectPool.GameObjectInstantiated.RaiseEvent(newGameObject);
RaiseGameObjectInstantiatedCallback(newGameObject);
return poolable;
}
Expand Down
6 changes: 3 additions & 3 deletions Runtime/GameObjectPool/Components/F8PoolDespawnTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public sealed class F8PoolDespawnTimer : MonoBehaviour, ISpawnable
#if DEBUG
private void Start()
{
if (FF8.GameObjectPool.IsClone(gameObject) == false)
if (GameObjectPool.Instance.IsClone(gameObject) == false)
{
LogF8.LogError("您已将一个取消生成计时器添加到不是克隆的游戏对象!", this);
}

if (FF8.GameObjectPool.TryGetPoolByClone(gameObject, out F8GameObjectPool pool))
if (GameObjectPool.Instance.TryGetPoolByClone(gameObject, out F8GameObjectPool pool))
{
if (pool.BehaviourOnCapacityReached == BehaviourOnCapacityReached.Recycle)
{
Expand Down Expand Up @@ -68,7 +68,7 @@ private void HandleDespawn(float deltaTime)
{
if (IsDespawnMoment(deltaTime))
{
FF8.GameObjectPool.Despawn(gameObject);
GameObjectPool.Instance.Despawn(gameObject);
}
}

Expand Down
46 changes: 23 additions & 23 deletions Runtime/GameObjectPool/Components/F8PoolGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ private void OnValidate()
{
if (Application.isPlaying)
{
FF8.GameObjectPool.s_f8PoolMode = _f8PoolMode;
FF8.GameObjectPool.s_checkForPrefab = _checkForPrefab;
FF8.GameObjectPool.s_checkClonesForNull = _checkClonesForNull;
FF8.GameObjectPool.s_despawnPersistentClonesOnDestroy = _despawnPersistentClonesOnDestroy;
GameObjectPool.s_f8PoolMode = _f8PoolMode;
GameObjectPool.s_checkForPrefab = _checkForPrefab;
GameObjectPool.s_checkClonesForNull = _checkClonesForNull;
GameObjectPool.s_despawnPersistentClonesOnDestroy = _despawnPersistentClonesOnDestroy;
}
}
#endif
Expand Down Expand Up @@ -103,11 +103,11 @@ public void OnFixedUpdate()

public void OnTermination()
{
FF8.GameObjectPool.ResetPool();
GameObjectPool.Instance.ResetPool();

if (_clearEventsOnDestroy || FF8.GameObjectPool.s_isApplicationQuitting)
if (_clearEventsOnDestroy || GameObjectPool.s_isApplicationQuitting)
{
FF8.GameObjectPool.GameObjectInstantiated.Clear();
GameObjectPool.GameObjectInstantiated.Clear();
}

Destroy(gameObject);
Expand All @@ -120,54 +120,54 @@ private void Start()

private void OnApplicationQuit()
{
FF8.GameObjectPool.s_isApplicationQuitting = true;
GameObjectPool.s_isApplicationQuitting = true;
}

private void Initialize()
{
#if DEBUG
if (FF8.GameObjectPool.s_instance != null && FF8.GameObjectPool.s_instance != this)
LogF8.LogError($"场景中的 {nameof(FF8.GameObjectPool)} 实例数量大于一个!");
if (GameObjectPool.s_instance != null && GameObjectPool.s_instance != this)
LogF8.LogError($"场景中的 {nameof(GameObjectPool)} 实例数量大于一个!");

if (enabled == false)
LogF8.LogEntity($"<{nameof(F8PoolGlobal)}> 实例已禁用!" +
"因此,某些功能可能无法正常工作!", this);
#endif
FF8.GameObjectPool.s_isApplicationQuitting = false;
FF8.GameObjectPool.s_instance = this;
FF8.GameObjectPool.s_hasTheF8PoolInitialized = true;
FF8.GameObjectPool.s_f8PoolMode = _f8PoolMode;
FF8.GameObjectPool.s_checkForPrefab = _checkForPrefab;
FF8.GameObjectPool.s_checkClonesForNull = _checkClonesForNull;
FF8.GameObjectPool.s_despawnPersistentClonesOnDestroy = _despawnPersistentClonesOnDestroy;
GameObjectPool.s_isApplicationQuitting = false;
GameObjectPool.s_instance = this;
GameObjectPool.s_hasTheF8PoolInitialized = true;
GameObjectPool.s_f8PoolMode = _f8PoolMode;
GameObjectPool.s_checkForPrefab = _checkForPrefab;
GameObjectPool.s_checkClonesForNull = _checkClonesForNull;
GameObjectPool.s_despawnPersistentClonesOnDestroy = _despawnPersistentClonesOnDestroy;
}

private void PreloadPools(PreloadType requiredType)
{
if (requiredType != preloadPoolsType)
return;

FF8.GameObjectPool.InstallPools(poolsPreset);
GameObjectPool.Instance.InstallPools(poolsPreset);
}

private void HandleDespawnRequests(float deltaTime)
{
for (int i = 0; i < FF8.GameObjectPool.DespawnRequests._count; i++)
for (int i = 0; i < GameObjectPool.DespawnRequests._count; i++)
{
ref DespawnRequest request = ref FF8.GameObjectPool.DespawnRequests._components[i];
ref DespawnRequest request = ref GameObjectPool.DespawnRequests._components[i];

if (request.Poolable._status == PoolableStatus.Despawned)
{
FF8.GameObjectPool.DespawnRequests.RemoveUnorderedAt(i);
GameObjectPool.DespawnRequests.RemoveUnorderedAt(i);
continue;
}

request.TimeToDespawn -= deltaTime;

if (request.TimeToDespawn <= 0f)
{
FF8.GameObjectPool.DespawnImmediate(request.Poolable);
FF8.GameObjectPool.DespawnRequests.RemoveUnorderedAt(i);
GameObjectPool.Instance.DespawnImmediate(request.Poolable);
GameObjectPool.DespawnRequests.RemoveUnorderedAt(i);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Runtime/GameObjectPool/Components/Poolable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal void SetupAsDefault()
if (_isSetup)
LogF8.LogError("池对象已经设置!");
#endif
FF8.GameObjectPool.ClonesMap.Add(_gameObject, this);
GameObjectPool.ClonesMap.Add(_gameObject, this);
_status = PoolableStatus.Despawned;
_isSetup = true;
}
Expand All @@ -37,14 +37,14 @@ internal void SetupAsSpawnedOverCapacity()
if (_isSetup)
LogF8.LogError("池对象已经设置!");
#endif
FF8.GameObjectPool.ClonesMap.Add(_gameObject, this);
GameObjectPool.ClonesMap.Add(_gameObject, this);
_status = PoolableStatus.SpawnedOverCapacity;
_isSetup = true;
}

internal void Dispose(bool immediately)
{
FF8.GameObjectPool.ClonesMap.Remove(_gameObject);
GameObjectPool.ClonesMap.Remove(_gameObject);

if (immediately)
Object.DestroyImmediate(_gameObject);
Expand Down
Loading

0 comments on commit c49b0f1

Please sign in to comment.