public void ObjectEnterWithLocalPosition(SceneObjectController sceneObjectController, Vector3 localPosition) { sceneObjectController.CurrSceneController = this; sceneObjectController.SceneId = name; Transform andAutoAdd = transform.FindAndAutoAdd(sceneObjectController.PathInScene); sceneObjectController.transform.parent = andAutoAdd.transform; sceneObjectController.transform.localPosition = localPosition; }
public void InitSceneEvent(SceneEvents sceneEvents) { currSceneEvents = sceneEvents; currSceneEvents.ResultDelegates += (Result result) => { switch (result.resultType) { case ResultType.AddRole: { string roleId = (string)result.parameters[0]; int count = Convert.ToInt32(result.parameters[1]); string roomId = (string)result.parameters[2]; string areaId = (string)result.parameters[3]; SceneController sceneController = GetScene(roomId); Debug.Assert(sceneController != null, "找不到场景:" + roomId); if (sceneController) { for (int i = 0; i < count; i++) { sceneController.AddRole(roleId, areaId); } } } break; case ResultType.SetObjState: { string objId = (string)result.parameters[0]; int state = Convert.ToInt32(result.parameters[1]); SceneObjectController sceneObjectController = SceneObjectControllerManager.Instance.GetFirst(objId); IInteractable interactable = sceneObjectController.GetComponent <IInteractable>(); // IInteractable interactable = GetObjectComponent<IInteractable>(objId, roomId); interactable.State = state; } break; case ResultType.GamePass: { GameManager.Instance.GamePass(); } break; default: break; } }; }
public void RemoveSceneObjectController(string id, SceneObjectController SceneObjectController) { List <SceneObjectController> SceneObjectControllers_; if (SceneObjectControllerDic.TryGetValue(id, out SceneObjectControllers_)) { SceneObjectControllers_.Remove(SceneObjectController); if (SceneObjectControllers_.Count <= 0) { SceneObjectControllerDic.Remove(id); } } #if UNITY_EDITOR SceneObjectControllers.Remove(SceneObjectController); #endif }
public void AddSceneObjectController(string id, SceneObjectController SceneObjectController) { List <SceneObjectController> SceneObjectControllers_; if (SceneObjectControllerDic.TryGetValue(id, out SceneObjectControllers_)) { SceneObjectControllers_.Add(SceneObjectController); } else { SceneObjectControllerDic.Add(id, new List <SceneObjectController>() { SceneObjectController }); } #if UNITY_EDITOR SceneObjectControllers.Add(SceneObjectController); #endif }
public void PlacementEnterWithLocalPosition(SceneObjectController sceneObjectController, Vector3 localPosition) { ObjectEnterWithLocalPosition(sceneObjectController, localPosition); }
public void ObjectEnterWithWorldPosition(SceneObjectController sceneObjectController, Vector3 position) { ObjectEnterWithLocalPosition(sceneObjectController, transform.InverseTransformPoint(position)); }
public bool ObjectEnterSceneLocalPosition(SceneObjectController sceneObjectController, string sceneId, Vector3 localPosition) { var sceneController = GetScene(sceneId); sceneController.ObjectEnterWithLocalPosition(sceneObjectController, localPosition); return true; }
// 进入场景方法 add by TangJian 2018/12/28 17:41 public bool ObjectEnterSceneWithWorldPosition(SceneObjectController sceneObjectController, string sceneId, Vector3 position) { var sceneController = GetScene(sceneId); sceneController.ObjectEnterWithLocalPosition(sceneObjectController, sceneController.transform.InverseTransformPoint(position)); return true; }
public bool DropItemEnterSceneWithWorldPosition(SceneObjectController sceneObjectController, string sceneId, Vector3 worldPosition) { return ObjectEnterSceneWithWorldPosition(sceneObjectController, sceneId, worldPosition); }
// 物品进入场景 本地坐标 add by TangJian 2019/4/2 12:19 public bool DropItemEnterSceneWithLocalPosition(SceneObjectController sceneObjectController, string sceneId, Vector3 localPosition) { return ObjectEnterSceneLocalPosition(sceneObjectController, sceneId, localPosition); }
public async Task<SceneController> CreateScene(SceneData sceneData, int difficultyLevel = 1) { // 新建场景 GameObject prefab = await AssetManager.LoadAssetAsync<GameObject>("Assets/Resources_moved/Prefabs/Scenes/" + sceneData.rawSceneId+".prefab"); Debug.Assert(prefab != null, "找不到场景预制体:" + "Prefabs / Scenes / " + sceneData.rawSceneId); GameObject scene = Instantiate(prefab); // Debug.Log(" 预制体id " + sceneData.rawSceneId); scene.transform.parent = SceneRoot.transform; scene.transform.localPosition = GetOnlyScenePosition(); scene.name = sceneData.sceneId; SceneController sceneController = scene.GetComponent<SceneController>(); sceneController.SceneData = sceneData; { // 添加怪物 add by TangJian 2017/08/03 21:35:51 { foreach (var roleData in sceneData.roleDatas) { roleData.locationData.position = sceneController.GetAreaRandomPosition(roleData.locationData.areaId); roleData.difficultyLevel = difficultyLevel; sceneController.AddRole(roleData); } } // 添加物品 add by TangJian 2017/08/22 19:45:51 { foreach (var itemData in sceneData.itemDatas) { var item = GameObjectManager.Instance.Create(itemData.id); DropItemController dropItemController = item.GetComponent<DropItemController>(); itemData.position = sceneController.GetAreaRandomPosition("MonsterAreas"); sceneController.DropItemEnterWithLocalPosition(dropItemController, itemData.position); } } // 添加放置物体 add by TangJian 2018/01/23 15:52:08 { foreach (var placementData in sceneData.PlacementDatas) { var placementObject = GameObjectManager.Instance.Create(placementData.id); SceneObjectController sceneObjectController = placementObject.GetComponent<SceneObjectController>(); PlacementController treasureBoxController = placementObject.GetComponent<PlacementController>(); treasureBoxController.Placementdata = placementData; placementData.position = sceneController.GetAreaRandomPosition("MonsterAreas"); sceneController.PlacementEnterWithLocalPosition(sceneObjectController, placementData.position); ScenePlacementComponent sceneComponent = treasureBoxController.gameObject.GetComponent<ScenePlacementComponent>(); if (sceneComponent != null) { sceneComponent.GridPos = placementObject.transform.localPosition; } } } // 设置门数据 add by TangJian 2018/12/26 16:00 for (int i = 0; i < sceneData.portalDatas.Count; i++) { PortalData portalData = sceneData.portalDatas[i]; Transform portalTransform = scene.transform.Find("Portals/" + portalData.id); Debug.Assert(portalTransform != null, "找不到门: " + sceneData.sceneId + ":" + portalData.id); PortalController portalController = portalTransform.GetComponent<PortalController>(); portalController.PortalData = portalData; portalController.State = 1; } // 为丢失NavMeshDataBuild { foreach(var item in scene.GetComponents<UnityEngine.AI.NavMeshSurface>()) { if (item.navMeshData == null) { item.BuildNavMesh(); } } } } // 初始化 // sceneController.InitData(); return sceneController; }
public void Remove(string id, SceneObjectController SceneObjectController) { RemoveSceneObjectController(id, SceneObjectController); }
public void Add(string id, SceneObjectController SceneObjectController) { AddSceneObjectController(id, SceneObjectController); }