public virtual void OnServerAddMapObject(string mapPath) { // Object entity manager var objectManagerGO = (GameObject)GameObject.Instantiate(spawnPrefabs [(int)EEntityType.ObjectManagerEntity], Vector3.zero, Quaternion.identity); objectManagerGO.name = "Network-ObjectManagerEntity"; NetworkServer.Spawn(objectManagerGO); // Map Object m_MapManager.LoadMap(mapPath, (mapData) => { var mapObjects = mapData.mapObjects; for (int i = 0; i < mapObjects.Length; i++) { var nonPlayable = (GameObject)GameObject.Instantiate(spawnPrefabs [(int)EEntityType.NonPlayableEntity], Vector3.zero, Quaternion.identity); var entityNonPlayable = nonPlayable.GetComponent <CEntity> (); var entityDataText = CResourceManager.Instance.LoadResourceOrAsset <TextAsset> (mapObjects[i].dataPath); if (entityDataText != null) { var entityPosition = mapObjects[i].position.ToV3(); entityNonPlayable.controlData = TinyJSON.JSON.Load(entityDataText.text).Make <CCharacterData> (); entityNonPlayable.SetPosition(entityPosition); entityNonPlayable.SetStartPosition(entityPosition); this.OnServerRegisterEntity(entityNonPlayable, nonPlayable.GetComponent <NetworkIdentity>().connectionToClient); nonPlayable.name = "Network-" + entityNonPlayable.controlData.name; NetworkServer.Spawn(nonPlayable); } } }); }
public virtual void LoadMap() { m_MapManager = new CMapManager(); m_MapManager.LoadMap("WorldMap0001", (mapData) => { var mapObjects = mapData.mapObjects; for (int i = 0; i < mapObjects.Length; i++) { var objDataText = CResourceManager.Instance.LoadResourceOrAsset <TextAsset> (mapObjects[i].dataPath); if (objDataText != null) { var objData = TinyJSON.JSON.Load(objDataText.text).Make <CCharacterData> (); var objModel = CResourceManager.Instance.LoadResourceOrAsset <CObjectController>(objData.modelPath); var objController = GameObject.Instantiate(objModel); objController.SetPosition(mapObjects[i].position.ToV3()); } } }); }