1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-25 17:54:19 +00:00

Add camera control

This commit is contained in:
Steffo 2019-10-05 11:48:36 +02:00
parent edd04b6776
commit d736aa97a2
12 changed files with 208 additions and 154 deletions

39
.vscode/launch.json vendored Normal file
View file

@ -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"
}
]
}

View file

@ -4,5 +4,6 @@ using UnityEngine;
public class GameController : MonoBehaviour public class GameController : MonoBehaviour
{ {
public float gravitationConstant = 1; [Header("Global Variables")]
public float gravitationConstant;
} }

View file

@ -2,20 +2,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Gravitation : MonoBehaviour public class Gravitation : MonoBehaviour
{ {
[Header("Forces")]
protected Vector3 appliedForce;
protected float forcesIntensity;
public static List<Gravitation> simulatedObjects = null; [Header("Internals")]
public static List<Gravitation> simulatedObjects;
protected new Rigidbody2D rigidbody;
protected GameController gameController;
public int positionInList; public int positionInList;
protected Vector3 appliedForce; [Header("References")]
protected new Rigidbody2D rigidbody;
protected GameController gameController;
protected float forcesIntensity;
protected float mass { protected float mass {
get { get {

View file

@ -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<Camera>();
}
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;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: faf7dfc2fa2059f4a96e4a134b4ef2ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c6157b8c0c98584db4becc892a8f6fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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<Camera>();
}
void Update()
{
float mouseWheel = Input.GetAxis(zoomAxisName);
if(mouseWheel != 0) {
camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - mouseWheel * zoomMultiplier, 0, float.PositiveInfinity);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 45a8a9da7e5b8734eb709105fd6e30e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -43,3 +43,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1d1d0978f263bec41af567152b121a2e, type: 3} m_Script: {fileID: 11500000, guid: 1d1d0978f263bec41af567152b121a2e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
gravitationConstant: 2

View file

@ -11,6 +11,9 @@ GameObject:
- component: {fileID: 9221969453073420272} - component: {fileID: 9221969453073420272}
- component: {fileID: 9221969453073420047} - component: {fileID: 9221969453073420047}
- component: {fileID: 9221969453073420045} - component: {fileID: 9221969453073420045}
- component: {fileID: 1504932582}
- component: {fileID: 1504932583}
- component: {fileID: 1504932587}
m_Layer: 0 m_Layer: 0
m_Name: MainCamera m_Name: MainCamera
m_TagString: MainCamera m_TagString: MainCamera
@ -83,3 +86,42 @@ AudioListener:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9221969453073420044} m_GameObject: {fileID: 9221969453073420044}
m_Enabled: 1 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:

View file

@ -121,140 +121,6 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 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 --- !u!1001 &1803533283597936005
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -322,11 +188,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4937878819460165300, guid: bf08d766b6e86cf4a8773489143ab2d5,
type: 3}
propertyPath: gravitationConstant
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bf08d766b6e86cf4a8773489143ab2d5, type: 3} m_SourcePrefab: {fileID: 100100000, guid: bf08d766b6e86cf4a8773489143ab2d5, type: 3}
--- !u!1001 &9221969453494073200 --- !u!1001 &9221969453494073200
@ -396,10 +257,5 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 9221969453073420047, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1,
type: 3}
propertyPath: orthographic size
value: 20
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, type: 3}