Added controls for gamepad, changed input & UI

This commit is contained in:
TAASONI3
2023-07-04 20:15:06 +02:00
parent 0b058f9248
commit 7aba856b17
48 changed files with 24176 additions and 15427 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class Controls : MonoBehaviour
@@ -13,6 +14,11 @@ public class Controls : MonoBehaviour
GameObject playerCam;
UIHandler uihandler;
GameObject currentHouse;
Vector3 input;
Vector2 view;
PlayerInput playerInput;
MoveDirection direction;
void Start()
{
@@ -21,122 +27,185 @@ public class Controls : MonoBehaviour
worldGen = GameObject.Find("WorldGenerator");
playerCam = GameObject.Find("Main Camera");
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
input = new Vector3();
view = new Vector2();
playerInput = GetComponent<PlayerInput>();
direction = MoveDirection.None;
}
// Update is called once per frame
void Update()
{
if(playerInput.currentControlScheme == "Controller"){
if(Cursor.lockState != CursorLockMode.Locked){
Cursor.lockState = CursorLockMode.Locked;
}
}
else{
if(uihandler.canPlayerRotate()){
Cursor.lockState = CursorLockMode.Locked;
}
else{
Cursor.lockState = CursorLockMode.Confined;
}
}
if(uihandler.state == UIState.GAME && playerInput.currentActionMap.name != "MainGame"){
playerInput.SwitchCurrentActionMap("MainGame");
}
if(uihandler.state != UIState.GAME && playerInput.currentActionMap.name != "Menu"){
playerInput.SwitchCurrentActionMap("Menu");
}
if (!player.GetComponent<Player>().takeDamage(0))
{
EventSystem.current.SetSelectedGameObject(null);
if (!uihandler.isPlayerInFight())
{
checkNormalControls();
}
else
{
checkFightControls();
if (uihandler.canPlayerRotate()){
playerCam.GetComponent<PlayerCamera>().lookAround(view, playerInput.currentControlScheme == "Controller");
}
}
}
}
private void checkNormalControls()
{
if (uihandler.canPlayerMove())
public void FixedUpdate(){
if (!player.GetComponent<Player>().takeDamage(0))
{
player.GetComponent<Player>().move();
if (Input.GetKeyDown(KeyCode.E))
if (!uihandler.isPlayerInFight())
{
GameObject target = playerCam.GetComponent<PlayerCamera>().interactWithObject();
if (target != null)
if (uihandler.canPlayerMove())
{
switch (target.tag.Split(':')[1])
{
case "Enemy":
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
break;
case "Tree":
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Wood"));
Destroy(target);
break;
case "Stone":
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Rock"));
Destroy(target);
break;
case "NPC":
target.GetComponent<NPC>().interact();
break;
case "Door":
target.GetComponent<Door>().interact();
break;
case "Chest":
target.GetComponent<Chest>().interact();
break;
case "Ore":
if(target.name.ToLower().Contains("iron")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Iron ore"));
}
else if(target.name.ToLower().Contains("gold")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Gold ore"));
}
else if(target.name.ToLower().Contains("copper")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Copper ore"));
}
else if(target.name.ToLower().Contains("tin")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Tin ore"));
}
Destroy(target);
break;
}
player.GetComponent<Player>().move(input);
}
}
else if (Input.GetKeyDown(KeyCode.C))
{
uihandler.switchCharactersheet();
}
if(direction != MoveDirection.None){
AxisEventData data = new AxisEventData(EventSystem.current);
data.moveDir = direction;
data.selectedObject = EventSystem.current.currentSelectedGameObject;
ExecuteEvents.Execute(data.selectedObject, data, ExecuteEvents.moveHandler);
}
}
public void OnLooking(InputValue value){
view = value.Get<Vector2>();
}
public void OnMovement(InputValue value){
try{
input = value.Get<Vector3>();
}catch{
if(value.Get<Vector2>().x < 0){
direction = MoveDirection.Left;
}
else if (Input.GetKeyDown(KeyCode.Q))
{
uihandler.switchQuestLog();
else if(value.Get<Vector2>().x > 0){
direction = MoveDirection.Right;
}
else if (Input.GetKeyDown(KeyCode.I))
{
uihandler.switchInventory();
else if(value.Get<Vector2>().y < 0){
direction = MoveDirection.Down;
}
else if(value.Get<Vector2>().y > 0){
direction = MoveDirection.Up;
}
}
if (Input.GetKeyDown(KeyCode.Escape))
}
public void OnInteraction(){
if (uihandler.canPlayerMove())
{
uihandler.switchPauseMenu();
GameObject target = playerCam.GetComponent<PlayerCamera>().interactWithObject();
if (target != null)
{
switch (target.tag.Split(':')[1])
{
case "Enemy":
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
break;
case "Tree":
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Wood"));
Destroy(target);
break;
case "Stone":
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Rock"));
Destroy(target);
break;
case "NPC":
target.GetComponent<NPC>().interact();
break;
case "Door":
target.GetComponent<Door>().interact();
break;
case "Chest":
target.GetComponent<Chest>().interact();
break;
case "Ore":
if(target.name.ToLower().Contains("iron")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Iron ore"));
}
else if(target.name.ToLower().Contains("gold")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Gold ore"));
}
else if(target.name.ToLower().Contains("copper")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Copper ore"));
}
else if(target.name.ToLower().Contains("tin")){
GameObject.Find("Inventory").GetComponent<Inventory>().addItem(new Item("Tin ore"));
}
Destroy(target);
break;
}
}
}
}
private void checkFightControls()
{
if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
{
public void OnCharsheet(){
uihandler.switchCharactersheet();
}
public void OnInventory(){
uihandler.switchInventory();
}
public void OnQuestlog(){
uihandler.switchQuestLog();
}
public void OnPause(){
uihandler.switchPauseMenu();
}
public void OnSkillOne(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(1);
}
else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
{
}
public void OnSkillTwo(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(2);
}
else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3))
{
}
public void OnSkillThree(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(3);
}
else if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4))
{
}
public void OnSkillFour(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(4);
}
else if (Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5))
{
}
public void OnSkillFive(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(5);
}
else if (Input.GetKeyDown(KeyCode.Alpha6) || Input.GetKeyDown(KeyCode.Keypad6))
{
}
public void OnSkillSix(){
if(uihandler.isPlayerInFight()){
fight.GetComponent<Fight>().playerAction(6);
}
}
}

