Skip to content

Commit 905fcd9

Browse files
Updates to Script Logic
Now can easily set Winter event campaign and also User.Score JEXL Audience Target
1 parent 3a13d35 commit 905fcd9

6 files changed

Lines changed: 96 additions & 34 deletions

File tree

Assets/Editor/RemoteConfig/Data/RemoteConfigDataStoreAsset.asset

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: 469c24fdb3bd6431b92cc1465bd9166b, type: 3}
1313
m_Name: RemoteConfigDataStoreAsset
1414
m_EditorClassIdentifier:
15-
_rsKeyList: "[\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"c16e1c18-a2df-42e6-b384-5746527d54ac\"\r\n
15+
_rsKeyList: "[\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"953b1421-7d82-47c7-a3ad-fa5ed7cf045d\"\r\n
1616
},\r\n \"rs\": {\r\n \"key\": \"ActiveHat\",\r\n \"type\": \"int\",\r\n
17-
\"value\": 5\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
18-
\"20cee204-9d92-48be-a5ee-3d48999d323f\"\r\n },\r\n \"rs\": {\r\n
19-
\"key\": \"Language\",\r\n \"type\": \"string\",\r\n \"value\": \"French\"\r\n
20-
}\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"6df60ee2-27ea-4d5c-abae-529caeb2230f\"\r\n
17+
\"value\": 1\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
18+
\"7e73a560-4c84-4510-8f1a-e65567e324ea\"\r\n },\r\n \"rs\": {\r\n
19+
\"key\": \"Language\",\r\n \"type\": \"string\",\r\n \"value\": \"English\"\r\n
20+
}\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"09781f68-252d-4a41-8263-df85a5e9a3b9\"\r\n
2121
},\r\n \"rs\": {\r\n \"key\": \"CharacterSize\",\r\n \"type\": \"float\",\r\n
2222
\"value\": 1.0\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
23-
\"ec2ce514-7fff-4871-90d4-8c0825b077c1\"\r\n },\r\n \"rs\": {\r\n
23+
\"7e142985-b288-4f5b-8a04-d65f7f331e7d\"\r\n },\r\n \"rs\": {\r\n
2424
\"key\": \"CharacterSpeed\",\r\n \"type\": \"float\",\r\n \"value\":
25-
3.0\r\n }\r\n }\r\n]"
26-
_rsLastCachedKeyList: "[\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"c16e1c18-a2df-42e6-b384-5746527d54ac\"\r\n
25+
4.0\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"f7fca076-39d4-45c4-b7f7-53b8e869ff94\"\r\n
26+
},\r\n \"rs\": {\r\n \"key\": \"Season\",\r\n \"type\": \"string\",\r\n
27+
\"value\": \"Winter\"\r\n }\r\n }\r\n]"
28+
_rsLastCachedKeyList: "[\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"953b1421-7d82-47c7-a3ad-fa5ed7cf045d\"\r\n
2729
},\r\n \"rs\": {\r\n \"key\": \"ActiveHat\",\r\n \"type\": \"int\",\r\n
28-
\"value\": 5\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
29-
\"20cee204-9d92-48be-a5ee-3d48999d323f\"\r\n },\r\n \"rs\": {\r\n
30-
\"key\": \"Language\",\r\n \"type\": \"string\",\r\n \"value\": \"French\"\r\n
31-
}\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"6df60ee2-27ea-4d5c-abae-529caeb2230f\"\r\n
30+
\"value\": 1\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
31+
\"7e73a560-4c84-4510-8f1a-e65567e324ea\"\r\n },\r\n \"rs\": {\r\n
32+
\"key\": \"Language\",\r\n \"type\": \"string\",\r\n \"value\": \"English\"\r\n
33+
}\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"09781f68-252d-4a41-8263-df85a5e9a3b9\"\r\n
3234
},\r\n \"rs\": {\r\n \"key\": \"CharacterSize\",\r\n \"type\": \"float\",\r\n
3335
\"value\": 1.0\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\":
34-
\"ec2ce514-7fff-4871-90d4-8c0825b077c1\"\r\n },\r\n \"rs\": {\r\n
36+
\"7e142985-b288-4f5b-8a04-d65f7f331e7d\"\r\n },\r\n \"rs\": {\r\n
3537
\"key\": \"CharacterSpeed\",\r\n \"type\": \"float\",\r\n \"value\":
36-
3.0\r\n }\r\n }\r\n]"
38+
4.0\r\n }\r\n },\r\n {\r\n \"metadata\": {\r\n \"entityId\": \"f7fca076-39d4-45c4-b7f7-53b8e869ff94\"\r\n
39+
},\r\n \"rs\": {\r\n \"key\": \"Season\",\r\n \"type\": \"string\",\r\n
40+
\"value\": \"Winter\"\r\n }\r\n }\r\n]"
3741
_environments: "[\r\n {\r\n \"projectId\": \"6425f585-dcf3-48ce-9486-732852d3a59e\",\r\n
3842
\"name\": \"production\",\r\n \"id\": \"951304dd-2b96-421c-ace2-a944d56b2948\",\r\n
3943
\"isDefault\": true,\r\n \"createdAt\": \"2021-08-12T18:16:15Z\",\r\n \"updatedAt\":

