继续调整,创建 Procedure 与 Presentation 程序集

- 创建 Procedure 与 Presentation 两个程序集
- 初步解决这两个程序集与原程序集的引用关系
This commit is contained in:
SepComet
2026-06-02 23:26:08 +08:00
parent affa44e4d0
commit 6b8a6a8789
50 changed files with 907 additions and 688 deletions
@@ -0,0 +1,188 @@
using System;
using System.Collections.Generic;
using SepCore.Definition;
using Entity.EntityData;
using UnityGameFramework.Runtime;
using SepCore.DataTable;
using CustomUtility;
namespace Entity
{
public static class EntityExtension
{
private static int s_SerialId = -10;
private const string EntityNamespace = "Entity.";
private static readonly Dictionary<string, Type> _typeDict;
private static readonly Dictionary<int, string> _assetNameDict;
static EntityExtension()
{
_typeDict = new Dictionary<string, Type>();
_assetNameDict = new Dictionary<int, string>();
}
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)
{
if (data == null)
{
Log.Warning("Enemy data is invalid.");
return;
}
var enemyType = TryGetType(data.EnemyType.ToString());
var assetName = TryGetAssetName(data.EntityTypeId);
entityComponent.ShowEntity(
entityId: data.Id,
entityLogicType: enemyType,
entityAssetName: AssetUtility.GetEntityAsset(assetName),
entityGroupName: "Enemy",
priority: Constant.AssetPriority.BulletAsset,
userData: data);
}
public static void ShowWeapon(this EntityComponent entityComponent, WeaponData data)
{
if (data == null)
{
Log.Warning("Weapon data is invalid.");
return;
}
var weaponType = TryGetType("Weapon." + data.WeaponType);
var assetName = TryGetAssetName(data.EntityTypeId);
entityComponent.ShowEntity(
entityId: data.Id,
entityLogicType: weaponType,
entityAssetName: AssetUtility.GetEntityAsset(assetName),
entityGroupName: "Weapon",
priority: Constant.AssetPriority.BulletAsset,
userData: data);
}
// public static void ShowBullet(this EntityComponent entityComponent, BulletData data)
// {
// if (data == null)
// {
// Log.Warning("Bullet data is invalid.");
// return;
// }
//
// var bulletType = TryGetType(data.BulletType.ToString());
// string assetName = TryGetAssetName(data.EntityTypeId);
//
// entityComponent.ShowEntity(
// entityId: data.Id,
// entityLogicType: bulletType,
// entityAssetName: AssetUtility.GetEntityAsset(assetName),
// entityGroupName: "Bullet",
// priority: Constant.AssetPriority.BulletAsset,
// userData: data);
// }
public static void ShowEffect(this EntityComponent entityComponent, EffectData data)
{
entityComponent.ShowEntity(typeof(Effect), "Effect", Constant.AssetPriority.EffectAsset, data);
}
public static void ShowCoin(this EntityComponent entityComponent, CoinData data)
{
entityComponent.ShowEntity(typeof(CoinEntity), "Drop", Constant.AssetPriority.EffectAsset, data);
}
public static void ShowExp(this EntityComponent entityComponent, ExpData data)
{
entityComponent.ShowEntity(typeof(ExpEntity), "Drop", Constant.AssetPriority.EffectAsset, 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;
}
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(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);
}
private static Type TryGetType(string rawTypeName)
{
string typeName = EntityNamespace + rawTypeName;
if (!_typeDict.TryGetValue(typeName, out Type type))
{
type = Type.GetType(typeName);
if (type == null)
{
Log.Warning("Can not load entity type '{0}'.", typeName);
return null;
}
_typeDict.Add(typeName, type);
}
return type;
}
private static string TryGetAssetName(int entityId)
{
if (!_assetNameDict.TryGetValue(entityId, out string assetName))
{
DREntity drEntity = GameEntry.DataTable.GetDataTableRow<DREntity>(entityId);
if (drEntity == null)
{
Log.Warning("Can not load bullet entity id '{0}' from data table.", entityId.ToString());
return null;
}
assetName = drEntity.AssetName;
_assetNameDict.Add(entityId, assetName);
}
return assetName;
}
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,171 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using SepCore.DataTable;
using SepCore.Definition;
using Entity;
using GameFramework;
using GameFramework.DataTable;
using GameFramework.Sound;
using UnityGameFramework.Runtime;
using CustomUtility;
namespace StarForce
{
public static class SoundExtension
{
private const float FadeVolumeDuration = 1f;
private static int? s_MusicSerialId = null;
public static int? PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
{
soundComponent.StopMusic();
IDataTable<DRMusic> dtMusic = GameEntry.DataTable.GetDataTable<DRMusic>();
DRMusic drMusic = dtMusic.GetDataRow(musicId);
if (drMusic == null)
{
Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
return null;
}
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = 64;
playSoundParams.Loop = true;
playSoundParams.VolumeInSoundGroup = 1f;
playSoundParams.FadeInSeconds = FadeVolumeDuration;
playSoundParams.SpatialBlend = 0f;
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
return s_MusicSerialId;
}
public static void StopMusic(this SoundComponent soundComponent)
{
if (!s_MusicSerialId.HasValue)
{
return;
}
soundComponent.StopSound(s_MusicSerialId.Value, FadeVolumeDuration);
s_MusicSerialId = null;
}
public static int? PlaySound(this SoundComponent soundComponent, int soundId, EntityBase bindingEntity = null, object userData = null)
{
IDataTable<DRSound> dtSound = GameEntry.DataTable.GetDataTable<DRSound>();
DRSound drSound = dtSound.GetDataRow(soundId);
if (drSound == null)
{
Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
return null;
}
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = drSound.Priority;
playSoundParams.Loop = drSound.Loop;
playSoundParams.VolumeInSoundGroup = drSound.Volume;
playSoundParams.SpatialBlend = drSound.SpatialBlend;
return soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData);
}
public static int? PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null)
{
IDataTable<DRUISound> dtUISound = GameEntry.DataTable.GetDataTable<DRUISound>();
DRUISound drUISound = dtUISound.GetDataRow(uiSoundId);
if (drUISound == null)
{
Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString());
return null;
}
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = drUISound.Priority;
playSoundParams.Loop = false;
playSoundParams.VolumeInSoundGroup = drUISound.Volume;
playSoundParams.SpatialBlend = 0f;
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
}
public static bool IsMuted(this SoundComponent soundComponent, string soundGroupName)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return true;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return true;
}
return soundGroup.Mute;
}
public static void Mute(this SoundComponent soundComponent, string soundGroupName, bool mute)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return;
}
soundGroup.Mute = mute;
GameEntry.Setting.SetBool(Utility.Text.Format(Constant.Setting.SoundGroupMuted, soundGroupName), mute);
GameEntry.Setting.Save();
}
public static float GetVolume(this SoundComponent soundComponent, string soundGroupName)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return 0f;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return 0f;
}
return soundGroup.Volume;
}
public static void SetVolume(this SoundComponent soundComponent, string soundGroupName, float volume)
{
if (string.IsNullOrEmpty(soundGroupName))
{
Log.Warning("Sound group is invalid.");
return;
}
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
if (soundGroup == null)
{
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
return;
}
soundGroup.Volume = volume;
GameEntry.Setting.SetFloat(Utility.Text.Format(Constant.Setting.SoundGroupVolume, soundGroupName), volume);
GameEntry.Setting.Save();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cded0c5c73a207a498c6e5af208e5f7e
timeCreated: 1528026160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: