From 41e971216a7bec820494fb99abf81bed279fbc76 Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 21:10:30 -0300 Subject: [PATCH 1/6] refactor: blood glucose to body namespace --- unity-project/Assets/Scripts/Body.meta | 8 +++ .../Assets/Scripts/Body/BloodGlucose.cs | 51 +++++++++++++++++++ .../BloodGlucose.cs.meta | 2 +- unity-project/Assets/Scripts/Body/UI.meta | 8 +++ .../Assets/Scripts/Body/UI/BloodGlucose.cs | 19 +++++++ .../Scripts/Body/UI/BloodGlucose.cs.meta | 11 ++++ .../Scripts/Controllers/BloodGlucose.cs | 50 ------------------ .../Assets/Scripts/Controllers/Exercise.cs | 2 +- .../Assets/Scripts/Controllers/Indicators.cs | 3 +- unity-project/Assets/Scripts/Foods/Plate.cs | 2 +- 10 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 unity-project/Assets/Scripts/Body.meta create mode 100644 unity-project/Assets/Scripts/Body/BloodGlucose.cs rename unity-project/Assets/Scripts/{Controllers => Body}/BloodGlucose.cs.meta (83%) create mode 100644 unity-project/Assets/Scripts/Body/UI.meta create mode 100644 unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs create mode 100644 unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs.meta delete mode 100644 unity-project/Assets/Scripts/Controllers/BloodGlucose.cs diff --git a/unity-project/Assets/Scripts/Body.meta b/unity-project/Assets/Scripts/Body.meta new file mode 100644 index 00000000..a17c04fc --- /dev/null +++ b/unity-project/Assets/Scripts/Body.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a43946addec4d0144b6491c97053ba78 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Body/BloodGlucose.cs b/unity-project/Assets/Scripts/Body/BloodGlucose.cs new file mode 100644 index 00000000..29498987 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/BloodGlucose.cs @@ -0,0 +1,51 @@ +using UnityEngine; + +namespace Body{ + public class BloodGlucose : MonoBehaviour{ + SaveState state; + + void Start(){ + state = SaveManager.Instance.state; + + DailyUpdate(); + + Timer.Clock.OnDayChange += DailyUpdate; + Timer.Clock.OnHourChange += PassiveBloodGlucoseReduction; + } + + public void Change(float value){ + state.bgp += value; + + if(value < 0){ + FindObjectOfType().AddMessage("Glicose ↓", Color.red); + }else{ + FindObjectOfType().AddMessage("Glicose ↑", Color.green); + } + + GetComponent().UpdateUI(); + } + + public void AddCarbsToBloodStream(float carbs){ + float kcalCarbs = carbs * 4; + float carbToBloodStream = Mathf.Lerp(0, kcalCarbs, SaveManager.Instance.state.diabetesSeverity); + float bgpChange = carbToBloodStream * SaveManager.Instance.state.ptc; + Change(bgpChange); + } + + void DailyUpdate(){ + state.tdi = 0.6f * state.currentWeightKg; + state.isf = 1500/state.tdi; + state.icr = 500/state.tdi; + state.insulinResistance = (((state.bmi / state.activityFactor)/state.bmi)-0.5f)*2f; + state.ptc = Mathf.Lerp(0,state.icr/state.isf, state.insulinResistance); + state.diabetesSeverity = state.bmi/50; + } + + void PassiveBloodGlucoseReduction(){ + float f = (state.activityFactor/2f) * state.currentWeightKg; + float bgpReduction = Mathf.Lerp(0, .75f * f * state.ptc, 1-state.diabetesSeverity); + float bgpChange = -1 * (bgpReduction * (state.bgp/200f)); + Change(bgpChange); + } + } +} diff --git a/unity-project/Assets/Scripts/Controllers/BloodGlucose.cs.meta b/unity-project/Assets/Scripts/Body/BloodGlucose.cs.meta similarity index 83% rename from unity-project/Assets/Scripts/Controllers/BloodGlucose.cs.meta rename to unity-project/Assets/Scripts/Body/BloodGlucose.cs.meta index 463852b2..773c1abb 100644 --- a/unity-project/Assets/Scripts/Controllers/BloodGlucose.cs.meta +++ b/unity-project/Assets/Scripts/Body/BloodGlucose.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bd40574762f76af48a422ec6adc15582 +guid: 7e2a826751536e341b02ce18c7e94507 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/unity-project/Assets/Scripts/Body/UI.meta b/unity-project/Assets/Scripts/Body/UI.meta new file mode 100644 index 00000000..cb30d0bc --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0ae43d7cf0be2594485232287e1fe65a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs b/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs new file mode 100644 index 00000000..4ab8c7a8 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using UnityEngine.UI; +using TMPro; + +namespace Body.UI{ + public class BloodGlucose : MonoBehaviour { + SaveState state; + public TMP_Text bgpText; + + private void Start() { + state = SaveManager.Instance.state; + } + + public void UpdateUI(){ + bgpText.text = "Glicemia: " + state.bgp + "mg/dL"; + } + } + +} \ No newline at end of file diff --git a/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs.meta b/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs.meta new file mode 100644 index 00000000..73740f0d --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/BloodGlucose.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f845d26c5ad997f4a9a7b685f0d361c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Controllers/BloodGlucose.cs b/unity-project/Assets/Scripts/Controllers/BloodGlucose.cs deleted file mode 100644 index e552c89b..00000000 --- a/unity-project/Assets/Scripts/Controllers/BloodGlucose.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using TMPro; - -public class BloodGlucose : MonoBehaviour{ - SaveState state; - - void Start(){ - state = SaveManager.Instance.state; - - DailyUpdate(); - - Timer.Clock.OnDayChange += DailyUpdate; - Timer.Clock.OnHourChange += PassiveBloodGlucoseReduction; - } - - public void Change(float value){ - state.bgp += value; - - if(value < 0){ - FindObjectOfType().AddMessage("Glicose ↓", Color.red); - }else{ - FindObjectOfType().AddMessage("Glicose ↑", Color.green); - } - } - - public void AddCarbsToBloodStream(float carbs){ - float kcalCarbs = carbs * 4; - float carbToBloodStream = Mathf.Lerp(0, kcalCarbs, SaveManager.Instance.state.diabetesSeverity); - float bgpChange = carbToBloodStream * SaveManager.Instance.state.ptc; - Change(bgpChange); - } - - void DailyUpdate(){ - state.tdi = 0.6f * state.currentWeightKg; - state.isf = 1500/state.tdi; - state.icr = 500/state.tdi; - state.insulinResistance = (((state.bmi / state.activityFactor)/state.bmi)-0.5f)*2f; - state.ptc = Mathf.Lerp(0,state.icr/state.isf, state.insulinResistance); - state.diabetesSeverity = state.bmi/50; - } - - void PassiveBloodGlucoseReduction(){ - float f = (state.activityFactor/2f) * state.currentWeightKg; - float bgpReduction = Mathf.Lerp(0, .75f * f * state.ptc, 1-state.diabetesSeverity); - float bgpChange = -1 * (bgpReduction * (state.bgp/200f)); //TODO preciso arranjar um jeito de essa redução ser dependente do bgp; - Change(bgpChange); - } -} diff --git a/unity-project/Assets/Scripts/Controllers/Exercise.cs b/unity-project/Assets/Scripts/Controllers/Exercise.cs index 5bde52b0..e474a999 100644 --- a/unity-project/Assets/Scripts/Controllers/Exercise.cs +++ b/unity-project/Assets/Scripts/Controllers/Exercise.cs @@ -46,7 +46,7 @@ private void Start() { energy.ChangeEnergy(energyDecreseValue); float bgpChange = -1 * Mathf.Lerp(0, 0.75f * (calorieExpenditure * state.ptc), 1-state.diabetesSeverity); - FindObjectOfType().Change(bgpChange); + FindObjectOfType().Change(bgpChange); int hoursHE = Mathf.FloorToInt(hoursExercising); int minutesHE = Mathf.RoundToInt((hoursExercising - hoursHE) * 60); diff --git a/unity-project/Assets/Scripts/Controllers/Indicators.cs b/unity-project/Assets/Scripts/Controllers/Indicators.cs index 1b616162..b194fbb6 100644 --- a/unity-project/Assets/Scripts/Controllers/Indicators.cs +++ b/unity-project/Assets/Scripts/Controllers/Indicators.cs @@ -18,7 +18,7 @@ public class Indicators : MonoBehaviour{ SaveState state; - public TMP_Text weightText, bmiText, restingHeartRateText, glycatedHemoglobinText, caloriesText; + public TMP_Text weightText, bmiText, restingHeartRateText, caloriesText; [Space] public GameObject popupHolder; @@ -34,7 +34,6 @@ void Update(){ weightText.text = "Peso: " + state.currentWeightKg.ToString("0.00") + "kg"; bmiText.text = "IMC: " + state.bmi.ToString("0.00"); restingHeartRateText.text = "FCD: " + state.restingHeartRate; - glycatedHemoglobinText.text = "GS: " + state.bgp + "mg/dL"; while(messages.Count > 0){ PopUpMessage(messages[0]); diff --git a/unity-project/Assets/Scripts/Foods/Plate.cs b/unity-project/Assets/Scripts/Foods/Plate.cs index de5ba686..bd0a1863 100644 --- a/unity-project/Assets/Scripts/Foods/Plate.cs +++ b/unity-project/Assets/Scripts/Foods/Plate.cs @@ -39,7 +39,7 @@ public void EatPlate(){ FindObjectOfType().ChangeEnergy(-1 * processingAverage/10f); SaveManager.Instance.state.sleepQuality -= processingAverage/10f; - FindObjectOfType().AddCarbsToBloodStream(4); + FindObjectOfType().AddCarbsToBloodStream(4); } } } \ No newline at end of file From 461663f1960212e4b70be4b25faf7c7f2c32afe6 Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 21:14:09 -0300 Subject: [PATCH 2/6] refactor: water to body namespace --- unity-project/Assets/Scenes/GameScene.unity | 175 ++++++++---------- unity-project/Assets/Scripts/Body/Water.cs | 31 ++++ .../{Controllers => Body}/Water.cs.meta | 2 +- .../Assets/Scripts/Controllers/Water.cs | 29 --- 4 files changed, 111 insertions(+), 126 deletions(-) create mode 100644 unity-project/Assets/Scripts/Body/Water.cs rename unity-project/Assets/Scripts/{Controllers => Body}/Water.cs.meta (83%) delete mode 100644 unity-project/Assets/Scripts/Controllers/Water.cs diff --git a/unity-project/Assets/Scenes/GameScene.unity b/unity-project/Assets/Scenes/GameScene.unity index 0564966c..28cc5777 100644 --- a/unity-project/Assets/Scenes/GameScene.unity +++ b/unity-project/Assets/Scenes/GameScene.unity @@ -1946,49 +1946,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 158687749} m_CullTransparentMesh: 1 ---- !u!1 &194031579 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 194031581} - - component: {fileID: 194031580} - m_Layer: 0 - m_Name: GlucoseController - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &194031580 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 194031579} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bd40574762f76af48a422ec6adc15582, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!4 &194031581 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 194031579} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 9 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &204314677 GameObject: m_ObjectHideFlags: 0 @@ -2499,7 +2456,7 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 1725731995} + - m_Target: {fileID: 0} m_TargetAssemblyTypeName: Water, Assembly-CSharp m_MethodName: Hydrate m_Mode: 4 @@ -2773,7 +2730,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 10 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &293531294 GameObject: @@ -3440,7 +3397,6 @@ MonoBehaviour: weightText: {fileID: 796537712} bmiText: {fileID: 228638086} restingHeartRateText: {fileID: 1085737332} - glycatedHemoglobinText: {fileID: 2047156592} caloriesText: {fileID: 859486119} popupHolder: {fileID: 1707670454} popupTemplate: {fileID: 677918529221931768, guid: 37c9d7ee5aafdfb4c9344f22d9221804, type: 3} @@ -6125,7 +6081,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 11 + m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &638958622 GameObject: @@ -7051,7 +7007,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 13 + m_RootOrder: 12 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &787821399 MonoBehaviour: @@ -7817,6 +7773,77 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 877183674} m_CullTransparentMesh: 1 +--- !u!1 &881363946 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 881363950} + - component: {fileID: 881363949} + - component: {fileID: 881363948} + - component: {fileID: 881363947} + m_Layer: 0 + m_Name: BodyController + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &881363947 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7e2a826751536e341b02ce18c7e94507, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &881363948 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f845d26c5ad997f4a9a7b685f0d361c2, type: 3} + m_Name: + m_EditorClassIdentifier: + bgpText: {fileID: 2047156592} +--- !u!114 &881363949 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c03ec489a5fcef54a93b4b89213a62a8, type: 3} + m_Name: + m_EditorClassIdentifier: + waterIndicator: {fileID: 442460072} +--- !u!4 &881363950 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 2.0119433, y: -1.1276704, z: 27.518997} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 15 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &910606087 GameObject: m_ObjectHideFlags: 0 @@ -10333,7 +10360,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 12 + m_RootOrder: 11 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1312690907 GameObject: @@ -11328,7 +11355,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 15 + m_RootOrder: 14 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1418312675 MonoBehaviour: @@ -12557,7 +12584,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 14 + m_RootOrder: 13 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1725231626 MonoBehaviour: @@ -12575,50 +12602,6 @@ MonoBehaviour: amountOfHoursToSleepText: {fileID: 355720586} wakeUpHourAndMinuteText: {fileID: 1040212941} sleepSelectorSlider: {fileID: 638958624} ---- !u!1 &1725731994 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1725731996} - - component: {fileID: 1725731995} - m_Layer: 0 - m_Name: Water - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1725731995 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1725731994} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d670365a987b8944ebb4c83b0f362a94, type: 3} - m_Name: - m_EditorClassIdentifier: - waterIndicator: {fileID: 442460072} ---- !u!4 &1725731996 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1725731994} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 16 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1743064809 GameObject: m_ObjectHideFlags: 0 @@ -13366,9 +13349,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1852776582} - - component: {fileID: 1852776586} - component: {fileID: 1852776585} - component: {fileID: 1852776584} + - component: {fileID: 1852776586} - component: {fileID: 1852776583} m_Layer: 0 m_Name: FoodController diff --git a/unity-project/Assets/Scripts/Body/Water.cs b/unity-project/Assets/Scripts/Body/Water.cs new file mode 100644 index 00000000..153ac550 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/Water.cs @@ -0,0 +1,31 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Body{ + public class Water : MonoBehaviour{ + public Slider waterIndicator; + SaveState state; + void Start(){ + state = SaveManager.Instance.state; + waterIndicator.value = state.hydration; + + Timer.Clock.OnHourChange += Dehydrate; + } + + public void ChangeWater(float value){ + state.hydration += value; + state.hydration = Mathf.Clamp01(state.hydration); + waterIndicator.value = state.hydration; + if(value > 0){ + FindObjectOfType().AddMessage("Hidratação ↑", Color.green); + }else{ + FindObjectOfType().AddMessage("Hidratação ↓", Color.red); + } + + } + + void Dehydrate(){ + ChangeWater(-0.01f); + } + } +} diff --git a/unity-project/Assets/Scripts/Controllers/Water.cs.meta b/unity-project/Assets/Scripts/Body/Water.cs.meta similarity index 83% rename from unity-project/Assets/Scripts/Controllers/Water.cs.meta rename to unity-project/Assets/Scripts/Body/Water.cs.meta index 0725c6cc..75a150f9 100644 --- a/unity-project/Assets/Scripts/Controllers/Water.cs.meta +++ b/unity-project/Assets/Scripts/Body/Water.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d670365a987b8944ebb4c83b0f362a94 +guid: c03ec489a5fcef54a93b4b89213a62a8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/unity-project/Assets/Scripts/Controllers/Water.cs b/unity-project/Assets/Scripts/Controllers/Water.cs deleted file mode 100644 index c384df19..00000000 --- a/unity-project/Assets/Scripts/Controllers/Water.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -public class Water : MonoBehaviour{ - public Slider waterIndicator; - SaveState state; - void Start(){ - state = SaveManager.Instance.state; - waterIndicator.value = state.hydration; - - Timer.Clock.OnHourChange += Dehydrate; - } - - public void Hydrate(float value){ - state.hydration += value; - state.hydration = Mathf.Clamp01(state.hydration); - waterIndicator.value = state.hydration; - FindObjectOfType().AddMessage("Hidratação ↑", Color.green); - - } - - void Dehydrate(){ - state.hydration -= 0.01f; - waterIndicator.value = state.hydration; - FindObjectOfType().AddMessage("Hidratação ↓", Color.red); - } -} From bb2ebd501d19a5060381281a5c5796db22f0d71e Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 21:40:57 -0300 Subject: [PATCH 3/6] refactor: weight to body namespace --- unity-project/Assets/Scenes/GameScene.unity | 28 +++++++++ .../Assets/Scripts/Body/UI/Weight.cs | 18 ++++++ .../Assets/Scripts/Body/UI/Weight.cs.meta | 11 ++++ unity-project/Assets/Scripts/Body/Weight.cs | 59 +++++++++++++++++++ .../Assets/Scripts/Body/Weight.cs.meta | 11 ++++ .../Assets/Scripts/Controllers/Exercise.cs | 40 ------------- 6 files changed, 127 insertions(+), 40 deletions(-) create mode 100644 unity-project/Assets/Scripts/Body/UI/Weight.cs create mode 100644 unity-project/Assets/Scripts/Body/UI/Weight.cs.meta create mode 100644 unity-project/Assets/Scripts/Body/Weight.cs create mode 100644 unity-project/Assets/Scripts/Body/Weight.cs.meta diff --git a/unity-project/Assets/Scenes/GameScene.unity b/unity-project/Assets/Scenes/GameScene.unity index 28cc5777..a84cdf1d 100644 --- a/unity-project/Assets/Scenes/GameScene.unity +++ b/unity-project/Assets/Scenes/GameScene.unity @@ -7785,6 +7785,8 @@ GameObject: - component: {fileID: 881363949} - component: {fileID: 881363948} - component: {fileID: 881363947} + - component: {fileID: 881363952} + - component: {fileID: 881363951} m_Layer: 0 m_Name: BodyController m_TagString: Untagged @@ -7844,6 +7846,32 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 15 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &881363951 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 20cad724eb4c4bd4699c42531e3c0904, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &881363952 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 40effd9bf11c5634f9198525125ceba6, type: 3} + m_Name: + m_EditorClassIdentifier: + weightText: {fileID: 796537712} + bmiText: {fileID: 228638086} --- !u!1 &910606087 GameObject: m_ObjectHideFlags: 0 diff --git a/unity-project/Assets/Scripts/Body/UI/Weight.cs b/unity-project/Assets/Scripts/Body/UI/Weight.cs new file mode 100644 index 00000000..5b2371e0 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/Weight.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using TMPro; + +namespace Body.UI{ + public class Weight : MonoBehaviour{ + SaveState state; + public TMP_Text weightText, bmiText; + + private void Start() { + state = SaveManager.Instance.state; + } + + public void UpdateUI(){ + weightText.text = "Peso: " + state.currentWeightKg.ToString("0.00") + "kg"; + bmiText.text = "IMC: " + state.bmi.ToString("0.00"); + } + } +} \ No newline at end of file diff --git a/unity-project/Assets/Scripts/Body/UI/Weight.cs.meta b/unity-project/Assets/Scripts/Body/UI/Weight.cs.meta new file mode 100644 index 00000000..4a4afbe4 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/Weight.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40effd9bf11c5634f9198525125ceba6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Body/Weight.cs b/unity-project/Assets/Scripts/Body/Weight.cs new file mode 100644 index 00000000..4fce2d68 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/Weight.cs @@ -0,0 +1,59 @@ +using System.Linq; +using UnityEngine; + +namespace Body{ + public class Weight : MonoBehaviour{ + SaveState state; + + private void Start() { + state = SaveManager.Instance.state; + Timer.Clock.OnDayChange += WeightChange; + } + + void CalculateExerciseMovingAverage(){ + for(int i = 0; i<6; i++){ + state.exerciseHistory[i] = state.exerciseHistory[i + 1]; + } + state.exerciseHistory[6] = state.currentDayExerciseQuantity; + state.currentDayExerciseQuantity = 0; + //?Debug.Log("Exercise history: " + state.exerciseHistory); + } + + void CalculateActivityFactor(){ + float pastWeekExerciseSum = state.exerciseHistory.Sum(); + + state.activityFactor += (2 * Mathf.Cos(0.4f*pastWeekExerciseSum - Mathf.PI/2))/100f; + state.activityFactor -= (-(1.4f*Mathf.Pow(state.activityFactor-2, 2))+2)/200f; + state.activityFactor = Mathf.Clamp(state.activityFactor, 1, 2); + //?Debug.Log("Activity Factor: " + state.activityFactor); + } + + void WeightChange(){ + CalculateExerciseMovingAverage(); + CalculateActivityFactor(); + + float c = state.currentWeightKg - + ((state.calorieDifference - state.activityFactor * (6.25f * state.heightCentimeters - 5 * state.ageYears + state.sexFactor))/ + (10 * state.activityFactor)); + + float weightChange = c * Mathf.Exp(-state.activityFactor/770) + ((state.calorieDifference - state.activityFactor * (6.25f * state.heightCentimeters - 5 * state.ageYears + state.sexFactor))/ + (10 * state.activityFactor)); + weightChange -= state.currentWeightKg; + + if(weightChange > 0){ + state.currentWeightKg += weightChange / state.sleepQuality; //sleep quality [0;1] will increase weight change if the person gains weight + }else{ + state.currentWeightKg += weightChange * state.sleepQuality; //sleep quality [0;1] will decrease weight loss + } + //?Debug.Log("New weight: " + state.currentWeightKg); + + state.bmi = state.currentWeightKg / Mathf.Pow(state.heightCentimeters / 100f, 2); + GetComponent().UpdateUI(); + + state.basalCalorie = Mathf.RoundToInt(state.activityFactor * (10f * state.currentWeightKg + + 6.25f * state.heightCentimeters - 5f * state.ageYears + state.sexFactor)); + state.dailyCalorieRealDefficit = state.calorieDifference - state.basalCalorie; + } + + } +} \ No newline at end of file diff --git a/unity-project/Assets/Scripts/Body/Weight.cs.meta b/unity-project/Assets/Scripts/Body/Weight.cs.meta new file mode 100644 index 00000000..d39d35a8 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/Weight.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 20cad724eb4c4bd4699c42531e3c0904 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Controllers/Exercise.cs b/unity-project/Assets/Scripts/Controllers/Exercise.cs index e474a999..dee54332 100644 --- a/unity-project/Assets/Scripts/Controllers/Exercise.cs +++ b/unity-project/Assets/Scripts/Controllers/Exercise.cs @@ -16,7 +16,6 @@ public class Exercise : MonoBehaviour{ private void Start() { energy = FindObjectOfType(); - Timer.Clock.OnDayChange += WeightChange; Timer.Clock.OnDayChange += Heart; } @@ -59,45 +58,6 @@ private void Start() { //?Debug.Log("Exercised for " + hoursExercising + " and spent " + calorieExpenditure + "kcal"); } - void WeightChange(){ - for(int i = 0; i<6; i++){ - state.exerciseHistory[i] = state.exerciseHistory[i + 1]; - } - state.exerciseHistory[6] = state.currentDayExerciseQuantity; - state.currentDayExerciseQuantity = 0; - //?Debug.Log("Exercise history: " + state.exerciseHistory); - - float pastWeekExerciseSum = state.exerciseHistory.Sum(); - - state.activityFactor += (2 * Mathf.Cos(0.4f*pastWeekExerciseSum - Mathf.PI/2))/100f; - state.activityFactor -= (-(1.4f*Mathf.Pow(state.activityFactor-2, 2))+2)/200f; - state.activityFactor = Mathf.Clamp(state.activityFactor, 1, 2); - //?Debug.Log("Activity Factor: " + state.activityFactor); - - float c = state.currentWeightKg - - ((state.calorieDifference - state.activityFactor * (6.25f * state.heightCentimeters - 5 * state.ageYears + state.sexFactor))/ - (10 * state.activityFactor)); - - float weightChange = c * Mathf.Exp(-state.activityFactor/770) + ((state.calorieDifference - state.activityFactor * (6.25f * state.heightCentimeters - 5 * state.ageYears + state.sexFactor))/ - (10 * state.activityFactor)); - weightChange -= state.currentWeightKg; - - //?Debug.Log("Weight Change: " + weightChange); - if(weightChange > 0){ - state.currentWeightKg += weightChange / state.sleepQuality; - }else{ - state.currentWeightKg += weightChange * state.sleepQuality; - } - - //?Debug.Log("New weight: " + state.currentWeightKg); - - state.bmi = state.currentWeightKg / Mathf.Pow(state.heightCentimeters / 100f, 2); - - state.basalCalorie = Mathf.RoundToInt(state.activityFactor * (10f * state.currentWeightKg + - 6.25f * state.heightCentimeters - 5f * state.ageYears + state.sexFactor)); - state.dailyCalorieRealDefficit = state.calorieDifference - state.basalCalorie; - } - void Heart(){ System.Random rnd = new System.Random(); From 3c1674acc6d2dd19ee609ef81be0ffd8870910a5 Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 21:52:57 -0300 Subject: [PATCH 4/6] refactor: heart to body namespace --- unity-project/Assets/Scripts/Body/Heart.cs | 21 +++++++++++++++++++ .../Assets/Scripts/Body/Heart.cs.meta | 11 ++++++++++ unity-project/Assets/Scripts/Body/UI/Heart.cs | 19 +++++++++++++++++ .../Assets/Scripts/Body/UI/Heart.cs.meta | 11 ++++++++++ .../Assets/Scripts/Controllers/Exercise.cs | 10 +-------- .../Assets/Scripts/Controllers/Indicators.cs | 4 ---- 6 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 unity-project/Assets/Scripts/Body/Heart.cs create mode 100644 unity-project/Assets/Scripts/Body/Heart.cs.meta create mode 100644 unity-project/Assets/Scripts/Body/UI/Heart.cs create mode 100644 unity-project/Assets/Scripts/Body/UI/Heart.cs.meta diff --git a/unity-project/Assets/Scripts/Body/Heart.cs b/unity-project/Assets/Scripts/Body/Heart.cs new file mode 100644 index 00000000..a4332744 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/Heart.cs @@ -0,0 +1,21 @@ +using UnityEngine; + +namespace Body{ + public class Heart : MonoBehaviour{ + SaveState state; + + private void Start() { + state = SaveManager.Instance.state; + + Timer.Clock.OnDayChange += CalculateRestHeartRate; + } + + void CalculateRestHeartRate(){ + System.Random rnd = new System.Random(); + + int goalHeartRate = 131 - 41 * (int)SaveManager.Instance.state.activityFactor; + SaveManager.Instance.state.restingHeartRate = rnd.Next(goalHeartRate - 2, goalHeartRate + 3); + GetComponent().UpdateUI(); + } + } +} \ No newline at end of file diff --git a/unity-project/Assets/Scripts/Body/Heart.cs.meta b/unity-project/Assets/Scripts/Body/Heart.cs.meta new file mode 100644 index 00000000..25c3f514 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/Heart.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6391f99d06e71734e90f0869ba5dd3a9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Body/UI/Heart.cs b/unity-project/Assets/Scripts/Body/UI/Heart.cs new file mode 100644 index 00000000..e1820134 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/Heart.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using UnityEngine.UI; +using TMPro; + +namespace Body.UI{ + public class Heart : MonoBehaviour { + SaveState state; + public TMP_Text restingHeartRateText; + + private void Start() { + state = SaveManager.Instance.state; + } + + public void UpdateUI(){ + restingHeartRateText.text = "FCD: " + state.restingHeartRate; + } + } + +} \ No newline at end of file diff --git a/unity-project/Assets/Scripts/Body/UI/Heart.cs.meta b/unity-project/Assets/Scripts/Body/UI/Heart.cs.meta new file mode 100644 index 00000000..fa6c23c3 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/UI/Heart.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0029d2a762a414145941fbed7a1d0a03 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity-project/Assets/Scripts/Controllers/Exercise.cs b/unity-project/Assets/Scripts/Controllers/Exercise.cs index dee54332..8854c4f7 100644 --- a/unity-project/Assets/Scripts/Controllers/Exercise.cs +++ b/unity-project/Assets/Scripts/Controllers/Exercise.cs @@ -14,9 +14,8 @@ public class Exercise : MonoBehaviour{ private void Start() { + state = SaveManager.Instance.state; energy = FindObjectOfType(); - - Timer.Clock.OnDayChange += Heart; } public void ExerciseAction(){ //only exercises if energy allows it @@ -58,11 +57,4 @@ private void Start() { //?Debug.Log("Exercised for " + hoursExercising + " and spent " + calorieExpenditure + "kcal"); } - void Heart(){ - System.Random rnd = new System.Random(); - - int goalHeartRate = 131 - 41 * (int)SaveManager.Instance.state.activityFactor; - SaveManager.Instance.state.restingHeartRate = rnd.Next(goalHeartRate - 2, goalHeartRate + 3); - } - } diff --git a/unity-project/Assets/Scripts/Controllers/Indicators.cs b/unity-project/Assets/Scripts/Controllers/Indicators.cs index b194fbb6..b16db7b1 100644 --- a/unity-project/Assets/Scripts/Controllers/Indicators.cs +++ b/unity-project/Assets/Scripts/Controllers/Indicators.cs @@ -31,10 +31,6 @@ private void Start() { } void Update(){ - weightText.text = "Peso: " + state.currentWeightKg.ToString("0.00") + "kg"; - bmiText.text = "IMC: " + state.bmi.ToString("0.00"); - restingHeartRateText.text = "FCD: " + state.restingHeartRate; - while(messages.Count > 0){ PopUpMessage(messages[0]); messages.RemoveAt(0); From fb533f02fef0831aaeb84d3670643423ebc37d0d Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 21:54:12 -0300 Subject: [PATCH 5/6] refactor: heart to body namespace --- unity-project/Assets/Scenes/GameScene.unity | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/unity-project/Assets/Scenes/GameScene.unity b/unity-project/Assets/Scenes/GameScene.unity index a84cdf1d..a3bf221b 100644 --- a/unity-project/Assets/Scenes/GameScene.unity +++ b/unity-project/Assets/Scenes/GameScene.unity @@ -7787,6 +7787,8 @@ GameObject: - component: {fileID: 881363947} - component: {fileID: 881363952} - component: {fileID: 881363951} + - component: {fileID: 881363954} + - component: {fileID: 881363953} m_Layer: 0 m_Name: BodyController m_TagString: Untagged @@ -7872,6 +7874,31 @@ MonoBehaviour: m_EditorClassIdentifier: weightText: {fileID: 796537712} bmiText: {fileID: 228638086} +--- !u!114 &881363953 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6391f99d06e71734e90f0869ba5dd3a9, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &881363954 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 881363946} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0029d2a762a414145941fbed7a1d0a03, type: 3} + m_Name: + m_EditorClassIdentifier: + restingHeartRateText: {fileID: 1085737332} --- !u!1 &910606087 GameObject: m_ObjectHideFlags: 0 From aae90d2a8ecd3695ddd717e4a79688f8f62f2f9f Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Mon, 26 Sep 2022 22:10:19 -0300 Subject: [PATCH 6/6] refactor: character creator to body namespace --- .../Assets/Scenes/CharacterSelection.unity | 8 +- .../Assets/Scripts/Body/CharacterCreator.cs | 110 ++++++++++++++++++ .../CharacterCreator.cs.meta | 2 +- .../Scripts/Controllers/CharacterCreator.cs | 110 ------------------ 4 files changed, 115 insertions(+), 115 deletions(-) create mode 100644 unity-project/Assets/Scripts/Body/CharacterCreator.cs rename unity-project/Assets/Scripts/{Controllers => Body}/CharacterCreator.cs.meta (83%) delete mode 100644 unity-project/Assets/Scripts/Controllers/CharacterCreator.cs diff --git a/unity-project/Assets/Scenes/CharacterSelection.unity b/unity-project/Assets/Scenes/CharacterSelection.unity index 5e606ece..cf5edc25 100644 --- a/unity-project/Assets/Scenes/CharacterSelection.unity +++ b/unity-project/Assets/Scenes/CharacterSelection.unity @@ -903,13 +903,13 @@ MonoBehaviour: m_GameObject: {fileID: 217245810} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6d7e21a932602b346bd16732ad6c01df, type: 3} + m_Script: {fileID: 11500000, guid: f4ed47aaa1507d84392f72f1bb8c4d6d, type: 3} m_Name: m_EditorClassIdentifier: activityText: {fileID: 1673338836} weightText: {fileID: 1540711096} - sleepText: {fileID: 781735418} - height: {fileID: 1180892471} + sleepText: {fileID: 1180892471} + heightText: {fileID: 25131603} age: {fileID: 1172363413} manPB: {fileID: 764844255} manColor: {fileID: 486396718} @@ -2701,7 +2701,7 @@ GameObject: - component: {fileID: 1180892472} - component: {fileID: 1180892471} m_Layer: 5 - m_Name: value + m_Name: heightText m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/unity-project/Assets/Scripts/Body/CharacterCreator.cs b/unity-project/Assets/Scripts/Body/CharacterCreator.cs new file mode 100644 index 00000000..22823689 --- /dev/null +++ b/unity-project/Assets/Scripts/Body/CharacterCreator.cs @@ -0,0 +1,110 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.SceneManagement; +using TMPro; + +namespace Body{ + public class CharacterCreator : MonoBehaviour{ + + SaveState state; + + public TMP_Text activityText, weightText, sleepText, heightText; + public TMP_InputField age; + + [Space] + public GameObject manPB; + public GameObject manColor, womanPB, womanColor; + + private void Start() { + state = SaveManager.Instance.state; + if(state.characterCreated){ + SceneManager.LoadScene(2); + return; + } + age.text = state.ageYears + ""; + GetDifficulty(0); + } + + public void GetHeight(float _h){ + heightText.text = _h + "cm"; + state.heightCentimeters = (int) _h; + GetDifficulty(state.difficulty); + } + + public void GetAge(string input){ + int _a = int.Parse(input); + if(13 <= _a && _a <= 70){ + state.ageYears = _a; + }else{ + age.text = state.ageYears + ""; + } + } + + public void GetSex(int index){ + if(index == 0){ + state.sexFactor = -161; //female + womanColor.SetActive(true); + manPB.SetActive(true); + womanPB.SetActive(false); + manColor.SetActive(false); + }else{ + state.sexFactor = 5; //male + manColor.SetActive(true); + womanPB.SetActive(true); + manPB.SetActive(false); + womanColor.SetActive(false); + } + } + + public void GetDifficulty(int index){ + state.difficulty = index; + switch(index){ + case 0: //facil + state.activityFactor = 1.2f; + state.currentWeightKg = 30 * Mathf.Pow(state.heightCentimeters/100f, 2); + state.numberOfSleeps = 50; + state.totalHoursSlept = state.numberOfSleeps * 7; + state.sleepQuality = 0.84f; + state.bgp = 120; + + activityText.text = "baixo"; + break; + case 1: //normal + state.activityFactor = 1.1f; + state.currentWeightKg = 33 * Mathf.Pow(state.heightCentimeters/100f, 2); + state.numberOfSleeps = 70; + state.totalHoursSlept = state.numberOfSleeps * 6.5f; + state.sleepQuality = 0.8f; + state.bgp = 150; + activityText.text = "pouco"; + break; + case 2: //dificil + state.activityFactor = 1f; + state.currentWeightKg = 37 * Mathf.Pow(state.heightCentimeters/100f, 2); + state.numberOfSleeps = 100; + state.totalHoursSlept = state.numberOfSleeps * 6; + state.sleepQuality = 0.7f; + state.bgp = 180; + activityText.text = "nenhum"; + break; + default: + state.activityFactor = 1f; + state.currentWeightKg = 37 * Mathf.Pow(state.heightCentimeters/100f, 2); + state.numberOfSleeps = 100; + state.totalHoursSlept = state.numberOfSleeps * 6; + state.sleepQuality = 0.7f; + state.bgp = 180; + activityText.text = "nenhum"; + break; + } + weightText.text = state.currentWeightKg.ToString("00.00") + "kg"; + sleepText.text = "~" + state.totalHoursSlept/state.numberOfSleeps + "hrs"; + } + + public void CreateCharacter(){ + state.characterCreated = true; + SceneManager.LoadScene(2); + } + + } +} diff --git a/unity-project/Assets/Scripts/Controllers/CharacterCreator.cs.meta b/unity-project/Assets/Scripts/Body/CharacterCreator.cs.meta similarity index 83% rename from unity-project/Assets/Scripts/Controllers/CharacterCreator.cs.meta rename to unity-project/Assets/Scripts/Body/CharacterCreator.cs.meta index 57ca6b2a..033b88cc 100644 --- a/unity-project/Assets/Scripts/Controllers/CharacterCreator.cs.meta +++ b/unity-project/Assets/Scripts/Body/CharacterCreator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6d7e21a932602b346bd16732ad6c01df +guid: f4ed47aaa1507d84392f72f1bb8c4d6d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/unity-project/Assets/Scripts/Controllers/CharacterCreator.cs b/unity-project/Assets/Scripts/Controllers/CharacterCreator.cs deleted file mode 100644 index 306a0891..00000000 --- a/unity-project/Assets/Scripts/Controllers/CharacterCreator.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; -using TMPro; - -public class CharacterCreator : MonoBehaviour{ - - SaveState state; - - public TMP_Text activityText, weightText, sleepText; - public TMP_Text height; - public TMP_InputField age; - - [Space] - public GameObject manPB; - public GameObject manColor, womanPB, womanColor; - - private void Start() { - state = SaveManager.Instance.state; - if(state.characterCreated){ - SceneManager.LoadScene(2); - return; - } - age.text = state.ageYears + ""; - GetDifficulty(0); - } - - public void GetHeight(float _h){ - height.text = _h + "cm"; - state.heightCentimeters = (int) _h; - GetDifficulty(state.difficulty); - } - - public void GetAge(string input){ - int _a = int.Parse(input); - if(13 <= _a && _a <= 70){ - state.ageYears = _a; - }else{ - age.text = state.ageYears + ""; - } - } - - public void GetSex(int index){ - if(index == 0){ - state.sexFactor = -161; //female - womanColor.SetActive(true); - manPB.SetActive(true); - womanPB.SetActive(false); - manColor.SetActive(false); - }else{ - state.sexFactor = 5; //male - manColor.SetActive(true); - womanPB.SetActive(true); - manPB.SetActive(false); - womanColor.SetActive(false); - } - } - - public void GetDifficulty(int index){ - state.difficulty = index; - switch(index){ - case 0: //facil - state.activityFactor = 1.2f; - state.currentWeightKg = 30 * Mathf.Pow(state.heightCentimeters/100f, 2); - state.numberOfSleeps = 50; - state.totalHoursSlept = state.numberOfSleeps * 7; - state.sleepQuality = 0.84f; - state.bgp = 120; - - activityText.text = "baixo"; - break; - case 1: //normal - state.activityFactor = 1.1f; - state.currentWeightKg = 33 * Mathf.Pow(state.heightCentimeters/100f, 2); - state.numberOfSleeps = 70; - state.totalHoursSlept = state.numberOfSleeps * 6.5f; - state.sleepQuality = 0.8f; - state.bgp = 150; - activityText.text = "pouco"; - break; - case 2: //dificil - state.activityFactor = 1f; - state.currentWeightKg = 37 * Mathf.Pow(state.heightCentimeters/100f, 2); - state.numberOfSleeps = 100; - state.totalHoursSlept = state.numberOfSleeps * 6; - state.sleepQuality = 0.7f; - state.bgp = 180; - activityText.text = "nenhum"; - break; - default: - state.activityFactor = 1f; - state.currentWeightKg = 37 * Mathf.Pow(state.heightCentimeters/100f, 2); - state.numberOfSleeps = 100; - state.totalHoursSlept = state.numberOfSleeps * 6; - state.sleepQuality = 0.7f; - state.bgp = 180; - activityText.text = "nenhum"; - break; - } - weightText.text = state.currentWeightKg.ToString("00.00") + "kg"; - sleepText.text = "~" + state.totalHoursSlept/state.numberOfSleeps + "hrs"; - } - - public void CreateCharacter(){ - state.characterCreated = true; - SceneManager.LoadScene(2); - } - -}