Added real time cursor coloring functionality, and dead unit removal.

This commit is contained in:
Vylion 2016-11-01 16:34:26 +01:00
parent ed9bb82606
commit 769ad502b9
6 changed files with 283 additions and 163 deletions

View file

@ -4,6 +4,14 @@ using UnityEngine.UI;
public class InputManagerScript : MonoBehaviour {
public enum MyColor {
red,
green,
blue,
yellow,
cyan
}
private GameObject cursor;
public Image imageMove;
public Image imageAttack;
@ -14,187 +22,233 @@ public class InputManagerScript : MonoBehaviour {
private float timeExpStep;
private float timeExpLimit;
private bool unitSelected;
private bool showActions;
private bool actionSelected;
private bool selectTargetPos;
private bool unitMenu;
private bool openMenu;
private bool unitActionSelected;
private bool generalActionSelected;
private bool imageSelected;
private Image[] images;
private int actualImage;
private GameObject gosel;
private Image[] menuOptions;
private int currentMenuOption;
private GameObject selectedGO;
private int actionOption;
private TurnManagerScript tmss;
private Color menuCursorColor = new Color (1f, 1f, 0f);
private MyColor currentCursorColor = MyColor.cyan;
private TurnManagerScript tms;
// Use this for initialization
void Start () {
cursor = GameObject.Find ("Cursor");
//cursor.transform.Rotate (new Vector3(90, 0, 0));
unitSelected = false;
showActions = false;
unitMenu = false;
openMenu = false;
actionOption = -1;
actionSelected = false;
selectTargetPos = false;
gosel = null;
images = new Image[3];
actualImage = 0;
unitActionSelected = false;
generalActionSelected = false;
selectedGO = null;
currentMenuOption = 0;
imageSelected = false;
}
// Update is called once per frame
void Update () {
if (!showActions) {
if (Input.GetKeyDown (KeyCode.A)) {
cursor.transform.Translate (-1f, 0, 0);
}
if (!openMenu)
moveCursor ();
if (Input.GetKeyDown (KeyCode.D)) {
cursor.transform.Translate (1f, 0, 0);
}
if (Input.GetKeyDown (KeyCode.W)) {
cursor.transform.Translate (0, 1f, 0);
}
if (Input.GetKeyDown (KeyCode.S)) {
cursor.transform.Translate (0, -1f, 0);
}
} else if (showActions) {
if (Input.GetKey (KeyCode.Escape)) {
showActions = false;
unitSelected = false;
for (int i = 0; i < images.Length; i++) {
DestroyObject (images [i]);
}
else if (openMenu)
moveMenuCursor ();
}
void moveMenuCursor() {
if (Input.GetKeyDown (KeyCode.Escape)) {
openMenu = false;
unitMenu = false;
for (int i = 0; i < menuOptions.Length; i++) {
DestroyObject (menuOptions [i]);
}
actionOption = -1;
}
else if (Input.GetKeyDown (KeyCode.D) && menuOptions.Length > 1) {
int previousOption = currentMenuOption;
currentMenuOption = (currentMenuOption+1) % menuOptions.Length;
menuOptions[currentMenuOption].color = menuCursorColor;
menuOptions[previousOption].color = new Color (1f, 1f, 1f);
}
if (Input.GetKeyUp(KeyCode.Space) && !unitSelected && !actionSelected) {
Vector3 tilePosition = cursor.transform.position;
int ipos = (int)tilePosition.z;
int jpos = (int)tilePosition.x;
GameObject c = tmss.getUnitAtTile(ipos, jpos);
else if (Input.GetKeyDown (KeyCode.A) && menuOptions.Length > 1) {
int previousOption = currentMenuOption;
currentMenuOption -= 1;
if (currentMenuOption < 0)
currentMenuOption = menuOptions.Length - 1;
menuOptions[currentMenuOption].color = menuCursorColor;
menuOptions[previousOption].color = new Color (1f, 1f, 1f);
}
if (c != null) {
UnitBehaviour ub = c.GetComponent<UnitBehaviour> ();
UnitBehaviour.Team mahteam = (UnitBehaviour.Team) tmss.actualPlayer+1;
if (ub.teamID == mahteam && ub.remainingActions != 0) {
gosel = c;
unitSelected = true;
showActions = true;
actualImage = 0;
else if (Input.GetKeyDown (KeyCode.Space)) {
actionOption = currentMenuOption;
if (unitMenu) {
unitMenu = false;
unitActionSelected = true;
changeCursorColor(MyColor.green);
} else {
if (actionOption == 0) {
endTurn ();
actionOption = -1;
GameObject canv = GameObject.Find ("Canvas");
images [0] = Instantiate (imageAttack);
images[0].transform.SetParent (canv.transform, false);
images [0].transform.position = new Vector3 (50, 0, 100);
images[0].color = new Color (1f, 0f, 0f);
images[1] = Instantiate (imageMove);
images[1].transform.SetParent (canv.transform, false);
images [1].transform.position = new Vector3 (150, 0, 100);
images[2] = Instantiate (imageEndTurn);
images[2].transform.SetParent (canv.transform, false);
images [2].transform.position = new Vector3 (250, 0, 100);
changeCursorColor (MyColor.cyan);
} else {
changeCursorColor (Color.red);
generalActionSelected = true;
changeCursorColor(MyColor.green);
}
}
openMenu = false;
for (int i = 0; i < menuOptions.Length; i++) {
DestroyObject (menuOptions [i]);
}
}
}
void moveCursor() {
if (Input.GetKeyDown (KeyCode.A)) {
cursor.transform.Translate (-1f, 0, 0);
updateCursorColor ();
}
if (actionSelected) {
if (Input.GetKeyUp (KeyCode.Escape)) {
actionSelected = false;
changeCursorColor (Color.cyan);
}
if (Input.GetKeyDown (KeyCode.D)) {
cursor.transform.Translate (1f, 0, 0);
updateCursorColor ();
}
if (Input.GetKeyUp (KeyCode.Space) ) {
if (Input.GetKeyDown (KeyCode.W)) {
cursor.transform.Translate (0, 1f, 0);
updateCursorColor ();
}
if (Input.GetKeyDown (KeyCode.S)) {
cursor.transform.Translate (0, -1f, 0);
updateCursorColor ();
}
if (Input.GetKeyDown (KeyCode.Escape)) {
if (unitActionSelected) {
unitActionSelected = false;
changeCursorColor (MyColor.cyan);
}
}
if (Input.GetKeyDown (KeyCode.Space)) {
if (!unitMenu && !unitActionSelected && !generalActionSelected)
openMenuOnSelection ();
else if (unitActionSelected) {
Vector3 tpos = cursor.transform.position;
switch (actionOption) {
case 0:
if (tmss.canAttackTo (gosel, (int)tpos.z, (int)tpos.x)) {
tmss.attackTo (gosel, (int)tpos.z, (int)tpos.x);
changeCursorColor (Color.cyan);
if (tms.canAttackTo (selectedGO, (int)tpos.z, (int)tpos.x)) {
tms.attackTo (selectedGO, (int)tpos.z, (int)tpos.x);
changeCursorColor (MyColor.cyan);
} else {
changeCursorColor (Color.red);
changeCursorColor (MyColor.red);
}
break;
case 1:
if (tmss.canMoveTo (gosel, (int)tpos.z, (int)tpos.x)) {
tmss.moveTo (gosel, (int)tpos.z, (int)tpos.x);
changeCursorColor (Color.cyan);
if (tms.canMoveTo (selectedGO, (int)tpos.z, (int)tpos.x)) {
tms.moveTo (selectedGO, (int)tpos.z, (int)tpos.x);
changeCursorColor (MyColor.cyan);
} else {
changeCursorColor (Color.red);
changeCursorColor (MyColor.red);
}
break;
case 2:
tmss.changeTeam ();
break;
default:
break;
}
actionSelected = false;
gosel = null;
unitActionSelected = false;
selectedGO = null;
actionOption = -1;
selectTargetPos = false;
}
}
if (unitSelected) {
if (Input.GetKeyUp (KeyCode.D)) {
int previousImage = actualImage;
if (actualImage < 2) {
actualImage += 1;
images[actualImage].color = new Color (1f, 0f, 0f);
images[previousImage].color = new Color (1f, 1f, 1f);
actionOption = actualImage;
}
}
if (Input.GetKeyUp (KeyCode.A)) {
int previousImage = actualImage;
if (actualImage > 0) {
actualImage -= 1;
images[actualImage].color = new Color (1f, 0f, 0f);
images[previousImage].color = new Color (1f, 1f, 1f);
actionOption = actualImage;
}
}
if (Input.GetKeyUp (KeyCode.Space) && actionOption > -1) {
selectTargetPos = false;
actionSelected = true;
unitSelected = false;
showActions = false;
for (int i = 0; i < images.Length; i++) {
DestroyObject (images [i]);
}
changeCursorColor(new Color(1,1,0));
}
}
}
public void setTurnMan(TurnManagerScript tms) {
tmss = tms;
void updateCursorColor() {
if (!unitActionSelected && currentCursorColor != MyColor.cyan)
changeCursorColor (MyColor.cyan);
else if (unitActionSelected) {
Vector3 pos = cursor.transform.position;
if (actionOption == 0) {
if (tms.canAttackTo (selectedGO, (int)pos.z, (int)pos.x))
changeCursorColor (MyColor.green);
else
changeCursorColor (MyColor.yellow);
}
else if(actionOption == 1) {
if (tms.canMoveTo (selectedGO, (int)pos.z, (int)pos.x))
changeCursorColor (MyColor.green);
else
changeCursorColor (MyColor.yellow);
}
}
}
void openMenuOnSelection () {
Vector3 tilePosition = cursor.transform.position;
int x = (int)tilePosition.z;
int y = (int)tilePosition.x;
selectedGO = tms.getUnitAtTile(x, y);
if (selectedGO != null) {
UnitBehaviour ub = selectedGO.GetComponent<UnitBehaviour> ();
UnitBehaviour.Team myTeam = (UnitBehaviour.Team) tms.currentPlayer;
if (ub.teamID == myTeam) {
if (ub.remainingActions != 0)
loadUnitMenu ();
else
changeCursorColor (MyColor.red);
} else
changeCursorColor (MyColor.red);
} else {
loadGeneralMenu ();
}
}
void loadUnitMenu() {
openMenu = true;
menuOptions = new Image[2];
unitMenu = true;
currentMenuOption = 0;
actionOption = 0;
GameObject canv = GameObject.Find ("Canvas");
menuOptions [0] = Instantiate (imageAttack);
menuOptions[0].transform.SetParent (canv.transform, false);
menuOptions [0].transform.position = new Vector3 (50, 0, 100);
menuOptions[0].color = menuCursorColor;
menuOptions[1] = Instantiate (imageMove);
menuOptions[1].transform.SetParent (canv.transform, false);
menuOptions [1].transform.position = new Vector3 (150, 0, 100);
}
void loadGeneralMenu() {
openMenu = true;
menuOptions = new Image[1];
currentMenuOption = 0;
actionOption = 0;
GameObject canv = GameObject.Find ("Canvas");
menuOptions[0] = Instantiate (imageEndTurn);
menuOptions[0].transform.SetParent (canv.transform, false);
menuOptions [0].transform.position = new Vector3 (50, 0, 100);
menuOptions[0].color = menuCursorColor;
}
private void changeCursorColor(Color c) {
@ -202,4 +256,39 @@ public class InputManagerScript : MonoBehaviour {
li.color = c;
}
private void changeCursorColor(MyColor cc) {
Color c;
switch (cc) {
default:
return;
case MyColor.red:
c = Color.red;
break;
case MyColor.green:
c = Color.green;
break;
case MyColor.blue:
c = Color.blue;
break;
case MyColor.yellow:
c = new Color (1, 1, 0);
break;
case MyColor.cyan:
c = Color.cyan;
break;
}
currentCursorColor = cc;
Light li = cursor.GetComponent<Light> () as Light;
li.color = c;
}
public void setTurnMan(TurnManagerScript s) {
tms = s;
}
void endTurn() {
tms.changeTeam ();
}
}

View file

@ -30,17 +30,17 @@ public class TurnManagerScript : MonoBehaviour {
public GameObject[,] unitMap;
public Vector2 mapSize;
public int actualPlayer;
private int actualNumChars;
private int actualNumFinishedChars = 0;
public int currentPlayer;
private int currentNumChars;
private int currentNumFinishedChars = 0;
// Use this for initialization
void Start () {
//Estamos en turno
inTurn = true;
actualPlayer = 0;
actualNumChars = unitList [actualPlayer].Count;
currentPlayer = 0;
currentNumChars = unitList [currentPlayer].Count;
// Characters that have finished its actions
@ -49,8 +49,8 @@ public class TurnManagerScript : MonoBehaviour {
// Update is called once per frame
void Update () {
if (actualNumFinishedChars == actualNumChars) {
changeTeam ((actualPlayer + 1) % playerNum);
if (currentNumFinishedChars == currentNumChars) {
changeTeam ();
}
}
@ -60,11 +60,6 @@ public class TurnManagerScript : MonoBehaviour {
act (c);
}
void attackRange (int i, int j, int k, int l, params int[] altParams ) {
}
public bool canMoveTo(GameObject go, int i, int j) {
UnitBehaviour ub = go.GetComponent<UnitBehaviour> ();
int ra = ub.remainingActions;
@ -87,7 +82,7 @@ public class TurnManagerScript : MonoBehaviour {
//TODO: MOVEMENT
if (ub.remainingActions == 0)
actualNumFinishedChars += 1;
currentNumFinishedChars += 1;
//Move the unit
go.transform.position = new Vector3 (j, 0, i);
//Update matrices
@ -149,23 +144,26 @@ public class TurnManagerScript : MonoBehaviour {
}
}
void changeTeam (int newTeam) {
int previousTeam = actualPlayer;
public void changeTeam () {
int previousTeam = currentPlayer;
currentPlayer = (currentPlayer + 1) % (playerNum + 1);
for (int i = 0; i < unitList [previousTeam].Count; i++) {
GameObject go = unitList [previousTeam][i];
UnitBehaviour ub = go.GetComponent<UnitBehaviour> ();
ub.remainingActions = ub.actionsPerTurn;
if (go != null) {
UnitBehaviour ub = go.GetComponent<UnitBehaviour> ();
ub.remainingActions = ub.actionsPerTurn;
} else {
unitList [previousTeam].RemoveAt (i);
i--;
}
}
actualPlayer = newTeam;
actualNumChars = unitList [actualPlayer].Count;
actualNumFinishedChars = 0;
}
public void changeTeam () {
actualPlayer = (actualPlayer+1) % playerNum;
actualNumChars = unitList [actualPlayer].Count;
actualNumFinishedChars = 0;
if (currentPlayer == 0)
turnNum++;
currentNumChars = unitList [currentPlayer].Count;
currentNumFinishedChars = 0;
Debug.Log ("switched to team " + currentPlayer);
}
public GameObject getUnitAtTile(int i, int j) {

View file

@ -45,7 +45,6 @@ public class UnitBehaviour : MonoBehaviour {
bool damageAnim = false;
bool dodgeAnim = false;
bool idleAnim = false;
float deathTimer = 0;
public Animator anim;
@ -158,14 +157,12 @@ public class UnitBehaviour : MonoBehaviour {
attackAnim = false;
} else if (deathAnim) {
anim.Play ("death", -1, 0f);
deathTimer = Time.time;
deathAnim = false;
if(idleAnim) idleAnim = false;
Die (1.5f);
} else if (moveAnim) {
anim.Play ("move", -1, 0f);
moveAnim = false;
} else if (deathTimer > 0 && Time.time - deathTimer > 1.5) {
Die ();
} else if (idleAnim) {
anim.Play ("idle", -1, 0f);
idleAnim = false;
@ -175,4 +172,8 @@ public class UnitBehaviour : MonoBehaviour {
public void Die () {
Destroy (gameObject);
}
public void Die (float t) {
Destroy (gameObject, t);
}
}

View file

@ -168,6 +168,7 @@ public class UnitCreator : MonoBehaviour {
createUnit (16, 24, UnitBehaviour.Team.Enemy1);
createUnit (17, 26, UnitBehaviour.Team.Enemy1, UnitType.Archer);
unitsByTeam.Add (teamNone);
unitsByTeam.Add (teamPlayer);
unitsByTeam.Add (teamEnemy1);
}

View file

@ -123,6 +123,7 @@ PlayerSettings:
iPhoneTargetOSVersion: 24
tvOSSdkVersion: 0
tvOSTargetOSVersion: 900
tvOSRequireExtendedGameController: 0
uIPrerenderedIcon: 0
uIRequiresPersistentWiFi: 0
uIRequiresFullScreen: 1
@ -162,6 +163,7 @@ PlayerSettings:
iOSLaunchScreeniPadCustomXibPath:
iOSDeviceRequirements: []
iOSURLSchemes: []
appleDeveloperTeamID:
AndroidTargetDevice: 0
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
@ -197,12 +199,15 @@ PlayerSettings:
wiiUSystemHeapSize: 128
wiiUTVStartupScreen: {fileID: 0}
wiiUGamePadStartupScreen: {fileID: 0}
wiiUDrcBufferDisabled: 0
wiiUProfilerLibPath:
actionOnDotNetUnhandledException: 1
enableInternalProfiler: 0
logObjCUncaughtExceptions: 1
enableCrashReportAPI: 0
cameraUsageDescription:
locationUsageDescription:
microphoneUsageDescription:
XboxTitleId:
XboxImageXexPath:
XboxSpaPath:
@ -242,7 +247,8 @@ PlayerSettings:
ps4AppType: 0
ps4ParamSfxPath:
ps4VideoOutPixelFormat: 0
ps4VideoOutResolution: 4
ps4VideoOutInitialWidth: 1920
ps4VideoOutReprojectionRate: 120
ps4PronunciationXMLPath:
ps4PronunciationSIGPath:
ps4BackgroundImagePath:
@ -271,9 +277,12 @@ PlayerSettings:
ps4pnFriends: 1
ps4pnGameCustomData: 1
playerPrefsSupport: 0
ps4UseResolutionFallback: 0
restrictedAudioUsageRights: 0
ps4ReprojectionSupport: 0
ps4UseAudio3dBackend: 0
ps4SocialScreenEnabled: 0
ps4ScriptOptimizationLevel: 3
ps4Audio3dVirtualSpeakerCount: 14
ps4attribCpuUsage: 0
ps4PatchPkgPath:
@ -407,12 +416,22 @@ PlayerSettings:
XboxOnePersistentLocalStorageSize: 0
intPropertyNames:
- Android::ScriptingBackend
- Metro::ScriptingBackend
- Standalone::ScriptingBackend
- WebGL::ScriptingBackend
- WebGL::audioCompressionFormat
- WebGL::exceptionSupport
- WebGL::memorySize
- WebPlayer::ScriptingBackend
- iOS::Architecture
- iOS::ScriptingBackend
Android::ScriptingBackend: 0
Metro::ScriptingBackend: 2
Standalone::ScriptingBackend: 0
WebGL::ScriptingBackend: 1
WebGL::audioCompressionFormat: 4
WebGL::exceptionSupport: 1
WebGL::memorySize: 256
WebPlayer::ScriptingBackend: 0
iOS::Architecture: 2
iOS::ScriptingBackend: 1
@ -428,6 +447,9 @@ PlayerSettings:
- Standalone::VR::enable
- Tizen::VR::enable
- WebGL::VR::enable
- WebGL::analyzeBuildSize
- WebGL::dataCaching
- WebGL::useEmbeddedResources
- WebPlayer::VR::enable
- WiiU::VR::enable
- Xbox360::VR::enable
@ -446,6 +468,9 @@ PlayerSettings:
Standalone::VR::enable: 0
Tizen::VR::enable: 0
WebGL::VR::enable: 0
WebGL::analyzeBuildSize: 0
WebGL::dataCaching: 0
WebGL::useEmbeddedResources: 0
WebPlayer::VR::enable: 0
WiiU::VR::enable: 0
Xbox360::VR::enable: 0
@ -463,6 +488,9 @@ PlayerSettings:
- Purchasing_ServiceEnabled::Purchasing_ServiceEnabled
- UNet_ServiceEnabled::UNet_ServiceEnabled
- Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled
- WebGL::emscriptenArgs
- WebGL::template
- additionalIl2CppArgs::additionalIl2CppArgs
Analytics_ServiceEnabled::Analytics_ServiceEnabled: False
Build_ServiceEnabled::Build_ServiceEnabled: False
Collab_ServiceEnabled::Collab_ServiceEnabled: False
@ -472,6 +500,9 @@ PlayerSettings:
Purchasing_ServiceEnabled::Purchasing_ServiceEnabled: False
UNet_ServiceEnabled::UNet_ServiceEnabled: False
Unity_Ads_ServiceEnabled::Unity_Ads_ServiceEnabled: False
WebGL::emscriptenArgs:
WebGL::template: APPLICATION:Default
additionalIl2CppArgs::additionalIl2CppArgs:
vectorPropertyNames:
- Android::VR::enabledDevices
- Metro::VR::enabledDevices

View file

@ -1,2 +1,2 @@
m_EditorVersion: 5.4.1f1
m_EditorVersion: 5.4.2f2
m_StandardAssetsVersion: 0