public void CreateUnVision() { //创建碰撞提 SpecialAreaInSceneData[] areaData = reader.GetSceneEditorElementData <SpecialAreaInSceneData>(); if (areaData != null && areaData.Length > 0) { GameObject ptObj = new GameObject("boxcollider"); UnityUtils.AddChild_Reverse(ptObj, ScenePoint); for (int i = 0; i < areaData.Length; i++) { GameObject obj = new GameObject(i.ToString()); UnityUtils.AddChild_Reverse(obj, ptObj); //调整大小 obj.transform.position = new Vector3(areaData [i].pos [0], areaData [i].pos [1], areaData [i].pos [2]); obj.transform.localScale = new Vector3(areaData [i].scale [0], areaData [i].scale [1], areaData [i].scale [2]); obj.transform.eulerAngles = new Vector3(areaData [i].rotation [0], areaData [i].rotation [1], areaData [i].rotation [2]); //添加碰撞 BoxCollider box = obj.AddComponent <BoxCollider>(); box.center = Vector3.zero; box.size = Vector3.one; } } }
/// <summary> /// 目前,Trigger的这个触发器,仅仅用来触发场景里面的,和技能无关 /// 技能触发器在WarManager里面 /// </summary> /// <returns>The trigger.</returns> protected ServerNPC createTrigger() { GameObject go = new GameObject("Trigger"); UnityUtils.AddChild_Reverse(go, WarPoint); ServerNPC npc = go.AddComponent <ServerNPC>(); npc.Group = 0; npc.Camp = CAMP.None; /// /// 向WarManager注册 /// if (WarSMgr != null) { WarSMgr.npcMgr.SignID(npc); WarSMgr.npcMgr.RegisterTagNpc("Trigger", npc); /// /// --- 这里创建的都是逻辑型触发器,没有配置 ---- /// --- UseSkill 和 OnKilled都有转发的功能 ---- /// WarSMgr.triMgr.CreateTrigger(WarMsg_Type.BeKilled, npc.UniqueID); WarSMgr.triMgr.CreateTrigger(WarMsg_Type.OnAttacked, npc.UniqueID); WarSMgr.triMgr.CreateTrigger(WarMsg_Type.BeAttacked, npc.UniqueID); WarSMgr.triMgr.CreateTrigger(WarMsg_Type.UseSkill, npc.UniqueID); WarSMgr.triMgr.CreateTrigger(WarMsg_Type.OnKilled, npc.UniqueID); } return(npc); }
/// <summary> /// 创建NPC, 使用初始化好的数据 /// </summary> /// <param name="num">Number.</param> /// <param name="id">Identifier.</param> /// <param name="camp">Camp.</param> public ClientNPC Load(CAMP camp, NPCData initedData, GameObject WarPoint) { #if DEBUG Utils.Assert(initedData == null, "NpcLoad can't be null "); #endif NPCConfigData configData = initedData.configData; string path = Path.Combine(ResourceSetting.PACKROOT, NPC); path = Path.Combine(path, configData.model.ToString()); //TODO: 是自己队伍里NPC则必须使用ObjLoader去创建 bool cached = ObjLoader.hitCache(path); Object obj = null; if (cached) { obj = ObjLoader.Load(path); } else { obj = WeakObjLoader.Load(path); } if (obj == null) { ConsoleEx.DebugWarning(configData.model + " not find models. Npc Num = " + configData.ID); return(null); } GameObject go = GameObject.Instantiate(obj) as GameObject; UnityUtils.AddChild_Reverse(go, WarPoint); /// /// 填充数据 /// InitedData(go, camp, initedData); ClientNPC npc = go.GetComponent <ClientNPC> (); if (npc != null) { go.name = "NPC_" + npc.data.configData.ID + "_" + npc.UniqueID; if (!string.IsNullOrEmpty(configData.controlScript)) { ClientNpcAnimState animState = go.AddComponent(configData.controlScript) as ClientNpcAnimState; npc.animState = animState; npc.broadcast = animState.OnNewStateReceived; } cliNpcMgr.CreateNpcUI(npc); } return(npc); }
public void CreateMap(MapInfo map) { //设置当前配置信息 if (map.type == ConfigType.PVEChapter) { ChapterModel chatperModel = Core.Data.getIModelConfig <ChapterModel>(); curChapConfig = chatperModel.get(map.ID); } else { PVPBattleModel pvpModel = Core.Data.getIModelConfig <PVPBattleModel>(); curChapConfig = pvpModel.get(map.ID); } //加载配表 reader.loadSceneConfig(map.ID); //TODO : According to the type of map, we should make up the right path StringBuilder strBld = new StringBuilder("Scenes/Stage_"); strBld.Append(map.ID.ToString()); GameObject go = Maploader.loadFromUnPack(strBld.ToString(), false); UnityUtils.AddChild_Reverse(go, ScenePoint); MapInSceneData[] mapdata = reader.GetSceneEditorElementData <MapInSceneData>(); if (mapdata != null && mapdata.Length > 0) { go.transform.localPosition = new Vector3(mapdata [0].pos [0], mapdata [0].pos [1], mapdata [0].pos [2]); go.transform.localScale = new Vector3(mapdata [0].scale [0], mapdata [0].scale [1], mapdata [0].scale [2]); go.transform.localEulerAngles = new Vector3(mapdata [0].rotation [0], mapdata [0].rotation [1], mapdata [0].rotation [2]); } strBld.Append("Graph"); string strPath = System.IO.Path.Combine(ResourceSetting.UNPACKROOT, strBld.ToString()); TextAsset mapTxt = UnityEngine.Resources.Load(strPath) as TextAsset; if (mapTxt == null) { Debug.LogError("scene textAsseet data is null :: " + strPath); } AstarPath.active.astarData.DeserializeGraphs(mapTxt.bytes); CreateUnVision(); GameObject helper = new GameObject("helper"); helper.AddComponent <TileHandlerHelper>(); }
public void OnLevelWasLoaded(int level) { //根据WarInfo来决定加载服务器端模块和客户端模块 if (Application.loadedLevelName == SceneName.BattleScene) { //创建出来战斗的客户端控制层 GameObject goCli = GameObject.FindGameObjectWithTag("WarClient"); WarClientManager warCliMgr = goCli.GetComponentInChildren <WarClientManager>(); warCliMgr.realCli = Client; warCliMgr.Init(); if (warInfo.Side == WarSide.ServerAndClient) { //创建出来战斗的服务器控制层 GameObject goSer = GameObject.FindGameObjectWithTag("WarServer"); GameObject goSerMgr = new GameObject("WarMgr"); UnityUtils.AddChild_Reverse(goSerMgr, goSer); WarServerManager warSerMgr = goSerMgr.AddComponent <WarServerManager>(); warSerMgr.realServer = Server; } } }
public ServerNPC Load(int num, CAMP camp, GameObject WarPoint) { if (NpcModel == null) { NpcModel = Core.Data.getIModelConfig <NPCModel>(); } NPCConfigData configData = NpcModel.get(num); #if DEBUG Utils.Assert(configData == null, "Virtual Npc load can't find npc configure. NPC id = " + num); #endif if (cached == null) { string path = SPath.Combine(ResourceSetting.PACKROOT, NPC); path = SPath.Combine(path, VIRTUAL); cached = URes.Load(path); } GameObject go = GameObject.Instantiate(cached) as GameObject; UnityUtils.AddChild_Reverse(go, WarPoint); if (configData.type == LifeNPCType.Build) { go.layer = LayerMask.NameToLayer(Consts.LAYER_BUILD); } else { go.layer = LayerMask.NameToLayer(Consts.LAYER_NPC); } ServerNPC npc = null; if (configData.healthpoint > 0) { npc = go.AddComponent <ServerLifeNpc>(); } else { npc = go.AddComponent <ServerNPC>(); } //如果是可以移动的,添加寻路脚本 if (configData.moveable == Moveable.Movable) { Seeker seek = go.AddComponent <Seeker>(); seek.drawGizmos = false; AIPath pathFinding = go.AddComponent <AIPath>(); pathFinding.speed = configData.speed; pathFinding.slowdownDistance = 0.0f; pathFinding.pickNextWaypointDist = 2; pathFinding.forwardLook = 1f; FunnelModifier modifer = go.AddComponent <FunnelModifier>(); modifer.Priority = 2; CharacterController box = go.AddComponent <CharacterController>(); box.radius = configData.radius; box.height = 2; if (box.radius >= box.height) { box.center = Vector3.up * box.radius; } else { box.center = Vector3.up * box.height / 2; } } else if (configData.radius > 0) { CapsuleCollider cap = go.AddComponent <CapsuleCollider>(); cap.radius = configData.radius; cap.height = 2; if (cap.radius >= cap.height) { cap.center = Vector3.up * cap.radius; } else { cap.center = Vector3.up * cap.height / 2; } NavmeshCut cut = go.AddComponent <NavmeshCut>(); cut.type = NavmeshCut.MeshType.Circle; cut.circleRadius = configData.radius; cut.height = 10; cut.center = Vector3.up * 5; } DynamicDataInit(npc, configData, camp); go.name = "NPC_" + configData.ID + "_" + npc.UniqueID; return(npc); }
/// /// 先尝试从ObjLoader里面取,如果不存在则再去WeakObjLoader取 /// /// 但是如果是自己队伍里NPC则必须使用ObjLoader去创建 /// public ClientNPC Load(int num, int id, CAMP camp, GameObject WarPoint) { if (NpcModel == null) { NpcModel = Core.Data.getIModelConfig <NPCModel>(); } NPCConfigData configData = NpcModel.get(num); if (configData == null) { ConsoleEx.DebugWarning("not find npc config data :: " + num); return(null); } string path = Path.Combine(ResourceSetting.PACKROOT, NPC); path = Path.Combine(path, configData.model.ToString()); //TODO: 是自己队伍里NPC则必须使用ObjLoader去创建 bool cached = ObjLoader.hitCache(path); Object obj = null; if (cached) { obj = ObjLoader.Load(path); } else { obj = WeakObjLoader.Load(path); } if (obj == null) { ConsoleEx.DebugWarning(configData.model + " not find models. Npc Num = " + num); return(null); } GameObject go = GameObject.Instantiate(obj) as GameObject; UnityUtils.AddChild_Reverse(go, WarPoint); /// /// 数据的初始化过程 /// DynamicDataInit(go, num, camp, id); ClientNPC npc = go.GetComponent <ClientNPC> (); if (npc != null) { go.name = "NPC_" + npc.data.configData.ID + "_" + npc.UniqueID; if (!string.IsNullOrEmpty(configData.controlScript)) { ClientNpcAnimState animState = go.AddComponent(configData.controlScript) as ClientNpcAnimState; npc.animState = animState; animState.CachedNpc = npc; animState.AttackCount = configData.normalHit.Length; npc.broadcast = animState.OnNewStateReceived; } cliNpcMgr.CreateNpcUI(npc); } return(npc); }