Skip to content

Commit

Permalink
Imput update
Browse files Browse the repository at this point in the history
inventory
  • Loading branch information
dpeter99 committed Aug 3, 2015
1 parent de00270 commit e5cdd1c
Show file tree
Hide file tree
Showing 45 changed files with 1,099 additions and 49 deletions.
91 changes: 91 additions & 0 deletions Assets/ActionButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using UnityEngine;
using System.Collections;
using System.Reflection;
using UnityEngine.UI;

public class ActionButton : MonoBehaviour
{


public float countdown;
public float fullcount;

public GameController GameCon;

GameObject playergo;

public Button buttonscript;


public float defaultYPos;
public float defaultXPos;

public RectTransform maskRect;
public string action = "Mine";


public bool ActionRuned;

// Use this for initialization
void Start()
{
GameCon = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();

countdown = 0;

buttonscript = gameObject.GetComponent<Button>();

if (buttonscript == null)
Debug.LogError("Can't find Button Script");

maskRect = gameObject.transform.FindChild("Mask").GetComponent<RectTransform>();


defaultYPos = maskRect.localPosition.y;


}

// Update is called once per frame
void Update()
{
if (countdown > 0)
{
buttonscript.interactable = false;



maskRect.localPosition = new Vector2(maskRect.localPosition.x, Mathf.Lerp(defaultYPos + maskRect.rect.height, defaultYPos, (countdown / fullcount)));
ActionRuned = false;
GameCon.playerclass.GetComponent<Rigidbody2D>().isKinematic = true;
countdown -= Time.deltaTime;
}
else
{
buttonscript.interactable = true;
maskRect.position = new Vector2(maskRect.position.x, defaultYPos + maskRect.rect.height);

if (!ActionRuned)
{

MethodInfo m = GameCon.playerclass.GetComponent<Player>().GetType().GetMethod(action);
m.Invoke(GameCon.playerclass.GetComponent<Player>(), null);
ActionRuned = true;
GameCon.playerclass.GetComponent<Rigidbody2D>().isKinematic = false;
}
}

}

public void Action(float time, string functionname)
{
if (countdown <= 0)
{
action = functionname;
countdown = time;
fullcount = time;
}
}


}
12 changes: 12 additions & 0 deletions Assets/ActionButton.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 164 additions & 0 deletions Assets/CameraChase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using UnityEngine;
using System.Collections;



//[AddComponentMenu("Camera/CameraChase")]
//public class CameraChase : MonoBehaviour
//{


// public Transform chase;
// public Rect area;
// public bool loaded = false;

// public RectTransform rectTrans;

// void Start()
// {
// }

// // Use this for initialization
// public void MapLoaded()
// {
// GameController GameCon = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
// if (GameCon.map == null)
// Debug.LogError("Can't find GameController");

// chase = GameObject.FindGameObjectWithTag("Player").transform;
// area = new Rect();

// /*
// area.x = 10.50f;
// area.y = -3f - (GameCon.map.mapHeight * 1.0f - 6f);
// area.width = GameCon.map.mapHeight * 1.0f - 11f;
// area.height = GameCon.map.mapHeight * 1.0f - 8f;
// */

// Debug.Log(Camera.main.rect);

// area.x = 0 + (Camera.main.rect.x / 2);
// area.y = 0f - (GameCon.map.mapHeight);
// area.width = (GameCon.map.mapHeight);
// area.height = (GameCon.map.mapHeight);


// Debug.Log(area);
// loaded = true;
// }

// // Update is called once per frame
// void Update()
// {
// if (chase == null)
// {



// return;

// }
// if (loaded)
// {
// if (area.Contains(new Vector2(chase.position.x, chase.position.y)))
// {
// transform.position = chase.position + Vector3.back * 10;

