private void AddNpc(int id, Vector3 position, Vector3 rotation, Vector3 scale) { NpcConfig tmpConfig = ConfigManager.Instance.GetNpcConfig(id); if (null == tmpConfig) { EditorUtility.DisplayDialog("id 错误", "请检查表中npc id ,错误 id= " + id, "ok"); return; } GameObject sourceObj = ResourceManager.Instance.LoadBuildInResource <GameObject>(tmpConfig.ModelResource, AssetType.Char); if (null == sourceObj) { EditorUtility.DisplayDialog("模型 id 错误", "请检查表中npc id ,错误 id= " + tmpConfig.ModelResource, "ok"); return; } if (IsExistNpcInScene(id)) { EditorUtility.DisplayDialog("npc重复", "场景中已经存在相同ID的npc,错误 id= " + id, "ok"); return; } NpcEditorData elem = new NpcEditorData(); elem.m_NpcData = new TerrainNpcData(); elem.m_NpcData.Pos = new ThriftVector3(); elem.m_NpcData.Rot = new ThriftVector3(); elem.m_NpcData.Scale = new ThriftVector3(); elem.m_NpcData.Id = id; elem.m_NpcData.Pos.SetVector3(position); elem.m_NpcData.Rot.SetVector3(rotation); elem.m_NpcData.Scale.SetVector3(scale); elem.m_Instance = new Npc(); elem.m_Instance.Initialize(id); GameObject instance = ((CharTransformData)(elem.m_Instance.GetTransformData())).GetGameObject(); ComponentTool.Attach(m_ObjNpcRoot.transform, instance.transform); ((CharTransformData)(elem.m_Instance.GetTransformData())).SetPhysicStatus(false); elem.m_Instance.GetTransformData().SetPosition(position); elem.m_Instance.GetTransformData().SetRotation(rotation); elem.m_Instance.GetTransformData().SetScale(scale); m_NpcList.Add(elem); }
private void AddNpc(int id, Vector3 position, Vector3 rotation, Vector3 scale) { NpcConfig tmpConfig = ConfigManager.Instance.GetNpcConfig(id); if (null == tmpConfig) { EditorUtility.DisplayDialog("id 错误", "请检查表中npc id ,错误 id= " + id, "ok"); return; } GameObject sourceObj = ResourceManager.Instance.LoadBuildInResource<GameObject>(tmpConfig.ModelResource, AssetType.Char); if (null == sourceObj) { EditorUtility.DisplayDialog("模型 id 错误", "请检查表中npc id ,错误 id= " + tmpConfig.ModelResource, "ok"); return; } if (IsExistNpcInScene(id)) { EditorUtility.DisplayDialog("npc重复","场景中已经存在相同ID的npc,错误 id= " + id, "ok"); return; } NpcEditorData elem = new NpcEditorData(); elem.m_NpcData = new TerrainNpcData(); elem.m_NpcData.Pos = new ThriftVector3(); elem.m_NpcData.Rot = new ThriftVector3(); elem.m_NpcData.Scale = new ThriftVector3(); elem.m_NpcData.Id = id; elem.m_NpcData.Pos.SetVector3(position); elem.m_NpcData.Rot.SetVector3(rotation); elem.m_NpcData.Scale.SetVector3(scale); elem.m_Instance = new Npc(); elem.m_Instance.Initialize(id); GameObject instance = ((CharTransformData)(elem.m_Instance.GetTransformData())).GetGameObject(); ComponentTool.Attach(m_ObjNpcRoot.transform, instance.transform); ((CharTransformData)(elem.m_Instance.GetTransformData())).SetPhysicStatus(false); elem.m_Instance.GetTransformData().SetPosition(position); elem.m_Instance.GetTransformData().SetRotation(rotation); elem.m_Instance.GetTransformData().SetScale(scale); m_NpcList.Add(elem); }
void DrawNpc() { if (NGUIEditorTools.DrawHeader("NPC配置")) { EditorGUILayout.BeginHorizontal(); { m_iSelectedNpcId = EditorGUILayout.Popup(m_iSelectedNpcId, m_NpcTypeList, GUILayout.Width(100f)); if (GUILayout.Button("添加一个NPC", GUILayout.Width(120f))) { AddNpc(int.Parse(m_NpcTypeList[m_iSelectedNpcId]), Vector3.zero, Vector3.zero, Vector3.one); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_NpcList.Count; ++i) { NpcEditorData data = m_NpcList[i]; GUIStyle textColor = new GUIStyle(); textColor.normal.textColor = data.m_bIsSelected ? Color.red : Color.white; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("NPCID: " + data.m_NpcData.Id, GUILayout.Width(300f)); if (GUILayout.Button("调整NPC位置", textColor, GUILayout.Width(120f))) { m_nCurrentSettingPosNpcIndex = i; TerrainEditorRuntime.Instance.SetRaycastCallBack(SetNpcPos); } if (GUILayout.Button("NPC高亮", textColor, GUILayout.Width(120f))) { if (null != m_CurrentSelectedNpc) { ((CharTransformData)(m_CurrentSelectedNpc.GetTransformData())).SetSelectedStatus(false); } m_CurrentSelectedNpc = data.m_Instance; ((CharTransformData)(m_CurrentSelectedNpc.GetTransformData())).SetSelectedStatus(true); } if (GUILayout.Button("删除NPC", textColor, GUILayout.Width(120f))) { m_RemovingNpcList.Add(data); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpPos = data.m_Instance.GetTransformData().GetPosition(); GUILayout.TextArea("NPC位置", textColor, GUILayout.Width(120f)); GUILayout.Label(tmpPos.ToString(), GUILayout.Width(100f)); GUILayout.Label("x", GUILayout.Width(20f)); tmpPos.x = EditorGUILayout.FloatField(tmpPos.x); GUILayout.Label("y", GUILayout.Width(20f)); tmpPos.y = EditorGUILayout.FloatField(tmpPos.y); GUILayout.Label("z", GUILayout.Width(20f)); tmpPos.z = EditorGUILayout.FloatField(tmpPos.z); if (m_LastTimePos != tmpPos) { data.m_Instance.GetTransformData().SetPosition(tmpPos); data.m_NpcData.Pos.SetVector3(tmpPos); } m_LastTimePos = tmpPos; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpRot = data.m_Instance.GetTransformData().GetRotation(); GUILayout.TextArea("NPC朝向", GUILayout.Width(120f)); GUILayout.Label(tmpRot.y.ToString(), GUILayout.Width(100f)); GUILayout.Label("y", GUILayout.Width(20f)); tmpRot.y = EditorGUILayout.Slider(tmpRot.y, 0f, 359.9f); if (data.m_Instance.GetTransformData().GetRotation() != tmpRot) { data.m_Instance.GetTransformData().SetRotation(tmpRot); data.m_NpcData.Rot.SetVector3(tmpRot); } } EditorGUILayout.EndHorizontal(); } CheckRemovingNpc(); } }