From 1d0e4a3ad9527daac44211a8fb8e6b5fadcafc36 Mon Sep 17 00:00:00 2001
From: Irgiansyah Mondo <13521167@std.stei.itb.ac.id>
Date: Sat, 11 May 2024 06:48:16 +0700
Subject: [PATCH] sinkron save object

---
 Assets/Scenes/MainMenu.unity                  | 240 ++++++++++--------
 Assets/Scripts/Global/CurrentStateData.cs     |  13 +-
 Assets/Scripts/Managers/MainMenuManager.cs    |  23 ++
 .../Managers/StatisticsCanvasManager.cs       |   8 +-
 Assets/Scripts/Player/PlayerShooting.cs       |   2 +
 Assets/Scripts/Utils/SaveEntry.cs             |   1 +
 6 files changed, 177 insertions(+), 110 deletions(-)

diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity
index 034c91c..5d07bbd 100644
--- a/Assets/Scenes/MainMenu.unity
+++ b/Assets/Scenes/MainMenu.unity
@@ -3565,11 +3565,6 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 877482665}
   m_CullTransparentMesh: 1
---- !u!224 &877916099 stripped
-RectTransform:
-  m_CorrespondingSourceObject: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-  m_PrefabInstance: {fileID: 2300734417490416992}
-  m_PrefabAsset: {fileID: 0}
 --- !u!1 &919526715
 GameObject:
   m_ObjectHideFlags: 0
@@ -4040,6 +4035,8 @@ MonoBehaviour:
   loadPanel: {fileID: 9719888}
   settingsCanvas: {fileID: 547012555}
   statisticsCanvas: {fileID: 1654839518}
+  statisticsPanel: {fileID: 64339434}
+  shootAccuracyText: {fileID: 1793447013}
 --- !u!114 &1052050027
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -7307,6 +7304,140 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1786002137}
   m_CullTransparentMesh: 1
+--- !u!1 &1793447012
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1793447015}
+  - component: {fileID: 1793447014}
+  - component: {fileID: 1793447013}
+  m_Layer: 5
+  m_Name: ShootAccuraacyText
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!114 &1793447013
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1793447012}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 1, g: 1, b: 1, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_text: 'Score :'
+  m_isRightToLeft: 0
+  m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
+  m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
+  m_fontSharedMaterials: []
+  m_fontMaterial: {fileID: 0}
+  m_fontMaterials: []
+  m_fontColor32:
+    serializedVersion: 2
+    rgba: 4294967295
+  m_fontColor: {r: 1, g: 1, b: 1, a: 1}
+  m_enableVertexGradient: 0
+  m_colorMode: 3
+  m_fontColorGradient:
+    topLeft: {r: 1, g: 1, b: 1, a: 1}
+    topRight: {r: 1, g: 1, b: 1, a: 1}
+    bottomLeft: {r: 1, g: 1, b: 1, a: 1}
+    bottomRight: {r: 1, g: 1, b: 1, a: 1}
+  m_fontColorGradientPreset: {fileID: 0}
+  m_spriteAsset: {fileID: 0}
+  m_tintAllSprites: 0
+  m_StyleSheet: {fileID: 0}
+  m_TextStyleHashCode: -1183493901
+  m_overrideHtmlColors: 0
+  m_faceColor:
+    serializedVersion: 2
+    rgba: 4294967295
+  m_fontSize: 36
+  m_fontSizeBase: 36
+  m_fontWeight: 400
+  m_enableAutoSizing: 0
+  m_fontSizeMin: 18
+  m_fontSizeMax: 72
+  m_fontStyle: 0
+  m_HorizontalAlignment: 1
+  m_VerticalAlignment: 256
+  m_textAlignment: 65535
+  m_characterSpacing: 0
+  m_wordSpacing: 0
+  m_lineSpacing: 0
+  m_lineSpacingMax: 0
+  m_paragraphSpacing: 0
+  m_charWidthMaxAdj: 0
+  m_enableWordWrapping: 1
+  m_wordWrappingRatios: 0.4
+  m_overflowMode: 0
+  m_linkedTextComponent: {fileID: 0}
+  parentLinkedComponent: {fileID: 0}
+  m_enableKerning: 1
+  m_enableExtraPadding: 0
+  checkPaddingRequired: 0
+  m_isRichText: 1
+  m_parseCtrlCharacters: 1
+  m_isOrthographic: 1
+  m_isCullingEnabled: 0
+  m_horizontalMapping: 0
+  m_verticalMapping: 0
+  m_uvLineOffset: 0
+  m_geometrySortingOrder: 0
+  m_IsTextObjectScaleStatic: 0
+  m_VertexBufferAutoSizeReduction: 0
+  m_useMaxVisibleDescender: 1
+  m_pageToDisplay: 1
+  m_margin: {x: 0, y: 0, z: 0, w: 0}
+  m_isUsingLegacyAnimationComponent: 0
+  m_isVolumetricText: 0
+  m_hasFontAssetChanged: 0
+  m_baseMaterial: {fileID: 0}
+  m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
+--- !u!222 &1793447014
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1793447012}
+  m_CullTransparentMesh: 1
+--- !u!224 &1793447015
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1793447012}
+  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_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 1886923669}
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0.5, y: 0.5}
+  m_AnchorMax: {x: 0.5, y: 0.5}
+  m_AnchoredPosition: {x: 0, y: 143}
+  m_SizeDelta: {x: 200, y: 50}
+  m_Pivot: {x: 0.5, y: 0.5}
 --- !u!1 &1857230669
 GameObject:
   m_ObjectHideFlags: 0