// }
// else if (chase.position.x > area.xMax && chase.position.y > area.yMax)
// {
// transform.position = new Vector3(area.xMax, area.yMax);
// }
// else if (chase.position.x > area.xMax && chase.position.y < area.yMin)
// {
// transform.position = new Vector3(area.xMax, area.yMin);
// }
// else if (chase.position.x < area.xMin && chase.position.y > area.yMax)
// {
// transform.position = new Vector3(area.xMin, area.yMax);
// }
// else if (chase.position.x < area.xMin && chase.position.y < area.yMin)
// {
// transform.position = new Vector3(area.xMin, area.yMin);

// }
// else if (chase.position.x < area.xMin && area.yMax > chase.position.y && chase.position.y > area.yMin)
// {
// transform.position = new Vector3(area.xMin, chase.position.y);
// }
// else if (chase.position.x > area.xMax && area.yMax > chase.position.y && chase.position.y > area.yMin)
// {
// transform.position = new Vector3(area.xMax, chase.position.y);
// }
// else if (area.xMax > chase.position.x && chase.position.x > area.xMin && chase.position.y < area.yMin)
// {
// transform.position = new Vector3(chase.position.x, area.yMin);
// }
// else if (area.xMax > chase.position.x && chase.position.x > area.xMin && chase.position.y > area.yMax)
// {
// transform.position = new Vector3(chase.position.x, area.yMax);
// }
// transform.position = new Vector3(transform.position.x, transform.position.y, -10);

// }
// }
//}


[AddComponentMenu("Camera/CameraChase")]
public class CameraChase : MonoBehaviour
{


public Transform chase;
public bool loaded = false;


public RectTransform rectTrans;

Camera CameraScript;
GameController GameCon;

void Start()
{


}

// Use this for initialization
public void MapLoaded()
{

CameraScript = this.GetComponent<Camera>();
GameCon = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();

if (GameCon.map == null)
{
Debug.LogError("Can't find GameController");
Debug.Break();
}

loaded = true;
}

// Update is called once per frame
void Update()
{
if (chase == null)
{

return;

}
if (loaded)
{
float xPos = chase.transform.position.x;
float yPos = chase.transform.position.y;
float horzExtent = CameraScript.orthographicSize * Screen.width / Screen.height;
transform.position = new Vector3(Mathf.Clamp(xPos, horzExtent, GameCon.map.mapHeight - horzExtent),-1 * Mathf.Clamp(-1*yPos, CameraScript.orthographicSize, GameCon.map.mapHeight - CameraScript.orthographicSize), transform.position.z);
//transform.position = new Vector3(Mathf.Clamp(xPos, ratio[0], GameCon.map.mapHeight - ratio[0]), Mathf.Clamp(yPos, ratio[1], GameCon.map.mapHeight - ratio[1]), transform.position.z);

}
}
}

12 changes: 12 additions & 0 deletions Assets/CameraChase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Assets/GUIHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GUIHandler : MonoBehaviour
{

public InventoryDesplay InventoryDisplay;
public GameObject actionGroup;

public ActionButton[] actions = new ActionButton[10];
public bool inventoryOn;

// Use this for initialization
void Start()
{
GameObject ac = GameObject.Find("Actions");
actionGroup = ac;
for (int i = 0; i < ac.transform.childCount; i++)
{
GameObject go = ac.transform.GetChild(i).gameObject;
actions[i] = go.AddComponent<ActionButton>();
}

}

// Update is called once per frame
void Update()
{

}
}
12 changes: 12 additions & 0 deletions Assets/GUIHandler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Assets/InputHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;

public class InputHandler : MonoBehaviour
{

public GameController GameCon;

// Use this for initialization
void Start()
{
GameCon = GameObject.Find("_GameController").GetComponent<GameController>();
}

void Awake()
{
DontDestroyOnLoad(transform.gameObject);
}

// Update is called once per frame
void Update()
{
if (GameCon.gameIsOn)
{
//Debug.Log("Check key");

if (Input.GetButtonUp("Inventory"))
{
Debug.Log("Inventory opening");
GameCon.TogleInventory();
}
}
}
}
12 changes: 12 additions & 0 deletions Assets/InputHandler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Inventory.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e5cdd1c

Please sign in to comment.