View File

@@ -13,6 +13,7 @@ namespace Assets.Scripts
System.Random rand = new System.Random();
BasicSlime slime;
SlimeFactory factory = new SlimeFactory();
// Start is called before the first frame update
void Start()

View File

@@ -2,6 +2,7 @@ using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Fight : MonoBehaviour
@@ -23,6 +24,7 @@ public class Fight : MonoBehaviour
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
uihandler.openFight();
uihandler.updateFightInterface(enemy, player);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnActionOne"));
}
private void endFight()
@@ -91,41 +93,21 @@ public class Fight : MonoBehaviour
int enemyDamage = -1;
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
int[] enemyStats = enemy.GetComponent<Enemy>().getStats();
int index = rand.Next(0,3);
if (enemyStats[0] <= enemyStats[1] / 4 && index != 0)
int index = rand.Next(0,2);
if (index == 1 && enemyStats[2] <= 0)
{
enemyDamage = secondChance();
if (enemyDamage != 0)
{
enemyDamage = secondChance();
}
}
else if (enemyStats[0] <= enemyStats[1] / 2 && index != 0)
{
enemyDamage = secondChance();
index = 0;
}
if (index == 2 && enemyStats[2] <= 0)
switch (index)
{
index = 1;
}
if (enemyDamage == 0 || index == 0)
{
endFight();
uihandler.showMessage("INFORMATION;The enemy escaped!");
}
else
{
switch (index)
{
case 1:
enemyDamage = enemy.GetComponent<Enemy>().calculateDamage();
break;
case 2:
enemyDamage = enemy.GetComponent<Enemy>().calculateHeavy();
break;
}
case 0:
enemyDamage = enemy.GetComponent<Enemy>().calculateDamage();
break;
case 1:
enemyDamage = enemy.GetComponent<Enemy>().calculateHeavy();
break;
}
if (player.GetComponent<Player>().takeDamage(enemyDamage))
@@ -134,10 +116,4 @@ public class Fight : MonoBehaviour
uihandler.showDeathScreen();
}
}
private int secondChance()
{
int result = rand.Next(0, 3);
return result;
}
}

View File

