Example #1
0
        ///<summary>
        /// 副本内怪物构建流程
        /// 单人副本通过Scene配置来产生怪物
        /// 多人副本通过服务器推送消息产生怪物
        /// </summary>
        //TODO: 多人副本怪物产生机制
        public void CreateMonster(UnitData unitData, SpawnTrigger spawn)
        {
            if (WorldManager.worldManager.station == WorldManager.WorldStation.Enter)
            {
                Log.Sys("UnityDataIs " + unitData.ID);
                if (unitData.Config == null)
                {
                    Debug.LogError("NotFoundMonster " + unitData.ID);
                    return;
                }

                Log.Sys("Create Monster Unit " + unitData.name);
                var Resource = Resources.Load <GameObject>(unitData.ModelName);
                //本地怪兽不需要Player信息
                GameObject   g   = Instantiate(Resource) as GameObject;
                NpcAttribute npc = NGUITools.AddMissingComponent <NpcAttribute>(g);
                npc.spawnTrigger = spawn.gameObject;

                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);
                //var petAI =
                geMethod.Invoke(null, new object[] { g });// as AIBase;


                g.transform.parent = transform;
                g.tag              = GameTag.Enemy;
                g.layer            = (int)GameLayer.Npc;
                spawn.FirstMonster = g;

                var netView = g.GetComponent <KBEngine.KBNetworkView>();
                netView.SetID(new KBEngine.KBViewID(-1, myPlayer));
                netView.IsPlayer = false;

                npc.SetObjUnitData(unitData);
                AddObject(netView.GetServerID(), netView);


                float   angle = UnityEngine.Random.Range(0, 360);
                Vector3 v     = Vector3.forward;
                v = Quaternion.Euler(new Vector3(0, angle, 0)) * v;
                float rg = UnityEngine.Random.Range(0, spawn.Radius);

                npc.transform.position = spawn.transform.position + v * rg;
                if (unitData.IsElite)
                {
                    npc.transform.localScale = new Vector3(2, 2, 2);
                }

                BattleManager.battleManager.AddEnemy(npc.gameObject);
                npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;
                //npc.Level = spawn.Level;
            }
            else
            {
                cacheMonster.Add(new MonsterInit(unitData, spawn));
            }
        }
Example #2
0
        public void SpawnChild(SpawnTrigger trigger)
        {
            var allChild = trigger.GetChildPoint();

            foreach (var c in allChild)
            {
                ObjectManager.objectManager.CreatePet(trigger.MonsterID, trigger.FirstMonster, (Affix)null,
                                                      c.transform.position);
            }
        }
Example #3
0
 public MonsterInit(UnitData ud, SpawnTrigger sp)
 {
     unitData = ud;
     spawn    = sp;
 }