private void AddTrigger(ETriggerAreaType TriggerAreaType, Vector3 position, Vector3 rotation, Vector3 scale, int targetId = 0, int enterLimitId = 0, int exitLimitId = 0, int enterFuncId = 0, int exitFuncId = 0) { GameObject sourceObj = m_TriggerTemplateMap[TriggerAreaType]; if (null == sourceObj) { Debug.Log(TriggerAreaType.ToString() + " " + m_TriggerTemplateMap.Count); } else { GameObject instance = GameObject.Instantiate(sourceObj); ComponentTool.Attach(m_ObjTriggerRoot.transform, instance.transform); TriggerEditorData elem = new TriggerEditorData(); elem.TriggerData = new TerrainTriggerData(); elem.TriggerData.Pos = new ThriftVector3(); elem.TriggerData.Rot = new ThriftVector3(); elem.TriggerData.Scale = new ThriftVector3(); elem.TriggerData.Pos.SetVector3(position); elem.TriggerData.Rot.SetVector3(rotation); elem.TriggerData.Scale.SetVector3(scale); elem.TriggerData.AreaType = TriggerAreaType; elem.TriggerData.TargetMethodId = targetId; elem.TriggerData.EnterLimitMethodId = enterLimitId; elem.TriggerData.ExitLimitMethodId = exitLimitId; elem.TriggerData.EnterFuncMethodId = enterFuncId; elem.TriggerData.ExitFuncMethodId = exitFuncId; elem.m_SourceObj = instance; elem.m_SourceObj.transform.position = position; elem.m_SourceObj.transform.eulerAngles = rotation; elem.m_SourceObj.transform.localScale = scale; m_TriggerList.Add(elem); } }
void DrawTrigger() { if (NGUIEditorTools.DrawHeader("触发器配置")) { EditorGUILayout.BeginHorizontal(); { m_ETriggerAreaType = (ETriggerAreaType)EditorGUILayout.Popup((int)m_ETriggerAreaType, m_TriggerTypeList, GUILayout.Width(100f)); if (GUILayout.Button("添加一个触发器", GUILayout.Width(120f))) { AddTrigger(m_ETriggerAreaType, Vector3.zero, Vector3.zero, Vector3.one); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_TriggerList.Count; ++i) { TriggerEditorData data = m_TriggerList[i]; GUIStyle textColor = new GUIStyle(); textColor.normal.textColor = data.m_bIsSelected ? Color.red:Color.white; if (NGUIEditorTools.DrawHeader(m_TriggerList[i].TriggerData.AreaType.ToString())) { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("调整触发器位置", textColor,GUILayout.Width(120f))) { m_nCurrentSettingPosTriggerIndex = i; TerrainEditorRuntime.Instance.SetRaycastCallBack(SetTriggerPos); } if (GUILayout.Button("删除触发器", textColor, GUILayout.Width(120f))) { m_RemovingTriggerList.Add(m_TriggerList[i]); } if (GUILayout.Button("编辑触发器事件", textColor, GUILayout.Width(120f))) { TerrainTriggerNodeEditorWindow.Instance.OpenWindow(data.TriggerData); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpPos = data.m_SourceObj.transform.position; GUILayout.TextArea("触发器位置", 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); data.m_SourceObj.transform.position = tmpPos; data.TriggerData.Pos.SetVector3(data.m_SourceObj.transform.position); } EditorGUILayout.EndHorizontal(); switch (data.TriggerData.AreaType) { case ETriggerAreaType.Cube: DrawCubeTrigger(data); break; case ETriggerAreaType.Sphere: DrawCircleTrigger(data); break; default: break; } } } CheckRemovingTrigger(); } }
void Init() { //m_strDataPath = Application.persistentDataPath + "/EditorData/terrainConfig_txtpkg.bytes"; m_strDataPath = Application.dataPath + "/EditorCommon/EditorResources/mmAdv/1.0/terrainConfig_txtpkg.bytes"; GameObject RootObj = GameObject.Find("TerrainEditorRoot"); m_ObjSceneRoot = GameObject.Find("SceneRoot"); m_ObjTriggerRoot = GameObject.Find("TriggerRoot"); var TriggerTemplateRoot = GameObject.Find("TriggerTemplateRoot"); m_ObjNpcRoot = GameObject.Find("NpcRoot"); if (null == RootObj || null == m_ObjSceneRoot || null == m_ObjTriggerRoot || null == TriggerTemplateRoot) { Debug.LogError("wrong scene"); } // init trigger int triggrCount = TriggerTemplateRoot.transform.childCount; m_TriggerTemplateMap = new Dictionary<ETriggerAreaType, GameObject>(triggrCount); m_TriggerTypeList = new string[triggrCount]; for (int i = 0; i < triggrCount; ++i) { ETriggerAreaType type = (ETriggerAreaType)(i); GameObject elem = TriggerTemplateRoot.transform.GetChild(i).gameObject; m_TriggerTemplateMap.Add(type, elem); m_TriggerTypeList[i] = type.ToString(); } NpcConfigTable npcConfigTable = ConfigManager.Instance.GetNpcTable(); if (null == npcConfigTable) { EditorUtility.DisplayDialog("", "npc配置文件读取失败", "ok"); ClearData(); CloseWindow(); return; } m_NpcTypeList = new string[npcConfigTable.NpcCofigMap.Count]; int tmpIndex = 0; foreach (var elem in npcConfigTable.NpcCofigMap) { m_NpcTypeList[tmpIndex++] = elem.Key.ToString(); } m_RemovingNpcList = new System.Collections.Generic.List<NpcEditorData>(); m_NpcList = new System.Collections.Generic.List<NpcEditorData>(); m_TriggerList = new System.Collections.Generic.List<TriggerEditorData>(); m_ETriggerAreaType = ETriggerAreaType.Sphere; m_RemovingTriggerList = new System.Collections.Generic.List<TriggerEditorData>(); m_MapNameInputBuffer = string.Empty; m_iSelectedNpcId = 0; CharactorConfigTable playerConfigTable = ConfigManager.Instance.GetCharactorConfigTable(); if (null == playerConfigTable) { EditorUtility.DisplayDialog("", "playerConfigTable 配置文件读取失败", "ok"); return; } m_PlayerTypeList = new string[playerConfigTable.CharactorCofigMap.Count]; tmpIndex = 0; foreach (var elem in playerConfigTable.CharactorCofigMap) { m_PlayerTypeList[tmpIndex++] = elem.Key.ToString(); } TerrainEditorRuntime.Instance.SetSelectCallBack(OnClickCallBack); Debug.Log(" initialize terrain"); }
void DrawTrigger() { if (NGUIEditorTools.DrawHeader("触发器配置")) { EditorGUILayout.BeginHorizontal(); { m_ETriggerAreaType = (ETriggerAreaType)EditorGUILayout.Popup((int)m_ETriggerAreaType, m_TriggerTypeList, GUILayout.Width(100f)); if (GUILayout.Button("添加一个触发器", GUILayout.Width(120f))) { AddTrigger(m_ETriggerAreaType, Vector3.zero, Vector3.zero, Vector3.one); } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < m_TriggerList.Count; ++i) { TriggerEditorData data = m_TriggerList[i]; GUIStyle textColor = new GUIStyle(); textColor.normal.textColor = data.m_bIsSelected ? Color.red:Color.white; if (NGUIEditorTools.DrawHeader(m_TriggerList[i].TriggerData.AreaType.ToString())) { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("调整触发器位置", textColor, GUILayout.Width(120f))) { m_nCurrentSettingPosTriggerIndex = i; TerrainEditorRuntime.Instance.SetRaycastCallBack(SetTriggerPos); } if (GUILayout.Button("删除触发器", textColor, GUILayout.Width(120f))) { m_RemovingTriggerList.Add(m_TriggerList[i]); } if (GUILayout.Button("编辑触发器事件", textColor, GUILayout.Width(120f))) { TerrainTriggerNodeEditorWindow.Instance.OpenWindow(data.TriggerData); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { Vector3 tmpPos = data.m_SourceObj.transform.position; GUILayout.TextArea("触发器位置", 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); data.m_SourceObj.transform.position = tmpPos; data.TriggerData.Pos.SetVector3(data.m_SourceObj.transform.position); } EditorGUILayout.EndHorizontal(); switch (data.TriggerData.AreaType) { case ETriggerAreaType.Cube: DrawCubeTrigger(data); break; case ETriggerAreaType.Sphere: DrawCircleTrigger(data); break; default: break; } } } CheckRemovingTrigger(); } }
void Init() { //m_strDataPath = Application.persistentDataPath + "/EditorData/terrainConfig_txtpkg.bytes"; m_strDataPath = Application.dataPath + "/EditorCommon/EditorResources/mmAdv/1.0/terrainConfig_txtpkg.bytes"; GameObject RootObj = GameObject.Find("TerrainEditorRoot"); m_ObjSceneRoot = GameObject.Find("SceneRoot"); m_ObjTriggerRoot = GameObject.Find("TriggerRoot"); var TriggerTemplateRoot = GameObject.Find("TriggerTemplateRoot"); m_ObjNpcRoot = GameObject.Find("NpcRoot"); if (null == RootObj || null == m_ObjSceneRoot || null == m_ObjTriggerRoot || null == TriggerTemplateRoot) { Debug.LogError("wrong scene"); } // init trigger int triggrCount = TriggerTemplateRoot.transform.childCount; m_TriggerTemplateMap = new Dictionary <ETriggerAreaType, GameObject>(triggrCount); m_TriggerTypeList = new string[triggrCount]; for (int i = 0; i < triggrCount; ++i) { ETriggerAreaType type = (ETriggerAreaType)(i); GameObject elem = TriggerTemplateRoot.transform.GetChild(i).gameObject; m_TriggerTemplateMap.Add(type, elem); m_TriggerTypeList[i] = type.ToString(); } NpcConfigTable npcConfigTable = ConfigManager.Instance.GetNpcTable(); if (null == npcConfigTable) { EditorUtility.DisplayDialog("", "npc配置文件读取失败", "ok"); ClearData(); CloseWindow(); return; } m_NpcTypeList = new string[npcConfigTable.NpcCofigMap.Count]; int tmpIndex = 0; foreach (var elem in npcConfigTable.NpcCofigMap) { m_NpcTypeList[tmpIndex++] = elem.Key.ToString(); } m_RemovingNpcList = new System.Collections.Generic.List <NpcEditorData>(); m_NpcList = new System.Collections.Generic.List <NpcEditorData>(); m_TriggerList = new System.Collections.Generic.List <TriggerEditorData>(); m_ETriggerAreaType = ETriggerAreaType.Sphere; m_RemovingTriggerList = new System.Collections.Generic.List <TriggerEditorData>(); m_MapNameInputBuffer = string.Empty; m_iSelectedNpcId = 0; CharactorConfigTable playerConfigTable = ConfigManager.Instance.GetCharactorConfigTable(); if (null == playerConfigTable) { EditorUtility.DisplayDialog("", "playerConfigTable 配置文件读取失败", "ok"); return; } m_PlayerTypeList = new string[playerConfigTable.CharactorCofigMap.Count]; tmpIndex = 0; foreach (var elem in playerConfigTable.CharactorCofigMap) { m_PlayerTypeList[tmpIndex++] = elem.Key.ToString(); } TerrainEditorRuntime.Instance.SetSelectCallBack(OnClickCallBack); Debug.Log(" initialize terrain"); }