@@ -12,6 +12,7 @@ namespace Assets.Scripts
Player player;
AudioHandler audioHandler;
WorldGenerator worldGenerator;
GameObject fight;
private void Start()
{
@@ -19,6 +20,7 @@ namespace Assets.Scripts
player = GameObject.Find("Player").GetComponent<Player>();
worldGenerator = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>();
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
fight = GameObject.Find("Fight");
}
public void openOptions()
@@ -49,35 +51,30 @@ namespace Assets.Scripts
{
audioHandler.playButtonClick();
player.upgradeStrength();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeDexterity()
{
audioHandler.playButtonClick();
player.upgradeDexterity();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeIntelligence()
{
audioHandler.playButtonClick();
player.upgradeIntelligence();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeHealth()
{
audioHandler.playButtonClick();
player.upgradeHealth();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeSecondary()
{
audioHandler.playButtonClick();
player.upgradeSecondary();
EventSystem.current.SetSelectedGameObject(null);
}
public void saveOptions()
@@ -86,8 +83,10 @@ namespace Assets.Scripts
audioHandler.playButtonClick();
saveText = saveText + uihandler.saveVideoSettings() + "\r\n";
saveText = saveText + audioHandler.saveAudioSettings() + "\r\n";
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().speed = GameObject.Find("slideSensitivity").GetComponent<Slider>().value;
saveText = saveText + "Sensitivity:"+GameObject.Find("slideSensitivity").GetComponent<Slider>().value;
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().mouseSpeed = GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value;
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().controllerSpeed = GameObject.Find("slideSensitivityController").GetComponent<Slider>().value;
saveText = saveText + "SensitivityMouse:"+GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value + "\r\n";
saveText = saveText + "SensitivityController:"+GameObject.Find("slideSensitivityController").GetComponent<Slider>().value;
FileHandler.saveOptions(saveText);
uihandler.closeOptions();
}
@@ -96,7 +95,6 @@ namespace Assets.Scripts
{
audioHandler.playButtonClick();
uihandler.startGame();
EventSystem.current.SetSelectedGameObject(null);
}
public void switchCharactersheet()
@@ -135,5 +133,17 @@ namespace Assets.Scripts
saveString = saveString + "\r\n}";
FileHandler.saveGame(saveString, "./save.json");
}
public void castSkill(int index){
fight.GetComponent<Fight>().playerAction(index);
}
public void switchOptionView(string key){
uihandler.showOptionView(key);
}
public void closeTutorial(){
uihandler.closeTutorial();
}
}
}

View File

@@ -95,9 +95,14 @@ namespace Assets.Scripts
break;
}
break;
case "Sensitivity":
case "SensitivityMouse":
if(isIngame){
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().speed = float.Parse(line.Split(':')[1]);
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().mouseSpeed = float.Parse(line.Split(':')[1]);
}
break;
case "SensitivityController":
if(isIngame){
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().controllerSpeed = float.Parse(line.Split(':')[1]);
}
break;
}
@@ -120,8 +125,11 @@ namespace Assets.Scripts
case "Mode":
GameObject.Find("dropMode").GetComponent<Dropdown>().value = int.Parse(line.Split(':')[1]);
break;
case "Sensitivity":
GameObject.Find("slideSensitivity").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
case "SensitivityMouse":
GameObject.Find("slideSensitivityMouse").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
break;
case "SensitivityController":
GameObject.Find("slideSensitivityController").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
break;
}
}

View File

