Skip to content

Commit bfcf260

Browse files
committed
fix: Use app settings
1 parent fe04ce6 commit bfcf260

File tree

17 files changed

+345
-233
lines changed

17 files changed

+345
-233
lines changed

Assets/_BossFight/Resources/BF_Settings.prefab

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
--- !u!1 &165316
44
GameObject:
55
m_ObjectHideFlags: 0
6-
m_PrefabParentObject: {fileID: 0}
7-
m_PrefabInternal: {fileID: 100100000}
8-
serializedVersion: 5
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
910
m_Component:
1011
- component: {fileID: 427038}
1112
- component: {fileID: 11423690}
13+
- component: {fileID: 2040626121319543717}
1214
- component: {fileID: 11476276}
1315
- component: {fileID: 11477830}
1416
m_Layer: 0
@@ -20,46 +22,63 @@ GameObject:
2022
m_IsActive: 1
2123
--- !u!4 &427038
2224
Transform:
23-
m_ObjectHideFlags: 1
24-
m_PrefabParentObject: {fileID: 0}
25-
m_PrefabInternal: {fileID: 100100000}
25+
m_ObjectHideFlags: 0
26+
m_CorrespondingSourceObject: {fileID: 0}
27+
m_PrefabInstance: {fileID: 0}
28+
m_PrefabAsset: {fileID: 0}
2629
m_GameObject: {fileID: 165316}
2730
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
2831
m_LocalPosition: {x: 0, y: 0, z: 0}
2932
m_LocalScale: {x: 1, y: 1, z: 1}
33+
m_ConstrainProportionsScale: 0
3034
m_Children: []
3135
m_Father: {fileID: 0}
3236
m_RootOrder: 0
3337
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3438
--- !u!114 &11423690
3539
MonoBehaviour:
36-
m_ObjectHideFlags: 1
37-
m_PrefabParentObject: {fileID: 0}
38-
m_PrefabInternal: {fileID: 100100000}
40+
m_ObjectHideFlags: 0
41+
m_CorrespondingSourceObject: {fileID: 0}
42+
m_PrefabInstance: {fileID: 0}
43+
m_PrefabAsset: {fileID: 0}
3944
m_GameObject: {fileID: 165316}
4045
m_Enabled: 1
4146
m_EditorHideFlags: 0
4247
m_Script: {fileID: 11500000, guid: 44537bddf53394d4ba5246f002f0fbb0, type: 3}
4348
m_Name:
4449
m_EditorClassIdentifier:
45-
mType: 0
50+
--- !u!114 &2040626121319543717
51+
MonoBehaviour:
52+
m_ObjectHideFlags: 0
53+
m_CorrespondingSourceObject: {fileID: 0}
54+
m_PrefabInstance: {fileID: 0}
55+
m_PrefabAsset: {fileID: 0}
56+
m_GameObject: {fileID: 165316}
57+
m_Enabled: 1
58+
m_EditorHideFlags: 0
59+
m_Script: {fileID: 11500000, guid: e15937d15e61fb34cbf14c466ec06293, type: 3}
60+
m_Name:
61+
m_EditorClassIdentifier:
4662
--- !u!114 &11476276
4763
MonoBehaviour:
48-
m_ObjectHideFlags: 1
49-
m_PrefabParentObject: {fileID: 0}
50-
m_PrefabInternal: {fileID: 100100000}
64+
m_ObjectHideFlags: 0
65+
m_CorrespondingSourceObject: {fileID: 0}
66+
m_PrefabInstance: {fileID: 0}
67+
m_PrefabAsset: {fileID: 0}
5168
m_GameObject: {fileID: 165316}
5269
m_Enabled: 1
5370
m_EditorHideFlags: 0
5471
m_Script: {fileID: 11500000, guid: 9764ce3382cb2f94a9fe5100d919e8c9, type: 3}
5572
m_Name:
5673
m_EditorClassIdentifier:
74+
mFullFilePath:
75+
mFullFileName:
5776
CHARACTERS_IN_TEAM: 2
5877
CHARACTERS_IN_GAME:
59-
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 2}
60-
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 2}
61-
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 2}
62-
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 2}
78+
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 3}
79+
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 3}
80+
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 3}
81+
- {fileID: 11474578, guid: 73ce54cd4bf0c4247a77c697d93cd090, type: 3}
6382
FILE_PATH: SavedData/
6483
FILE_NAME: BF_GameData
6584
TOTAL_MOB_IN_SCENE: 15
@@ -68,24 +87,14 @@ MonoBehaviour:
6887
LEVEL_SELECTED_NAME:
6988
--- !u!114 &11477830
7089
MonoBehaviour:
71-
m_ObjectHideFlags: 1
72-
m_PrefabParentObject: {fileID: 0}
73-
m_PrefabInternal: {fileID: 100100000}
90+
m_ObjectHideFlags: 0
91+
m_CorrespondingSourceObject: {fileID: 0}
92+
m_PrefabInstance: {fileID: 0}
93+
m_PrefabAsset: {fileID: 0}
7494
m_GameObject: {fileID: 165316}
7595
m_Enabled: 1
7696
m_EditorHideFlags: 0
7797
m_Script: {fileID: 11500000, guid: 9163d7bc70d879d4fa24769c3703d4c1, type: 3}
7898
m_Name:
7999
m_EditorClassIdentifier:
80100
EXP_BASE: 'Get exp '
81-
--- !u!1001 &100100000
82-
Prefab:
83-
m_ObjectHideFlags: 1
84-
serializedVersion: 2
85-
m_Modification:
86-
m_TransformParent: {fileID: 0}
87-
m_Modifications: []
88-
m_RemovedComponents: []
89-
m_ParentPrefab: {fileID: 0}
90-
m_RootGameObject: {fileID: 165316}
91-
m_IsPrefabParent: 1

