public void SnapToAttached() { if (attachedCamera && attachedCamera._camera) { LookAtCentre(); isSmoothChanging = false; _camera.orthographic = attachedCamera._camera.orthographic; _camera.fieldOfView = attachedCamera._camera.fieldOfView; _camera.orthographicSize = attachedCamera._camera.orthographicSize; transform.position = attachedCamera.transform.position; transform.rotation = attachedCamera.transform.rotation; focalDistance = attachedCamera.focalDistance; if (attachedCamera is GameCamera2D) { GameCamera2D cam2D = (GameCamera2D)attachedCamera; perspectiveOffset = cam2D.perspectiveOffset; } else { perspectiveOffset = new Vector2(0f, 0f); } if (KickStarter.stateHandler.gameState == GameState.Normal && KickStarter.settingsManager.movementMethod == MovementMethod.Direct && KickStarter.settingsManager.directMovementType == DirectMovementType.RelativeToCamera && KickStarter.settingsManager.inputMethod != InputMethod.TouchScreen) { if (KickStarter.player.GetPath() == null || !KickStarter.player.lockedPath) { KickStarter.playerInput.cameraLockSnap = true; } } } }
public override void OnInspectorGUI() { GameCamera2D _target = (GameCamera2D)target; _target.ShowCursorInfluenceGUI(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Horizontal movement", EditorStyles.boldLabel); _target.lockHorizontal = CustomGUILayout.Toggle("Lock?", _target.lockHorizontal, "", "If True, then horizontal panning is prevented"); if (!_target.GetComponent <Camera>().orthographic || !_target.lockHorizontal) { _target.afterOffset.x = CustomGUILayout.FloatField("Offset:", _target.afterOffset.x, "", "The horizontal panning offset"); } if (!_target.lockHorizontal) { _target.freedom.x = CustomGUILayout.FloatField("Track freedom:", _target.freedom.x, "", "The amount of freedom when tracking a target. Higher values will result in looser tracking"); _target.directionInfluence.x = CustomGUILayout.FloatField("Target direction factor:", _target.directionInfluence.x, "", "The influence that the target's facing direction has on the tracking position"); _target.limitHorizontal = CustomGUILayout.Toggle("Constrain?", _target.limitHorizontal, "", "If True, then horizontal panning will be limited to minimum and maximum values"); if (_target.limitHorizontal) { EditorGUILayout.BeginVertical("Button"); _target.constrainHorizontal[0] = CustomGUILayout.FloatField("Minimum constraint:", _target.constrainHorizontal[0], "", "The lower horizontal panning limit"); _target.constrainHorizontal[1] = CustomGUILayout.FloatField("Maximum constraint:", _target.constrainHorizontal[1], "", "The upper horizontal panning limit"); EditorGUILayout.EndVertical(); } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Vertical movement", EditorStyles.boldLabel); _target.lockVertical = CustomGUILayout.Toggle("Lock?", _target.lockVertical, "", "If True, then vertical panning is prevented"); if (!_target.GetComponent <Camera>().orthographic || !_target.lockVertical) { _target.afterOffset.y = CustomGUILayout.FloatField("Offset:", _target.afterOffset.y, "", "The vertical panning offset"); } if (!_target.lockVertical) { _target.freedom.y = CustomGUILayout.FloatField("Track freedom:", _target.freedom.y, "", "The amount of freedom when tracking a target. Higher values will result in looser tracking"); _target.directionInfluence.y = CustomGUILayout.FloatField("Target direction factor:", _target.directionInfluence.y, "", "The influence that the target's facing direction has on the tracking position"); _target.limitVertical = CustomGUILayout.Toggle("Constrain?", _target.limitVertical, "", "If True, then vertical panning will be limited to minimum and maximum values"); if (_target.limitVertical) { EditorGUILayout.BeginVertical("Button"); _target.constrainVertical[0] = CustomGUILayout.FloatField("Minimum constraint:", _target.constrainVertical[0], "", "The lower vertical panning limit"); _target.constrainVertical[1] = CustomGUILayout.FloatField("Maximum constraint:", _target.constrainVertical[1], "", "The upper vertical panning limit"); EditorGUILayout.EndVertical(); } } EditorGUILayout.EndVertical(); if (!_target.lockHorizontal || !_target.lockVertical) { EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Target object to control camera movement", EditorStyles.boldLabel); _target.targetIsPlayer = CustomGUILayout.Toggle("Target is Player?", _target.targetIsPlayer, "", "If True, the camera will follow the active Player"); if (!_target.targetIsPlayer) { _target.target = (Transform)CustomGUILayout.ObjectField <Transform> ("Target:", _target.target, true, "", "The object for the camera to follow"); } _target.dampSpeed = CustomGUILayout.FloatField("Follow speed", _target.dampSpeed, "", "The follow speed when tracking a target"); _target.doSnapping = CustomGUILayout.Toggle("Snap to grid?", _target.doSnapping, "", "If True, the camera will only move in steps, as if snapping to a grid"); if (_target.doSnapping) { _target.unitSnap = CustomGUILayout.FloatField("Snap unit size:", _target.unitSnap, "", "The step size when snapping"); } EditorGUILayout.EndVertical(); } if (!_target.IsCorrectRotation()) { if (GUILayout.Button("Set correct rotation")) { Undo.RecordObject(_target, "Clear " + _target.name + " rotation"); _target.SetCorrectRotation(); } } if (!Application.isPlaying) { _target.GetComponent <Camera>().ResetProjectionMatrix(); if (!_target.GetComponent <Camera>().orthographic) { _target.SnapToOffset(); } } UnityVersionHandler.CustomSetDirty(_target); }
public override void OnInspectorGUI() { GameCamera2D _target = (GameCamera2D)target; EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Horizontal movement", EditorStyles.boldLabel); _target.lockHorizontal = EditorGUILayout.Toggle("Lock?", _target.lockHorizontal); if (!_target.GetComponent <Camera>().orthographic || !_target.lockHorizontal) { _target.afterOffset.x = EditorGUILayout.FloatField("Offset:", _target.afterOffset.x); } if (!_target.lockHorizontal) { _target.freedom.x = EditorGUILayout.FloatField("Track freedom:", _target.freedom.x); _target.directionInfluence.x = EditorGUILayout.FloatField("Target direction fac.:", _target.directionInfluence.x); _target.limitHorizontal = EditorGUILayout.BeginToggleGroup("Constrain?", _target.limitHorizontal); EditorGUILayout.BeginVertical("Button"); _target.constrainHorizontal[0] = EditorGUILayout.FloatField("Minimum:", _target.constrainHorizontal[0]); _target.constrainHorizontal[1] = EditorGUILayout.FloatField("Maximum:", _target.constrainHorizontal[1]); EditorGUILayout.EndVertical(); EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Vertical movement", EditorStyles.boldLabel); _target.lockVertical = EditorGUILayout.Toggle("Lock?", _target.lockVertical); if (!_target.GetComponent <Camera>().orthographic || !_target.lockVertical) { _target.afterOffset.y = EditorGUILayout.FloatField("Offset:", _target.afterOffset.y); } if (!_target.lockVertical) { _target.freedom.y = EditorGUILayout.FloatField("Track freedom:", _target.freedom.y); _target.directionInfluence.y = EditorGUILayout.FloatField("Target direction fac.:", _target.directionInfluence.y); _target.limitVertical = EditorGUILayout.BeginToggleGroup("Constrain?", _target.limitVertical); EditorGUILayout.BeginVertical("Button"); _target.constrainVertical[0] = EditorGUILayout.FloatField("Minimum:", _target.constrainVertical[0]); _target.constrainVertical[1] = EditorGUILayout.FloatField("Maximum:", _target.constrainVertical[1]); EditorGUILayout.EndVertical(); EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndVertical(); if (!_target.lockHorizontal || !_target.lockVertical) { EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Target object to control camera movement", EditorStyles.boldLabel); _target.targetIsPlayer = EditorGUILayout.Toggle("Target is player?", _target.targetIsPlayer); if (!_target.targetIsPlayer) { _target.target = (Transform)EditorGUILayout.ObjectField("Target:", _target.target, typeof(Transform), true); } _target.dampSpeed = EditorGUILayout.FloatField("Follow speed", _target.dampSpeed); EditorGUILayout.EndVertical(); } if (!_target.IsCorrectRotation()) { if (GUILayout.Button("Set correct rotation")) { Undo.RecordObject(_target, "Clear " + _target.name + " rotation"); _target.SetCorrectRotation(); } } if (!Application.isPlaying) { _target.GetComponent <Camera>().ResetProjectionMatrix(); if (!_target.GetComponent <Camera>().orthographic) { _target.SetCameraComponent(); _target.SnapToOffset(); } } if (GUI.changed) { EditorUtility.SetDirty(_target); } }
public void _LateUpdate() { if (KickStarter.settingsManager && KickStarter.settingsManager.IsInLoadingScene()) { return; } if (KickStarter.stateHandler.gameState == GameState.Normal) { if (attachedCamera) { if (lastNavCamera != attachedCamera) { lastNavCamera2 = lastNavCamera; } lastNavCamera = attachedCamera; } } if (attachedCamera && (!(attachedCamera is GameCamera25D))) { if (!isSmoothChanging) { transform.rotation = attachedCamera.transform.rotation; transform.position = attachedCamera.transform.position; focalDistance = attachedCamera.focalDistance; if (attachedCamera is GameCamera2D) { GameCamera2D cam2D = (GameCamera2D)attachedCamera; perspectiveOffset = cam2D.perspectiveOffset; if (!_camera.orthographic) { _camera.projectionMatrix = AdvGame.SetVanishingPoint(_camera, perspectiveOffset); } else { _camera.orthographicSize = attachedCamera._camera.orthographicSize; } } else { _camera.fieldOfView = attachedCamera._camera.fieldOfView; if (cursorAffectsRotation) { SetlookAtTransformation(); transform.LookAt(lookAtTransform, attachedCamera.transform.up); } } } else { // Move from one GameCamera to another if (Time.time < startTime + changeTime) { if (attachedCamera is GameCamera2D) { GameCamera2D cam2D = (GameCamera2D)attachedCamera; perspectiveOffset.x = AdvGame.Lerp(startPerspectiveOffset.x, cam2D.perspectiveOffset.x, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); perspectiveOffset.y = AdvGame.Lerp(startPerspectiveOffset.y, cam2D.perspectiveOffset.y, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); _camera.ResetProjectionMatrix(); } if (moveMethod == MoveMethod.Curved) { // Don't slerp y position as this will create a "bump" effect Vector3 newPosition = Vector3.Slerp(startPosition, attachedCamera.transform.position, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); newPosition.y = Mathf.Lerp(startPosition.y, attachedCamera.transform.position.y, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); transform.position = newPosition; transform.rotation = Quaternion.Slerp(startRotation, attachedCamera.transform.rotation, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); } else { transform.position = AdvGame.Lerp(startPosition, attachedCamera.transform.position, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); transform.rotation = AdvGame.Lerp(startRotation, attachedCamera.transform.rotation, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); } focalDistance = AdvGame.Lerp(startFocalDistance, attachedCamera.focalDistance, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); _camera.fieldOfView = AdvGame.Lerp(startFOV, attachedCamera._camera.fieldOfView, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); _camera.orthographicSize = AdvGame.Lerp(startOrtho, attachedCamera._camera.orthographicSize, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve)); if (attachedCamera is GameCamera2D && !_camera.orthographic) { _camera.projectionMatrix = AdvGame.SetVanishingPoint(_camera, perspectiveOffset); } } else { LookAtCentre(); isSmoothChanging = false; } } if (cursorAffectsRotation) { lookAtTransform.localPosition = Vector3.Lerp(lookAtTransform.localPosition, lookAtTarget, Time.deltaTime * 3f); } } else if (attachedCamera && (attachedCamera is GameCamera25D)) { transform.position = attachedCamera.transform.position; transform.rotation = attachedCamera.transform.rotation; } // Shake if (shakeIntensity > 0f) { if (shakeMove) { shakePosition = Random.insideUnitSphere * shakeIntensity * 0.5f; } shakeRotation = new Vector3 ( Random.Range(-shakeIntensity, shakeIntensity) * 0.2f, Random.Range(-shakeIntensity, shakeIntensity) * 0.2f, Random.Range(-shakeIntensity, shakeIntensity) * 0.2f ); shakeIntensity = Mathf.Lerp(shakeStartIntensity, 0f, AdvGame.Interpolate(shakeStartTime, shakeDuration, MoveMethod.Linear, null)); transform.position += shakePosition; transform.localEulerAngles += shakeRotation; } else if (shakeIntensity < 0f) { StopShaking(); } }
public void ShowGUI() { GUILayout.Label("Basic structure", EditorStyles.boldLabel); if (GUILayout.Button("Organise room objects")) { InitialiseObjects(); } if (AdvGame.GetReferences().settingsManager == null) { EditorGUILayout.HelpBox("No Settings Manager defined - cannot display full Editor without it!", MessageType.Warning); return; } if (KickStarter.sceneSettings == null) { return; } SettingsManager settingsManager = AdvGame.GetReferences().settingsManager; EditorGUILayout.BeginHorizontal(); newFolderName = EditorGUILayout.TextField(newFolderName); if (GUILayout.Button("Create new folder", buttonWidth)) { if (newFolderName != "") { GameObject newFolder = new GameObject(); if (!newFolderName.StartsWith("_")) { newFolder.name = "_" + newFolderName; } else { newFolder.name = newFolderName; } Undo.RegisterCreatedObjectUndo(newFolder, "Create folder " + newFolder.name); if (Selection.activeGameObject) { newFolder.transform.parent = Selection.activeGameObject.transform; } Selection.activeObject = newFolder; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.Label("Scene settings", EditorStyles.boldLabel); KickStarter.sceneSettings.navigationMethod = (AC_NavigationMethod)EditorGUILayout.EnumPopup("Pathfinding method:", KickStarter.sceneSettings.navigationMethod); KickStarter.navigationManager.ResetEngine(); if (KickStarter.navigationManager.navigationEngine != null) { KickStarter.navigationManager.navigationEngine.SceneSettingsGUI(); } if (settingsManager.IsUnity2D() && KickStarter.sceneSettings.navigationMethod != AC_NavigationMethod.PolygonCollider) { EditorGUILayout.HelpBox("This pathfinding method is not compatible with 'Unity 2D'.", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultPlayerStart = (PlayerStart)EditorGUILayout.ObjectField("Default PlayerStart:", KickStarter.sceneSettings.defaultPlayerStart, typeof(PlayerStart), true); if (KickStarter.sceneSettings.defaultPlayerStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { PlayerStart newPlayerStart = AddPrefab("Navigation", "PlayerStart", true, false, true).GetComponent <PlayerStart>(); newPlayerStart.gameObject.name = "Default PlayerStart"; KickStarter.sceneSettings.defaultPlayerStart = newPlayerStart; } } EditorGUILayout.EndHorizontal(); if (KickStarter.sceneSettings.defaultPlayerStart) { EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = (_Camera)EditorGUILayout.ObjectField("Default Camera:", KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart, typeof(_Camera), true); if (KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { if (settingsManager == null || settingsManager.cameraPerspective == CameraPerspective.ThreeD) { GameCamera newCamera = AddPrefab("Camera", "GameCamera", true, false, true).GetComponent <GameCamera>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } else if (settingsManager.cameraPerspective == CameraPerspective.TwoD) { GameCamera2D newCamera = AddPrefab("Camera", "GameCamera2D", true, false, true).GetComponent <GameCamera2D>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } else if (settingsManager.cameraPerspective == CameraPerspective.TwoPointFiveD) { GameCamera25D newCamera = AddPrefab("Camera", "GameCamera2.5D", true, false, true).GetComponent <GameCamera25D>(); newCamera.gameObject.name = "NavCam 1"; KickStarter.sceneSettings.defaultPlayerStart.cameraOnStart = newCamera; } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.sortingMap = (SortingMap)EditorGUILayout.ObjectField("Default Sorting map:", KickStarter.sceneSettings.sortingMap, typeof(SortingMap), true); if (KickStarter.sceneSettings.sortingMap == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { SortingMap newSortingMap = AddPrefab("Navigation", "SortingMap", true, false, true).GetComponent <SortingMap>(); newSortingMap.gameObject.name = "Default SortingMap"; KickStarter.sceneSettings.sortingMap = newSortingMap; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.defaultSound = (Sound)EditorGUILayout.ObjectField("Default Sound prefab:", KickStarter.sceneSettings.defaultSound, typeof(Sound), true); if (KickStarter.sceneSettings.defaultSound == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Sound newSound = AddPrefab("Logic", "Sound", true, false, true).GetComponent <Sound>(); newSound.gameObject.name = "Default Sound"; KickStarter.sceneSettings.defaultSound = newSound; newSound.playWhilePaused = true; } } EditorGUILayout.EndHorizontal(); GUILayout.Label("Scene cutscenes", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnStart = (Cutscene)EditorGUILayout.ObjectField("On start:", KickStarter.sceneSettings.cutsceneOnStart, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnStart == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnStart"; KickStarter.sceneSettings.cutsceneOnStart = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnLoad = (Cutscene)EditorGUILayout.ObjectField("On load:", KickStarter.sceneSettings.cutsceneOnLoad, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnLoad == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnLoad"; KickStarter.sceneSettings.cutsceneOnLoad = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); KickStarter.sceneSettings.cutsceneOnVarChange = (Cutscene)EditorGUILayout.ObjectField("On variable change:", KickStarter.sceneSettings.cutsceneOnVarChange, typeof(Cutscene), true); if (KickStarter.sceneSettings.cutsceneOnVarChange == null) { if (GUILayout.Button("Create", GUILayout.MaxWidth(60f))) { Cutscene newCutscene = AddPrefab("Logic", "Cutscene", true, false, true).GetComponent <Cutscene>(); newCutscene.gameObject.name = "OnVarChange"; KickStarter.sceneSettings.cutsceneOnVarChange = newCutscene; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.Label("Visibility", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); GUILayout.Label("Triggers", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetTriggerVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetTriggerVisibility(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Collision", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetCollisionVisiblity(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetCollisionVisiblity(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Hotspots", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { SetHotspotVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { SetHotspotVisibility(false); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("NavMesh", buttonWidth); if (GUILayout.Button("On", EditorStyles.miniButtonLeft)) { KickStarter.navigationManager.navigationEngine.SetVisibility(true); } if (GUILayout.Button("Off", EditorStyles.miniButtonRight)) { KickStarter.navigationManager.navigationEngine.SetVisibility(false); } GUILayout.EndHorizontal(); ListPrefabs(); if (GUI.changed) { EditorUtility.SetDirty(KickStarter.sceneSettings); EditorUtility.SetDirty(KickStarter.playerMovement); if (KickStarter.sceneSettings.defaultPlayerStart) { EditorUtility.SetDirty(KickStarter.sceneSettings.defaultPlayerStart); } } }