diff options
| author | Alee <Alee14498@gmail.com> | 2019-05-31 20:34:40 -0400 |
|---|---|---|
| committer | Alee <Alee14498@gmail.com> | 2019-05-31 20:34:40 -0400 |
| commit | 1a218e49d6c23b0d1da5c30d81784ea9d8350016 (patch) | |
| tree | c9470c471ea23e377fa69ad74fe4ef459ebc2a4a /Assets/RTS_Camera | |
| parent | 15c23e28f3bd5ac8015cb93df034a1196031d97b (diff) | |
| download | Unicity-1a218e49d6c23b0d1da5c30d81784ea9d8350016.tar.gz Unicity-1a218e49d6c23b0d1da5c30d81784ea9d8350016.tar.bz2 Unicity-1a218e49d6c23b0d1da5c30d81784ea9d8350016.zip | |
UI changesexperimental-1
Diffstat (limited to 'Assets/RTS_Camera')
| -rw-r--r-- | Assets/RTS_Camera/RTS_Camera.prefab | 175 | ||||
| -rw-r--r-- | Assets/RTS_Camera/RTS_Camera.prefab.meta | 8 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts.meta | 9 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/Editor.meta | 9 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs | 108 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs.meta | 12 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs | 158 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs.meta | 12 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/RTS_Camera.cs | 344 | ||||
| -rw-r--r-- | Assets/RTS_Camera/Scripts/RTS_Camera.cs.meta | 12 |
10 files changed, 0 insertions, 847 deletions
diff --git a/Assets/RTS_Camera/RTS_Camera.prefab b/Assets/RTS_Camera/RTS_Camera.prefab deleted file mode 100644 index 628ddc8..0000000 --- a/Assets/RTS_Camera/RTS_Camera.prefab +++ /dev/null @@ -1,175 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &120296 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 459968} - - component: {fileID: 2056488} - - component: {fileID: 9275010} - - component: {fileID: 12455804} - - component: {fileID: 8165074} - - component: {fileID: 11488424} - - component: {fileID: 11455738} - m_Layer: 0 - m_Name: RTS_Camera - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &459968 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_LocalRotation: {x: 0.7071069, y: 0, z: 0, w: 0.70710677} - m_LocalPosition: {x: 0, y: 6.75, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!20 &2056488 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844} - m_projectionMatrixMode: 1 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_GateFitMode: 2 - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 0 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!92 &9275010 -Behaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 ---- !u!124 &12455804 -Behaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 ---- !u!81 &8165074 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 ---- !u!114 &11488424 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 20048c13a5d194941bac6cd566a5e468, type: 3} - m_Name: - m_EditorClassIdentifier: - targetsTag: target ---- !u!114 &11455738 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 120296} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 28ef8c68bade09b41aca258d42a632f2, type: 3} - m_Name: - m_EditorClassIdentifier: - lastTab: 0 - movementSettingsFoldout: 1 - zoomingSettingsFoldout: 0 - rotationSettingsFoldout: 1 - heightSettingsFoldout: 1 - mapLimitSettingsFoldout: 1 - targetingSettingsFoldout: 1 - inputSettingsFoldout: 1 - useFixedUpdate: 0 - keyboardMovementSpeed: 5 - screenEdgeMovementSpeed: 3 - followingSpeed: 5 - rotationSped: 3 - panningSpeed: 25 - mouseRotationSpeed: 100 - autoHeight: 1 - groundMask: - serializedVersion: 2 - m_Bits: 55 - maxHeight: 15 - minHeight: 10 - heightDampening: 5 - keyboardZoomingSensitivity: 2 - scrollWheelZoomingSensitivity: 25 - limitMap: 1 - limitX: 10 - limitY: 10 - targetFollow: {fileID: 0} - targetOffset: {x: 0, y: 0, z: 0} - useScreenEdgeInput: 1 - screenEdgeBorder: 25 - useKeyboardInput: 1 - horizontalAxis: Horizontal - verticalAxis: Vertical - usePanning: 1 - panningKey: 325 - useKeyboardZooming: 1 - zoomInKey: 101 - zoomOutKey: 113 - useScrollwheelZooming: 1 - zoomingAxis: Mouse ScrollWheel - useKeyboardRotation: 1 - rotateRightKey: 120 - rotateLeftKey: 122 - useMouseRotation: 1 - mouseRotationKey: 324 diff --git a/Assets/RTS_Camera/RTS_Camera.prefab.meta b/Assets/RTS_Camera/RTS_Camera.prefab.meta deleted file mode 100644 index f5bb07f..0000000 --- a/Assets/RTS_Camera/RTS_Camera.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 407bd5cbe8c43334bb1b25c0f3826974 -timeCreated: 1440059567 -licenseType: Store -NativeFormatImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/RTS_Camera/Scripts.meta b/Assets/RTS_Camera/Scripts.meta deleted file mode 100644 index dd00394..0000000 --- a/Assets/RTS_Camera/Scripts.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 0093e3f39000d9b47a825023d8a01b0e -folderAsset: yes -timeCreated: 1438769848 -licenseType: Store -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/RTS_Camera/Scripts/Editor.meta b/Assets/RTS_Camera/Scripts/Editor.meta deleted file mode 100644 index e25e69e..0000000 --- a/Assets/RTS_Camera/Scripts/Editor.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: e5e4a28cbe8c55244bb1b72b33e5f8b6 -folderAsset: yes -timeCreated: 1438769856 -licenseType: Store -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs b/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs deleted file mode 100644 index 2c41a09..0000000 --- a/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs +++ /dev/null @@ -1,108 +0,0 @@ -using UnityEngine; -using System; -using System.Collections.Generic; -using UnityEditor; -using System.Linq; - - -public class VerticalBlock : IDisposable -{ - public VerticalBlock(params GUILayoutOption[] options) - { - GUILayout.BeginVertical(options); - } - - public VerticalBlock(GUIStyle style, params GUILayoutOption[] options) - { - GUILayout.BeginVertical(style, options); - } - - public void Dispose() - { - GUILayout.EndVertical(); - } -} - -public class ScrollviewBlock : IDisposable -{ - public ScrollviewBlock(ref Vector2 scrollPos, params GUILayoutOption[] options) - { - scrollPos = GUILayout.BeginScrollView(scrollPos, options); - } - - public void Dispose() - { - GUILayout.EndScrollView(); - } -} - -public class HorizontalBlock : IDisposable -{ - public HorizontalBlock(params GUILayoutOption[] options) - { - GUILayout.BeginHorizontal(options); - } - - public HorizontalBlock(GUIStyle style, params GUILayoutOption[] options) - { - GUILayout.BeginHorizontal(style, options); - } - - public void Dispose() - { - GUILayout.EndHorizontal(); - } -} - -public class ColoredBlock : System.IDisposable -{ - public ColoredBlock(Color color) - { - GUI.color = color; - } - - public void Dispose() - { - GUI.color = Color.white; - } -} - -[Serializable] -public class TabsBlock -{ - private Dictionary<string, Action> methods; - private Action currentGuiMethod; - public int curMethodIndex = -1; - - public TabsBlock(Dictionary<string, Action> _methods) - { - methods = _methods; - SetCurrentMethod(0); - } - - public void Draw() - { - var keys = methods.Keys.ToArray(); - using (new VerticalBlock(EditorStyles.helpBox)) - { - using (new HorizontalBlock()) - { - for (int i = 0; i < keys.Length; i++) - { - var btnStyle = i == 0 ? EditorStyles.miniButtonLeft : i == (keys.Length - 1) ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid; - using (new ColoredBlock(currentGuiMethod == methods[keys[i]] ? Color.grey : Color.white)) - if (GUILayout.Button(keys[i], btnStyle)) - SetCurrentMethod(i); - } - } - GUILayout.Label(keys[curMethodIndex], EditorStyles.centeredGreyMiniLabel); - currentGuiMethod(); - } - } - - public void SetCurrentMethod(int index) - { - curMethodIndex = index; - currentGuiMethod = methods[methods.Keys.ToArray()[index]]; - } -}
\ No newline at end of file diff --git a/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs.meta b/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs.meta deleted file mode 100644 index 07148cb..0000000 --- a/Assets/RTS_Camera/Scripts/Editor/LayoutHelpers.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e6604c54827307c4083b63203d4fed4b -timeCreated: 1451938860 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs b/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs deleted file mode 100644 index d4a828f..0000000 --- a/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs +++ /dev/null @@ -1,158 +0,0 @@ -using UnityEngine; -using System.Collections.Generic; -using UnityEditor; - -namespace RTS_Cam -{ - [CustomEditor(typeof(RTS_Camera))] - public class RTS_CameraEditor : Editor - { - private RTS_Camera camera { get { return target as RTS_Camera; } } - - private TabsBlock tabs; - - private void OnEnable() - { - tabs = new TabsBlock(new Dictionary<string, System.Action>() - { - {"Movement", MovementTab}, - {"Rotation", RotationTab}, - {"Height", HeightTab} - }); - tabs.SetCurrentMethod(camera.lastTab); - } - - public override void OnInspectorGUI() - { - //base.OnInspectorGUI(); - Undo.RecordObject(camera, "RTS_CAmera"); - tabs.Draw(); - if (GUI.changed) - camera.lastTab = tabs.curMethodIndex; - EditorUtility.SetDirty(camera); - } - - private void MovementTab() - { - using (new HorizontalBlock()) - { - GUILayout.Label("Use keyboard input: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useKeyboardInput = EditorGUILayout.Toggle( camera.useKeyboardInput); - } - if(camera.useKeyboardInput) - { - camera.horizontalAxis = EditorGUILayout.TextField("Horizontal axis name: ", camera.horizontalAxis); - camera.verticalAxis = EditorGUILayout.TextField("Vertical axis name: ", camera.verticalAxis); - camera.keyboardMovementSpeed = EditorGUILayout.FloatField("Movement speed: ", camera.keyboardMovementSpeed); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Screen edge input: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useScreenEdgeInput = EditorGUILayout.Toggle( camera.useScreenEdgeInput); - } - - if(camera.useScreenEdgeInput) - { - EditorGUILayout.FloatField("Screen edge border size: ", camera.screenEdgeBorder); - camera.screenEdgeMovementSpeed = EditorGUILayout.FloatField("Screen edge movement speed: ", camera.screenEdgeMovementSpeed); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Panning with mouse: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.usePanning = EditorGUILayout.Toggle(camera.usePanning); - } - if(camera.usePanning) - { - camera.panningKey = (KeyCode)EditorGUILayout.EnumPopup("Panning when holding: ", camera.panningKey); - camera.panningSpeed = EditorGUILayout.FloatField("Panning speed: ", camera.panningSpeed); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Limit movement: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.limitMap = EditorGUILayout.Toggle(camera.limitMap); - } - if (camera.limitMap) - { - camera.limitX = EditorGUILayout.FloatField("Limit X: ", camera.limitX); - camera.limitY = EditorGUILayout.FloatField("Limit Y: ", camera.limitY); - } - - GUILayout.Label("Follow target", EditorStyles.boldLabel); - camera.targetFollow = EditorGUILayout.ObjectField("Target to follow: ", camera.targetFollow, typeof(Transform)) as Transform; - camera.targetOffset = EditorGUILayout.Vector3Field("Target offset: ", camera.targetOffset); - camera.followingSpeed = EditorGUILayout.FloatField("Following speed: ", camera.followingSpeed); - } - - private void RotationTab() - { - using (new HorizontalBlock()) - { - GUILayout.Label("Keyboard input: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useKeyboardRotation = EditorGUILayout.Toggle(camera.useKeyboardRotation); - } - if(camera.useKeyboardRotation) - { - camera.rotateLeftKey = (KeyCode)EditorGUILayout.EnumPopup("Rotate left: ", camera.rotateLeftKey); - camera.rotateRightKey = (KeyCode)EditorGUILayout.EnumPopup("Rotate right: ", camera.rotateRightKey); - camera.rotationSped = EditorGUILayout.FloatField("Keyboard rotation speed", camera.rotationSped); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Mouse input: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useMouseRotation = EditorGUILayout.Toggle(camera.useMouseRotation); - } - if(camera.useMouseRotation) - { - camera.mouseRotationKey = (KeyCode)EditorGUILayout.EnumPopup("Mouse rotation key: ", camera.mouseRotationKey); - camera.mouseRotationSpeed = EditorGUILayout.FloatField("Mouse rotation speed: ", camera.mouseRotationSpeed); - } - } - - private void HeightTab() - { - using (new HorizontalBlock()) - { - GUILayout.Label("Auto height: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.autoHeight = EditorGUILayout.Toggle(camera.autoHeight); - } - if (camera.autoHeight) - { - camera.heightDampening = EditorGUILayout.FloatField("Height dampening: ", camera.heightDampening); - EditorGUILayout.PropertyField(serializedObject.FindProperty("groundMask")); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Keyboard zooming: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useKeyboardZooming = EditorGUILayout.Toggle(camera.useKeyboardZooming); - } - if(camera.useKeyboardZooming) - { - camera.zoomInKey = (KeyCode)EditorGUILayout.EnumPopup("Zoom In: ", camera.zoomInKey); - camera.zoomOutKey = (KeyCode)EditorGUILayout.EnumPopup("Zoom Out: ", camera.zoomOutKey); - camera.keyboardZoomingSensitivity = EditorGUILayout.FloatField("Keyboard sensitivity: ", camera.keyboardZoomingSensitivity); - } - - using (new HorizontalBlock()) - { - GUILayout.Label("Scrollwheel zooming: ", EditorStyles.boldLabel, GUILayout.Width(170f)); - camera.useScrollwheelZooming = EditorGUILayout.Toggle(camera.useScrollwheelZooming); - } - if (camera.useScrollwheelZooming) - camera.scrollWheelZoomingSensitivity = EditorGUILayout.FloatField("Scrollwheel sensitivity: ", camera.scrollWheelZoomingSensitivity); - - if (camera.useScrollwheelZooming || camera.useKeyboardZooming) - { - using (new HorizontalBlock()) - { - camera.maxHeight = EditorGUILayout.FloatField("Max height: ", camera.maxHeight); - camera.minHeight = EditorGUILayout.FloatField("Min height: ", camera.minHeight); - } - } - } - } -}
\ No newline at end of file diff --git a/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs.meta b/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs.meta deleted file mode 100644 index 2c39be4..0000000 --- a/Assets/RTS_Camera/Scripts/Editor/RTS_CameraEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: f43923eb579b5ab44bc30687c03d3abe -timeCreated: 1438769886 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/RTS_Camera/Scripts/RTS_Camera.cs b/Assets/RTS_Camera/Scripts/RTS_Camera.cs deleted file mode 100644 index 5e5ee76..0000000 --- a/Assets/RTS_Camera/Scripts/RTS_Camera.cs +++ /dev/null @@ -1,344 +0,0 @@ -using UnityEngine; -using System.Collections; - -namespace RTS_Cam -{ - [RequireComponent(typeof(Camera))] - [AddComponentMenu("RTS Camera")] - public class RTS_Camera : MonoBehaviour - { - - #region Foldouts - -#if UNITY_EDITOR - - public int lastTab = 0; - - public bool movementSettingsFoldout; - public bool zoomingSettingsFoldout; - public bool rotationSettingsFoldout; - public bool heightSettingsFoldout; - public bool mapLimitSettingsFoldout; - public bool targetingSettingsFoldout; - public bool inputSettingsFoldout; - -#endif - - #endregion - - private Transform m_Transform; //camera tranform - public bool useFixedUpdate = false; //use FixedUpdate() or Update() - - #region Movement - - public float keyboardMovementSpeed = 5f; //speed with keyboard movement - public float screenEdgeMovementSpeed = 3f; //spee with screen edge movement - public float followingSpeed = 5f; //speed when following a target - public float rotationSped = 3f; - public float panningSpeed = 10f; - public float mouseRotationSpeed = 10f; - - #endregion - - #region Height - - public bool autoHeight = true; - public LayerMask groundMask = -1; //layermask of ground or other objects that affect height - - public float maxHeight = 10f; //maximal height - public float minHeight = 15f; //minimnal height - public float heightDampening = 5f; - public float keyboardZoomingSensitivity = 2f; - public float scrollWheelZoomingSensitivity = 25f; - - private float zoomPos = 0; //value in range (0, 1) used as t in Matf.Lerp - - #endregion - - #region MapLimits - - public bool limitMap = true; - public float limitX = 50f; //x limit of map - public float limitY = 50f; //z limit of map - - #endregion - - #region Targeting - - public Transform targetFollow; //target to follow - public Vector3 targetOffset; - - /// <summary> - /// are we following target - /// </summary> - public bool FollowingTarget - { - get - { - return targetFollow != null; - } - } - - #endregion - - #region Input - - public bool useScreenEdgeInput = true; - public float screenEdgeBorder = 25f; - - public bool useKeyboardInput = true; - public string horizontalAxis = "Horizontal"; - public string verticalAxis = "Vertical"; - - public bool usePanning = true; - public KeyCode panningKey = KeyCode.Mouse2; - - public bool useKeyboardZooming = true; - public KeyCode zoomInKey = KeyCode.E; - public KeyCode zoomOutKey = KeyCode.Q; - - public bool useScrollwheelZooming = true; - public string zoomingAxis = "Mouse ScrollWheel"; - - public bool useKeyboardRotation = true; - public KeyCode rotateRightKey = KeyCode.X; - public KeyCode rotateLeftKey = KeyCode.Z; - - public bool useMouseRotation = true; - public KeyCode mouseRotationKey = KeyCode.Mouse1; - - private Vector2 KeyboardInput - { - get { return useKeyboardInput ? new Vector2(Input.GetAxis(horizontalAxis), Input.GetAxis(verticalAxis)) : Vector2.zero; } - } - - private Vector2 MouseInput - { - get { return Input.mousePosition; } - } - - private float ScrollWheel - { - get { return Input.GetAxis(zoomingAxis); } - } - - private Vector2 MouseAxis - { - get { return new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); } - } - - private int ZoomDirection - { - get - { - bool zoomIn = Input.GetKey(zoomInKey); - bool zoomOut = Input.GetKey(zoomOutKey); - if (zoomIn && zoomOut) - return 0; - else if (!zoomIn && zoomOut) - return 1; - else if (zoomIn && !zoomOut) - return -1; - else - return 0; - } - } - - private int RotationDirection - { - get - { - bool rotateRight = Input.GetKey(rotateRightKey); - bool rotateLeft = Input.GetKey(rotateLeftKey); - if(rotateLeft && rotateRight) - return 0; - else if(rotateLeft && !rotateRight) - return -1; - else if(!rotateLeft && rotateRight) - return 1; - else - return 0; - } - } - - #endregion - - #region Unity_Methods - - private void Start() - { - m_Transform = transform; - } - - private void Update() - { - if (!useFixedUpdate) - CameraUpdate(); - } - - private void FixedUpdate() - { - if (useFixedUpdate) - CameraUpdate(); - } - - #endregion - - #region RTSCamera_Methods - - /// <summary> - /// update camera movement and rotation - /// </summary> - private void CameraUpdate() - { - if (FollowingTarget) - FollowTarget(); - else - Move(); - - HeightCalculation(); - Rotation(); - LimitPosition(); - } - - /// <summary> - /// move camera with keyboard or with screen edge - /// </summary> - private void Move() - { - if (useKeyboardInput) - { - Vector3 desiredMove = new Vector3(KeyboardInput.x, 0, KeyboardInput.y); - - desiredMove *= keyboardMovementSpeed; - desiredMove *= Time.deltaTime; - desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; - desiredMove = m_Transform.InverseTransformDirection(desiredMove); - - m_Transform.Translate(desiredMove, Space.Self); - } - - if (useScreenEdgeInput) - { - Vector3 desiredMove = new Vector3(); - - Rect leftRect = new Rect(0, 0, screenEdgeBorder, Screen.height); - Rect rightRect = new Rect(Screen.width - screenEdgeBorder, 0, screenEdgeBorder, Screen.height); - Rect upRect = new Rect(0, Screen.height - screenEdgeBorder, Screen.width, screenEdgeBorder); - Rect downRect = new Rect(0, 0, Screen.width, screenEdgeBorder); - - desiredMove.x = leftRect.Contains(MouseInput) ? -1 : rightRect.Contains(MouseInput) ? 1 : 0; - desiredMove.z = upRect.Contains(MouseInput) ? 1 : downRect.Contains(MouseInput) ? -1 : 0; - - desiredMove *= screenEdgeMovementSpeed; - desiredMove *= Time.deltaTime; - desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; - desiredMove = m_Transform.InverseTransformDirection(desiredMove); - - m_Transform.Translate(desiredMove, Space.Self); - } - - if(usePanning && Input.GetKey(panningKey) && MouseAxis != Vector2.zero) - { - Vector3 desiredMove = new Vector3(-MouseAxis.x, 0, -MouseAxis.y); - - desiredMove *= panningSpeed; - desiredMove *= Time.deltaTime; - desiredMove = Quaternion.Euler(new Vector3(0f, transform.eulerAngles.y, 0f)) * desiredMove; - desiredMove = m_Transform.InverseTransformDirection(desiredMove); - - m_Transform.Translate(desiredMove, Space.Self); - } - } - - /// <summary> - /// calcualte height - /// </summary> - private void HeightCalculation() - { - float distanceToGround = DistanceToGround(); - if(useScrollwheelZooming) - zoomPos += ScrollWheel * Time.deltaTime * scrollWheelZoomingSensitivity; - if (useKeyboardZooming) - zoomPos += ZoomDirection * Time.deltaTime * keyboardZoomingSensitivity; - - zoomPos = Mathf.Clamp01(zoomPos); - - float targetHeight = Mathf.Lerp(minHeight, maxHeight, zoomPos); - float difference = 0; - - if(distanceToGround != targetHeight) - difference = targetHeight - distanceToGround; - - m_Transform.position = Vector3.Lerp(m_Transform.position, - new Vector3(m_Transform.position.x, targetHeight + difference, m_Transform.position.z), Time.deltaTime * heightDampening); - } - - /// <summary> - /// rotate camera - /// </summary> - private void Rotation() - { - if(useKeyboardRotation) - transform.Rotate(Vector3.up, RotationDirection * Time.deltaTime * rotationSped, Space.World); - - if (useMouseRotation && Input.GetKey(mouseRotationKey)) - m_Transform.Rotate(Vector3.up, -MouseAxis.x * Time.deltaTime * mouseRotationSpeed, Space.World); - } - - /// <summary> - /// follow targetif target != null - /// </summary> - private void FollowTarget() - { - Vector3 targetPos = new Vector3(targetFollow.position.x, m_Transform.position.y, targetFollow.position.z) + targetOffset; - m_Transform.position = Vector3.MoveTowards(m_Transform.position, targetPos, Time.deltaTime * followingSpeed); - } - - /// <summary> - /// limit camera position - /// </summary> - private void LimitPosition() - { - if (!limitMap) - return; - - m_Transform.position = new Vector3(Mathf.Clamp(m_Transform.position.x, -limitX, limitX), - m_Transform.position.y, - Mathf.Clamp(m_Transform.position.z, -limitY, limitY)); - } - - /// <summary> - /// set the target - /// </summary> - /// <param name="target"></param> - public void SetTarget(Transform target) - { - targetFollow = target; - } - - /// <summary> - /// reset the target (target is set to null) - /// </summary> - public void ResetTarget() - { - targetFollow = null; - } - - /// <summary> - /// calculate distance to ground - /// </summary> - /// <returns></returns> - private float DistanceToGround() - { - Ray ray = new Ray(m_Transform.position, Vector3.down); - RaycastHit hit; - if (Physics.Raycast(ray, out hit, groundMask.value)) - return (hit.point - m_Transform.position).magnitude; - - return 0f; - } - - #endregion - } -}
\ No newline at end of file diff --git a/Assets/RTS_Camera/Scripts/RTS_Camera.cs.meta b/Assets/RTS_Camera/Scripts/RTS_Camera.cs.meta deleted file mode 100644 index 70a41e8..0000000 --- a/Assets/RTS_Camera/Scripts/RTS_Camera.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 28ef8c68bade09b41aca258d42a632f2 -timeCreated: 1438769867 -licenseType: Store -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: |
