Skip to content

Commit

Permalink
Overhauled Input
Browse files Browse the repository at this point in the history
Changed up how information on what you're looking at is handled and
changed how input is handled as well.
  • Loading branch information
Kelvoid committed Feb 8, 2017
1 parent 63246ad commit 73a0925
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 186 deletions.
67 changes: 0 additions & 67 deletions Satellite/Assets/CursorController.cs

This file was deleted.

Binary file modified Satellite/Assets/_Scenes/Observatory.unity
Binary file not shown.
13 changes: 12 additions & 1 deletion Satellite/Assets/_Scripts/CameraMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ public class CameraMovement : MonoBehaviour
{

internal GameManager gameManager;
internal StateManager stateManager;
internal TargetedLerp targetedLerp;

void Start()
{
gameManager = FindObjectOfType<GameManager>();
targetedLerp = GetComponent<TargetedLerp>();
}

public void MouseLook()
{

}

public void CameraTravel(Vector3 target)
{
targetedLerp.StartLerping(gameManager.mainCamera.gameObject, target, 1f, 1);
}
}
40 changes: 40 additions & 0 deletions Satellite/Assets/_Scripts/CursorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CursorController : MonoBehaviour
{
public GameObject cross;
public GameObject ring;

GameManager gameManager;
TargetedLerp targetedLerp;

void Start ()
{
gameManager = FindObjectOfType<GameManager>();
targetedLerp = GetComponentInChildren<TargetedLerp>();
}

void Update()
{
ring.transform.position = gameManager.inputManager.mousePosition;

//if(gameManager.inputManager)

if (gameManager.currentFocus != null)
{
if (Vector2.Distance(gameManager.inputManager.mousePosition, gameManager.currentFocus.screenPos) < gameManager.focalRange)
{
targetedLerp.StartLerping(cross, gameManager.currentFocus.screenPos, 0.05f, 1);
}
}

else
{
targetedLerp.StartLerping(cross, gameManager.inputManager.mousePosition, 0.05f, 1);
}

}

}
File renamed without changes.
8 changes: 4 additions & 4 deletions Satellite/Assets/_Scripts/Cutoff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void FixedUpdate()
{
if (material.GetFloat(shaderValue) <= 0.8)
{
Debug.Log("Shell Up");
//Debug.Log("Shell Up");
stateManager.shellUp = true;
}
else if (material.GetFloat(shaderValue) > 0.8f)
{
Debug.Log("Shell Down");
//Debug.Log("Shell Down");
stateManager.shellUp = false;
}

Expand All @@ -50,7 +50,7 @@ void FixedUpdate()

if (percentageComplete >= percentageOfCutoff)
{
Debug.Log("Done Lerping");
//Debug.Log("Done Lerping");
isLerping = false;
}
}
Expand All @@ -60,7 +60,7 @@ public void StartLerpingCutoff(float target, float percentage, float duration)
{
if(isLerping == false)
{
Debug.Log("Began Lerping");
//Debug.Log("Began Lerping");
isLerping = true;
percentageOfCutoff = percentage;
cutoffTime = duration;
Expand Down
14 changes: 5 additions & 9 deletions Satellite/Assets/_Scripts/FocusTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
public class FocusTarget : MonoBehaviour
{
GameManager gameManager;

Vector3 screenPos;
internal float distanceFromCenter;
internal Vector3 screenPos;
internal float distanceFromCursor;

void Awake ()
{
Expand All @@ -16,15 +15,12 @@ void Awake ()

void Update ()
{
if (screenPos.z < 0)
return;
screenPos = gameManager.mainCamera.WorldToScreenPoint(gameObject.transform.position);

distanceFromCenter = Vector2.Distance(screenPos, gameManager.screenCenter);
distanceFromCursor = Vector2.Distance(screenPos, gameManager.inputManager.mousePosition);

if (distanceFromCenter < gameManager.focalRange)
if (gameManager.stateManager.shellUp == false && distanceFromCursor < gameManager.focalRange)
{
gameManager.currentFocus = gameObject;
gameManager.currentFocus = gameObject.GetComponent<FocusTarget>();
}
}
}
36 changes: 17 additions & 19 deletions Satellite/Assets/_Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,45 @@

public class GameManager : MonoBehaviour
{
public GameObject currentFocus;
public FocusTarget currentFocus;
public GameObject lastDestination;
public GameObject lastFocus;

public GameObject home;

public LinkLine linkLine;
public Camera mainCamera;
public StateManager stateManager;
internal CameraMovement cameraMovement;
internal StateManager stateManager;
internal InputManager inputManager;
internal Cutoff cutoff;

public float meshRenderDistance;
public float focalRange;
internal Vector2 screenCenter;
internal Vector3 screenCenter;

public Vector3 targetPosition;
public Vector2 focusScreenPos;
public Vector3 homePosition;

void Awake()
{
stateManager = GetComponent<StateManager>();
inputManager = GetComponent<InputManager>();
cameraMovement = mainCamera.GetComponent<CameraMovement>();
cutoff = FindObjectOfType<Cutoff>();
}

void Start ()
{
stateManager.isHome = true;
screenCenter = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);
currentFocus = null;
lastFocus = null;
lastDestination = null;
}

void FixedUpdate()
{
if(currentFocus != null && currentFocus.GetComponent<FocusTarget>().distanceFromCenter < focalRange)
void Update()
{
screenCenter = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f,0);

Debug.Log(currentFocus);

if(currentFocus != null && currentFocus.distanceFromCursor >= focalRange)
{
focusScreenPos = mainCamera.WorldToScreenPoint(currentFocus.transform.position);
}

if (currentFocus != null && currentFocus.GetComponent<FocusTarget>().distanceFromCenter > focalRange)
{
lastFocus = currentFocus;
currentFocus = null;
}
}
Expand Down
File renamed without changes.
76 changes: 16 additions & 60 deletions Satellite/Assets/_Scripts/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,54 @@
using System.Collections.Generic;
using UnityEngine;

public class InputManager : MonoBehaviour {

public class InputManager : MonoBehaviour
{
internal GameManager gameManager;
internal StateManager stateManager;
internal CameraMovement cameraMovement;
internal Cutoff cutoff;

internal bool lockControl;

[Range(0, 1)]
public float percent;

Vector3 mousePosition;
internal Vector3 mousePosition;

Input leftClick;
Input rightClick;
internal Ray ray;
internal RaycastHit hit;

void Start ()
{
Cursor.visible = false;
CursorUnlocked();
gameManager = FindObjectOfType<GameManager>();
stateManager = FindObjectOfType<StateManager>();
cameraMovement = GetComponent<CameraMovement>();
cutoff = FindObjectOfType<Cutoff>();
cameraMovement = gameManager.mainCamera.GetComponent<CameraMovement>();
}

void Update()
{
if(stateManager.isInteracting == true)
{
CursorUnlocked();
}
else
{
CursorLocked();
}
mousePosition = Input.mousePosition;
ray = gameManager.mainCamera.ScreenPointToRay(mousePosition);

if(lockControl == false)
if (Input.GetAxisRaw("Fire1") == 1)
{

if (Input.GetMouseButtonDown(0)) //Left Click
Debug.Log("Left Click");
if(gameManager.currentFocus != null)
{
LeftClick();
cameraMovement.CameraTravel(gameManager.currentFocus.transform.position);
}

if (Input.GetMouseButtonDown(1)) //Right Click
{
RightClick();
}
}
}

void LeftClick()
{
if (stateManager.shellUp == true && stateManager.isHome)
{
cutoff.StartLerpingCutoff(Mathf.Clamp01(1f), Mathf.Clamp01(1f), Mathf.Clamp01(1f));
}

else if (stateManager.shellUp == false && gameManager.currentFocus != null && gameManager.currentFocus != gameManager.lastDestination)
if (Input.GetAxisRaw("Fire2") == 1)
{
gameManager.mainCamera.GetComponent<TargetedLerp>().StartLerping(gameObject, gameManager.currentFocus.transform.position, 0.5f, 1);
}

else if (gameManager.currentFocus != null && gameManager.currentFocus == gameManager.lastFocus)
{
Debug.Log("Interacting with " + gameManager.currentFocus.name);
}
}

void RightClick()
{
if (stateManager.isHome)
{
cutoff.StartLerpingCutoff(Mathf.Clamp01(0f), Mathf.Clamp01(1f), Mathf.Clamp01(1f));
gameManager.lastDestination = null;
}
else if (stateManager.isHome == false)
{
gameManager.mainCamera.GetComponent<TargetedLerp>().StartLerping(gameObject, new Vector3(0, 0, 0), 0.5f, 1);
Debug.Log("Right Click");
cameraMovement.CameraTravel(gameManager.homePosition);
}
}

void CursorUnlocked()
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
}

void CursorLocked()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}
Loading

0 comments on commit 73a0925

Please sign in to comment.