@@ -7469,7 +7600,7 @@ RectTransform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children:
-  - {fileID: 877916099}
+  - {fileID: 1793447015}
   m_Father: {fileID: 1978127427}
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
@@ -8364,103 +8495,6 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2143643814}
   m_CullTransparentMesh: 1
---- !u!1001 &2300734417490416992
-PrefabInstance:
-  m_ObjectHideFlags: 0
-  serializedVersion: 2
-  m_Modification:
-    serializedVersion: 3
-    m_TransformParent: {fileID: 1886923669}
-    m_Modifications:
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_Pivot.x
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_Pivot.y
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchorMax.x
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchorMax.y
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchorMin.x
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchorMin.y
-      value: 0.5
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_SizeDelta.x
-      value: 200
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_SizeDelta.y
-      value: 50
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalPosition.x
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalPosition.y
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalPosition.z
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalRotation.w
-      value: 1
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalRotation.x
-      value: -0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalRotation.y
-      value: -0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalRotation.z
-      value: -0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchoredPosition.x
-      value: 20
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_AnchoredPosition.y
-      value: 155
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalEulerAnglesHint.x
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalEulerAnglesHint.y
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 243333824829638858, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_LocalEulerAnglesHint.z
-      value: 0
-      objectReference: {fileID: 0}
-    - target: {fileID: 5023658776569483927, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
-      propertyPath: m_Name
-      value: Text (TMP)
-      objectReference: {fileID: 0}
-    m_RemovedComponents: []
-    m_RemovedGameObjects: []
-    m_AddedGameObjects: []
-    m_AddedComponents: []
-  m_SourcePrefab: {fileID: 100100000, guid: 9266beedda7b1cc488a20f1a21ea96bd, type: 3}
 --- !u!1660057539 &9223372036854775807
 SceneRoots:
   m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/Global/CurrentStateData.cs b/Assets/Scripts/Global/CurrentStateData.cs
index a47a2a9..26ffdad 100644
--- a/Assets/Scripts/Global/CurrentStateData.cs
+++ b/Assets/Scripts/Global/CurrentStateData.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using UnityEngine;
 
 public class CurrentStateData
 {
@@ -22,6 +23,7 @@ public class CurrentStateData
         _currentGameData.weapons = new []{true, true, true};
         _currentGameData.dmgMultiplier = 1f;
         _currentGameData.currentPetHealth = -1;
+        _currentGameData.currentShootAccuracy = 0;
     }
 
     public static void SaveStateData()
@@ -76,6 +78,7 @@ public class CurrentStateData
         _currentGameData.weapons = loadedSaveEntry.weapons;
         _currentGameData.currentPetHealth = loadedSaveEntry.currentPetHealth;
         _currentGameData.pets = loadedSaveEntry.pets;
+        _currentGameData.currentShootAccuracy = loadedSaveEntry.currentShootAccuracy;
 
         return true;
     }
@@ -93,7 +96,8 @@ public class CurrentStateData
             currentWeapon = _currentGameData.currentWeapon,
             weapons = _currentGameData.weapons,
             currentPetHealth = _currentGameData.currentPetHealth,
-            pets = _currentGameData.pets
+            pets = _currentGameData.pets,
+            currentShootAccuracy = _currentGameData.currentShootAccuracy
         };
         
         _currentStateData.saveEntries[index] = saveEntry;
@@ -241,8 +245,11 @@ public class CurrentStateData
         return _currentGameData.currentShootAccuracy;
     }
 
-    public static void SetCurrentShootAccuracy(int accuracy)
+    public static int SetCurrentShootAccuracy(int shootInTarget, int shootOutTarget )
     {
-        _currentGameData.currentShootAccuracy = accuracy;
+        float accuracy =  (shootInTarget / shootOutTarget) * 100.0f;
+        float roundedAccuracy = Mathf.Floor(accuracy);
+        _currentGameData.currentShootAccuracy = (int)roundedAccuracy;
+        return _currentGameData.currentShootAccuracy;
     }
 }