Assets/_BossFight/Scripts/BF_GoldObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ protected override void Awake()
4242
/// <param name="other"> collider detection if needed. </param>
4343
public void AfterPicked(Collider other)
4444
{
45-
BF_GameSettings.GAME_DATA.Cash += mCashValue;
45+
BF_AppSettings.instance.APP_DATA.Cash += mCashValue;
4646
}
4747
}

Assets/_BossFight/Scripts/SaveLoad/BF_GameData.cs renamed to Assets/_BossFight/Scripts/SaveLoad/BF_AppData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* $File: BF_GameData.cs $
2+
* $File: BF_AppData.cs $
33
* $Date: $
44
* $Revision: $
55
* $Creator: Jen-Chieh Shen $
@@ -13,7 +13,7 @@
1313
/// Game Data design here.
1414
/// </summary>
1515
[Serializable] // NOTE(jenchieh): we need this for `JCS_BinGameData'.
16-
public class BF_GameData : JCS_BinData
16+
public class BF_AppData : JCS_BinData
1717
{
1818
/* Variables */
1919

@@ -47,7 +47,7 @@ public struct ItemIdInclude
4747

4848
/* Functions */
4949

50-
public BF_GameData()
50+
public BF_AppData()
5151
{
5252

5353
// get the length of the enum.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* $File: BF_AppSettings.cs $
3+
* $Date: $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright (c) 2023 by Shen, Jen-Chieh $
8+
*/
9+
using System.IO;
10+
using UnityEngine;
11+
using JCSUnity;
12+
using MyBox;
13+
14+
public class BF_AppSettings : JCS_Settings<BF_AppSettings>
15+
{
16+
/* Variables */
17+
18+
[Separator("Check Variables (BF_GameSettings)")]
19+
20+
[SerializeField]
21+
[ReadOnly]
22+
private string mFullFilePath = "";
23+
24+
[SerializeField]
25+
[ReadOnly]
26+
private string mFullFileName = "";
27+
28+
[Separator("Runtime Variables (BF_AppSettings)")]
29+
30+
[Header("- Save Load")]
31+
32+
public string FILE_PATH = "SavedData/";
33+
34+
public string FILE_NAME = "BF_AppData";
35+
36+
public BF_AppData APP_DATA = null;
37+
38+
/* Setter & Getter */
39+
40+
/* Functions */
41+
42+
private void Awake()
43+
{
44+
instance = CheckSingleton(instance, this);
45+
}
46+
47+
private void Start()
48+
{
49+
// IMPORTANT: initial the path before save and load!
50+
InitPath();
51+
52+
// only load once
53+
if (APP_DATA == null)
54+
LoadAppData();
55+
56+
// set load and save game data
57+
var apps = JCS_ApplicationSettings.instance;
58+
apps.SAVE_APP_DATA_FUNC = SaveAppData;
59+
apps.LOAD_APP_DATA_FUNC = LoadAppData;
60+
}
61+
62+
/// <summary>
63+
/// Instead of Unity Engine's scripting layer's DontDestroyOnLoad.
64+
/// I would like to use own define to transfer the old instance
65+
/// to the newer instance.
66+
///
67+
/// Every time when unity load the scene. The script have been
68+
/// reset, in order not to lose the original setting.
69+
/// transfer the data from old instance to new instance.
70+
/// </summary>
71+
/// <param name="_old"> old instance </param>
72+
/// <param name="_new"> new instance </param>
73+
protected override void TransferData(BF_AppSettings _old, BF_AppSettings _new)
74+
{
75+
_new.APP_DATA = _old.APP_DATA;
76+
}
77+
78+
/// <summary>
79+
/// Initialize the path base on the JCSUnity Framework's
80+
/// format.
81+
/// </summary>
82+
private void InitPath()
83+
{
84+
var apps = JCS_ApplicationSettings.instance;
85+
86+
mFullFilePath = JCS_Path.Combine(Application.persistentDataPath, apps.DATA_PATH, FILE_PATH);
87+
mFullFileName = FILE_NAME + apps.DATA_EXTENSION;
88+
}
89+
90+
private void LoadAppData()
91+
{
92+
JCS_IO.CreateDirectory(mFullFilePath);
93+
94+
// if file does not exist, create the default value file!
95+
if (!File.Exists(mFullFilePath + mFullFileName))
96+
{
97+
CreateDefaultGameData();
98+
return;
99+
}
100+
101+
// else we just load the data commonly.
102+
APP_DATA = BF_AppData.LoadFromFile<BF_AppData>(mFullFilePath, mFullFileName);
103+
}
104+
105+
/// <summary>
106+
/// Use only when player "First" play this game or
107+
/// "Reset" the game.
108+
/// </summary>
109+
private void CreateDefaultGameData()
110+
{
111+
APP_DATA = new BF_AppData();
112+
113+
// Set game data's default values
114+
{
115+
APP_DATA.Name = "";
116+
APP_DATA.Cash = 1500; // [default: 1500]
117+
}
118+
119+
SaveAppData();
120+
}
121+
122+
private void SaveAppData()
123+
{
124+
if (APP_DATA == null)
125+
{
126+
JCS_Debug.LogError("Save Data without data");
127+
return;
128+
}
129+
130+
APP_DATA.Save<BF_AppData>(mFullFilePath, mFullFileName);
131+
}
132+
}

Assets/_BossFight/Scripts/Settings/BF_AppSettings.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)