public override void OnInspectorGUI() { if (isValid) { EditorGUILayout.HelpBox("Please ensure your camera not controled by other scripts", MessageType.Warning, true); //Updates the object we are editing serializedObject.Update(); //Quick reference to the Quicktakecutscenecontroller script SmoothMoveCamera q = target as SmoothMoveCamera; q.waitUntilFinished = EditorGUILayout.Toggle("等待播放结束开始下一个事件", q.waitUntilFinished); EditorGUILayout.BeginHorizontal(); //Button to manually call the StartCutscene function, only if the game is in play mode if (GUILayout.Button("Play")) { if (Application.isPlaying) { q.ActivateCutscene(); } if (!Application.isPlaying) { Debug.Log("You can only play the cutscene when the game is running"); } } //Button to manually call the StartCutscene function, only if the game is in play mode if (GUILayout.Button("Stop")) { if (Application.isPlaying) { q.EndCutscene(); } if (!Application.isPlaying) { Debug.Log("You can only play/stop the cutscene when the game is running"); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Toggle Path (" + q.showPathType.GetHashCode() + ")")) { q.ToggleShowPath(); } if (GUILayout.Button("Add camera point")) { GameObject g = new GameObject(); g.transform.position = (Selection.activeTransform.position + Random.insideUnitSphere * 5f); g.transform.rotation = Selection.activeTransform.rotation; g.transform.parent = Selection.activeTransform; string n = ("CameraPoint_" + numberOfEvents.ToString()); g.name = n; Undo.RegisterCreatedObjectUndo(g, n); this.OnEnable(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); //Camera selector EditorGUILayout.LabelField(cameraContent); q.mainCutsceneCam = EditorGUILayout.ObjectField(q.mainCutsceneCam, typeof(Camera), true) as Camera; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //Use delta time //EditorGUILayout.BeginHorizontal(); //q.useDeltaTime = EditorGUILayout.Toggle(deltaTimeContent, q.useDeltaTime); //EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //This for loop controls the display of each camera transition event, and the variables relating to it. for (int i = 0; i < (numberOfEvents - 2); i++) { //Handle error which occurs when we undo a deleted CP if (!points[i + 2]) { this.OnEnable(); } else { GUIContent popoutContent = new GUIContent("Camera transition " + (i + 1) + " --> " + (i + 2) + " (" + points[i + 1].name + " -> " + points[i + 2].name + ")"); showEvent[i] = EditorGUILayout.Foldout(showEvent[i], popoutContent);//"Camera transition " + (i+1) + " --> " + (i+2)); } if (showEvent[i] == true) { if (i >= q.cutsceneEventKeyTime.Length) { //Debug.Log("Refreshing Editor GUI"); //EditorGUIUtility.ExitGUI(); this.OnEnable(); } q.cutsceneEventKeyTime[i] = EditorGUILayout.FloatField(delayContent, q.cutsceneEventKeyTime[i]); //EditorGUILayout.Space(); q.cutsceneCameraSpeedOptions[i] = (CameraSpeedOptions)EditorGUILayout.EnumPopup(moveContent, q.cutsceneCameraSpeedOptions[i]); if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve || q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.MobileCurve) { q.curveChoice[i] = true; EditorGUILayout.BeginHorizontal(); q.lerpCurveChoice[i] = EditorGUILayout.Toggle(lerpCurveContent, q.lerpCurveChoice[i]); EditorGUILayout.EndHorizontal(); if (q.lerpCurveChoice[i]) { q.customCurveMovementSpeed[i] = EditorGUILayout.Slider(" >Time (sec)", q.customCurveMovementSpeed[i], 0.0001f, 120f); } else { moveContent = new GUIContent("Movement ", "Movement speed options. Mobile curves require 1 mid-point, normal curves require 2 mid-points."); EditorGUILayout.BeginHorizontal(); q.curveNodeCount[i] = EditorGUILayout.IntSlider(nodesContent, q.curveNodeCount[i], 10, 1000); EditorGUILayout.EndHorizontal(); q.customCurveMovementSpeed[i] = EditorGUILayout.Slider(curveSpeedContent, q.customCurveMovementSpeed[i], 0.0001f, 120f); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(midPointContent); EditorGUILayout.LabelField(midPoints[i + 1].name); EditorGUILayout.EndHorizontal(); if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(midPointTwoContent); EditorGUILayout.LabelField(cubicPoints[i + 1].name); EditorGUILayout.EndHorizontal(); } } else { q.curveChoice[i] = false; moveContent = new GUIContent("Movement ", "Camera positional movement speed during this event. (Units)"); } //Custom movement speed if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Custom) { q.customMovementSpeed[i] = EditorGUILayout.FloatField(" >Movement speed", q.customMovementSpeed[i]); } if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Lerp) { q.customMovementSpeed[i] = EditorGUILayout.FloatField(" >Movement time", q.customMovementSpeed[i]); } //EditorGUILayout.Space(); //Rotation speed q.cutsceneCameraRotationSpeedOptions[i] = (CameraRotationSpeedOptions)EditorGUILayout.EnumPopup(rotationContent, q.cutsceneCameraRotationSpeedOptions[i]); if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.FollowTarget) { q.smoothFollowTarget[i] = (Transform)EditorGUILayout.ObjectField(" >Follow target", q.smoothFollowTarget[i], typeof(Transform), true) as Transform; } //Custom rotation speed if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.Custom) { q.customRotationSpeed[i] = EditorGUILayout.FloatField(" >Rotation speed", q.customRotationSpeed[i]); } //Custom rotation speed if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.Lerp) { q.customRotationSpeed[i] = EditorGUILayout.FloatField(" >Rotation time", q.customRotationSpeed[i]); } //EditorGUILayout.Space(); //Camera shake q.doShake[i] = EditorGUILayout.Toggle("Shake camera ", q.doShake[i]); if (q.doShake[i]) { q.cameraShakeAmount[i] = EditorGUILayout.Slider(" >Shake intensity", q.cameraShakeAmount[i], 0.1f, 5f); } //EditorGUILayout.Space(); //time scale and broadcastmessage q.cutsceneEventTimescale[i] = EditorGUILayout.Slider("Time scale", q.cutsceneEventTimescale[i], 0f, 2f); //EditorGUILayout.Space(); q.broadcastMessageChoice[i] = EditorGUILayout.Toggle(broadcastContent, q.broadcastMessageChoice[i]); if (q.broadcastMessageChoice[i] == true) { EditorGUILayout.BeginVertical(); q.broadcastMessageString[i] = EditorGUILayout.TextField(" >Method name", q.broadcastMessageString[i]); q.broadcastMessageTarget[i] = EditorGUILayout.ObjectField(" >Target", q.broadcastMessageTarget[i], typeof(GameObject), true) as GameObject; EditorGUILayout.EndVertical(); } //EditorGUILayout.Space(); q.cutsceneEventZoom[i] = EditorGUILayout.Toggle(zoomContent, q.cutsceneEventZoom[i]); if (q.cutsceneEventZoom[i] == true) { q.cutsceneEventZoomAmount[i] = EditorGUILayout.Slider(" >Field of View", q.cutsceneEventZoomAmount[i], 1f, 144f); q.cutsceneEventZoomSpeed[i] = EditorGUILayout.Slider(" >Zoom speed", q.cutsceneEventZoomSpeed[i], 0.001f, 40f); } //EditorGUILayout.EndVertical(); } } if (GUI.changed) { EditorUtility.SetDirty(target); } //And apply serializedObject.ApplyModifiedProperties(); } }
void OnSceneGUI() { if (isValid) { //Quick reference to the Quicktakecutscenecontroller script SmoothMoveCamera q = target as SmoothMoveCamera; q.SetCameraPointReferences(); //The size of the gizmos to draw for each camera point float gizmoSize = 0.4f; EditorGUI.BeginChangeCheck(); //Only draw gizmos if we want to if (q.showPathType == PathType.PathOnly || q.showPathType == PathType.PathAndFrustum) { //Draw circles for each main cam point for (int i = 1; i < q.cutsceneCameraPoints.Length; i++) { Handles.color = Color.green; Undo.RecordObject(q.cutsceneCameraPoints[i], "Move"); q.cutsceneCameraPoints[i].position = Handles.FreeMoveHandle(q.cutsceneCameraPoints[i].position, Quaternion.identity, gizmoSize, Vector3.zero, Handles.SphereHandleCap); } //Draw for each mid point for (int i = 0; i < q.cutsceneCameraPoints.Length - 2; i++) { Handles.color = Color.yellow; if (q.curveChoice[i] == true) { Undo.RecordObject(q.cutsceneMidPoints[i + 1], "Move"); q.cutsceneMidPoints[i + 1].position = Handles.FreeMoveHandle(q.cutsceneMidPoints[i + 1].position, Quaternion.identity, gizmoSize * 0.9f, Vector3.zero, Handles.SphereHandleCap); } } //And draw for each cubic mid point, and a path for (int i = 0; i < q.cutsceneCameraPoints.Length - 2; i++) { Handles.color = Color.magenta; if (q.curveChoice[i] == true && q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve)//Only draw this midpoint if it is a cubic curve { Undo.RecordObject(q.cutsceneCubicMidPoints[i + 1], "Move"); q.cutsceneCubicMidPoints[i + 1].position = Handles.FreeMoveHandle(q.cutsceneCubicMidPoints[i + 1].position, Quaternion.identity, gizmoSize * 0.8f, Vector3.zero, Handles.SphereHandleCap); } Handles.color = Color.green; } } } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Changes"); EditorUtility.SetDirty(target); } }