op
This commit is contained in:
parent
a68e177ab6
commit
ab74af8938
4 changed files with 195 additions and 0 deletions
53
Assets/Input Manager.prefab
Normal file
53
Assets/Input Manager.prefab
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1001 &100100000
|
||||||
|
Prefab:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications: []
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_ParentPrefab: {fileID: 0}
|
||||||
|
m_RootGameObject: {fileID: 1000013132162768}
|
||||||
|
m_IsPrefabParent: 1
|
||||||
|
--- !u!1 &1000013132162768
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
serializedVersion: 4
|
||||||
|
m_Component:
|
||||||
|
- 4: {fileID: 4000012265747864}
|
||||||
|
- 114: {fileID: 114000011730117312}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Input Manager
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &4000012265747864
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 1000013132162768}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 372.20374, y: -16.273315, z: 1327.7058}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
--- !u!114 &114000011730117312
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 1
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 100100000}
|
||||||
|
m_GameObject: {fileID: 1000013132162768}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e30eb79cd423fd04691b1402c8e578ef, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
8
Assets/Input Manager.prefab.meta
Normal file
8
Assets/Input Manager.prefab.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c25c1548ba0651c429c11b0a9718bda8
|
||||||
|
timeCreated: 1477744744
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
122
Assets/InputManagerScript.cs
Normal file
122
Assets/InputManagerScript.cs
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class InputManagerScript : MonoBehaviour {
|
||||||
|
|
||||||
|
public GameObject cursor;
|
||||||
|
public Image image_move;
|
||||||
|
public Image image_attack;
|
||||||
|
|
||||||
|
private float accTime;
|
||||||
|
private float timeStep;
|
||||||
|
private float timeExp;
|
||||||
|
private float timeExpStep;
|
||||||
|
private float timeExpLimit;
|
||||||
|
|
||||||
|
|
||||||
|
private bool unitSelected;
|
||||||
|
private bool showActions;
|
||||||
|
private Image i1;
|
||||||
|
private Image i2;
|
||||||
|
|
||||||
|
private TurnManagerScript tmss;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start () {
|
||||||
|
timeStep = 0.3f;
|
||||||
|
timeExp = 0.0f;
|
||||||
|
timeExpStep = 0.02f;
|
||||||
|
timeExpLimit = 0.15f;
|
||||||
|
|
||||||
|
cursor = Instantiate (cursor, new Vector3 (1.0f, 1.5f, 1.0f), Quaternion.identity) as GameObject;
|
||||||
|
cursor.transform.Rotate (new Vector3(90, 0, 0));
|
||||||
|
|
||||||
|
unitSelected = false;
|
||||||
|
showActions = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
accTime += Time.deltaTime;
|
||||||
|
|
||||||
|
if (!showActions) {
|
||||||
|
if (Input.GetKey (KeyCode.A) && accTime > (timeStep - timeExp)) {
|
||||||
|
accTime -= (timeStep - timeExp);
|
||||||
|
if (timeExp < timeExpLimit)
|
||||||
|
timeExp += timeExpStep;
|
||||||
|
cursor.transform.Translate (-1f, 0, 0);
|
||||||
|
} else if (Input.GetKeyUp (KeyCode.LeftArrow)) {
|
||||||
|
timeExp = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey (KeyCode.D) && accTime > (timeStep - timeExp)) {
|
||||||
|
accTime -= (timeStep - timeExp);
|
||||||
|
if (timeExp < timeExpLimit)
|
||||||
|
timeExp += timeExpStep;
|
||||||
|
cursor.transform.Translate (1f, 0, 0);
|
||||||
|
} else if (Input.GetKeyUp (KeyCode.D)) {
|
||||||
|
timeExp = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey (KeyCode.W) && accTime > (timeStep - timeExp)) {
|
||||||
|
accTime -= (timeStep - timeExp);
|
||||||
|
if (timeExp < timeExpLimit)
|
||||||
|
timeExp += timeExpStep;
|
||||||
|
cursor.transform.Translate (0, 1f, 0);
|
||||||
|
} else if (Input.GetKeyUp (KeyCode.W)) {
|
||||||
|
timeExp = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey (KeyCode.S) && accTime > (timeStep - timeExp)) {
|
||||||
|
accTime -= (timeStep - timeExp);
|
||||||
|
if (timeExp < timeExpLimit)
|
||||||
|
timeExp += timeExpStep;
|
||||||
|
cursor.transform.Translate (0, -1f, 0);
|
||||||
|
} else if (Input.GetKeyUp (KeyCode.S)) {
|
||||||
|
timeExp = 0.0f;
|
||||||
|
}
|
||||||
|
} else if (showActions) {
|
||||||
|
if (Input.GetKey (KeyCode.Escape)) {
|
||||||
|
showActions = false;
|
||||||
|
unitSelected = false;
|
||||||
|
DestroyObject (i1);
|
||||||
|
DestroyObject (i2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Input.GetKeyUp(KeyCode.Space) && !unitSelected) {
|
||||||
|
Vector3 tilePosition = cursor.transform.position;
|
||||||
|
int ipos = (int)tilePosition.z;
|
||||||
|
int jpos = (int)tilePosition.x;
|
||||||
|
GameObject c = tmss.getUnitAtTile(ipos, jpos);
|
||||||
|
//UnitBehaviour ub = c.GetComponent<UnitBehaviour> ();
|
||||||
|
if (c != null) {
|
||||||
|
unitSelected = true;
|
||||||
|
showActions = true;
|
||||||
|
GameObject canv = GameObject.Find ("Canvas");
|
||||||
|
i1 = Instantiate (image_move);
|
||||||
|
i1.transform.SetParent (canv.transform, false);
|
||||||
|
i2 = Instantiate (image_attack);
|
||||||
|
i2.transform.SetParent (canv.transform, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unitSelected) {
|
||||||
|
if (Input.GetKeyUp (KeyCode.D)) {
|
||||||
|
Color lol = i1.color;
|
||||||
|
i1.color = new Color (1f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTurnMan(TurnManagerScript tms) {
|
||||||
|
tmss = tms;
|
||||||
|
}
|
||||||
|
}
|
12
Assets/InputManagerScript.cs.meta
Normal file
12
Assets/InputManagerScript.cs.meta
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e30eb79cd423fd04691b1402c8e578ef
|
||||||
|
timeCreated: 1477744255
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue