private MonsterCreature GetMonsterCreature(PNmlMonster monsterData) { MonsterCreature monster = null; List <MonsterCreature> list = m_deadMonsterCreatureDic.Get(monsterData.monster); if (list != null && list.Count > 0) { monster = list[0]; monster.monsterUID = monsterData.uid; list.RemoveAt(0); } if (monster == null) { monster = MonsterCreature.CreateBordlandMonster(monsterData, Vector3.zero, new Vector3(0f, 90f, 0f)); } if (!monster) { return(null); } if (!monster.gameObject) { Logger.LogError("monster is valid ,but monster gameobject is null ,monster mesh is {0}", monsterData.mesh); monster.Destroy(); return(null); } monster.enableUpdate = false; monster.gameObject?.SetActive(true); return(monster); }
private void CreateMonsterCreature(PNmlMonster[] datas) { StopCreateMonster(); m_loadMonsterCoroutine = Level.PrepareAssets(GetMonsterPreloadAssets(datas), (flag) => { if (!flag) { Logger.LogError("borderland player assets isn't prepare....."); return; } for (int i = 0; i < datas.Length; i++) { PNmlMonster data = datas[i]; if (!m_bordlandMonster.ContainsKey(data.uid)) { continue; } MonsterCreature monster = GetMonsterCreature(data); HandleMonster(monster, data); } }); }
public void LoadMonsterRuntimeAnimator(string animatorName, PNmlMonster data) { playerType = BordLandCreatureType.Monster; monsterData = data; useStateMachine = false; var ani = Level.GetPreloadObject <Object>(animatorName, false); if (animator == null) { animator = GetComponent <Animator>(); } animator.runtimeAnimatorController = (RuntimeAnimatorController)ani; animator.enabled = true; m_standHash = Animator.StringToHash(data.standAction); m_runHash = Animator.StringToHash(data.moveAction); if (!animator.HasState(0, m_standHash)) { Logger.LogError("[recv server data ID = {0} stand action = {1}] cannot be finded in animator_borderlandr", data.monster, data.standAction); } if (!animator.HasState(0, m_runHash)) { Logger.LogError("[recv server data ID = {0} move action = {1}] cannot be finded in animator_borderland", data.monster, data.moveAction); } }
/// <summary> /// 延迟处理怪物,等待资源加载完毕 /// </summary> /// <param name="monster"></param> public void HandleMonster(MonsterCreature monster, PNmlMonster data) { if (!monster || !monster.gameObject || !monster.behaviour || !monster.activeRootNode) { return; } monster.behaviour.enabled = false; monster.behaviour.collider_.syncPosition = false; monster.behaviour.collider_.transform.localPosition = Vector3.zero; Util.SetLayer(monster.gameObject, Layers.MODEL); monster.gameObject.name = Util.Format("monster_{0}_{1}_{2}", data.uid, (EnumBordlandMonsterType)data.type, data.boss); monster.isPlayer = false; BordlandsCreature bc = monster.activeRootNode.GetComponentDefault <BordlandsCreature>(); bc.LoadMonsterRuntimeAnimator(BORDLAND_MONSTER_ANIMATOR_NAME, data); bc.moveSpeed = GetMonsterMoveSpeed(data.mesh); bc.creature = monster; bc.ResetToOriginal(); bc.SetMonsterRandomDir(); bc.InitPVECreatureBehaviour(); bc.CreateCollider(); Vector3 pos = data.pos.ToVector3(); Vector4 levelEdge = bordlandsEdge; if (levelEdge.z == levelEdge.w) { levelEdge = new Vector4(-22f, 22f, -1.4f, 2f); m_edge = levelEdge; } // edge check if (levelEdge.x != 0 || levelEdge.x != levelEdge.y) { pos.x = Mathf.Clamp(pos.x, levelEdge.x, levelEdge.y); } if (levelEdge.z != 0 || levelEdge.z != levelEdge.w) { pos.z = Mathf.Clamp(pos.z, levelEdge.z, levelEdge.w); } bc.creaturePos = pos; if (!m_monsterCreature.ContainsKey(data.uid)) { m_monsterCreature.Add(data.uid, bc); } else { m_monsterCreature[data.uid] = bc; } }
/// <summary> /// 初始化创建怪物 /// </summary> public void CreateMonsterFromModuleData() { //只用于初始化 if (m_isInitMonster) { return; } m_isInitMonster = true; PNmlMonster[] monsters = new PNmlMonster[m_bordlandMonster.Count]; m_bordlandMonster.Values.CopyTo(monsters, 0); CreateMonsterCreature(monsters); }
public static MonsterCreature CreateBordlandMonster(PNmlMonster monsterData, Vector3_ pos, Vector3 rot, string name = "", string uiName = "") { if (monsterData == null) { Logger.LogError("MonsterCreature::CreateBordlandMonster: Create monster failed, invalid monster data"); return(null); } var rootNode = new GameObject().transform; if (!CreateMorphNodes(new string[] { monsterData.mesh.ToLower() }, rootNode)) { Logger.LogError("MonsterCreature::CreateBordlandMonster: Create monster failed, model [{0}] not loaded", monsterData.mesh.ToLower()); return(null); } rootNode.position = pos; rootNode.eulerAngles = rot; var c = Create <MonsterCreature>(string.IsNullOrEmpty(name) ? Util.Format("bordland_monster_{0}", monsterData.uid) : name, rootNode.gameObject); c.InitPosition(pos); c.isPlayer = false; c.isMonster = true; c.uiName = string.IsNullOrEmpty(uiName) ? c.name : uiName; c.monsterId = monsterData.monster; //怪物属性记录 c.monsterInfo = ConfigManager.Find <MonsterInfo>(config => config.GetModel() == monsterData.mesh.ToLower()); c.height = (c.monsterInfo && c.monsterInfo.hitColliderSize.y > 0) ? c.monsterInfo.hitColliderSize.y : 2.0f; c.monsterUID = monsterData.uid; c.monsterGroup = 0; c.creatureCamp = CreatureCamp.MonsterCamp; c.monsterLevel = 0; c.isBoss = false; c.isSendDeathCondition = false; return(c); }
private void CreateMonsterFromMsg(PNmlMonster[] pMonster) { PNmlMonster[] monsterList = null; pMonster.CopyTo(ref monsterList); //管理本地怪物对象池 for (int i = 0; i < monsterList.Length; i++) { PNmlMonster monster = monsterList[i]; if (m_bordlandMonster.ContainsKey(monster.uid)) { Logger.LogInfo("monster_uid = {0} is has loaded,check out!", monster.uid); continue; } //Logger.LogInfo("monster.uid = {0}", monster.uid); m_bordlandMonster.Add(monster.uid, monster); } //已经生成了怪物之后才能直接通过消息生成怪物 if (m_isInitMonster) { CreateMonsterCreature(monsterList); } }
void _Packet(ScNmlSceneObjState p) { EnumBordlandCreatureState state = (EnumBordlandCreatureState)p.state; if (m_bordlandMonster.ContainsKey(p.uid)) { Logger.LogInfo("monster.uid = {0},state change to {1}", p.uid, state); if (state == EnumBordlandCreatureState.LeaveFromScene) { m_bordlandMonster.Remove(p.uid); BordlandsCreature bc = m_monsterCreature.Get(p.uid); if (bc) { bc.gameObject.SetActive(false); bc.ResetToOriginal(); m_monsterCreature.Remove(p.uid); AddDeadMonsterCreature(bc.creature as MonsterCreature); } } else { //更新数据层 PNmlMonster pm = m_bordlandMonster.Get(p.uid); if (pm != null) { pm.state = p.state; } //更新UI层 BordlandsCreature bc = m_monsterCreature.Get(p.uid); if (bc) { bc.monsterData.state = p.state; bc.isInBattle = state == EnumBordlandCreatureState.Fighting; } } } else if (m_bordlandPlayers.ContainsKey(p.uid)) { Logger.LogInfo("player.uid = {0},state change to {1}", p.uid, state); if (state == EnumBordlandCreatureState.LeaveFromScene) { m_bordlandPlayers.Remove(p.uid); BordlandsCreature bc = m_otherPlayerCreatures.Get(p.uid); if (bc) { //离开后需要关掉宠物AI if (bc.creature.pet != null) { moduleAI.RemovePetAI(bc.creature.pet); } bc.gameObject.SetActive(false); m_otherPlayerCreatures.Remove(p.uid); bc.creature.Destroy(); } } else { PNmlPlayer pm = m_bordlandPlayers.Get(p.uid); if (pm != null) { pm.state = p.state; } BordlandsCreature bc = m_otherPlayerCreatures.Get(p.uid); if (bc) { bc.roleInfo.state = p.state; bc.isInBattle = state == EnumBordlandCreatureState.Fighting; } } } else { Logger.LogError("scene_obj_uid = {0} doesn't load,check out!", p.uid); } }