Skip to content
This repository was archived by the owner on Oct 17, 2020. It is now read-only.

Commit c87dbac

Browse files
Merge pull request #59 from PlayFab/mw
Fixed: Issues where Editor Extensions was resetting PlayFabSettings …
2 parents 4acc0ca + d2e1c3f commit c87dbac

File tree

7 files changed

+94
-45
lines changed

7 files changed

+94
-45
lines changed
-11 KB
Binary file not shown.

Source/Assets/NewBehaviourScript.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Source/Assets/NewBehaviourScript.cs.meta

Lines changed: 0 additions & 12 deletions
This file was deleted.

Source/Assets/PlayFabEditorExtensions/Editor/PlayFabEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,13 @@ public void StateUpdateHandler(EdExStates state, string status, string json)
318318
switch(state)
319319
{
320320
case EdExStates.OnMenuItemClicked:
321-
//Debug.Log(string.Format("MenuItem: {0} Clicked", status));
321+
//Debug.Log(string.Format("State: {0} - MenuItem: {1} Clicked", state, status));
322322
PlayFabEditorDataService.editorSettings.currentSubMenu = 0;
323323
PlayFabEditorDataService.SaveEditorSettings();
324324
break;
325325

326326
case EdExStates.OnSubmenuItemClicked:
327+
//Debug.Log(string.Format("State: {0} - SubMenuItem: {1} Clicked", state, status));
327328
int parsed;
328329
if(Int32.TryParse(json, out parsed))
329330
{

Source/Assets/PlayFabEditorExtensions/Editor/Scripts/Components/TitleDataViewer.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
namespace PlayFab.Editor
1+
using System.Linq;
2+
using NUnit.Framework.Constraints;
3+
4+
namespace PlayFab.Editor
25
{
36
using System;
47
using UnityEngine;
58
using UnityEditor;
9+
using System.Collections;
610
using System.Collections.Generic;
711
using EditorModels;
812

@@ -157,18 +161,44 @@ public void SaveRecords()
157161

158162
if(dirtyItems.Count > 0)
159163
{
164+
float nextSeconds = 1f;
165+
foreach (var di in dirtyItems)
166+
{
167+
EditorCoroutine.start( SaveItem(di, nextSeconds) );
168+
nextSeconds += 1f;
169+
}
170+
171+
/*
160172
PlayFabEditorApi.SetTitleData(dirtyItems, (result) =>
161173
{
162174
foreach(var item in items)
163175
{
164176
item.CleanItem();
165177
}
166178
}, PlayFabEditorHelper.SharedErrorCallback);
179+
*/
180+
181+
foreach (var item in items)
182+
{
183+
item.CleanItem();
184+
}
185+
167186
}
168187
}
169188

170189

171190

191+
private IEnumerator SaveItem(KeyValuePair<string,string> dirtyItem, float seconds)
192+
{
193+
yield return new EditorCoroutine.EditorWaitForSeconds(seconds);
194+
//Debug.LogFormat("{0} - Co-Start: {1}", dirtyItem.Key, seconds);
195+
var itemToUpdateDic = new Dictionary<string, string> { { dirtyItem.Key, dirtyItem.Value } };
196+
PlayFabEditorApi.SetTitleData(itemToUpdateDic, (result) =>
197+
{
198+
//Do Nothing with the result.
199+
}, PlayFabEditorHelper.SharedErrorCallback);
200+
}
201+
172202
public TitleDataViewer(List<KvpItem> i = null)
173203
{
174204
this.items = i ?? new List<KvpItem>();

Source/Assets/PlayFabEditorExtensions/Editor/Scripts/Utils/EditorCoroutine.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Net;
1+
using System.Collections.Generic;
2+
using System.Net;
23

34
namespace PlayFab.Editor
45
{
@@ -8,16 +9,40 @@ namespace PlayFab.Editor
89

910
public class EditorCoroutine
1011
{
12+
public string Id;
13+
public class EditorWaitForSeconds : YieldInstruction
14+
{
15+
public float Seconds;
16+
17+
/// <summary>
18+
///
19+
/// <para>
20+
/// Creates a yield instruction to wait for a given number of seconds using scaled time.
21+
/// </para>
22+
///
23+
/// </summary>
24+
/// <param name="seconds"/>
25+
public EditorWaitForSeconds(float seconds)
26+
{
27+
this.Seconds = seconds;
28+
}
29+
}
30+
31+
private SortedList<float, IEnumerator> shouldRunAfterTimes = new SortedList<float, IEnumerator>();
32+
private const float _tick = .02f;
33+
1134
public static EditorCoroutine start(IEnumerator _routine)
1235
{
1336
EditorCoroutine coroutine = new EditorCoroutine(_routine);
37+
coroutine.Id = System.Guid.NewGuid().ToString();
1438
coroutine.start();
1539
return coroutine;
1640
}
1741

1842
public static EditorCoroutine start(IEnumerator _routine, WWW www)
1943
{
2044
EditorCoroutine coroutine = new EditorCoroutine(_routine);
45+
coroutine.Id = System.Guid.NewGuid().ToString();
2146
coroutine._www = www;
2247
coroutine.start();
2348
return coroutine;
@@ -41,8 +66,12 @@ public void stop()
4166
EditorApplication.update -= update;
4267
}
4368

69+
private float _timeCounter = 0;
4470
void update()
4571
{
72+
_timeCounter += _tick;
73+
//Debug.LogFormat("ID:{0} TimeCounter:{1}", this.Id, _timeCounter);
74+
4675
try
4776
{
4877
if (_www != null)
@@ -52,17 +81,35 @@ void update()
5281
stop();
5382
}
5483
}
55-
else
84+
else
5685
{
57-
/* NOTE: no need to try/catch MoveNext,
58-
* if an IEnumerator throws its next iteration returns false.
59-
* Also, Unity probably catches when calling EditorApplication.update.
60-
*/
61-
if (!routine.MoveNext())
86+
var seconds = routine.Current as EditorWaitForSeconds;
87+
if (seconds != null)
88+
{
89+
var wait = seconds;
90+
shouldRunAfterTimes.Add(_timeCounter + wait.Seconds, routine);
91+
}
92+
else if (!routine.MoveNext())
6293
{
6394
stop();
6495
}
6596
}
97+
98+
var shouldRun = shouldRunAfterTimes;
99+
var index = 0;
100+
foreach (var runAfterSeconds in shouldRun)
101+
{
102+
if (_timeCounter >= runAfterSeconds.Key)
103+
{
104+
//Debug.LogFormat("RunAfterSeconds: {0} >= {1}", runAfterSeconds.Key, _timeCounter);
105+
shouldRunAfterTimes.RemoveAt(index);
106+
if (!runAfterSeconds.Value.MoveNext())
107+
{
108+
stop();
109+
}
110+
}
111+
index++;
112+
}
66113
}
67114
catch (System.Exception ex)
68115
{

Source/Assets/PlayFabEditorExtensions/Editor/Scripts/Utils/PlayFabEditorDataService.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,24 @@ public static void LoadEnvDetails()
163163

164164
public static void LoadEditorSettings()
165165
{
166-
if(EditorPrefs.HasKey(keyPrefix+"PlayFab_EditorSettings"))
166+
if (EditorPrefs.HasKey(keyPrefix + "PlayFab_EditorSettings"))
167167
{
168-
var serialized = EditorPrefs.GetString(keyPrefix+"PlayFab_EditorSettings");
168+
var serialized = EditorPrefs.GetString(keyPrefix + "PlayFab_EditorSettings");
169169
try
170170
{
171171
editorSettings = Json.JsonWrapper.DeserializeObject<PlayFab_EditorSettings>(serialized);
172172
LoadFromScriptableObject();
173173
return;
174174
}
175-
catch(Exception ex)
175+
catch (Exception ex)
176176
{
177177
PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnError, ex.Message);
178178
}
179179
}
180-
editorSettings = new PlayFab_EditorSettings();
180+
else
181+
{
182+
editorSettings = new PlayFab_EditorSettings();
183+
}
181184
}
182185

183186
public static void SaveAllData()
@@ -228,8 +231,6 @@ from type in assembly.GetTypes()
228231
PlayFabEditorSDKTools.isSdkSupported = false;
229232
}
230233

231-
232-
233234
#if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
234235
envDetails.developerSecretKey = (string) props.ToList().Find(p => p.Name == "DeveloperSecretKey").GetValue(null, null) ?? envDetails.developerSecretKey;
235236
#else
@@ -316,7 +317,6 @@ public static bool DoesTitleExistInStudios(string searchFor) //out Studio studio
316317
return false;
317318
}
318319

319-
320320
public static bool DoesTitleExistInStudios(string searchFor, out int studioIndex, out int titleIndex) //out Studio studio
321321
{
322322
for(int z = 0; z < PlayFabEditorDataService.accountDetails.studios.Count; z++)
@@ -338,8 +338,6 @@ public static bool DoesTitleExistInStudios(string searchFor, out int studioIndex
338338

339339
}
340340

341-
342-
343341
//CTOR
344342
static PlayFabEditorDataService()
345343
{

0 commit comments

Comments
 (0)