public override void OnPlayerJoin(EntityBase entity) { if (!entity.GetExistComp(ComponentType.MoveComponent)) { MoveComponent c = new MoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp(ComponentType.CommandComponent)) { CommandComponent c = new CommandComponent(); entity.AddComp(c); } }
public override void OnPlayerJoin(EntityBase entity) { if (!entity.GetExistComp <TestMoveComponent>()) { TestMoveComponent c = new TestMoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <TestCommandComponent>()) { TestCommandComponent c = new TestCommandComponent(); entity.AddComp(c); } }
/// <summary> /// 使用指定的实体ID创建实体,不建议直接使用 /// </summary> /// <param name="ID"></param> /// <returns></returns> public EntityBase CreateEntity(int ID, params ComponentBase[] compList) { if (m_entityDict.ContainsKey(ID)) { throw new Exception("CreateEntity Exception: Entity ID has exist ! ->" + ID + "<-"); } EntityBase entity = new EntityBase(); entity.ID = ID; entity.World = this; m_entityList.Add(entity); m_entityDict.Add(ID, entity); if (compList != null) { for (int i = 0; i < compList.Length; i++) { entity.AddComp(compList[i].GetType().Name, compList[i]); } } entity.OnComponentAdded += OnEntityComponentAdded; entity.OnComponentRemoved += OnEntityComponentRemoved; entity.OnComponentReplaced += OnEntityComponentChange; if (OnEntityCreated != null) { OnEntityCreated(entity); } return(entity); }
void AddComp(EntityBase entity) { if (!entity.GetExistComp <BuffEffectComponent>()) { entity.AddComp <BuffEffectComponent>(); } }
EntityBase NewEntity(int ID, params ComponentBase[] compList) { EntityBase entity = null; if (GetIsExistDispatchDestroyCache(ID)) { entity = GetDispatchDestroyCache(ID); CopyValue(compList, entity); } else { entity = new EntityBase(); entity.ID = ID; entity.World = this; entity.m_CreateFrame = FrameCount; if (compList != null) { for (int i = 0; i < compList.Length; i++) { entity.AddComp(compList[i].GetType().Name, compList[i]); } } } return(entity); }
void AddComp(EntityBase entity) { if (!entity.GetExistComp <SkillBehaviorCompoent>()) { entity.AddComp <SkillBehaviorCompoent>(); } }
void AddComp(EntityBase entity) { if (!entity.GetExistComp <PerfabComponent>()) { entity.AddComp <PerfabComponent>(); } }
public void AddRecordComponent(EntityBase entity) { if (!entity.GetExistComp(ComponentType.PlayerCommandRecordComponent)) { PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent(); //自动添加记录组件 entity.AddComp(rc); } }
//void ReceviceCmdMsg(CommandMsg msg, params object[] objs) //{ // //Debug.Log("ReceviceCmdMsg " + msg.index + " currentframe " + m_world.FrameCount); // //立即返回确认消息 // AffirmMsg amsg = new AffirmMsg(); // amsg.index = msg.index; // amsg.time = msg.serverTime; // ProtocolAnalysisService.SendCommand(amsg); // if (m_world.IsStart) // { // //TODO 如果全部都与本地预测相同则不再重计算 // for (int i = 0; i < msg.msg.Count; i++) // { // //Debug.Log("RecordCommand " + Serializer.Serialize(msg.msg[i])); // RecordCommand(msg.msg[i]); // } // Recalc(); // } // else // { // //存入未执行命令列表 // //Debug.Log("存入未执行命令列表"); // //GameDataCacheComponent gdcc = m_world.GetSingletonComp<GameDataCacheComponent>(); // //gdcc.m_noExecuteCommandList.Add(msg); // } //} //void RecordCommand(CommandInfo cmd) //{ // //EntityBase entity = m_world.GetEntity(cmd.id); // //AddComp(entity); //自动添加记录组件 // //PlayerCommandRecordComponent pcrc = entity.GetComp<PlayerCommandRecordComponent>(); // //PlayerCommandBase remote = cmd.ToCommand(); // //PlayerCommandBase record = pcrc.GetInputCahae(cmd.frame); // //if (entity.GetExistComp<SelfComponent>()) // //{ // // Debug.LogWarning("set is all"); // //} // ////判断和本地的预测有没有冲突 // //if (record == null || !record.EqualsCmd(remote)) // //{ // // if (entity.GetExistComp<SelfComponent>()) // // { // // Debug.LogWarning("覆盖本地指令! "); // // } // // pcrc.SetConflict(cmd.frame, true); // //} // //else // //{ // // pcrc.SetConflict(cmd.frame, false); // //} // //pcrc.RecordCommand(remote); //} public void AddComp(EntityBase entity) { if (!entity.GetExistComp <PlayerCommandRecordComponent>()) { PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent(); rc.m_defaultInput = new T(); //自动添加记录组件 entity.AddComp(rc); } }
public override void OnEntityCompAdd(EntityBase entity, string compName, ComponentBase component) { if (entity.GetExistComp <T>()) { if (!entity.GetExistComp <PlayerCommandRecordComponent>()) { //自动添加记录组件 entity.AddComp <PlayerCommandRecordComponent>(); } } }
public void AddComp(EntityBase entity) { if (!entity.GetExistComp(ComponentType.PlayerCommandRecordComponent)) { //Debug.Log("OnEntityCompAdd PlayerCommandRecordComponent"); PlayerCommandRecordComponent rc = new PlayerCommandRecordComponent(); rc.m_defaultInput = new T(); //自动添加记录组件 entity.AddComp(rc); } }
public override void OnEntityCreate(EntityBase entity) { //Debug.Log("OnEntityCreate ID: " + entity.ID + " frame " + m_world.FrameCount); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { //Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } }
EntityBase NewEntity(int ID, params ComponentBase[] compList) { EntityBase entity = new EntityBase(); entity.ID = ID; entity.World = this; if (compList != null) { for (int i = 0; i < compList.Length; i++) { entity.AddComp(compList[i].GetType().Name, compList[i]); } } return(entity); }
public override void OnEntityOptimizeCreate(EntityBase entity) { if (GetAllExistComp(new string[] { "AssetComponent", "TransfromComponent" }, entity)) { Debug.Log("接收到创建 "); AddComp(entity); AssetComponent ac = entity.GetComp <AssetComponent>(); TransfromComponent tc = entity.GetComp <TransfromComponent>(); PerfabComponent comp = entity.GetComp <PerfabComponent>(); comp.perfab = GameObjectManager.CreateGameObject(ac.m_assetName); comp.hardPoint = comp.perfab.GetComponent <HardPointComponent>(); if (tc.parentID == 0) { comp.perfab.transform.position = tc.pos.ToVector(); } else { EntityBase parent = m_world.GetEntity(tc.parentID); //if (parent.GetExistComp<PerfabComponent>()) //{ // PerfabComponent pc = parent.GetComp<PerfabComponent>(); // comp.perfab.transform.SetParent(pc.perfab.transform); //} comp.perfab.transform.localPosition = tc.pos.ToVector(); } //创建动画组件 if (comp.perfab.GetComponent <Animator>() != null) { AnimComponent anc = entity.AddComp <AnimComponent>(); anc.anim = comp.perfab.GetComponent <Animator>(); anc.perfab = comp.perfab; anc.waistNode = comp.hardPoint.waistNode; } } }
protected override void OnNewSessionConnected(SyncSession session) { Debug.Log("SyncService OnNewSessionConnected " + session.SessionID); base.OnNewSessionConnected(session); WaitSyncComponent wsc = new WaitSyncComponent(); ConnectionComponent conn = new ConnectionComponent(); conn.m_session = session; PlayerComponent pc = new PlayerComponent(); CommandComponent cc = new CommandComponent(); SyncComponent syc = new SyncComponent(); syc.m_waitSyncList.Add(conn); ViewComponent vc = new ViewComponent(); AssetComponent ac = new AssetComponent(); MoveComponent mc = new MoveComponent(); ac.m_assetName = "Cube"; EntityBase entity = m_world.CreateEntity(id++); entity.AddComp(conn); entity.AddComp(pc); entity.AddComp(syc); entity.AddComp(vc); entity.AddComp(ac); entity.AddComp(cc); entity.AddComp(mc); entity.AddComp(wsc); session.m_entity = entity; session.m_connect = conn; Debug.Log("new entity " + id); }
public override void OnEntityCreate(EntityBase entity) { Debug.Log("OnEntityCreate ID: " + entity.ID + " frame " + m_world.FrameCount); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } //if (m_world.SyncRule == SyncRule.Status) //{ // SetAllSync(sc); //} }
public override void OnEntityCreate(EntityBase entity) { Debug.Log("OnEntityCreate "); SyncComponent sc = null; //自动创建Sync组件 if (!entity.GetExistComp <SyncComponent>()) { Debug.Log("自动创建Sync组件 "); sc = entity.AddComp <SyncComponent>(); } else { sc = entity.GetComp <SyncComponent>(); } if (m_world.SyncRule == SyncRule.Status) { SetAllSync(sc); } }
///// <summary> ///// 立即创建一个实体,不要在游戏逻辑中使用 ///// </summary> ///// <param name="ID"></param> ///// <param name="compList"></param> ///// <returns></returns> //public EntityBase CreateEntityImmediately(int ID, params ComponentBase[] compList) //{ // if (m_entityDict.ContainsKey(ID)) // { // throw new Exception("CreateEntity Exception: Entity ID has exist ! ->" + ID + "<-"); // } // EntityBase entity = NewEntity(ID, compList); // CreateEntityAndDispatch(entity); // return entity; //} EntityBase NewEntity(string name, int ID, params ComponentBase[] compList) { EntityBase entity = null; if (GetIsExistDispatchDestroyCache(ID)) { entity = GetDispatchDestroyCache(ID); CopyValue(compList, entity); } else { entity = new EntityBase(); entity.ID = ID; entity.name = name; entity.World = this; entity.CreateFrame = FrameCount; if (compList != null) { for (int i = 0; i < compList.Length; i++) { if (compList[i] != null) { entity.AddComp(compList[i].GetType().Name, compList[i]); } else { Debug.LogError("NewEntity component is null ! name " + name + " id " + ID); } } } } return(entity); }
public void PlayerJoin(EntityBase entity) { PlayerComponent playerComp = null; if (!entity.GetExistComp <PlayerComponent>()) { playerComp = new PlayerComponent(); playerComp.characterID = "1"; playerComp.nickName = "Test model"; ElementData e1 = new ElementData(); e1.id = 100; e1.num = 10; playerComp.elementData.Add(e1); ElementData e2 = new ElementData(); e2.id = 101; e2.num = 10; playerComp.elementData.Add(e2); ElementData e3 = new ElementData(); e3.id = 102; e3.num = 10; playerComp.elementData.Add(e3); ElementData e4 = new ElementData(); e4.id = 103; e4.num = 00; playerComp.elementData.Add(e4); entity.AddComp(playerComp); } if (!entity.GetExistComp <CommandComponent>()) { CommandComponent c = new CommandComponent(); entity.AddComp(c); } if (!entity.GetExistComp <TransfromComponent>()) { TransfromComponent c = new TransfromComponent(); entity.AddComp(c); } if (!entity.GetExistComp <AssetComponent>()) { AssetComponent c = new AssetComponent(); c.m_assetName = "famale_01"; entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); c.pos.FromVector(new Vector3(15, 0, 0)); entity.AddComp(c); } if (!entity.GetExistComp <SkillStatusComponent>()) { SkillStatusComponent c = new SkillStatusComponent(); DataTable data = DataManager.GetData("SkillData"); for (int i = 0; i < data.TableIDs.Count; i++) { c.m_skillList.Add(new SkillData(data.TableIDs[i], i)); } entity.AddComp(c); } if (!entity.GetExistComp <CDComponent>()) { CDComponent c = new CDComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CampComponent>()) { CampComponent c = new CampComponent(); c.creater = entity.ID; entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CollisionComponent>()) { CollisionComponent c = new CollisionComponent(); c.area.areaType = AreaType.Circle; c.area.radius = 0.5f; entity.AddComp(c); } if (!entity.GetExistComp <LifeComponent>()) { LifeComponent c = new LifeComponent(); c.maxLife = playerComp.CharacterData.m_hp; c.life = playerComp.CharacterData.m_hp; entity.AddComp(c); } if (!entity.GetExistComp <BlowFlyComponent>()) { BlowFlyComponent c = new BlowFlyComponent(); entity.AddComp(c); } }
public void RevertRemoveComp(ChangeRecordInfo info) { EntityBase entity = m_world.GetEntity(info.m_EnityID); entity.AddComp(info.m_compName, info.m_comp); }
public void PlayerJoin(EntityBase entity) { if (!entity.GetExistComp <CommandComponent>()) { CommandComponent c = new CommandComponent(); entity.AddComp(c); } if (!entity.GetExistComp <ViewComponent>()) { ViewComponent c = new ViewComponent(); entity.AddComp(c); } if (!entity.GetExistComp <AssetComponent>()) { AssetComponent c = new AssetComponent(); c.m_assetName = "famale_01"; entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <PlayerComponent>()) { PlayerComponent c = new PlayerComponent(); entity.AddComp(c); } if (!entity.GetExistComp <SkillStatusComponent>()) { SkillStatusComponent c = new SkillStatusComponent(); DataTable data = DataManager.GetData("SkillData"); for (int i = 0; i < data.TableIDs.Count; i++) { c.m_skillList.Add(new SkillData(data.TableIDs[i], i)); } entity.AddComp(c); } if (!entity.GetExistComp <CDComponent>()) { CDComponent c = new CDComponent(); entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CampComponent>()) { CampComponent c = new CampComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CollisionComponent>()) { CollisionComponent c = new CollisionComponent(); c.area.areaType = AreaType.Circle; c.area.radius = 0.5f; entity.AddComp(c); } if (!entity.GetExistComp <LifeComponent>()) { LifeComponent c = new LifeComponent(); c.maxLife = 100; c.life = 100; entity.AddComp(c); } //预测一个输入 //TODO 放在框架中 if (entity.GetExistComp <ConnectionComponent>()) { ConnectionComponent cc = entity.GetComp <ConnectionComponent>(); cc.m_lastInputCache = new CommandComponent(); } }
public void PlayerJoin(EntityBase entity) { ConnectionComponent connectComp = entity.GetComp <ConnectionComponent>(); PlayerComponent playerComp = null; if (!entity.GetExistComp <PlayerComponent>()) { playerComp = new PlayerComponent(); entity.AddComp(playerComp); } else { playerComp = entity.GetComp <PlayerComponent>(); } //将角色ID传入游戏 playerComp.characterID = connectComp.m_session.player.characterID; playerComp.nickName = connectComp.m_session.player.playerID; ElementData e1 = new ElementData(); e1.id = 100; e1.num = 10; playerComp.elementData.Add(e1); ElementData e2 = new ElementData(); e2.id = 101; e2.num = 10; playerComp.elementData.Add(e2); ElementData e3 = new ElementData(); e3.id = 102; e3.num = 10; playerComp.elementData.Add(e3); ElementData e4 = new ElementData(); e4.id = 103; e4.num = 00; playerComp.elementData.Add(e4); if (!entity.GetExistComp <CommandComponent>()) { CommandComponent c = new CommandComponent(); entity.AddComp(c); } if (!entity.GetExistComp <TransfromComponent>()) { TransfromComponent c = new TransfromComponent(); c.pos.FromVector(new Vector3(15, 0, 0)); entity.AddComp(c); } if (!entity.GetExistComp <AssetComponent>()) { AssetComponent c = new AssetComponent(); c.m_assetName = playerComp.CharacterData.m_ModelID; entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); c.pos.FromVector(new Vector3(15, 0, 0)); entity.AddComp(c); } if (!entity.GetExistComp <SkillStatusComponent>()) { SkillStatusComponent c = new SkillStatusComponent(); DataTable data = DataManager.GetData("SkillData"); for (int i = 0; i < data.TableIDs.Count; i++) { c.m_skillList.Add(new SkillData(data.TableIDs[i], i)); } entity.AddComp(c); } if (!entity.GetExistComp <CDComponent>()) { CDComponent c = new CDComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CampComponent>()) { CampComponent c = new CampComponent(); c.creater = entity.ID; entity.AddComp(c); } if (!entity.GetExistComp <MoveComponent>()) { MoveComponent c = new MoveComponent(); entity.AddComp(c); } if (!entity.GetExistComp <CollisionComponent>()) { CollisionComponent c = new CollisionComponent(); c.area.areaType = AreaType.Circle; c.area.radius = 0.5f; entity.AddComp(c); } if (!entity.GetExistComp <LifeComponent>()) { LifeComponent c = new LifeComponent(); c.maxLife = playerComp.CharacterData.m_hp; c.life = playerComp.CharacterData.m_hp; entity.AddComp(c); } if (!entity.GetExistComp <BlowFlyComponent>()) { BlowFlyComponent c = new BlowFlyComponent(); entity.AddComp(c); } //预测一个输入 //TODO 放在框架中 if (entity.GetExistComp <ConnectionComponent>()) { ConnectionComponent cc = entity.GetComp <ConnectionComponent>(); cc.m_lastInputCache = new CommandComponent(); cc.m_defaultInput = new CommandComponent(); } GameTimeComponent gtc = m_world.GetSingletonComp <GameTimeComponent>(); gtc.GameTime = 10000 * 1000; }