1,技能,前面博客已经写过
有限状态机的变化控制,Itentity类,怪物打斗Entity中的OnTriggerEnter方法
//玩家进入塔,碰到别的怪物,走进树林
private void OnTriggerEnter(Collider other)
{
if (this.SyncEntity == null || !(other is SphereCollider))
{
return;
}
Iselfplayer player = PlayerManager.Instance.LocalPlayer;
if (this.SyncEntity.GameObjGUID != player.GameObjGUID) //当前ENTITY 不是玩家
{
return;
}
Entity entity = other.gameObject.GetComponent<Entity>();
if(entity == null || entity.SyncEntity == null) //进入对象的entity为空
{
return;
}
if (player.AbsorbMonsterType[0] == 0 && player.AbsorbMonsterType[1] == 0) //没有附身对象
{
return;
}
if (entity.SyncEntity.EntityCamp != player.EntityCamp || entity.SyncEntity.entityType != EntityType.Building //如果进入的不是友方祭坛、
|| entity.SyncEntity.NPCCateChild != ENPCCateChild.eNPCChild_BUILD_Altar)
{
return;
}
Game.AudioManager.Instance.PlayEffectAudio(player.GetAltarClip());
EventCenter.Broadcast(EGameEvent.eGameEvent_PlayerEnterAltar);
if (UIAltarSelect.Instance == null)
{
GameUI.Instance.OnOpenUI(GameConstDefine.AltarSoldierSelect);
UIAltarSelect.Instance.OnTriggerAltar(entity.SyncEntity);
}
}
2,数据
//战斗类信息
public class HeroBattleInfo
{
public UInt64 SGUID;
public string HeroName;
public int Level;
public int Kills;
public int Deaths;
public int Assist;//助攻
public int HeadIcon;
public int LastHit;//
public int Cp;
public EntityCampType campType;
public Dictionary<int, int> GoodsItemsInfo = new Dictionary<int, int>();
public Dictionary<int, int> GetItemsInfo()
{
return GoodsItemsInfo;
}
public void AddGoodItem(int index, int id)
{
if (!GoodsItemsInfo.ContainsKey(index))
{
GoodsItemsInfo.Add(index, id);
return;
}
GoodsItemsInfo[index] = id;
}
public void DelGoodsItem(int index)
{
if (GoodsItemsInfo.ContainsKey(index))
{
GoodsItemsInfo[index] = 0;
}
}
public int GetId(int index)
{
for (int i = 0; i < GoodsItemsInfo.Count; i++)
{
int id = GoodsItemsInfo.ElementAt(i).Value;
int temp = GoodsItemsInfo.ElementAt(i).Key;
if ((index) == temp)
{
index = id;
return index;
}
}
return 0;
}
public void ClearGoods()
{
GoodsItemsInfo.Clear();
}
}
/// <summary>
/// 播放效果音
/// </summary>
/// <param name="adClip"></param>
/// <returns></returns>
public AudioSource PlayEffectAudio(AudioClip adClip)
{
if (adClip == null)
{
return null;
}
AudioSource adio = EffectAudioSourceQueue.Dequeue();
adio.clip = adClip;
adio.volume = 1.0f;
adio.Play();
EffectAudioSourceQueue.Enqueue(adio);
return adio;
}
音效的队列
3,特效
频繁使用的放对象池中,如:特效,小怪,UITip,血条
每实例化一次都要申请内存造成很多内存碎片
对象池,一次性实例化出需要的数目,用的时候激活,不用的时候藏起来,
IselfPlayer====》Iplayer====》IEntity
经常改动的和具体逻辑放子类,玩家自己=======玩家=======建筑怪物玩家
数据驱动,模块化处理,FSM,网络处理
有限状态机 EntityFSM 状态类函数的父类
Itentity 实物类接口 EntityManager来管理
创建事物,已经把实物加入字典中进行存储
游戏物体在场景中出现的时候服务端会发消息
//游戏实体在场景中出现
public void OnNetMsg_NotifyGameObjectAppearCoroutine(System.IO.Stream stream)
{
if (GameStateManager.Instance.GetCurState().GetStateType() == GameStateType.GS_Play)
{
GSToGC.GOAppear pMsg;
if (!ProtoDes(out pMsg, stream))
{
return;
}
foreach (GSToGC.GOAppear.AppearInfo info in pMsg.info)
{
UInt64 sMasterGUID = info.masterguid;
UInt64 sObjGUID = info.objguid;
if (sObjGUID < 1)
{
Debug.LogError("objguid:" + sObjGUID);
}
Int32 IntCamp = info.camp;
Vector3 mvPos = this.ConvertPosToVector3(info.pos);
Vector3 mvDir = this.ConvertDirToVector3(info.dir);
mvDir.y = 0.0f;
EntityCampType Type = GameMethod.GetEntityCamp(IntCamp);
GSToGC.ObjType objType = info.obj_type;
if (EntityManager.AllEntitys.ContainsKey(sObjGUID))
{
if (objType == GSToGC.ObjType.ObjType_Hero)
{
PlayerManager.Instance.ShowEntity(sObjGUID, mvPos, mvDir);
//发送通知
EventCenter.Broadcast<Ientity>(EGameEvent.eGameEvent_AddMiniMap, EntityManager.AllEntitys[sObjGUID]);
}
continue;
}
Ientity entity = null;
if (CTools.IfTypeNPC((EObjectType)info.obj_type_id))
{
entity = NpcManager.Instance.HandleCreateEntity(sObjGUID, Type);
entity.EntityCamp = Type;
entity.ObjTypeID = info.obj_type_id;
NpcManager.Instance.CreateEntityModel(entity, sObjGUID, mvDir, mvPos);
}
else if (CTools.IfTypeHero((EObjectType)info.obj_type_id))
{
Iplayer player = null;
if (!PlayerManager.Instance.AccountDic.TryGetValue(sMasterGUID, out player))
{
player = (Iplayer)PlayerManager.Instance.HandleCreateEntity(sMasterGUID, Type);
player.ObjTypeID = info.obj_type_id;
PlayerManager.Instance.AddAccount(sMasterGUID, player);
}
player.EntityCamp = Type;
entity = player;
entity.ObjTypeID = info.obj_type_id;
PlayerManager.Instance.CreateEntityModel(entity, sObjGUID, mvDir, mvPos);
GameMethod.CreateCharacterController(player);
ReadPreLoadConfig.Instance.AddPreLoadRoleEffect((int)entity.ObjTypeID);
}
if (entity != null)
{
entity.GameObjGUID = sObjGUID;
EntityManager.Instance.AddEntity(sObjGUID, entity);
if (GameUserModel.Instance.IsLocalPlayer(sMasterGUID))
{
Debug.Log("Set local player guid!" + sMasterGUID);
PlayerManager.Instance.LocalPlayer = (Iselfplayer)entity;
GameMethod.GetMainCamera.target = entity.realObject.transform;
GamePlayCtrl.Instance.UpdateSkillPriv((int)info.obj_type_id);
CPChanggeManager.Instance.ClearList();
EventCenter.Broadcast(EGameEvent.eGameEvent_InitMiniMap);
}
entity.InitWhenCreateModel();
entity.OnCreateShadow();
entity.GOSSI.sServerBeginPos = mvPos;
entity.GOSSI.sServerSyncPos = mvPos;
//先改变状态机的数据层
entity.EntityFSMChangedata(mvPos, mvDir);
//实例化了一个freeFSM
entity.OnFSMStateChange(EntityFreeFSM.Instance);
//播放加载小地图的消息
EventCenter.Broadcast<Ientity>(EGameEvent.eGameEvent_AddMiniMap, entity);
}
}
}
// StartBattle();
}