Added basic scene switching, v.1.3.0
This commit is contained in:
70
Assets/Scripts/Menu/ButtonHandlerMenu.cs
Normal file
70
Assets/Scripts/Menu/ButtonHandlerMenu.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Menu
|
||||
{
|
||||
public class ButtonHandlerMenu : MonoBehaviour
|
||||
{
|
||||
UIHandlerMenu uihandler;
|
||||
AudioHandler audioHandler;
|
||||
SceneHandler sceneHandler;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandlerMenu>();
|
||||
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
||||
sceneHandler = GameObject.Find("SceneHandlerLoaded").GetComponent<SceneHandler>();
|
||||
}
|
||||
|
||||
public void startGame()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.startGame(sceneHandler);
|
||||
}
|
||||
|
||||
public void closeGame()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#endif
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void openOptions()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.openOptions();
|
||||
}
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
audioHandler.loadAudioSettings();
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
|
||||
public void openCreation()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.openCharacterCreation();
|
||||
}
|
||||
|
||||
public void closeCreation()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closeCharacterCreation();
|
||||
}
|
||||
|
||||
public void saveOptions()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.adaptScreen();
|
||||
audioHandler.saveAudioSettings();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Menu/ButtonHandlerMenu.cs.meta
Normal file
11
Assets/Scripts/Menu/ButtonHandlerMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6e81e6787d831a4d98448435186e09e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
178
Assets/Scripts/Menu/UIHandlerMenu.cs
Normal file
178
Assets/Scripts/Menu/UIHandlerMenu.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using Assets.Scripts.Classes;
|
||||
using Assets.Scripts.Races;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Menu
|
||||
{
|
||||
public class UIHandlerMenu : MonoBehaviour
|
||||
{
|
||||
public GameObject mainMenu;
|
||||
public GameObject options;
|
||||
public GameObject characterCreation;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
options.SetActive(false);
|
||||
characterCreation.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void startGame(SceneHandler sceneHandler)
|
||||
{
|
||||
int cityAmount = 0;
|
||||
switch (GameObject.Find("dropSize").GetComponent<Dropdown>().value)
|
||||
{
|
||||
case 0:
|
||||
cityAmount = 5;
|
||||
break;
|
||||
case 1:
|
||||
cityAmount = 10;
|
||||
break;
|
||||
case 2:
|
||||
cityAmount = 20;
|
||||
break;
|
||||
case 3:
|
||||
cityAmount = 40;
|
||||
break;
|
||||
}
|
||||
PlayerPrefs.SetInt("cityAmount", cityAmount);
|
||||
PlayerPrefs.SetInt("class", GameObject.Find("dropClass").GetComponent<Dropdown>().value);
|
||||
PlayerPrefs.SetInt("race", GameObject.Find("dropRace").GetComponent<Dropdown>().value);
|
||||
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
|
||||
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
||||
sceneHandler.openGameScene();
|
||||
}
|
||||
|
||||
private void setPlayerInformation()
|
||||
{
|
||||
string name = GameObject.Find("inName").GetComponent<InputField>().text;
|
||||
int role = GameObject.Find("dropClass").GetComponent<Dropdown>().value;
|
||||
int race = GameObject.Find("dropRace").GetComponent<Dropdown>().value;
|
||||
BasicRace playerRace = new BasicRace();
|
||||
BasicClass playerClass = new BasicClass();
|
||||
switch (role)
|
||||
{
|
||||
case 0:
|
||||
playerClass = new WarriorClass();
|
||||
break;
|
||||
case 1:
|
||||
playerClass = new MageClass();
|
||||
break;
|
||||
case 2:
|
||||
playerClass = new ThiefClass();
|
||||
break;
|
||||
}
|
||||
switch (race)
|
||||
{
|
||||
case 0:
|
||||
playerRace = new HumanRace();
|
||||
break;
|
||||
case 1:
|
||||
playerRace = new ElvenRace();
|
||||
break;
|
||||
case 2:
|
||||
playerRace = new DwarvenRace();
|
||||
break;
|
||||
case 3:
|
||||
playerRace = new GoblinRace();
|
||||
break;
|
||||
case 4:
|
||||
playerRace = new GiantRace();
|
||||
break;
|
||||
}
|
||||
GameObject.Find("Player").GetComponent<Player>().generatePlayer(playerRace, playerClass, name, GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
|
||||
}
|
||||
|
||||
public void openCharacterCreation()
|
||||
{
|
||||
characterCreation.SetActive(true);
|
||||
mainMenu.SetActive(false);
|
||||
}
|
||||
|
||||
public void closeCharacterCreation()
|
||||
{
|
||||
characterCreation.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
}
|
||||
|
||||
public void openOptions()
|
||||
{
|
||||
options.SetActive(true);
|
||||
mainMenu.SetActive(false);
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().setSlider();
|
||||
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
|
||||
}
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
options.SetActive(false);
|
||||
mainMenu.SetActive(true);
|
||||
}
|
||||
|
||||
public void adaptScreen()
|
||||
{
|
||||
GameObject resolution = GameObject.Find("dropResolution");
|
||||
GameObject mode = GameObject.Find("dropMode");
|
||||
|
||||
switch (resolution.GetComponent<Dropdown>().value)
|
||||
{
|
||||
case 0:
|
||||
Screen.SetResolution(800, 600, Screen.fullScreenMode);
|
||||
break;
|
||||
case 1:
|
||||
Screen.SetResolution(1280, 800, Screen.fullScreenMode);
|
||||
break;
|
||||
case 2:
|
||||
Screen.SetResolution(1920, 1080, Screen.fullScreenMode);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (mode.GetComponent<Dropdown>().value)
|
||||
{
|
||||
case 0:
|
||||
if (Screen.fullScreenMode != FullScreenMode.Windowed)
|
||||
{
|
||||
Screen.fullScreenMode = FullScreenMode.Windowed;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (Screen.fullScreenMode != FullScreenMode.ExclusiveFullScreen)
|
||||
{
|
||||
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (Screen.fullScreenMode != FullScreenMode.FullScreenWindow)
|
||||
{
|
||||
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCreationInformation()
|
||||
{
|
||||
setPlayerInformation();
|
||||
|
||||
// health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points
|
||||
int[] playerstats = GameObject.Find("Player").GetComponent<Player>().getStats();
|
||||
|
||||
GameObject.Find("txtStrength_Creation").GetComponent<Text>().text = "Strength: " + playerstats[4];
|
||||
GameObject.Find("txtDexterity_Creation").GetComponent<Text>().text = "Dexterity: " + playerstats[5];
|
||||
GameObject.Find("txtIntelligence_Creation").GetComponent<Text>().text = "Intelligence: " + playerstats[6];
|
||||
GameObject.Find("txtHealth_Creation").GetComponent<Text>().text = "Health: " + playerstats[1];
|
||||
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + playerstats[3];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Menu/UIHandlerMenu.cs.meta
Normal file
11
Assets/Scripts/Menu/UIHandlerMenu.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6b8dcdcfecec7941902e305daff9eb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user