Assets/Scripts/ApplyRemoteConfigSettings.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class ApplyRemoteConfigSettings : MonoBehaviour
1717

1818
// We'll be using these variables throughout the project
1919
public string language = "English";
20+
public string season = "Default";
2021
public float characterSize = 1.0f;
2122
public float characterSpeed = 1.0f;
2223
public int activeHat = 0;
@@ -28,10 +29,11 @@ public class ApplyRemoteConfigSettings : MonoBehaviour
2829
public struct userAttributes
2930
{
3031
// Optionally declare variables for any custom user attributes:
31-
// This variable can be updated as the game progresses and then used in Campaign Audience Targeting!
32+
// These variables can be updated as the game progresses and then used in Campaign Audience Targeting!
33+
public int score;
3234

33-
// user.inventory.item
34-
// user.levelsCompleted
35+
// items inventory[]
36+
// levelsCompleted
3537
}
3638

3739
public struct appAttributes
@@ -59,6 +61,7 @@ async Task InitializeRemoteConfigAsync()
5961
}
6062
}
6163

64+
// Simple Instance set-up
6265
void Awake()
6366
{
6467
if (Instance == null)
@@ -71,14 +74,18 @@ void Awake()
7174
}
7275
}
7376

77+
// Async start() function
7478
async void Start()
7579
{
7680
// call with await keyword our async Task function
7781
await InitializeRemoteConfigAsync();
7882

83+
userAttributes uaStruct = new userAttributes();
84+
uaStruct.score = 10;
85+
7986
// Fetch the Dashboard Remote Config from RemoteConfigManager
8087
// We also append the userAttributes and appAttributes struct in our Fetch request
81-
ConfigManager.FetchConfigs<userAttributes, appAttributes>(new userAttributes(){}, new appAttributes(){});
88+
ConfigManager.FetchConfigs<userAttributes, appAttributes>(uaStruct, new appAttributes(){});
8289

8390
// Optional Settings
8491
// Set the user’s unique ID:
@@ -115,16 +122,18 @@ private void RemoteConfigLoaded(ConfigResponse configResponse)
115122
}
116123

117124
activeHat = ConfigManager.appConfig.GetInt("ActiveHat");
125+
//Debug.Log("RC Active Hat " + (ConfigManager.appConfig.GetInt("ActiveHat")));
118126

119-
Debug.Log("RC Size " + (ConfigManager.appConfig.GetFloat("CharacterSize")));
120127

121128
characterSize = ConfigManager.appConfig.GetFloat("CharacterSize");
129+
//Debug.Log("RC Size " + (ConfigManager.appConfig.GetFloat("CharacterSize")));
122130

123-
Debug.Log("RC Speed " + (ConfigManager.appConfig.GetFloat("CharacterSpeed")));
124131

125132
characterSpeed = ConfigManager.appConfig.GetFloat("CharacterSpeed");
133+
//Debug.Log("RC Speed " + (ConfigManager.appConfig.GetFloat("CharacterSpeed")));
126134

127-
Debug.Log("RC Active Hat " + (ConfigManager.appConfig.GetInt("ActiveHat")));
135+
season = ConfigManager.appConfig.GetString("Season");
136+
//Debug.Log("RC Season " + (ConfigManager.appConfig.GetString("Season")));
128137
break;
129138
}
130139
}

Assets/Scripts/GameManager.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,27 @@
44

