public MonsterInit(UnitData ud, GameObject obj) { unitData = ud; spawnObj = obj; }
public void CreateChestFromNetwork(UnitData unitData, SpawnChest spawn, EntityInfo info = null) { Log.Sys("Create Chest Unit " + unitData.name); var Resource = Resources.Load <GameObject>(unitData.ModelName); GameObject g = Instantiate(Resource) as GameObject; NpcAttribute npc = NGUITools.AddMissingComponent <NpcAttribute>(g); npc.spawnTrigger = spawn.gameObject; g.transform.parent = transform; g.tag = GameTag.Enemy; g.layer = (int)GameLayer.Npc; var type = Type.GetType("MyLib." + unitData.AITemplate); var t = typeof(NGUITools); var m = t.GetMethod("AddMissingComponent"); Log.AI("Monster Create Certain AI " + unitData.AITemplate + " " + type); var geMethod = m.MakeGenericMethod(type); geMethod.Invoke(null, new object[] { g });// as AIBase; var netView = g.GetComponent <KBEngine.KBNetworkView>(); //服务器返回的ViewId //Owner 客户端怪物 服务器怪物 //Id ViewId if (info != null) { netView.SetID(new KBEngine.KBViewID(info.Id, myPlayer)); } else { netView.SetID(new KBEngine.KBViewID(-1, myPlayer)); } netView.IsPlayer = false; npc.SetObjUnitData(unitData); AddObject(netView.GetServerID(), netView); //不算怪物允许不去打 if (info != null) { npc.transform.position = NetworkUtil.FloatPos(info.X, info.Y, info.Z); } else { npc.transform.position = spawn.transform.position; } BattleManager.battleManager.AddEnemy(npc.gameObject); npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead; var sync = npc.GetComponent <MonsterSync>(); if (sync != null) { sync.SyncAttribute(info); } }
public MonsterInit(UnitData ud, SpawnTrigger sp) { unitData = ud; spawn = sp; }