diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a3715d1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,39 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Unity Editor", + "type": "unity", + "path": "/d:/Codice/LD45/Library/EditorInstance.json", + "request": "launch" + }, + { + "name": "Windows Player", + "type": "unity", + "request": "launch" + }, + { + "name": "OSX Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Linux Player", + "type": "unity", + "request": "launch" + }, + { + "name": "iOS Player", + "type": "unity", + "request": "launch" + }, + { + "name": "Android Player", + "type": "unity", + "request": "launch" + } + ] +} \ No newline at end of file diff --git a/Assets/Components/GameController.cs b/Assets/Components/GameController.cs index 968fc8f..6a284eb 100644 --- a/Assets/Components/GameController.cs +++ b/Assets/Components/GameController.cs @@ -4,5 +4,6 @@ using UnityEngine; public class GameController : MonoBehaviour { - public float gravitationConstant = 1; + [Header("Global Variables")] + public float gravitationConstant; } diff --git a/Assets/Components/Gravitation.cs b/Assets/Components/Gravitation.cs index 2fc98e7..adc4b2e 100644 --- a/Assets/Components/Gravitation.cs +++ b/Assets/Components/Gravitation.cs @@ -2,20 +2,21 @@ using System.Collections.Generic; using UnityEngine; +[RequireComponent(typeof(Rigidbody2D))] public class Gravitation : MonoBehaviour -{ - - public static List simulatedObjects = null; - - protected new Rigidbody2D rigidbody; - - protected GameController gameController; +{ + [Header("Forces")] + protected Vector3 appliedForce; + protected float forcesIntensity; + [Header("Internals")] + public static List simulatedObjects; public int positionInList; - protected Vector3 appliedForce; + [Header("References")] + protected new Rigidbody2D rigidbody; + protected GameController gameController; - protected float forcesIntensity; protected float mass { get { diff --git a/Assets/Components/PanWithMMB.cs b/Assets/Components/PanWithMMB.cs new file mode 100644 index 0000000..5f266a3 --- /dev/null +++ b/Assets/Components/PanWithMMB.cs @@ -0,0 +1,32 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Camera))] +public class PanWithMMB : MonoBehaviour +{ + [Header("References")] + protected new Camera camera; + + [Header("Internals")] + protected Vector3? lastMousePosition; + + private void Start() { + lastMousePosition = null; + camera = GetComponent(); + } + + private void Update() { + bool mmbIsPressed = Input.GetMouseButton(2); + Vector3? currentMousePosition = null; + if(mmbIsPressed) { + currentMousePosition = camera.ScreenToWorldPoint(Input.mousePosition); + if(lastMousePosition.HasValue) { + Vector3 positionDelta = lastMousePosition.Value - currentMousePosition.Value; + camera.transform.position += positionDelta; + currentMousePosition = camera.ScreenToWorldPoint(Input.mousePosition); + } + } + lastMousePosition = currentMousePosition; + } +} diff --git a/Assets/Components/PanWithMMB.cs.meta b/Assets/Components/PanWithMMB.cs.meta new file mode 100644 index 0000000..812c428 --- /dev/null +++ b/Assets/Components/PanWithMMB.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: faf7dfc2fa2059f4a96e4a134b4ef2ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Components/SpawnOnMouseClick.cs b/Assets/Components/SpawnOnMouseClick.cs new file mode 100644 index 0000000..89a1cc4 --- /dev/null +++ b/Assets/Components/SpawnOnMouseClick.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SpawnOnMouseClick : MonoBehaviour +{ + [Header("Config")] + public GameObject prefabToSpawn; + public int mouseButton; + + protected Vector3 GetWorldMousePosition() { + return Camera.main.ScreenToWorldPoint(Input.mousePosition); + } + + void Update() + { + if(Input.GetMouseButtonDown(mouseButton)) { + Vector3 mousePosition = GetWorldMousePosition(); + GameObject instance = Instantiate(prefabToSpawn, new Vector3(mousePosition.x, mousePosition.y, 0f), Quaternion.identity); + } + } +} diff --git a/Assets/Components/SpawnOnMouseClick.cs.meta b/Assets/Components/SpawnOnMouseClick.cs.meta new file mode 100644 index 0000000..688984b --- /dev/null +++ b/Assets/Components/SpawnOnMouseClick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c6157b8c0c98584db4becc892a8f6fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Components/ZoomWithScrollWheel.cs b/Assets/Components/ZoomWithScrollWheel.cs new file mode 100644 index 0000000..9aaf1e8 --- /dev/null +++ b/Assets/Components/ZoomWithScrollWheel.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(Camera))] +public class ZoomWithScrollWheel : MonoBehaviour +{ + [Header("Config")] + public float zoomMultiplier; + public string zoomAxisName; + + [Header("References")] + protected new Camera camera; + + void Start() + { + camera = GetComponent(); + } + + void Update() + { + float mouseWheel = Input.GetAxis(zoomAxisName); + if(mouseWheel != 0) { + camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - mouseWheel * zoomMultiplier, 0, float.PositiveInfinity); + } + } +} diff --git a/Assets/Components/ZoomWithScrollWheel.cs.meta b/Assets/Components/ZoomWithScrollWheel.cs.meta new file mode 100644 index 0000000..90d2e7c --- /dev/null +++ b/Assets/Components/ZoomWithScrollWheel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45a8a9da7e5b8734eb709105fd6e30e1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/GameController.prefab b/Assets/Prefabs/GameController.prefab index 6cb56f5..3dbc1da 100644 --- a/Assets/Prefabs/GameController.prefab +++ b/Assets/Prefabs/GameController.prefab @@ -43,3 +43,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1d1d0978f263bec41af567152b121a2e, type: 3} m_Name: m_EditorClassIdentifier: + gravitationConstant: 2 diff --git a/Assets/Prefabs/MainCamera.prefab b/Assets/Prefabs/MainCamera.prefab index 5faa415..25616a1 100644 --- a/Assets/Prefabs/MainCamera.prefab +++ b/Assets/Prefabs/MainCamera.prefab @@ -11,6 +11,9 @@ GameObject: - component: {fileID: 9221969453073420272} - component: {fileID: 9221969453073420047} - component: {fileID: 9221969453073420045} + - component: {fileID: 1504932582} + - component: {fileID: 1504932583} + - component: {fileID: 1504932587} m_Layer: 0 m_Name: MainCamera m_TagString: MainCamera @@ -83,3 +86,42 @@ AudioListener: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9221969453073420044} m_Enabled: 1 +--- !u!114 &1504932582 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9221969453073420044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6c6157b8c0c98584db4becc892a8f6fd, type: 3} + m_Name: + m_EditorClassIdentifier: + prefab: {fileID: 5473375028011702754, guid: e73d8e05bd7498c4a80a63094f4594a8, type: 3} +--- !u!114 &1504932583 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9221969453073420044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 45a8a9da7e5b8734eb709105fd6e30e1, type: 3} + m_Name: + m_EditorClassIdentifier: + zoomMultiplier: 1 + zoomAxisName: MouseWheel +--- !u!114 &1504932587 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9221969453073420044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: faf7dfc2fa2059f4a96e4a134b4ef2ab, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 732d7f5..6ff1b0e 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -121,140 +121,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &1005736364 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1005736369} - - component: {fileID: 1005736368} - - component: {fileID: 1005736367} - - component: {fileID: 1005736366} - - component: {fileID: 1005736365} - m_Layer: 0 - m_Name: Gravitation Object - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1005736365 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1005736364} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d16f17bda197c324f8b088f106c66c5c, type: 3} - m_Name: - m_EditorClassIdentifier: - positionInList: 0 ---- !u!212 &1005736366 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1005736364} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: d8cf31929ca287542bdc219ec19f002e, type: 3} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 1, y: 1} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 ---- !u!58 &1005736367 -CircleCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1005736364} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} - serializedVersion: 2 - m_Radius: 0.5 ---- !u!50 &1005736368 -Rigidbody2D: - serializedVersion: 4 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1005736364} - m_BodyType: 0 - m_Simulated: 1 - m_UseFullKinematicContacts: 0 - m_UseAutoMass: 1 - m_Mass: 0.7853982 - m_LinearDrag: 0 - m_AngularDrag: 0.05 - m_GravityScale: 0 - m_Material: {fileID: 0} - m_Interpolate: 0 - m_SleepingMode: 1 - m_CollisionDetection: 0 - m_Constraints: 0 ---- !u!4 &1005736369 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1005736364} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -15.4, y: 6.35, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1803533283597936005 PrefabInstance: m_ObjectHideFlags: 0 @@ -322,11 +188,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 4937878819460165300, guid: bf08d766b6e86cf4a8773489143ab2d5, - type: 3} - propertyPath: gravitationConstant - value: 2 - objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: bf08d766b6e86cf4a8773489143ab2d5, type: 3} --- !u!1001 &9221969453494073200 @@ -396,10 +257,5 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 9221969453073420047, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, - type: 3} - propertyPath: orthographic size - value: 20 - objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, type: 3}