@@ -42,6 +42,9 @@ namespace Assets.Scripts
updatePlayerHUD();
switchWaterLayer();
updateCoordinates();
if(EventSystem.current.currentSelectedGameObject != null){
EventSystem.current.SetSelectedGameObject(null);
}
}
}
@@ -107,6 +110,7 @@ namespace Assets.Scripts
tutorial.transform.localScale = new Vector3(1, 1, 1);
showHUD();
state = UIState.TUTORIAL;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnCloseTutorial"));
}
public void switchCharactersheet()
@@ -127,7 +131,8 @@ namespace Assets.Scripts
FileHandler.loadOptionDisplay();
hideOtherElements(options);
state = UIState.PAUSEOPTIONS;
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnAudio"));
showOptionView("audio");
}
public void closeOptions()
@@ -141,6 +146,9 @@ namespace Assets.Scripts
{
hideOtherElements(charactersheet);
state = UIState.CHARACTER;
if(GameObject.Find("btnStrengthIncrease").transform.localScale != new Vector3(0,0,0)){
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStrengthIncrease"));
}
}
public void closeCharactersheet()
@@ -166,12 +174,13 @@ namespace Assets.Scripts
{
hideOtherElements(inventory);
state = UIState.INVENTORY;
EventSystem.current.SetSelectedGameObject(GameObject.Find("bagOne"));
}
public void closeInventory()
{
inventory.GetComponent<Inventory>().OnMouseUp();
inventory.transform.localScale = new Vector3(0, 0, 0);
GameObject.Find("pnlInventoryActions").transform.localScale = new Vector3(0,0,0);
showHUD();
state = UIState.GAME;
}
@@ -242,6 +251,7 @@ namespace Assets.Scripts
questlog.GetComponent<QuestLog>().showQuests();
state = UIState.QUEST;
hideOtherElements(questlog);
EventSystem.current.SetSelectedGameObject(GameObject.Find("scrollQuestlog"));
}
public void closeQuestLog()
@@ -298,6 +308,7 @@ namespace Assets.Scripts
{
hideOtherElements(pauseMenu);
state = UIState.PAUSE;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnContinue"));
}
public void closePauseMenu()
@@ -311,6 +322,7 @@ namespace Assets.Scripts
{
state = UIState.DEATH;
hideOtherElements(deathscreen);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnMenu"));
}
public void hideOtherElements(GameObject obj)
@@ -358,9 +370,9 @@ namespace Assets.Scripts
private void updateFightInterfaceActions(GameObject player)
{
GameObject actionFour = GameObject.Find("action4");
GameObject actionFive = GameObject.Find("action5");
GameObject actionSix = GameObject.Find("action6");
GameObject actionFour = GameObject.Find("btnActionFour");
GameObject actionFive = GameObject.Find("btnActionFive");
GameObject actionSix = GameObject.Find("btnActionSix");
player.GetComponent<Player>().displayAction(0, actionFour.transform.Find("imgAction").gameObject, actionFour.transform.Find("descAction").gameObject);
player.GetComponent<Player>().displayAction(1, actionFive.transform.Find("imgAction").gameObject, actionFive.transform.Find("descAction").gameObject);
@@ -533,6 +545,7 @@ namespace Assets.Scripts
GameObject.Find("Player").GetComponent<Player>().finishPlayerCreation();
hideOtherElements(introduction);
state = UIState.INTRODUCTION;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnClose"));
}
else
{
@@ -551,5 +564,17 @@ namespace Assets.Scripts
tutorial.transform.localScale = new Vector3(0,0,0);
state = UIState.GAME;
}
public void showOptionView(string key){
GameObject optionContent = GameObject.Find("pnlContent");
for(int i = 0; i < optionContent.transform.childCount; i++){
if(optionContent.transform.GetChild(i).name.ToLower().Contains(key)){
optionContent.transform.GetChild(i).transform.localScale = new Vector3(1,1,1);
}
else{
optionContent.transform.GetChild(i).transform.localScale = new Vector3(0,0,0);
}
}
}
}
}

View File

