From c868d738b99c063ed9129ee7e973cfa7b7dedf52 Mon Sep 17 00:00:00 2001 From: Shaun M Reed Date: Mon, 4 Sep 2017 13:53:03 -0400 Subject: [PATCH] Improved scripting -Added accurate rotationPerSec & secondPerRot values!... Up to a speed of ~720. --Used for new idle expgain calculation in Load() -Added scripting for assigning button events within InitializeButtonArrays() --stored all buttons to arrays depending on contents of the parent UI panel's name --mainButtons[], rotationButtons[], colorButtons[]... etc --Future buttons will automatically exist within the array, only events need assigning. --Buttons do not include tick boxes, etc! --Buttons cannot have onClick() even assigned through editor (Unity bug?) --- Assets/Scenes/Main.unity | Bin 114160 -> 111968 bytes Assets/Scripts/ExperienceBar.cs | 5 - Assets/Scripts/GameManager.cs | 10 +- Assets/Scripts/ToggleMenus.cs | 180 +++++++++++++++++++++++++------- 4 files changed, 149 insertions(+), 46 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 35e8a899664b6ab1aa48bf71eb4e0e3ca669e9bb..ff1af1c5d103aedcd842f3cd1e92a5a7c7866876 100644 GIT binary patch delta 7745 zcmZ9R33yY*7RP7W0%0pDEl?DnVewfNu_!!>P#a_mn_r;93s58#3MrNn+9EB2Nm(nh zU*T54M^V&@2!WspvPD@eAX4_Ke7t}Ql@Fx~KC4vw{&RE2Dc*jQd+%>%&NgSxy-90s zHx6HGY-X%VXZ!;vV=NBWz8&TjL;VL<#PB2&o3Q2Z+ar4?^xZeJ`hUGH+dDsUG}wPo z>Ero7{`&QT-MOzey%&=fGJo9EK~a2@=6maIZD%mC{UFd7w7by6!ST0=G4E(C&C)J) zGKlEyAi8kK-W*&Devg1S1iyq?b8s#AKLpe)Gaed0X;xldR&GJMJ1c84qnjbQlk&2r zgR;CC1(^leGji=&dFfe`Sbo+dT#X{gax(J^M%mK^o{>8_-=3MD41S6cIC ze(!|rro6fT+7!JRZ{c5=JiOKYvFx$x34exym*%gjN^u-2c{agawD?xim#zEjk6o*} z@ZRA*X)th~-|1T!8M(^TU@KgbDN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A().Save(); - } - // Update is called once per frame void Update () { fillAmount = currentExp / currentRequirement; diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 1761c96..51560bd 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -18,6 +18,7 @@ public class GameManager : MonoBehaviour { public float requirement; public float speed; public float increment; + public float rotationsPerSec; public DateTime currentTime; } @@ -50,6 +51,7 @@ public class GameManager : MonoBehaviour { int currentLevel = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel; float currentExp = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp; float currentRequirement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement; + float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent().rotationPerSec; float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed; float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement; @@ -59,6 +61,7 @@ public class GameManager : MonoBehaviour { data.requirement = currentRequirement; data.speed = currentSpeed; data.increment = currentIncrement; + data.rotationsPerSec = rotationPerSec; data.currentTime = DateTime.Now; bf.Serialize(file, data); @@ -75,6 +78,7 @@ public class GameManager : MonoBehaviour { PlayerData data = (PlayerData)bf.Deserialize(file); file.Close(); + GameObject.FindGameObjectWithTag("Player").GetComponent().rotationPerSec = data.rotationsPerSec; GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed = data.speed; GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement = data.increment; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel = data.level; @@ -82,9 +86,9 @@ public class GameManager : MonoBehaviour { GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement = data.requirement; DateTime loadTime = DateTime.Now; - int secondsPassed = GetIdleRewards(data.currentTime, loadTime); + int secondsPassed = GetIdleTime(data.currentTime, loadTime); float radianSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed * Mathf.Deg2Rad; - float idleExp = radianSpeed * secondsPassed; + float idleExp = (data.rotationsPerSec * secondsPassed) * data.increment; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp += idleExp; Debug.Log("Loaded"); @@ -92,7 +96,7 @@ public class GameManager : MonoBehaviour { } } - public int GetIdleRewards(DateTime saveTime, DateTime loadTime) + public int GetIdleTime(DateTime saveTime, DateTime loadTime) { int daysPassed = 0; int hoursPassed = 0; diff --git a/Assets/Scripts/ToggleMenus.cs b/Assets/Scripts/ToggleMenus.cs index 168a21a..34f291c 100644 --- a/Assets/Scripts/ToggleMenus.cs +++ b/Assets/Scripts/ToggleMenus.cs @@ -1,19 +1,21 @@ using UnityEngine; using UnityEngine.UI; using System.Collections; +using System.Collections.Generic; public class ToggleMenus : MonoBehaviour { //Menus - public GameObject RotMenu; - public GameObject ColorMenu; - public GameObject ShapesMenu; - public GameObject LightingMenu; - public GameObject ExpMenu; + public GameObject rotMenu; + public GameObject colorMenu; + public GameObject shapesMenu; + public GameObject lightingMenu; + public GameObject expMenu; private bool ActiveMenu = false; //Shapes - Prefabs + public GameObject player; public GameObject Square; public GameObject Sphere; public GameObject Cylinder; @@ -28,18 +30,22 @@ public class ToggleMenus : MonoBehaviour //private GameObject lighting = GameObject.FindGameObjectWithTag("Lighting"); public float lightRotX, lightRotY, lightRotZ; - public GameObject[] buttons; // Use this for initialization void Start() { + player = GameObject.FindGameObjectWithTag("Player"); + InitializeButtonArrays(); + Temp = Square; lightRotX = 0; lightRotY = 0; lightRotZ = 0; - EditLightingRotation(); + //EditLightingRotation(); //EditLightingLocation(); + + } public void Update() @@ -49,57 +55,57 @@ public class ToggleMenus : MonoBehaviour public void ToggleRotationMenu() { - if (RotMenu.gameObject.active) + if (rotMenu.gameObject.activeSelf) { - RotMenu.gameObject.SetActive(false); + rotMenu.gameObject.SetActive(false); ActiveMenu = !ActiveMenu; } - else if (!RotMenu.gameObject.active && ActiveMenu) + else if (!rotMenu.gameObject.activeSelf && ActiveMenu) { CloseAll(); - RotMenu.gameObject.SetActive(true); + rotMenu.gameObject.SetActive(true); } else { - RotMenu.gameObject.SetActive(true); + rotMenu.gameObject.SetActive(true); ActiveMenu = !ActiveMenu; } } public void ToggleColorMenu() { - if (ColorMenu.gameObject.active) + if (colorMenu.activeSelf) { - ColorMenu.gameObject.SetActive(false); + colorMenu.gameObject.SetActive(false); ActiveMenu = !ActiveMenu; } - else if (!ColorMenu.gameObject.active && ActiveMenu) + else if (!colorMenu.activeSelf && ActiveMenu) { CloseAll(); - ColorMenu.gameObject.SetActive(true); + colorMenu.SetActive(true); } else { - ColorMenu.gameObject.SetActive(true); + colorMenu.SetActive(true); ActiveMenu = !ActiveMenu; } } public void ToggleShapesMenu() { - if (ShapesMenu.gameObject.active) + if (shapesMenu.gameObject.activeSelf) { - ShapesMenu.gameObject.SetActive(false); + shapesMenu.gameObject.SetActive(false); ActiveMenu = !ActiveMenu; } - else if (!ShapesMenu.gameObject.active && ActiveMenu) + else if (!shapesMenu.gameObject.activeSelf && ActiveMenu) { CloseAll(); - ShapesMenu.gameObject.SetActive(true); + shapesMenu.gameObject.SetActive(true); } else { - ShapesMenu.gameObject.SetActive(true); + shapesMenu.gameObject.SetActive(true); ActiveMenu = !ActiveMenu; } @@ -107,50 +113,50 @@ public class ToggleMenus : MonoBehaviour public void ToggleLightingMenu() { - if (LightingMenu.gameObject.active) + if (lightingMenu.gameObject.activeSelf) { - LightingMenu.gameObject.SetActive(false); + lightingMenu.gameObject.SetActive(false); ActiveMenu = !ActiveMenu; } - else if (!LightingMenu.gameObject.active && ActiveMenu) + else if (!lightingMenu.gameObject.activeSelf && ActiveMenu) { CloseAll(); - LightingMenu.gameObject.SetActive(true); + lightingMenu.gameObject.SetActive(true); } else { - LightingMenu.gameObject.SetActive(true); + lightingMenu.gameObject.SetActive(true); ActiveMenu = !ActiveMenu; } } public void ToggleExpMenu() { - if (ExpMenu.gameObject.active) + if (expMenu.gameObject.activeSelf) { - ExpMenu.gameObject.SetActive(false); + expMenu.gameObject.SetActive(false); //check if another menu is open to avoid overlapping ActiveMenu = !ActiveMenu; } - else if (!ExpMenu.gameObject.active && ActiveMenu) + else if (!expMenu.gameObject.activeSelf && ActiveMenu) { CloseAll(); - ExpMenu.gameObject.SetActive(true); + expMenu.gameObject.SetActive(true); } else { - ExpMenu.gameObject.SetActive(true); + expMenu.gameObject.SetActive(true); ActiveMenu = !ActiveMenu; } } public void CloseAll() { - ShapesMenu.gameObject.SetActive(false); - RotMenu.gameObject.SetActive(false); - ColorMenu.gameObject.SetActive(false); - LightingMenu.gameObject.SetActive(false); - ExpMenu.gameObject.SetActive(false); + shapesMenu.gameObject.SetActive(false); + rotMenu.gameObject.SetActive(false); + colorMenu.gameObject.SetActive(false); + lightingMenu.gameObject.SetActive(false); + expMenu.gameObject.SetActive(false); } public void ChangeShapeSquare() @@ -188,7 +194,7 @@ public class ToggleMenus : MonoBehaviour Active = "Cylinder(Clone)"; Debug.Log(Active); } - + /* public void EditLightingRotation() { buttons = GameObject.FindGameObjectsWithTag("RotationMenuButtons"); @@ -197,9 +203,11 @@ public class ToggleMenus : MonoBehaviour gameObject.GetComponent