-
Notifications
You must be signed in to change notification settings - Fork 42
Status
jiepengtan edited this page Nov 20, 2019
·
3 revisions
- 需要在文件 __DllSourceFiles/Tools.UnsafeECS.ECDefine/Src/Unsafe/Status.cs 中进行定义
- 其中类型 GameStateService 中的 public 成员定义的是在游戏中可以改变的全局变量
- 框架会帮你自动进行状态的备份以及还原
public partial class GameStateService : IServiceState,IGameStateService {
// states
public bool IsPlaying;
public bool IsGameOver;
public byte LocalEntityId;
// volatile states
public int CurScore;
}
- 在相应的System 中可以直接 通过成员 _gameStateService 进行数据的读写
public unsafe partial class DestroySystem : GameExecuteSystem {
public void Execute(Entity* entity, ref BoidState boidState){
if (!boidState.IsDied) return;
if (!boidState.IsScored) {
_gameStateService.CurScore++;// 代码在这里
var ptr = _context.GetBoidObstacle(boidState.Killer);
if (ptr!= null && ptr->IsActive) {
ptr->Player.Score++;
}
boidState.IsScored = true;
}
if (boidState.SinkTimer < 0) {
_context.PostCmdDestroyEntity(entity);
}
}
protected override void AfterSchedule(bool isSucc){
//assign jobData info
_gameStateService.CurEnemyCount = _context.CurBoidCount;// 代码在这里
}
}
- 其中类型 GameConfigService 中的 public 成员定义的是在游戏中的简单配置,在游戏加载后就不再变动,
- 框架会自动帮你生成相关的ScriptObject 方便进行配置(其中使用到的类型只需要声明有这样的一个类型,仅需编译通过即可)
public class CollisionConfig { }//仅需在这里给出声明,相应的定义可以放到Game.Model dll 中
public class Msg_G2C_GameStartInfo { }//仅需在这里给出声明,相应的定义可以放到Game.Model dll 中
public class ConfigPlayerInfo{}//仅需在这里给出声明,相应的定义可以放到Game.Model dll 中
public partial class GameConfigService : IServiceState,IGameConfigService {
public string RelPath;//保留给框架使用
public string RecorderFilePath;//保留给框架使用
public string DumpStrPath;//保留给框架使用
public CollisionConfig CollisionConfig;//保留给框架使用
public Msg_G2C_GameStartInfo ClientModeInfo;//保留给框架使用
public int MaxPlayerCount;
public List<ConfigPlayerInfo> PlayerInfos;
}
- 在相应的System 中可以直接 通过成员 _gameConfigService 进行数据的读写
public unsafe class InitSystem : GameBaseSystem, IInitializeSystem {
public void Initialize(IContext context){
_context.HasInit = true;
var config = _gameConfigService;// 代码在这里
int playerId = 0;
var count = _globalStateService.ActorCount;
for (int i = 0; i < count; i++) {
var obstacleInfo = config.PlayerInfos[i % config.PlayerInfos.Count];
var entity = _context.PostCmdCreatePlayerCube();
entity->Transform.Position = obstacleInfo.Position;
//... other codes
Debug.Log("Create ObstacleInfos " + entity->Player.LocalId);
}
}
}
- 相应的配置文件在目录 Resources/Config/UnityGameConfig.asset
- 如果修改了配置,请点击ToJson按钮,生成运行时数据