//Main GUI goes here void OnGUI() { GUI.depth = 1; GUI.backgroundColor = Color.clear; GUI.color = new Color(1.0f, 1.0f, 1.0f, _mainAlpha); if (MainGuiShow) { if (currentSelect.chess != null) { CurrentChess = currentSelect.chess; } if (CurrentChess != null) { CharacterProperty chessProperty = CurrentChess.GetComponent <CharacterProperty>(); // move button if (chessProperty.Moved) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posMoveBt, MoveTex)) { MainGuiFade = false; SubGuiFade = true; moveShow = true; currentSelect.moveCommand(CurrentChess); currentSelect.MoveCommandNetwork(); if (InTutorial) { init.ShowMoveCmd = false; GameObject.Find("InitStage").transform.GetComponent <Tutorial>().AfterMove(); init.ShowMap = true; } } GUI.enabled = true; //roll over move button if (!chessProperty.Moved && !InTutorial) { if (posMoveBt.Contains(mousePos)) { GUI.DrawTexture(posMoveBt, MoveTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + 16, 100, 30), "move", mainStyle); } } // summon button if (!chessProperty.Summoner || init.stage == 1) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posSummonBt, SummonTex)) { MainGuiFade = false; SubGuiFade = true; summonShow = true; } GUI.enabled = true; //roll over summon button if (chessProperty.Summoner && init.stage != 1) { if (posSummonBt.Contains(mousePos)) { GUI.DrawTexture(posSummonBt, SummonTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment + 16, 100, 30), "summon", mainStyle); } } // Attack button if (chessProperty.Attacked || !MapHelper.Attackable(CurrentChess)) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posAttackBt, AttackTex)) { MainGuiFade = false; SubGuiFade = true; attackShow = true; currentSelect.attackCommand(CurrentChess); currentSelect.AttackCommandNetwork(); if (InSecondTutor) { init.ShowAtk = false; } } GUI.enabled = true; //roll over attack button if (!chessProperty.Attacked && MapHelper.Attackable(CurrentChess)) { if (posAttackBt.Contains(mousePos)) { GUI.DrawTexture(posAttackBt, AttackTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 2 + 16, 100, 30), "attack", mainStyle); } } // skill button if (chessProperty.Activated || init.stage == 1) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posSkillBt, SkillTex)) { MainGuiFade = false; SubGuiFade = true; skillShow = true; } GUI.enabled = true; //roll over skill button if (!chessProperty.Activated && init.stage != 1) { if (posSkillBt.Contains(mousePos)) { GUI.DrawTexture(posSkillBt, SkillTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 3 + 16, 100, 30), "skill", mainStyle); } } //Defense button if (chessProperty.Attacked || init.ShowBuff || InSecondTutor) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posDefenseBt, DefenseTex)) { DefenseCmd(CurrentChess); if (init.ShowDef) { init.ShowDef = false; InTutorial = false; InSecondTutor = true; } } GUI.enabled = true; //roll over defense button if (!chessProperty.Attacked) { if (posDefenseBt.Contains(mousePos)) { GUI.DrawTexture(posDefenseBt, DefenseTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 4 + 16, 100, 30), "defence", mainStyle); } } // End turn button if (InTutorial) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUI.Button(posEndTurnBt, EndTurnTex)) { MainGuiFade = false; //SubGuiFade = true; chessProperty.Activated = true; chessProperty.Attacked = true; chessProperty.Moved = true; chessProperty.TurnFinished = true; CurrentChess.gameObject.layer = 10; currentSelect.MoveToLayer(CurrentChess, 10); currentSelect.EndTurnNetwork(); } GUI.enabled = true; //roll over end turn button if (!InTutorial) { if (posEndTurnBt.Contains(mousePos)) { GUI.DrawTexture(posEndTurnBt, EndTurnTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 5 + 13, 100, 30), "end turn", mainStyle); } } } } GUI.color = new Color(1.0f, 1.0f, 1.0f, _subAlpha); if (moveShow) { GUI.DrawTexture(posMoveBt, MoveTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + 16, 100, 30), "move", mainStyle); if (Input.GetMouseButtonDown(0) && posMoveBt.Contains(mousePos)) { Cancel = true; MainGuiFade = true; SubGuiFade = false; TurnFinished(CurrentChess); } } if (attackShow) { GUI.DrawTexture(posAttackBt, AttackTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 2 + 16, 100, 30), "attack", mainStyle); if (Input.GetMouseButtonDown(0) && posAttackBt.Contains(mousePos)) { Cancel = true; MainGuiFade = true; SubGuiFade = false; TurnFinished(CurrentChess); } } if (summonShow) { Rect posSummonList = new Rect(posSummonBt.x + posSummonBt.width / 2, posSummonBt.y + posSummonBt.height / 2, 200.0f, 200.0f); GUI.DrawTexture(posSummonList, SubWindow); GUI.DrawTexture(posSummonBt, SummonTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment + 16, 100, 30), "summon", mainStyle); if (Input.GetMouseButtonDown(0) && posSummonBt.Contains(mousePos)) { Cancel = true; MainGuiFade = true; SubGuiFade = false; } IList soldiers = new List <Transform>(); if (CurrentChess.GetComponent <CharacterProperty>().Player == 1) { foreach (Transform gf in players.PlayerAChesses) { if (!gf.GetComponent <CharacterProperty>().Summoner) { soldiers.Add(gf); } } } else if (CurrentChess.GetComponent <CharacterProperty>().Player == 2) { foreach (Transform gf in players.PlayerBChesses) { if (!gf.GetComponent <CharacterProperty>().Summoner) { soldiers.Add(gf); } } } int seg = 0; foreach (Transform gf in soldiers) { CharacterProperty gfp = gf.GetComponent <CharacterProperty>(); if (gfp.Ready && (gfp.summonCost <= currentSelect.player.GetComponent <ManaCounter>().Mana) && gfp.death) { GUI.enabled = true; } else { GUI.enabled = false; } Rect posGFBt = CreateGFBt(gf, seg); if (posGFBt.Contains(mousePos)) { infoUI.CreatedGFRollOver(gf, subStyle); } if (GUI.Button(posGFBt, "", subStyle)) { currentSelect.summonCommand(CurrentChess, gf); //update network UI currentSelect.SummonNetwork(); } seg += 1; } } if (skillShow) { Rect posSkillsBt = new Rect(posSkillBt.x + posSkillBt.width / 2, posSkillBt.y + posSkillBt.height / 2, 200.0f, 100.0f); GUI.DrawTexture(posSkillsBt, SubWindow); GUI.DrawTexture(posSkillBt, SkillTex); GUI.Label(new Rect(btSize + leftMargin + 5, topMargin + segment * 3 + 16, 100, 30), "skill", mainStyle); if (Input.GetMouseButtonDown(0) && posSkillBt.Contains(mousePos)) { Cancel = true; MainGuiFade = true; SubGuiFade = false; } Transform[] skills = CurrentChess.GetComponent <SkillSets>().Skills; int seg = 0; if (skills.Length > 0) { foreach (Transform skill in skills) { if (currentSelect.player.GetComponent <ManaCounter>().Mana >= skill.GetComponent <SkillProperty>().SkillCost) { GUI.enabled = true; } else { GUI.enabled = false; } Rect skillBtRect = CreateSkillBt(skill, seg); if (skillBtRect.Contains(mousePos)) { ShowSkillInfo(skill); } if (GUI.Button(skillBtRect, "", subStyle)) { currentSelect.SkillUINetwork(); if (!skill.GetComponent <SkillProperty>().NeedToSelect) { skill.GetComponent <SkillProperty>().GetRealSkillRate(); skill.GetComponent <SkillProperty>().PassSkillRate = MapHelper.Success(skill.GetComponent <SkillProperty>().SkillRate); skill.GetComponent <SkillProperty>().ActivateSkill(); currentSelect.player.GetComponent <ManaCounter>().Mana -= skill.GetComponent <SkillProperty>().SkillCost; CurrentChess.GetComponent <CharacterProperty>().Activated = true; currentSelect.AnimStateNetWork(CurrentChess, AnimVault.AnimState.skill); SubGuiFade = false; TurnFinished(CurrentChess); //update network currentSelect.SkillCmdNetwork(CurrentChess, skill); } else { currentSelect.skillCommand(skill); } } seg += 1; GUI.enabled = true; } } } }
// Update is called once per frame void Update() { if (Step > 0) { mUI.MainGuiFade = false; mUI.SubGuiFade = true; t += Time.deltaTime / timeToReach; r += Time.deltaTime / timeToRotate; Vector3 fowardPos = Chess.transform.forward * accl + Chess.transform.position; if (cPass.PassiveDict[PassiveType.Flying]) { } Vector3 relativePos = target - Chess.transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); Chess.transform.rotation = Quaternion.Lerp(OldRotation, rotation, r); //networkView.RPC("RPCRotateCharacter",RPCMode.Others, Chess.name, OldRotation, rotation, r); Vector3 plannedPos = Vector3.Lerp(startPosition, target, t); Chess.transform.position = Vector3.Lerp(fowardPos, plannedPos, 0.01f); //networkView.RPC("RPCMoveCharacter",RPCMode.Others,Chess.name,fowardPos,plannedPos,0.01f); float d = Vector3.Distance(Chess.transform.position, target); if (d <= 0.05f) { Step -= 1; init += 1; if (Step > 0) { SetDestination(); } else if (Step == 0) { init = 0; t = 0; r = 0; s = 0; OldRotation = Chess.transform.rotation; facingTower = true; } } } if (Step == 0 && facingTower) { s += Time.deltaTime / timeToRotate; Vector3 relativePos = tower.transform.position - Chess.transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); float yAngle = Mathf.LerpAngle(OldRotation.eulerAngles.y, rotation.eulerAngles.y, s); Chess.transform.rotation = Quaternion.Euler(new Vector3(OldRotation.eulerAngles.x, yAngle, OldRotation.eulerAngles.z)); //networkView.RPC("RPCRotateCharacter",RPCMode.Others, Chess.name, OldRotation, rotation, s); //float angle = Quaternion.Angle(Chess.transform.rotation, rotation); float angle = Mathf.Abs(rotation.eulerAngles.y - yAngle); if (Mathf.RoundToInt(angle) == 360) { angle -= 360.0f; angle = Mathf.Abs(angle); } if (angle <= 1.0f) { s = 0; facingTower = false; mUI.MainGuiFade = true; mUI.SubGuiFade = false; MoveMode = false; Chess.GetComponent <CharacterProperty>().Moved = true; //networkView.RPC("RPCUpdateChessMoved", RPCMode.Others,Chess.name,true); currentSelect.updateAllCharactersPowers(); if (chessModel.GetComponent <AnimVault>() != null) { //chessModel.GetComponent<AnimVault>().CurrentState = AnimVault.AnimState.idle; currentSelect.AnimStateNetWork(Chess, AnimVault.AnimState.idle); } if (!currentSelect.Playing) { Transform npc = GameObject.Find("NpcPlayer").transform; NpcPlayer npcPlayer = npc.GetComponent <NpcPlayer>(); npcPlayer.InPause = true; } if (mUI.InTutorial) { GameObject.Find("InitStage").GetComponent <InitStage>().ShowBuff = true; } } } }
// Update is called once per frame void Update() { if (Step > 0) { mUI.MainGuiFade = false; mUI.SubGuiFade = true; t += Time.deltaTime / timeToReach; r += Time.deltaTime / timeToRotate; Vector3 fowardPos = Chess.transform.forward * accl + Chess.transform.position; if (cPass.PassiveDict[PassiveType.Flying]) { } Vector3 relativePos = target - Chess.transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); Chess.transform.rotation = Quaternion.Lerp(OldRotation, rotation, r); networkView.RPC("RPCRotateCharacter", RPCMode.Others, Chess.name, OldRotation, rotation, r); Vector3 plannedPos = Vector3.Lerp(startPosition, target, t); Chess.transform.position = Vector3.Lerp(fowardPos, plannedPos, 0.01f); networkView.RPC("RPCMoveCharacter", RPCMode.Others, Chess.name, fowardPos, plannedPos, 0.01f); float d = Vector3.Distance(Chess.transform.position, target); if (d <= 0.05f) { Step -= 1; init += 1; if (Step > 0) { SetDestination(); } else if (Step == 0) { init = 0; t = 0; r = 0; s = 0; OldRotation = Chess.transform.rotation; facingTower = true; } } } if (Step == 0 && facingTower) { s += Time.deltaTime / timeToRotate; Vector3 relativePos = tower.transform.position - Chess.transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); Chess.transform.rotation = Quaternion.Lerp(OldRotation, rotation, s); networkView.RPC("RPCRotateCharacter", RPCMode.Others, Chess.name, OldRotation, rotation, s); float angle = Quaternion.Angle(Chess.transform.rotation, rotation); if (angle < 1.0f) { s = 0; facingTower = false; mUI.MainGuiFade = true; mUI.SubGuiFade = false; MoveMode = false; Chess.GetComponent <CharacterProperty>().Moved = true; networkView.RPC("RPCUpdateChessMoved", RPCMode.Others, Chess.name, true); currentSelect.updateAllCharactersPowers(); if (chessModel.GetComponent <AnimVault>() != null) { //chessModel.GetComponent<AnimVault>().CurrentState = AnimVault.AnimState.idle; currentSelect.AnimStateNetWork(Chess, AnimVault.AnimState.idle); } } } }