public GameObject AddTrigger(MapTrigger trigger, Vector3 pos) { Object prefab = EditorTool.LoadAssetBundle("model/scene_portal_e.unity3d"); if (prefab == null) { Debug.LogError("传送门 资源找不到:model/scene_portal_e.unity3d"); return(null); } string subpath = "trigger"; Transform parentTrans = getRoot().FindChild(subpath); if (parentTrans == null) { GameObject subroot = new GameObject(subpath); subroot.transform.SetParent(getRoot()); parentTrans = subroot.transform; } string nodeName = "trigger_" + trigger.id; GameObject npcObj = (GameObject)GameObject.Instantiate(prefab); npcObj.name = nodeName; npcObj.transform.SetParent(parentTrans); npcObj.transform.localPosition = pos; if (trigger.eulerangles != null) { string[] arr = trigger.eulerangles.Split(','); if (arr.Length == 3) { //npcObj.transform.Rotate(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2])); npcObj.transform.localRotation = Quaternion.Euler(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2])); } } MapTriggerView view = npcObj.AddComponent <MapTriggerView>(); view.data = trigger; foreach (ParticleSystem ps in npcObj.GetComponentsInChildren <ParticleSystem>()) { ps.Play(true); } trigger.target = npcObj; return(npcObj); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(propTriggerId, new GUIContent("触发器ID为")); EditorGUILayout.PropertyField(propType, new GUIContent("触发器类型")); EditorGUILayout.PropertyField(propWidth, new GUIContent("触发器宽度")); EditorGUILayout.PropertyField(propHeight, new GUIContent("触发器高度")); EditorGUILayout.PropertyField(propType, new GUIContent("传送门类型(0默认1副本下层2退副本)")); EditorGUILayout.PropertyField(propTriggerType, new GUIContent("触发类型(1通过碰撞触发2通过打完怪触发)")); EditorGUILayout.PropertyField(propTriggerParam, new GUIContent("触发参数")); EditorGUILayout.PropertyField(propTargetType, new GUIContent("目标类型(1阻挡门)")); //EditorGUILayout.PropertyField(propState, new GUIContent("传送门状态(0闭1开)")); EditorGUILayout.PropertyField(propTargetParam, new GUIContent("目标参数(1<阻挡门ID)")); MapTriggerView view = (MapTriggerView)target; if (view.gameObject.transform.hasChanged) { Vector3 pos = view.gameObject.transform.localPosition; IntPoint logic = PathUtilEdit.Real2Logic(pos); Quaternion rotat = view.gameObject.transform.localRotation; if (logic.x != propX.intValue || logic.y != propY.intValue) { pos = PathUtilEdit.LogicCenter2Real(logic); //Debug.Log("npc pos changed:" + logic.x + " != " + propX.intValue + "," + logic.y+" != "+propY.intValue); if (EditorData.terrainMan != null) { pos.y = EditorData.terrainMan.GetHeight(pos.x, pos.z); view.gameObject.transform.localPosition = pos; } } propX.intValue = logic.x; propY.intValue = logic.y; propEulerangles.stringValue = rotat.eulerAngles.x.ToString() + "," + rotat.eulerAngles.y.ToString() + "," + rotat.eulerAngles.z.ToString(); } EditorGUILayout.LabelField("X:\t" + propX.intValue); EditorGUILayout.LabelField("Y:\t" + propY.intValue); serializedObject.ApplyModifiedProperties(); }