Reworked code, Code cleanup, No new Version
This commit is contained in:
128
Assets/Scripts/Handler/AudioHandler.cs
Normal file
128
Assets/Scripts/Handler/AudioHandler.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Assets.Scripts;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AudioHandler : MonoBehaviour
|
||||
{
|
||||
public AudioClip buttonClick;
|
||||
public AudioClip damage;
|
||||
public AudioClip explosion;
|
||||
public AudioClip hit;
|
||||
public AudioClip hitDagger;
|
||||
public AudioClip IceHit;
|
||||
public AudioClip LevelUp;
|
||||
public AudioClip jump;
|
||||
|
||||
AudioSource cameraAudio;
|
||||
AudioSource playerAudio;
|
||||
|
||||
string filepath = "./audiosettings.txt";
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void Start()
|
||||
{
|
||||
cameraAudio = GameObject.Find("Main Camera").GetComponent<AudioSource>();
|
||||
playerAudio = GameObject.Find("Player").GetComponent<AudioSource>();
|
||||
loadAudioSettings();
|
||||
}
|
||||
|
||||
public void playButtonClick()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = buttonClick;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playDamage()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = damage;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playExplosion()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = explosion;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = hit;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playDaggerHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = hitDagger;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playIceHit()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = IceHit;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playJump()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = jump;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void playLevelUp()
|
||||
{
|
||||
cameraAudio.mute = true;
|
||||
playerAudio.clip = LevelUp;
|
||||
playerAudio.Play();
|
||||
cameraAudio.mute = false;
|
||||
}
|
||||
|
||||
public void changeVolumeMusic()
|
||||
{
|
||||
cameraAudio.volume = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
int volume = (int)(cameraAudio.volume * 100);
|
||||
GameObject.Find("txtMusic").GetComponent<Text>().text = "Music (" + volume + "%)";
|
||||
}
|
||||
|
||||
public void changeVolumeEffects()
|
||||
{
|
||||
playerAudio.volume = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
int volume = (int)(playerAudio.volume * 100);
|
||||
GameObject.Find("txtEffects").GetComponent<Text>().text = "Effects (" + volume + "%)";
|
||||
}
|
||||
|
||||
public void setSlider()
|
||||
{
|
||||
GameObject.Find("slideEffects").GetComponent<Slider>().value = playerAudio.volume;
|
||||
GameObject.Find("slideMusic").GetComponent<Slider>().value = cameraAudio.volume;
|
||||
}
|
||||
|
||||
public void loadAudioSettings()
|
||||
{
|
||||
FileHandler.loadAudio(filepath, cameraAudio, playerAudio);
|
||||
}
|
||||
|
||||
public void saveAudioSettings()
|
||||
{
|
||||
float music = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
float effects = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
FileHandler.saveAudio(filepath, music, effects);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/AudioHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/AudioHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f49961101d617314a83ae0efcd6e4e53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
136
Assets/Scripts/Handler/ButtonHandler.cs
Normal file
136
Assets/Scripts/Handler/ButtonHandler.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class ButtonHandler : MonoBehaviour
|
||||
{
|
||||
UIHandler uihandler;
|
||||
Player player;
|
||||
AudioHandler audioHandler;
|
||||
WorldGenerator worldGenerator;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
player = GameObject.Find("Player").GetComponent<Player>();
|
||||
worldGenerator = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>();
|
||||
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
|
||||
}
|
||||
|
||||
public void openOptions()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.openOptions();
|
||||
}
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
audioHandler.loadAudioSettings();
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
|
||||
public void exitToMenu()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.openMainMenu();
|
||||
}
|
||||
|
||||
public void closePauseMenu()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closePauseMenu();
|
||||
}
|
||||
|
||||
public void upgradeStrength()
|
||||
{
|
||||
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()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.adaptScreen();
|
||||
audioHandler.saveAudioSettings();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
|
||||
public void closeIntroduction()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.startGame();
|
||||
EventSystem.current.SetSelectedGameObject(null);
|
||||
}
|
||||
|
||||
public void switchCharactersheet()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.switchCharactersheet();
|
||||
}
|
||||
|
||||
public void switchQuestlog()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.switchQuestLog();
|
||||
}
|
||||
|
||||
public void switchOptions()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.switchPauseMenu();
|
||||
}
|
||||
|
||||
public void switchInventory()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.switchInventory();
|
||||
}
|
||||
|
||||
public void saveGame()
|
||||
{
|
||||
audioHandler.playButtonClick();
|
||||
FileHandler.generateDirectory();
|
||||
string saveString = "{\r\n";
|
||||
saveString = saveString + "\"player\": {\r\n" + player.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"inventory\": {\r\n" + GameObject.Find("Inventory").GetComponent<Inventory>().saveGame() + "\r\n},\r\n";
|
||||
saveString = saveString + "\"questlog\": {\r\n" + GameObject.Find("QuestLog").GetComponent<QuestLog>().saveGame() + "\r\n}\r\n";
|
||||
saveString = saveString + "\r\n}";
|
||||
FileHandler.saveGame(saveString, "./save.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/ButtonHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/ButtonHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d229e5b0d08dea24787131fcabebdf42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Scripts/Handler/EasterEggHandler.cs
Normal file
84
Assets/Scripts/Handler/EasterEggHandler.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
class EasterEggHandler
|
||||
{
|
||||
public static void applyEasterEgg(Player player)
|
||||
{
|
||||
if (player.getPlayerName().ToLower().Length > 0)
|
||||
{
|
||||
applyNameEasterEgg(player);
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyNameEasterEgg(Player player)
|
||||
{
|
||||
//maxHealth, maxSecondary, strength, dexterity, intelligence
|
||||
int[] result = new int[5];
|
||||
int[] stats = player.getStats();
|
||||
switch (player.getPlayerName().ToLower())
|
||||
{
|
||||
case "threetimes8":
|
||||
result[0] = 240;
|
||||
result[1] = 240;
|
||||
result[2] = 24;
|
||||
result[3] = 24;
|
||||
result[4] = 24;
|
||||
break;
|
||||
case "finnchen123":
|
||||
result[0] = 1230;
|
||||
result[1] = 1230;
|
||||
result[2] = 123;
|
||||
result[3] = 123;
|
||||
result[4] = 123;
|
||||
break;
|
||||
case "thefluffeypanda":
|
||||
result[0] = 470;
|
||||
result[1] = 470;
|
||||
result[2] = 47;
|
||||
result[3] = 47;
|
||||
result[4] = 47;
|
||||
break;
|
||||
case "nicola":
|
||||
result[0] = stats[1];
|
||||
result[1] = stats[3];
|
||||
result[2] = stats[4];
|
||||
result[3] = stats[5];
|
||||
result[4] = stats[6];
|
||||
SteamWorksHandler.getGodModeAchievement();
|
||||
break;
|
||||
default:
|
||||
result[0] = stats[1];
|
||||
result[1] = stats[3];
|
||||
result[2] = stats[4];
|
||||
result[3] = stats[5];
|
||||
result[4] = stats[6];
|
||||
break;
|
||||
}
|
||||
player.setStats(result);
|
||||
}
|
||||
|
||||
public static bool isGodMode(Player player)
|
||||
{
|
||||
bool result = false;
|
||||
if (player != null)
|
||||
{
|
||||
if (player.getPlayerName() != null)
|
||||
{
|
||||
if (player.getPlayerName().ToLower() == "nicola")
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/EasterEggHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/EasterEggHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2fc753c5a9822f42a6cb9451e7ac30a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
122
Assets/Scripts/Handler/FileHandler.cs
Normal file
122
Assets/Scripts/Handler/FileHandler.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class FileHandler
|
||||
{
|
||||
static StreamWriter sw;
|
||||
public static void saveGame(string data, string path)
|
||||
{
|
||||
sw = new StreamWriter(path);
|
||||
sw.Write(data);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void loadGame(Player player, WorldGenerator worldGenerator, Inventory inventory, QuestLog questLog)
|
||||
{
|
||||
if (hasSaveFile())
|
||||
{
|
||||
string[] lines = File.ReadAllLines("./save.json");
|
||||
string jsonString = "";
|
||||
foreach (string line in lines)
|
||||
{
|
||||
jsonString = jsonString + line.Replace("\r\n", "");
|
||||
}
|
||||
JObject json = JsonConvert.DeserializeObject<JObject>(jsonString);
|
||||
player.loadPlayer(json["player"]);
|
||||
worldGenerator.loadWorld(json["world"]);
|
||||
inventory.loadInventory(json["inventory"]);
|
||||
questLog.loadQuests(json["questlog"]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveAudio(string path, float music, float effects)
|
||||
{
|
||||
sw = new StreamWriter(path);
|
||||
sw.WriteLine("Music:" + music);
|
||||
sw.WriteLine("Effects:" + effects);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void loadAudio(string path, AudioSource cameraAudio, AudioSource playerAudio)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
cameraAudio.volume = float.Parse(lines[0].Split(':')[1]);
|
||||
playerAudio.volume = float.Parse(lines[1].Split(':')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw = File.CreateText(path);
|
||||
sw.WriteLine("Music:0.5");
|
||||
sw.WriteLine("Effects:0.5");
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static string generateJSON(string key, object value)
|
||||
{
|
||||
return "\"" + key + "\": " + value;
|
||||
}
|
||||
|
||||
public static bool hasSaveFile()
|
||||
{
|
||||
return File.Exists("./save.json");
|
||||
}
|
||||
|
||||
public static void saveTile(string content, string path)
|
||||
{
|
||||
sw = new StreamWriter(path);
|
||||
sw.Write(content);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void saveNoise(string content, string path)
|
||||
{
|
||||
sw = new StreamWriter(path, true);
|
||||
sw.Write(content);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void generateDirectory()
|
||||
{
|
||||
if (Directory.Exists("./save/"))
|
||||
{
|
||||
foreach (string file in Directory.GetFiles("./save/"))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory("./save/");
|
||||
}
|
||||
}
|
||||
|
||||
public static string loadTile(string path)
|
||||
{
|
||||
string result = "";
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
result = result + line.Replace("\r\n", "");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/FileHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/FileHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aa6cfe5b8d20a24d9aa6ebaa044c2e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/Scripts/Handler/SceneHandler.cs
Normal file
59
Assets/Scripts/Handler/SceneHandler.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Assets.Scripts.Races;
|
||||
using Assets.Scripts.Classes;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class SceneHandler : MonoBehaviour
|
||||
{
|
||||
static bool sceneSwitched = false;
|
||||
private void OnEnable()
|
||||
{
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
bool hasSceneHandler = false;
|
||||
foreach (Object o in FindObjectsOfType(typeof(MonoBehaviour)))
|
||||
{
|
||||
if (o.name == "SceneHandlerLoaded")
|
||||
{
|
||||
hasSceneHandler = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasSceneHandler)
|
||||
{
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
this.gameObject.name = "SceneHandlerLoaded";
|
||||
}
|
||||
}
|
||||
|
||||
public void openMenuScene()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("MenuScene", LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
public void openGameScene()
|
||||
{
|
||||
SceneManager.LoadSceneAsync("GameScene", LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
public static void switchGameToMenu()
|
||||
{
|
||||
if (!sceneSwitched)
|
||||
{
|
||||
SceneManager.LoadSceneAsync("MenuScene", LoadSceneMode.Single);
|
||||
sceneSwitched = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (scene.name == "GameScene")
|
||||
{
|
||||
GameObject.Find("UIHandler").GetComponent<UIHandler>().openIntroduction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/SceneHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/SceneHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e6f2701c6e622a42aba50dab602e362
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
134
Assets/Scripts/Handler/SteamWorksHandler.cs
Normal file
134
Assets/Scripts/Handler/SteamWorksHandler.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Assets.Scripts;
|
||||
|
||||
public class SteamWorksHandler : MonoBehaviour
|
||||
{
|
||||
/* Steam Achievements
|
||||
* FORMAT = Requirement: Message
|
||||
* (Currently dropped) Playing for 5 hours: Got nothing else to do?
|
||||
* (Currently dropped) Playing for 10 hours: Look at THAT sunset!
|
||||
* (Currently dropped) Playing for 20 hours: You want coffee to your bagel?
|
||||
* (Currently dropped) Playing for 40 hours: I guess I have a true fan here
|
||||
* (Currently dropped) Playing for 80 hours: You should consider going outside
|
||||
*/
|
||||
static int counterForest = 0;
|
||||
|
||||
public static void getForestAchievement(string tiletype)
|
||||
{
|
||||
if (counterForest != -1 && !isGodMode())
|
||||
{
|
||||
if (tiletype == "Forest")
|
||||
{
|
||||
counterForest++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counterForest = 0;
|
||||
}
|
||||
if (counterForest >= 5)
|
||||
{
|
||||
if (SteamManager.Initialized)
|
||||
{
|
||||
SteamUserStats.SetAchievement("ForestAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
}
|
||||
counterForest = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void getStandardAchievement(string name)
|
||||
{
|
||||
if (!isGodMode())
|
||||
{
|
||||
if (SteamManager.Initialized)
|
||||
{
|
||||
SteamUserStats.SetAchievement(name);
|
||||
SteamUserStats.StoreStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void getGodModeAchievement()
|
||||
{
|
||||
if (SteamManager.Initialized)
|
||||
{
|
||||
SteamUserStats.SetAchievement("GodAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
}
|
||||
}
|
||||
|
||||
public static void getSlimeAchievement(int killcount)
|
||||
{
|
||||
string name = "";
|
||||
switch (killcount)
|
||||
{
|
||||
case 1:
|
||||
name = "Kill1Slime";
|
||||
break;
|
||||
case 10:
|
||||
name = "Kill10Slime";
|
||||
break;
|
||||
case 50:
|
||||
name = "Kill50Slime";
|
||||
break;
|
||||
case 100:
|
||||
name = "Kill100Slime";
|
||||
break;
|
||||
case 500:
|
||||
name = "Kill500Slime";
|
||||
break;
|
||||
case 1000:
|
||||
name = "Kill1000Slime";
|
||||
break;
|
||||
}
|
||||
if (!isGodMode())
|
||||
{
|
||||
if (SteamManager.Initialized)
|
||||
{
|
||||
SteamUserStats.SetAchievement(name);
|
||||
SteamUserStats.StoreStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isGodMode()
|
||||
{
|
||||
return EasterEggHandler.isGodMode(GameObject.Find("Player").GetComponent<Player>());
|
||||
}
|
||||
|
||||
public static void getItemAchievement(Item item)
|
||||
{
|
||||
if (SteamManager.Initialized)
|
||||
{
|
||||
if (!isGodMode())
|
||||
{
|
||||
SteamUserStats.SetAchievement("ItemAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
switch (item.getRarity())
|
||||
{
|
||||
case ItemRarity.COMMON:
|
||||
SteamUserStats.SetAchievement("CommonAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
break;
|
||||
case ItemRarity.RARE:
|
||||
SteamUserStats.SetAchievement("RareAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
break;
|
||||
case ItemRarity.EPIC:
|
||||
SteamUserStats.SetAchievement("EpicAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
break;
|
||||
case ItemRarity.LEGENDARY:
|
||||
SteamUserStats.SetAchievement("LegendaryAchievement");
|
||||
SteamUserStats.StoreStats();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/SteamWorksHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/SteamWorksHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d3ed29954b7b9746a1c1331c03220c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/Handler/TooltipHandler.cs
Normal file
40
Assets/Scripts/Handler/TooltipHandler.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public class TooltipHandler : MonoBehaviour
|
||||
{
|
||||
public GameObject tooltip;
|
||||
Player player;
|
||||
UIHandler uihandler;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
player = GameObject.Find("Player").GetComponent<Player>();
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void showTooltip(string text)
|
||||
{
|
||||
tooltip.transform.Find("txtTooltip").GetComponent<Text>().text = text;
|
||||
tooltip.transform.localScale = new Vector3(1,1,1);
|
||||
}
|
||||
|
||||
public void hideToolTip()
|
||||
{
|
||||
tooltip.transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Handler/TooltipHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/TooltipHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff63195da43e3a145abba1304336b467
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
534
Assets/Scripts/Handler/UIHandler.cs
Normal file
534
Assets/Scripts/Handler/UIHandler.cs
Normal file
@@ -0,0 +1,534 @@
|
||||
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
|
||||
{
|
||||
public class UIHandler : MonoBehaviour
|
||||
{
|
||||
public GameObject compass;
|
||||
public GameObject information;
|
||||
public GameObject fight;
|
||||
public GameObject message;
|
||||
public GameObject charactersheet;
|
||||
public GameObject deathscreen;
|
||||
public GameObject options;
|
||||
public GameObject pauseMenu;
|
||||
public GameObject playerHUD;
|
||||
public GameObject questlog;
|
||||
public GameObject introduction;
|
||||
public GameObject tooltip;
|
||||
public GameObject tutorial;
|
||||
public GameObject buttonsHUD;
|
||||
public GameObject inventory;
|
||||
public GameObject waterLayer;
|
||||
|
||||
public UIState state;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (state == UIState.GAME)
|
||||
{
|
||||
updatePlayerHUD();
|
||||
switchWaterLayer();
|
||||
updateCoordinates();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCoordinates()
|
||||
{
|
||||
GameObject coordinates = GameObject.Find("txtCoordinates");
|
||||
Vector3 position = GameObject.Find("Player").transform.position;
|
||||
string tiletype = GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().getCurrentTile().GetComponent<Tile>().getTileType();
|
||||
if (tiletype != null)
|
||||
{
|
||||
tiletype = tiletype.Replace("Tile", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
tiletype = "Spawn";
|
||||
}
|
||||
coordinates.GetComponent<Text>().text = tiletype + "(" + (int)position.x + "/" + (int)position.y + "/" + (int)position.z + ")";
|
||||
}
|
||||
|
||||
private void switchWaterLayer()
|
||||
{
|
||||
if (GameObject.Find("Player").transform.position.y < -1)
|
||||
{
|
||||
waterLayer.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
waterLayer.transform.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayerHUD()
|
||||
{
|
||||
updateHUD(GameObject.Find("Player").GetComponent<Player>());
|
||||
}
|
||||
|
||||
public bool canPlayerMove()
|
||||
{
|
||||
if (state == UIState.GAME || state == UIState.CHARACTER || state == UIState.QUEST || state == UIState.INVENTORY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool isPlayerInFight()
|
||||
{
|
||||
return state == UIState.FIGHT;
|
||||
}
|
||||
|
||||
public void startGame()
|
||||
{
|
||||
introduction.transform.localScale = new Vector3(0, 0, 0);
|
||||
tutorial.transform.localScale = new Vector3(1, 1, 1);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
|
||||
public void switchCharactersheet()
|
||||
{
|
||||
if (state == UIState.CHARACTER)
|
||||
{
|
||||
closeCharactersheet();
|
||||
}
|
||||
else
|
||||
{
|
||||
openCharactersheet();
|
||||
}
|
||||
}
|
||||
|
||||
public void openOptions()
|
||||
{
|
||||
options.SetActive(true);
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().setSlider();
|
||||
hideOtherElements(options);
|
||||
state = UIState.PAUSEOPTIONS;
|
||||
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
|
||||
}
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
options.SetActive(false);
|
||||
state = UIState.PAUSE;
|
||||
openPauseMenu();
|
||||
}
|
||||
|
||||
public void openCharactersheet()
|
||||
{
|
||||
hideOtherElements(charactersheet);
|
||||
state = UIState.CHARACTER;
|
||||
}
|
||||
|
||||
public void closeCharactersheet()
|
||||
{
|
||||
charactersheet.transform.localScale = new Vector3(0, 0, 0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
|
||||
public void switchInventory()
|
||||
{
|
||||
if (state == UIState.INVENTORY)
|
||||
{
|
||||
closeInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
openInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public void openInventory()
|
||||
{
|
||||
hideOtherElements(inventory);
|
||||
state = UIState.INVENTORY;
|
||||
}
|
||||
|
||||
public void closeInventory()
|
||||
{
|
||||
inventory.transform.localScale = new Vector3(0, 0, 0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
|
||||
public void openFight()
|
||||
{
|
||||
GameObject.Find("txtRounds").GetComponent<Text>().text = "-1";
|
||||
hideOtherElements(fight);
|
||||
state = UIState.FIGHT;
|
||||
}
|
||||
|
||||
public void closeFight()
|
||||
{
|
||||
fight.transform.localScale = new Vector3(0, 0, 0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
|
||||
public void showHUD()
|
||||
{
|
||||
playerHUD.transform.localScale = new Vector3(1,1,1);
|
||||
compass.transform.localScale = new Vector3(1, 1, 1);
|
||||
buttonsHUD.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
public void openMainMenu()
|
||||
{
|
||||
GameObject.Find("SceneHandlerLoaded").GetComponent<SceneHandler>().openMenuScene();
|
||||
}
|
||||
|
||||
public void switchPauseMenu()
|
||||
{
|
||||
if (state == UIState.GAME || state == UIState.CHARACTER || state == UIState.PAUSE || state == UIState.QUEST)
|
||||
{
|
||||
if (state == UIState.PAUSE)
|
||||
{
|
||||
closePauseMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state == UIState.GAME)
|
||||
{
|
||||
openPauseMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
hideOtherElements(null);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void switchQuestLog()
|
||||
{
|
||||
if (state == UIState.QUEST)
|
||||
{
|
||||
closeQuestLog();
|
||||
}
|
||||
else
|
||||
{
|
||||
openQuestLog();
|
||||
}
|
||||
}
|
||||
|
||||
public void openQuestLog()
|
||||
{
|
||||
questlog.GetComponent<QuestLog>().showQuests();
|
||||
state = UIState.QUEST;
|
||||
hideOtherElements(questlog);
|
||||
}
|
||||
|
||||
public void closeQuestLog()
|
||||
{
|
||||
questlog.transform.localScale = new Vector3(0,0,0);
|
||||
state = UIState.GAME;
|
||||
showHUD();
|
||||
}
|
||||
|
||||
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 openPauseMenu()
|
||||
{
|
||||
hideOtherElements(pauseMenu);
|
||||
state = UIState.PAUSE;
|
||||
}
|
||||
|
||||
public void closePauseMenu()
|
||||
{
|
||||
pauseMenu.transform.localScale = new Vector3(0, 0, 0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
|
||||
public void showDeathScreen()
|
||||
{
|
||||
state = UIState.DEATH;
|
||||
hideOtherElements(deathscreen);
|
||||
}
|
||||
|
||||
public void hideOtherElements(GameObject obj)
|
||||
{
|
||||
for (int i = 0; i < GameObject.Find("Canvas").transform.childCount; i++)
|
||||
{
|
||||
if (!GameObject.Find("Canvas").transform.GetChild(i).gameObject.Equals(obj))
|
||||
{
|
||||
GameObject.Find("Canvas").transform.GetChild(i).localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
if (obj != fight)
|
||||
{
|
||||
showHUD();
|
||||
}
|
||||
}
|
||||
|
||||
public void displayInformation(string information)
|
||||
{
|
||||
GameObject.Find("txtObjectName").GetComponent<Text>().text = information;
|
||||
this.information.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
public void hideInformation()
|
||||
{
|
||||
information.transform.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
public void showMessage(string message)
|
||||
{
|
||||
this.message.GetComponent<LogWriter>().addMessage(message);
|
||||
}
|
||||
|
||||
public void updateFightInterface(GameObject enemy, GameObject player)
|
||||
{
|
||||
updateFightInterfacePlayer(player);
|
||||
updateFightInterfaceEnemy(enemy);
|
||||
updateFightInterfaceActions(player);
|
||||
GameObject.Find("txtRounds").GetComponent<Text>().text = (int.Parse(GameObject.Find("txtRounds").GetComponent<Text>().text) + 1).ToString();
|
||||
}
|
||||
|
||||
private void updateFightInterfaceActions(GameObject player)
|
||||
{
|
||||
GameObject actionFour = GameObject.Find("action4");
|
||||
GameObject actionFive = GameObject.Find("action5");
|
||||
GameObject actionSix = GameObject.Find("action6");
|
||||
|
||||
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);
|
||||
player.GetComponent<Player>().displayAction(2, actionSix.transform.Find("imgAction").gameObject, actionSix.transform.Find("descAction").gameObject);
|
||||
}
|
||||
|
||||
private void updateFightInterfacePlayer(GameObject player)
|
||||
{
|
||||
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
|
||||
int[] playerStats = player.GetComponent<Player>().getStats();
|
||||
Dictionary<string, int> equipment = inventory.GetComponent<Inventory>().getEquipmentBonus();
|
||||
|
||||
GameObject foreground = GameObject.Find("healthForegroundPlayer");
|
||||
GameObject background = GameObject.Find("healthBackgroundPlayer");
|
||||
GameObject text = GameObject.Find("healthTextPlayer");
|
||||
updateBar(foreground, background, text, playerStats[1] + equipment["HP"], playerStats[0]);
|
||||
|
||||
foreground = GameObject.Find("secondaryForegroundPlayer");
|
||||
background = GameObject.Find("secondaryBackgroundPlayer");
|
||||
text = GameObject.Find("secondaryTextPlayer");
|
||||
updateBar(foreground, background, text, playerStats[3] + equipment["MP"], playerStats[2]);
|
||||
}
|
||||
|
||||
private void updateFightInterfaceEnemy(GameObject enemy)
|
||||
{
|
||||
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
|
||||
int[] enemyStats = enemy.GetComponent<Enemy>().getStats();
|
||||
|
||||
GameObject foreground = GameObject.Find("healthForegroundEnemy");
|
||||
GameObject background = GameObject.Find("healthBackgroundEnemy");
|
||||
GameObject text = GameObject.Find("healthTextEnemy");
|
||||
updateBar(foreground, background, text, enemyStats[1], enemyStats[0]);
|
||||
|
||||
foreground = GameObject.Find("secondaryForegroundEnemy");
|
||||
background = GameObject.Find("secondaryBackgroundEnemy");
|
||||
text = GameObject.Find("secondaryTextEnemy");
|
||||
updateBar(foreground, background, text, enemyStats[3], enemyStats[2]);
|
||||
}
|
||||
|
||||
public void adjustInformation(Player player)
|
||||
{
|
||||
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points};
|
||||
int[] playerStats = player.GetComponent<Player>().getStats();
|
||||
Dictionary<string, int> equipment = inventory.GetComponent<Inventory>().getEquipmentBonus();
|
||||
|
||||
GameObject.Find("txtStrength").GetComponent<Text>().text = "STR: " + playerStats[4] + " (+" + equipment["STR"] + ")";
|
||||
GameObject.Find("txtDexterity").GetComponent<Text>().text = "DEX: " + playerStats[5] + " (+" + equipment["DEX"] + ")";
|
||||
GameObject.Find("txtIntelligence").GetComponent<Text>().text = "INT: " + playerStats[6] + " (+" + equipment["INT"] + ")";
|
||||
GameObject.Find("txtHealth").GetComponent<Text>().text = "Health: " + playerStats[1] + " (+" + equipment["HP"] + ")";
|
||||
GameObject.Find("txtSecondary").GetComponent<Text>().text = "Mana: " + playerStats[3] + " (+" + equipment["MP"] + ")";
|
||||
|
||||
updateHealthUI(playerStats[0], playerStats[1] + equipment["HP"]);
|
||||
updateSecondaryUI(playerStats[2], playerStats[3] + equipment["MP"]);
|
||||
updateExperienceUI(playerStats[8], playerStats[9]);
|
||||
|
||||
player.updateName(GameObject.Find("txtName").GetComponent<Text>());
|
||||
updatePoints(playerStats[10]);
|
||||
player.displaySkills(GameObject.Find("pnlSkills"));
|
||||
}
|
||||
|
||||
private void updatePoints(int points)
|
||||
{
|
||||
GameObject strength = GameObject.Find("btnStrengthIncrease");
|
||||
GameObject dexterity = GameObject.Find("btnDexterityIncrease");
|
||||
GameObject intelligence = GameObject.Find("btnIntelligenceIncrease");
|
||||
GameObject health = GameObject.Find("btnHealthIncrease");
|
||||
GameObject secondary = GameObject.Find("btnSecondaryIncrease");
|
||||
GameObject txtPoints = GameObject.Find("txtPoints");
|
||||
|
||||
txtPoints.GetComponent<Text>().text = "Your available points: " + points;
|
||||
|
||||
if (points > 0)
|
||||
{
|
||||
strength.transform.localScale = new Vector3(1, 1, 1);
|
||||
dexterity.transform.localScale = new Vector3(1, 1, 1);
|
||||
intelligence.transform.localScale = new Vector3(1, 1, 1);
|
||||
health.transform.localScale = new Vector3(1, 1, 1);
|
||||
secondary.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strength.transform.localScale = new Vector3(0, 0, 0);
|
||||
dexterity.transform.localScale = new Vector3(0, 0, 0);
|
||||
intelligence.transform.localScale = new Vector3(0, 0, 0);
|
||||
health.transform.localScale = new Vector3(0, 0, 0);
|
||||
secondary.transform.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHealthUI(int health, int maxHealth)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("healthForegroundInformation");
|
||||
GameObject background = GameObject.Find("healthBackgroundInformation");
|
||||
GameObject text = GameObject.Find("healthTextInformation");
|
||||
|
||||
updateBar(foreground, background, text, maxHealth, health);
|
||||
}
|
||||
|
||||
private void updateSecondaryUI(int secondary, int maxSecondary)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("secondaryForegroundInformation");
|
||||
GameObject background = GameObject.Find("secondaryBackgroundInformation");
|
||||
GameObject text = GameObject.Find("secondaryTextInformation");
|
||||
|
||||
updateBar(foreground, background, text, maxSecondary, secondary);
|
||||
}
|
||||
|
||||
private void updateExperienceUI(int experience, int maxExperience)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("experienceForeground");
|
||||
GameObject background = GameObject.Find("experienceBackground");
|
||||
GameObject text = GameObject.Find("experienceText");
|
||||
|
||||
updateBar(foreground, background, text, maxExperience, experience);
|
||||
}
|
||||
|
||||
public void updateHUD(Player player)
|
||||
{
|
||||
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience};
|
||||
int[] playerStats = player.GetComponent<Player>().getStats();
|
||||
Dictionary<string, int> equipment = inventory.GetComponent<Inventory>().getEquipmentBonus();
|
||||
|
||||
GameObject information = GameObject.Find("txtInformationHUD");
|
||||
player.updateNameHUD(information.GetComponent<Text>());
|
||||
|
||||
GameObject foreground = GameObject.Find("healthForegroundHUD");
|
||||
GameObject background = GameObject.Find("healthBackgroundHUD");
|
||||
updateBar(foreground, background, null, playerStats[1] + equipment["HP"], playerStats[0]);
|
||||
|
||||
foreground = GameObject.Find("secondaryForegroundHUD");
|
||||
background = GameObject.Find("secondaryBackgroundHUD");
|
||||
updateBar(foreground, background, null, playerStats[3] + equipment["MP"], playerStats[2]);
|
||||
}
|
||||
|
||||
public void updateBar(GameObject bar, GameObject barBackground, GameObject textField, int maxValue, int minValue)
|
||||
{
|
||||
string text = minValue + "/" + maxValue;
|
||||
double percentage = 0;
|
||||
if (maxValue > 0)
|
||||
{
|
||||
percentage = (1 / (double)maxValue) * minValue;
|
||||
}
|
||||
|
||||
float change = (float)(barBackground.GetComponent<RectTransform>().rect.width - (barBackground.GetComponent<RectTransform>().rect.width * percentage));
|
||||
|
||||
if (textField != null)
|
||||
{
|
||||
textField.GetComponent<Text>().text = text;
|
||||
}
|
||||
bar.GetComponent<RectTransform>().offsetMax = new Vector2(-change, bar.GetComponent<RectTransform>().offsetMax.y);
|
||||
}
|
||||
|
||||
public void openIntroduction()
|
||||
{
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().Start();
|
||||
if (PlayerPrefs.GetInt("isLoad") == 0)
|
||||
{
|
||||
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().resetGame(PlayerPrefs.GetInt("cityAmount"));
|
||||
GameObject.Find("Player").GetComponent<Player>().generatePlayer();
|
||||
GameObject.Find("Player").GetComponent<Player>().finishPlayerCreation();
|
||||
hideOtherElements(introduction);
|
||||
state = UIState.TUTORIAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileHandler.loadGame(GameObject.Find("Player").GetComponent<Player>(), GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>(), GameObject.Find("Inventory").GetComponent<Inventory>(), GameObject.Find("QuestLog").GetComponent<QuestLog>());
|
||||
hideOtherElements(introduction);
|
||||
introduction.transform.localScale = new Vector3(0, 0, 0);
|
||||
tutorial.transform.localScale = new Vector3(0,0,0);
|
||||
showHUD();
|
||||
state = UIState.GAME;
|
||||
}
|
||||
updatePlayerHUD();
|
||||
}
|
||||
|
||||
public void closeTutorial()
|
||||
{
|
||||
tutorial.transform.localScale = new Vector3(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Handler/UIHandler.cs.meta
Normal file
11
Assets/Scripts/Handler/UIHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d858d7fd66f78a44e9e67ec2a2d4f1e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user