@@ -18,7 +18,6 @@ namespace Assets.Scripts
public GameObject amulet;
public GameObject leftHand;
public GameObject rightHand;
public GameObject dragImage;
public GameObject itemDisplay;
public GameObject[] bags;
@@ -28,8 +27,9 @@ namespace Assets.Scripts
public int currentBag = -1;
GameObject startDrag;
TooltipHandler tooltip;
public GameObject currentSlot;
// Start is called before the first frame update
@@ -101,10 +101,10 @@ namespace Assets.Scripts
{
if (currentBag != -1)
{
bags[currentBag].transform.Find("Selected").GetComponent<RawImage>().color = Color.white;
bags[currentBag].transform.parent.Find("Selected").GetComponent<RawImage>().color = Color.white;
}
currentBag = index;
bags[currentBag].transform.Find("Selected").GetComponent<RawImage>().color = Color.cyan;
bags[currentBag].transform.parent.Find("Selected").GetComponent<RawImage>().color = Color.cyan;
checkInventoryColors();
foreach(GameObject slot in slots)
{
@@ -177,41 +177,6 @@ namespace Assets.Scripts
}
}
public void setDrag(GameObject slot)
{
startDrag = slot;
}
public GameObject getDrag()
{
return startDrag;
}
/*public Item getEquip(ItemPlace place)
{
switch (place)
{
case ItemPlace.LEFTHAND:
return leftHand.GetComponent<InventorySlot>().getEquip();
case ItemPlace.RIGHTHAND:
return rightHand.GetComponent<InventorySlot>().getEquip();
case ItemPlace.HELMET:
return head.GetComponent<InventorySlot>().getEquip();
case ItemPlace.BOOTS:
return feet.GetComponent<InventorySlot>().getEquip();
case ItemPlace.SHOULDER:
return shoulders.GetComponent<InventorySlot>().getEquip();
case ItemPlace.AMULET:
return amulet.GetComponent<InventorySlot>().getEquip();
case ItemPlace.RING:
return ring.GetComponent<InventorySlot>().getEquip();
case ItemPlace.ARMOR:
return chest.GetComponent<InventorySlot>().getEquip();
default:
return null;
}
}*/
public void calculateStatBoost(Dictionary<string, int> attributes, bool isAddition)
{
foreach (string key in attributes.Keys)
@@ -382,12 +347,79 @@ namespace Assets.Scripts
}
}
}
public void OnMouseUp(){
if(dragImage.GetComponent<RawImage>().texture != null){
dragImage.GetComponent<RawImage>().color = new Color(0,0,0,0);
dragImage.GetComponent<RawImage>().texture = null;
dragImage.transform.position = new Vector3(0,0,0);
public void trashItem(){
InventorySlot invSlot = currentSlot.GetComponent<InventorySlot>();
if (invSlot.place == ItemPlace.BAG)
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", invSlot.getItem(invSlot.getCurrentBag()), -1);
invSlot.removeItem();
}
else
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", invSlot.getEquip(), -1);
invSlot.removeEquip();
}
hideSlotOptions();
}
public void equipItem(){
InventorySlot invSlot = currentSlot.GetComponent<InventorySlot>();
if(invSlot.place == ItemPlace.BAG){
Equipment save = (Equipment)invSlot.getItem(currentBag);
InventorySlot equipSlot;
switch(save.getPlace()){
case ItemPlace.HELMET:
equipSlot = head.GetComponent<InventorySlot>();
break;
case ItemPlace.SHOULDER:
equipSlot = shoulders.GetComponent<InventorySlot>();
break;
case ItemPlace.BOOTS:
equipSlot = feet.GetComponent<InventorySlot>();
break;
case ItemPlace.AMULET:
equipSlot = amulet.GetComponent<InventorySlot>();
break;
case ItemPlace.ARMOR:
equipSlot = chest.GetComponent<InventorySlot>();
break;
case ItemPlace.RING:
equipSlot = ring.GetComponent<InventorySlot>();
break;
case ItemPlace.RIGHTHAND:
equipSlot = rightHand.GetComponent<InventorySlot>();
break;
case ItemPlace.LEFTHAND:
equipSlot = leftHand.GetComponent<InventorySlot>();
break;
default:
equipSlot = invSlot;
break;
}
if(equipSlot.getEquip() != null){
invSlot.setItem(equipSlot.getEquip(), currentBag);
calculateStatBoost(equipSlot.getEquip().getAttributes(), false);
}
else{
invSlot.removeItem();
}
equipSlot.setEquip(save);
calculateStatBoost(equipSlot.getEquip().getAttributes(), true);
}
else{
addItem(invSlot.getEquip());
calculateStatBoost(invSlot.getEquip().getAttributes(), false);
invSlot.removeEquip();
}
hideSlotOptions();
}
public void hideSlotOptions(){
GameObject.Find("pnlInventoryActions").transform.localScale = new Vector3(0,0,0);
GameObject.Find("btnEquip").transform.Find("Text").GetComponent<Text>().text = "Equip";
GameObject.Find("btnEquip").GetComponent<Button>().interactable = true;
EventSystem.current.SetSelectedGameObject(currentSlot);
}
}
}

View File