\ No newline at end of file
diff --git a/Assets/Scripts/Managers/MainMenuManager.cs b/Assets/Scripts/Managers/MainMenuManager.cs
index fc1ad96..2df29aa 100644
--- a/Assets/Scripts/Managers/MainMenuManager.cs
+++ b/Assets/Scripts/Managers/MainMenuManager.cs
@@ -15,6 +15,8 @@ public class MainMenuManager : MonoBehaviour
     public GameObject loadPanel;
     public GameObject settingsCanvas;
     public GameObject statisticsCanvas;
+    public GameObject statisticsPanel;
+    public TMP_Text shootAccuracyText;
 
     private void Awake()
     {
@@ -102,6 +104,27 @@ public class MainMenuManager : MonoBehaviour
         loadCanvas.SetActive(false);
         statisticsCanvas.SetActive(true);
         settingsCanvas.SetActive(false);
+
+        var saveEntries = CurrentStateData.GetSaveEntries();
+
+        //shootAccuracyText.text = "Score : " + saveEntries[-1].currentShootAccuracy.ToString() + "%";
+        //shootAccuracyText.text = "Score : " + CurrentStateData.GetCurrentShootAccuracy().ToString() + "%";
+        //textsStats.text = saveEntries.saveDateTime.ToString() + " WIB";
+
+        if (saveEntries != null && saveEntries.Length > 0)
+        {
+            // Get the last SaveEntry in the array
+            SaveEntry lastSaveEntry = saveEntries[saveEntries.Length - 1];
+
+            // Set the shootAccuracyText to display the currentShootAccuracy
+            shootAccuracyText.text = "Score : " + lastSaveEntry.currentShootAccuracy.ToString() + "%";
+        }
+        else
+        {
+            // Handle case where saveEntries array is null or empty
+            shootAccuracyText.text = "Score : N/A"; // Display a default value or error message
+            Debug.LogWarning("No save entries found or array is empty.");
+        }
     }
 
     public void CloseStatistic()
diff --git a/Assets/Scripts/Managers/StatisticsCanvasManager.cs b/Assets/Scripts/Managers/StatisticsCanvasManager.cs
index 1e4406b..f2feea3 100644
--- a/Assets/Scripts/Managers/StatisticsCanvasManager.cs
+++ b/Assets/Scripts/Managers/StatisticsCanvasManager.cs
@@ -8,16 +8,16 @@ using UnityEngine.UI;
 namespace Nightmare { 
 public class StatisticsCanvasManager : MonoBehaviour
 {
-    public TMP_Text shootAccuracyText;
+    /*public TMP_Text shootAccuracyText;*/
 
-    public void GetShootAccuracy()
+/*        public void GetShootAccuracy()
         {
             int _receivedShootInTarget = PlayerShooting._shootInTarget;
             int _receveidShootOutTarget = PlayerShooting._shootOutTarget;
             int _shootAccuracy = (_receivedShootInTarget / _receveidShootOutTarget) * 100;
             CurrentStateData.SetCurrentShootAccuracy(_shootAccuracy);
             shootAccuracyText.text = CurrentStateData.GetCurrentShootAccuracy().ToString();
-        }
+        }*/
 
-}
+    }
 }
diff --git a/Assets/Scripts/Player/PlayerShooting.cs b/Assets/Scripts/Player/PlayerShooting.cs
index 661cdd8..d1e2d7e 100644
--- a/Assets/Scripts/Player/PlayerShooting.cs
+++ b/Assets/Scripts/Player/PlayerShooting.cs
@@ -173,7 +173,9 @@ namespace Nightmare
                 gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
             }
             _shootOutTarget += 1;
+            CurrentStateData.SetCurrentShootAccuracy(_shootInTarget, _shootOutTarget);
             Debug.Log("Anda tidak mengenai target : " + _shootOutTarget);
+            Debug.Log("Accuracy : " + CurrentStateData.GetCurrentShootAccuracy());
         }
 
         private void ChangeGunLine(float midPoint)
diff --git a/Assets/Scripts/Utils/SaveEntry.cs b/Assets/Scripts/Utils/SaveEntry.cs
index 19464fe..5d075d9 100644
--- a/Assets/Scripts/Utils/SaveEntry.cs
+++ b/Assets/Scripts/Utils/SaveEntry.cs
@@ -14,4 +14,5 @@ public struct SaveEntry
     public List<int> pets;
     public int currentWeapon;
     public bool[] weapons;
+    public int currentShootAccuracy;
 }
\ No newline at end of file
-- 
GitLab