55
public class GameManager : MonoBehaviour
66
{
7+
public static GameManager Instance {get; private set;}
8+
79
public static int s_CurrentLevel = 0;
810

911
public static int s_MaxAvailableLevel = 5;
1012

1113
// The value of -1 means no hats have been purchased
1214
public static int s_ActiveHat = 0;
1315

16+
public void Awake()
17+
{
18+
if (Instance == null)
19+
{
20+
Instance = this;
21+
}
22+
else
23+
{
24+
Destroy(gameObject);
25+
}
26+
}
27+
1428
public void OnEnable()
1529
{
1630
// When we go to the
@@ -22,6 +36,11 @@ public void ExitGame()
2236
s_CurrentLevel = 0;
2337
}
2438

39+
public void SetCurrentLevel(int level)
40+
{
41+
s_CurrentLevel = level;
42+
}
43+
2544
public static void LoadNextLevel()
2645
{
2746
// We are going to be using the Addressables API to manage our scene loading and unloading, the equivalent way on the UnityEngine.SceneManagement API is:

Assets/Scripts/Loading.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ private void OnSceneLoaded(AsyncOperationHandle obj)
6060

6161
public void GoToNextLevel()
6262
{
63-
Addressables.LoadSceneAsync("Level_0" + GameManager.s_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Single, true);
63+
if(ApplyRemoteConfigSettings.Instance.season != "Winter")
64+
{
65+
Addressables.LoadSceneAsync("Level_0" + GameManager.s_CurrentLevel, UnityEngine.SceneManagement.LoadSceneMode.Single, true);
66+
}
67+
68+
// Else If the season is supposed to be Winter
69+
else if (ApplyRemoteConfigSettings.Instance.season == "Winter")
70+
{
71+
Debug.LogError("InsideGoToNextLevel()");
72+
Addressables.LoadSceneAsync("Level_0" + "4", UnityEngine.SceneManagement.LoadSceneMode.Single, true);
73+
}
6474
}
6575

6676
private void Update()

Assets/Scripts/PlayerConfigurator.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,25 @@ void Start()
2323
if(GameManager.s_ActiveHat >= 0)
2424
{
2525
//SetHat(string.Format("Hat{0:00}", UnityEngine.Random.Range(0, 4)));
26-
26+
2727
// Fetch the correct hat variable from the ApplyRemoteConfigSettings instance
28-
Debug.Log("SetHat Format: " + string.Format("Hat{0:00}", remoteConfigScript.activeHat));
29-
SetHat(string.Format("Hat{0:00}", remoteConfigScript.activeHat));
3028

29+
if (ApplyRemoteConfigSettings.Instance.season == "Default")
30+
{
31+
//Debug.Log("Formatted String 2 " + string.Format("Hat{0:00}", remoteConfigScript.activeHat));
32+
33+
SetHat(string.Format("Hat{0:00}", remoteConfigScript.activeHat));
34+
}
35+
36+
else if (ApplyRemoteConfigSettings.Instance.season == "Winter")
37+
{
38+
SetHat(string.Format("Hat{0:00}", "04"));
39+
}
40+
41+
else if (ApplyRemoteConfigSettings.Instance.season == "Halloween")
42+
{
43+
SetHat(string.Format("Hat{0:00}", "05"));
44+
}
3145

3246
// hatKey is an Addressable Label
3347
//Debug.Log("Hat String: " + string.Format("Hat{0:00}", UnityEngine.Random.Range(0, 4)));

Assets/Scripts/PlayerController.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ public class PlayerController : MonoBehaviour
88
private ApplyRemoteConfigSettings rcInstance;
99

1010
[SerializeField]
11-
private float m_MovementSpeed = 5.0f;
11+
private float m_MovementSpeed = 5.0f, m_CharacterSize = 1.0f;
1212

1313
[SerializeField]
1414
private Animator m_AnimatorController;
1515

1616
[SerializeField]
1717
private LayerMask m_InputCollisionLayer;
1818

19-
[SerializeField]
20-
private GameManager m_GameManager;
19+
// [SerializeField]
20+
// private GameManager m_GameManager;
2121

2222
private bool m_HasKey = false;
2323

@@ -33,16 +33,14 @@ public class PlayerController : MonoBehaviour
3333

3434
void Awake()
3535
{
36-
rcInstance = new ApplyRemoteConfigSettings();
36+
rcInstance = ApplyRemoteConfigSettings.Instance;
37+
38+
SetMovementSpeed(rcInstance.characterSpeed);
39+
SetCharacterSize(rcInstance.characterSize);
3740
}
3841

3942
void Start()
4043
{
41-
if (rcInstance)
42-
{
43-
SetMovementSpeed(rcInstance.characterSpeed);
44-
}
45-
4644
m_Rigidbody = GetComponent<Rigidbody>();
4745
m_MainCamera = Camera.main;
4846
}
@@ -162,5 +160,13 @@ void ApplyMoveToPosition()
162160
public void SetMovementSpeed(float speed)
163161
{
164162
m_MovementSpeed = speed;
163+
Debug.Log("Movement Speed Set! " + m_MovementSpeed);
164+
}
165+
166+
public void SetCharacterSize(float size)
167+
{
168+
m_CharacterSize = size;
169+
gameObject.transform.localScale = new Vector3(m_CharacterSize,m_CharacterSize,m_CharacterSize);
170+
Debug.Log("Local Scale Set! " + gameObject.transform.localScale);
165171
}
166172
}

0 commit comments

Comments
 (0)