@@ -94,46 +94,7 @@ namespace Assets.Scripts
inventory.itemDisplay.transform.localScale = new Vector3(0,0,0);
}
public void OnMouseDrag()
{
inventory.setDrag(gameObject);
Item toMove;
if (place == ItemPlace.BAG)
{
toMove = items[currentBag];
}
else
{
toMove = equip;
}
if (toMove != null)
{
inventory.dragImage.GetComponent<RawImage>().color = toMove.rarityColor;
inventory.dragImage.GetComponent<RawImage>().texture = toMove.image;
inventory.dragImage.transform.position = new Vector3(Input.mousePosition.x + 50, Input.mousePosition.y - 50, 0);
}
}
public void OnMouseUp()
{
inventory.dragImage.GetComponent<RawImage>().color = new Color(0,0,0,0);
inventory.dragImage.GetComponent<RawImage>().texture = null;
inventory.dragImage.transform.position = new Vector3(0,0,0);
InventorySlot startDrag = inventory.getDrag().GetComponent<InventorySlot>();
Item item;
if (startDrag.place == ItemPlace.BAG)
{
item = startDrag.getItem(startDrag.currentBag);
}
else
{
item = startDrag.getEquip();
}
if (item != null)
{
item.move(startDrag, inventory, this);
}
}
public Equipment getEquip()
{
@@ -235,5 +196,29 @@ namespace Assets.Scripts
}
}
public void showSlotOptions(){
GameObject current = EventSystem.current.currentSelectedGameObject;
GameObject.Find("Inventory").GetComponent<Inventory>().currentSlot = current;
GameObject.Find("btnEquip").transform.Find("Text").GetComponent<Text>().text = "Equip";
GameObject.Find("btnEquip").GetComponent<Button>().interactable = true;
if(equip != null || items[currentBag] != null){
if(equip != null){
GameObject.Find("btnEquip").transform.Find("Text").GetComponent<Text>().text = "Unequip";
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnEquip"));
}
if(items[currentBag] != null){
if(items[currentBag] is Equipment){
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnEquip"));
}
else{
GameObject.Find("btnEquip").GetComponent<Button>().interactable = false;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnTrash"));
}
}
GameObject.Find("pnlInventoryActions").transform.position = new Vector3(current.transform.position.x + 125, current.transform.position.y, 0);
GameObject.Find("pnlInventoryActions").transform.localScale = new Vector3(1,1,1);
}
}
}
}

View File

@@ -34,20 +34,7 @@ namespace Assets.Scripts
public void deleteItem()
{
InventorySlot toDelete = GameObject.Find("Inventory").GetComponent<Inventory>().getDrag().GetComponent<InventorySlot>();
if (toDelete.place == ItemPlace.BAG)
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", toDelete.getItem(toDelete.getCurrentBag()), -1);
toDelete.removeItem();
}
else
{
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("collect", toDelete.getEquip(), -1);
toDelete.removeEquip();
}
GameObject.Find("Inventory").GetComponent<Inventory>().dragImage.GetComponent<RawImage>().color = new Color(0, 0, 0, 0);
GameObject.Find("Inventory").GetComponent<Inventory>().dragImage.GetComponent<RawImage>().texture = null;
GameObject.Find("Inventory").GetComponent<Inventory>().dragImage.transform.position = new Vector3(0, 0, 0);
}
}
}

View File

@@ -343,82 +343,6 @@ namespace Assets.Scripts
}
return text;
}
override
public void move(InventorySlot startDrag, Inventory inventory, InventorySlot endDrag)
{
bool isSwap = false;
if (endDrag.place != place && endDrag.place != ItemPlace.BAG)
{
return;
}
if (endDrag.place == ItemPlace.BAG)
{
Item endItem = endDrag.getItem(endDrag.getCurrentBag());
if (endItem != null)
{
if (endItem is Equipment)
{
if (((Equipment)endItem).getPlace() != startDrag.place)
{
return;
}
}
else
{
if (startDrag.place == ItemPlace.BAG)
{
startDrag.setItem(endItem, endDrag.getCurrentBag());
}
else
{
if (endItem is Equipment)
{
startDrag.setEquip((Equipment)endItem);
inventory.calculateStatBoost(attributes, false);
inventory.calculateStatBoost(((Equipment)endItem).getAttributes(), true);
}
else
{
return;
}
}
}
isSwap = true;
}
endDrag.setItem(this, endDrag.getCurrentBag());
}
else
{
if (endDrag.getEquip() != null)
{
if (startDrag.place == ItemPlace.BAG)
{
startDrag.setItem(endDrag.getEquip(), startDrag.getCurrentBag());
isSwap = true;
inventory.calculateStatBoost(endDrag.getEquip().getAttributes(), false);
}
else
{
return;
}
}
inventory.calculateStatBoost(getAttributes(), true);
endDrag.setEquip(this);
}
if (!isSwap)
{
if (startDrag.place != ItemPlace.BAG)
{
inventory.calculateStatBoost(startDrag.getEquip().getAttributes(), false);
startDrag.removeEquip();
}
else
{
startDrag.removeItem();
}
}
}
}
}

View File

@@ -172,27 +172,6 @@ namespace Assets.Scripts
return result;
}
public virtual void move(InventorySlot startDrag, Inventory inventory, InventorySlot endDrag)
{
if (endDrag.place != ItemPlace.BAG)
{
return;
}
Item item = endDrag.getItem(endDrag.getCurrentBag());
if (item != null)
{
startDrag.setItem(item, endDrag.getCurrentBag());
}
else
{
startDrag.removeItem();
}
endDrag.setItem(this, startDrag.getCurrentBag());
}
private void chooseItem()
{
int index = rand.Next(4);

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
using Assets.Scripts;
using Assets.Scripts.Menu;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class ControlsMenu : MonoBehaviour
{
UIHandlerMenu uihandler;
MoveDirection direction;
PlayerInput playerInput;
void Start()
{
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandlerMenu>();
direction = MoveDirection.None;
playerInput = GetComponent<PlayerInput>();
}
// Update is called once per frame
void Update()
{
changeNameInput();
if(playerInput.currentControlScheme == "Controller"){
if(EventSystem.current.currentSelectedGameObject == null){
EventSystem.current.SetSelectedGameObject(FindFirstObjectByType<Button>().gameObject);
}
if(Cursor.lockState != CursorLockMode.Locked){
Cursor.lockState = CursorLockMode.Locked;
}
if(playerInput.currentActionMap.name != "Menu"){
playerInput.SwitchCurrentActionMap("Menu");
}
}
else{
if(Cursor.lockState != CursorLockMode.Confined){
Cursor.lockState = CursorLockMode.Confined;
}
}
}
public void FixedUpdate(){
if(direction != MoveDirection.None){
AxisEventData data = new AxisEventData(EventSystem.current);
data.moveDir = direction;
data.selectedObject = EventSystem.current.currentSelectedGameObject;
ExecuteEvents.Execute(data.selectedObject, data, ExecuteEvents.moveHandler);
}
}
public void OnMovement(InputValue value){
if(value.Get<Vector2>().x < 0){
direction = MoveDirection.Left;
}
else if(value.Get<Vector2>().x > 0){
direction = MoveDirection.Right;
}
else if(value.Get<Vector2>().y < 0){
direction = MoveDirection.Down;
}
else if(value.Get<Vector2>().y > 0){
direction = MoveDirection.Up;
}
}
public void OnBack(){
}
public void changeNameInput(){
if(uihandler.isCharacterCreation()){
if(playerInput.currentControlScheme == "Controller"){
if(EventSystem.current.currentSelectedGameObject == null || EventSystem.current.currentSelectedGameObject == GameObject.Find("inName")){
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnRandomName"));
}
GameObject.Find("inName").GetComponent<InputField>().interactable = false;
}
else{
GameObject.Find("inName").GetComponent<InputField>().interactable = true;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ecb843ecde843f11c98ebad43887bfde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -22,6 +22,7 @@ namespace Assets.Scripts.Menu
characterCreation.SetActive(false);
mainMenu.SetActive(true);
SteamWorksHandler.getStandardAchievement("StartAchievement");
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public void startGame(SceneHandler sceneHandler)
@@ -96,12 +97,14 @@ namespace Assets.Scripts.Menu
{
characterCreation.SetActive(true);
mainMenu.SetActive(false);
EventSystem.current.SetSelectedGameObject(GameObject.Find("inName"));
}
public void closeCharacterCreation()
{
characterCreation.SetActive(false);
mainMenu.SetActive(true);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public void openOptions()
@@ -109,13 +112,15 @@ namespace Assets.Scripts.Menu
options.SetActive(true);
mainMenu.SetActive(false);
FileHandler.loadOptionDisplay();
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnAudio"));
showOptionView("audio");
}
public void closeOptions()
{
options.SetActive(false);
mainMenu.SetActive(true);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public string saveVideoSettings(){
@@ -181,5 +186,21 @@ namespace Assets.Scripts.Menu
PlayerPrefs.SetInt("isLoad", 1);
sceneHandler.openGameScene();
}
public bool isCharacterCreation(){
return characterCreation.activeSelf;
}
public void showOptionView(string key){
GameObject optionContent = GameObject.Find("pnlContent");
for(int i = 0; i < optionContent.transform.childCount; i++){
if(optionContent.transform.GetChild(i).name.ToLower().Contains(key)){
optionContent.transform.GetChild(i).transform.localScale = new Vector3(1,1,1);
}
else{
optionContent.transform.GetChild(i).transform.localScale = new Vector3(0,0,0);
}
}
}
}
}

View File

@@ -8,6 +8,7 @@ using UnityEngine.UI;
using Assets.Scripts.Classes;
using Assets.Scripts.Races;
using Newtonsoft.Json.Linq;
using UnityEngine.InputSystem;
namespace Assets.Scripts
{
@@ -46,6 +47,8 @@ namespace Assets.Scripts
Dictionary<string, int> equipment;
bool finishedGame = false;
private void OnEnable()
{
#if UNITY_EDITOR
@@ -62,6 +65,7 @@ namespace Assets.Scripts
{
equipment = GameObject.Find("Inventory").GetComponent<Inventory>().getEquipmentBonus();
}
}
public void finishPlayerCreation()
@@ -247,13 +251,11 @@ namespace Assets.Scripts
}
}
public void move()
public void move(Vector3 input)
{
GameObject camera = GameObject.Find("Main Camera");
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
if (Input.GetKeyDown(KeyCode.Space))
if (input.y != 0)
{
if (jumpTimer != null)
{
@@ -272,12 +274,12 @@ namespace Assets.Scripts
}
}
Vector3 movement = new Vector3(x, 0, z);
Vector3 movement = new Vector3(input.x, 0, input.z);
movement = camera.transform.TransformDirection(movement);
movement.y = 0;
gameObject.transform.Translate(movement * speed * Time.deltaTime);
if (z != 0)
if (input.z != 0)
{
if (camera.transform.localPosition.y >= 0.5)
{

View File

@@ -10,9 +10,10 @@ namespace Assets.Scripts
UIHandler uihandler;
GameObject player;
Vector2 rotation = Vector2.zero;
public float speed = 1; //the sensibility
public float xMaxLimit = 5.0f;
public float xMinLimit = -5.0f;
public float mouseSpeed = 1; //the sensibility
public float controllerSpeed = 0.01f; //the sensibility
float xMaxLimit = 50.0f;
float xMinLimit = -50.0f;
GameObject interact;
// Start is called before the first frame update
@@ -27,16 +28,6 @@ namespace Assets.Scripts
// Update is called once per frame
void Update()
{
if(uihandler.canPlayerRotate()){
Cursor.lockState = CursorLockMode.Locked;
rotation.y += Input.GetAxis("Mouse X");
rotation.x += -Input.GetAxis("Mouse Y");
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
transform.eulerAngles = (Vector2)rotation * speed;
}
else{
Cursor.lockState = CursorLockMode.Confined;
}
transform.position = new Vector3(transform.parent.transform.position.x, transform.position.y, transform.parent.transform.position.z);
}
@@ -45,6 +36,18 @@ namespace Assets.Scripts
showInformation();
}
public void lookAround(Vector2 view, bool isController){
rotation.y += view.x;
rotation.x += -view.y;
rotation.x = Mathf.Clamp(rotation.x, xMinLimit, xMaxLimit);
if(isController){
transform.eulerAngles = (Vector2)rotation * controllerSpeed;
}
else{
transform.eulerAngles = (Vector2)rotation * mouseSpeed;
}
}
public GameObject interactWithObject()
{
RaycastHit hit;

View File

@@ -101,7 +101,7 @@ namespace Assets.Scripts.Slimes
public Item getItem()
{
int rand = new System.Random().Next(100) + 1;
if (rand < 10 + luck)
if (rand < 15 + luck)
{
int type = new System.Random().Next(2);
switch (type)

View File

@@ -314,4 +314,4 @@ public class Tile : MonoBehaviour
setPosition(pos);
setBorders();
}
}
}

View File

@@ -88,11 +88,10 @@ public class WorldGenerator : MonoBehaviour
Vector3 pos = currentTile.GetComponent<Tile>().needConnectedTile(playerX, playerZ);
if (!tiles.ContainsKey(pos) && pos.y == 0)
{
GameObject newTile;
string name = "";
int chance = rand.Next(1,11);
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
newTile = Instantiate(tile, mapPos, Quaternion.identity);
GameObject newTile = Instantiate(tile, mapPos, Quaternion.identity);
if (chance == 1)
{
if (cityAmount > 0)