/// <summary> /// Gets a GameCircle syncable number out of the data map. /// The SyncableNumber retrieved is based on the behavior of this syncable number helper. /// </summary> /// <returns> /// The syncable number. /// </returns> /// <param name='dataMap'> /// GameCircle data map. /// </param> AGSSyncableNumber GetSyncableNumber(AGSGameDataMap dataMap) { if (null == dataMap) { return(null); } // using the behavior and type is a convenient way to create variable names. string variableName = BehaviorAndTypeAsString(); switch (behavior) { case SyncableNumberBehavior.Highest: return(dataMap.GetHighestNumber(variableName)); case SyncableNumberBehavior.Lowest: return(dataMap.GetLowestNumber(variableName)); case SyncableNumberBehavior.Latest: return(dataMap.GetLatestNumber(variableName)); default: AGSClient.LogGameCircleWarning(unhandledSyncableNumberTypeError); return(null); } }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// Whispersync data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // if the datamap is not available, display a message and leave. if (null == dataMap) { AmazonGUIHelpers.CenteredLabel(nullDataMapLabel); return; } // if the hash sets aren't initialize, attempt to initialize them. if (null == hashSets) { InitializeHashSets(dataMap); } // if the hash sets are still null, display a message and leave. if (null == hashSets) { AmazonGUIHelpers.CenteredLabel(nullHashSets); return; } // This button refreshes all hash sets at once. if (GUILayout.Button(refreshAllHashSetsButtonLabel)) { RefreshAllHashSets(); } // display each hash set. foreach (AmazonGameCircleExampleWSHashSet hashSet in hashSets) { hashSet.DrawGUI(); } }
/// <summary> /// Decrements the accumulating number value. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void DecrementValue(AGSGameDataMap dataMap) { // Increments the accumulating number value based on its type. AGSSyncableAccumulatingNumber accumulatingNumber = dataMap.GetAccumulatingNumber(SyncableVariableName()); switch (type) { case AvailableAccumulatingNumberType.Double: accumulatingNumber.Decrement(doubleIncrementValue); break; case AvailableAccumulatingNumberType.Int: accumulatingNumber.Decrement(intIncrementValue); break; case AvailableAccumulatingNumberType.Long: accumulatingNumber.Decrement(longIncrementValue); break; case AvailableAccumulatingNumberType.String: accumulatingNumber.Decrement(stringIncrementValue); break; } // after the decrement is complete, update the value locally. RetrieveAccumulatingNumberValue(dataMap); }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// Whispersync data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // if the datamap is not available, display a message and leave. if(null == dataMap) { AmazonGUIHelpers.CenteredLabel(nullDataMapLabel); return; } // if the hash sets aren't initialize, attempt to initialize them. if(null == hashSets) { InitializeHashSets(dataMap); } // if the hash sets are still null, display a message and leave. if(null == hashSets) { AmazonGUIHelpers.CenteredLabel(nullHashSets); return; } // This button refreshes all hash sets at once. if(GUILayout.Button(refreshAllHashSetsButtonLabel)) { RefreshAllHashSets(); } // display each hash set. foreach(AmazonGameCircleExampleWSHashSet hashSet in hashSets) { hashSet.DrawGUI(); } }
/// <summary> /// Draws an interface for this developer string. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // if the datamap is not available, display a message and leave. if (null == dataMap) { AmazonGUIHelpers.CenteredLabel(nullDataMapLabel); return; } // if the hash sets aren't initialize, attempt to initialize them. if (null == developerString) { InitializeDeveloperString(dataMap); } // if the hash sets are still null, display a message and leave. if (null == developerString) { AmazonGUIHelpers.CenteredLabel(nullDeveloperString); return; } if (GUILayout.Button(refreshDeveloperStringsButtonLabel)) { developerStringKeys = dataMap.getDeveloperStringKeys(); } if (null != developerStringKeys) { foreach (string key in developerStringKeys) { AmazonGUIHelpers.CenteredLabel(key); } } // Display the data available on the developer string AmazonGUIHelpers.CenteredLabel(string.Format(cloudValueLabel, developerString.getCloudValue())); AmazonGUIHelpers.CenteredLabel(string.Format(valueLabel, developerString.getValue())); AmazonGUIHelpers.CenteredLabel(string.Format(inConflictLabel, developerString.inConflict().ToString())); AmazonGUIHelpers.CenteredLabel(string.Format(isSetLabel, developerString.isSet().ToString())); // This button sets the developer string to the developerStringValue. if (GUILayout.Button(string.Format(setValueButtonLabel, developerStringValue))) { developerString.setValue(developerStringValue); // If there was a conflict, mark it was resolved, the value has been set. if (developerString.inConflict()) { developerString.markAsResolved(); } } }
public void Initialize() { GlobaldataMap = AGSWhispersyncClient.GetGameData(); if (GlobaldataMap == null) { Debug.Log("Globaldata map es null"); Managers.GameCircleAmazon.WhisperInitialized = false; return; } Debug.Log("Inicializando WhisperScores"); ScoreList.Clear(); foreach (var packName in Globals.Constants.PackNameArray) { for (var i = 1; i <= Globals.Constants.LevelsPerPack; i++) { foreach (var enumVal in Enum.GetValues(typeof(GameType))) { SyncableLevelScore synclevelscore = new SyncableLevelScore(); synclevelscore.map = GlobaldataMap.GetMap(packName + "@" + enumVal.ToString() + "@LEVEL-" + i.ToString()); synclevelscore.score.BestScore = synclevelscore.map.GetHighestNumber("BestScore"); if (!synclevelscore.score.BestScore.IsSet()) { synclevelscore.score.BestScore.Set(0); } synclevelscore.score.PackName = synclevelscore.map.GetLatestString("PackName"); synclevelscore.score.GameType = synclevelscore.map.GetLatestString("GameType"); synclevelscore.score.LevelName = synclevelscore.map.GetLatestString("LevelName"); synclevelscore.score.PackName.Set(packName); synclevelscore.score.GameType.Set(enumVal.ToString()); synclevelscore.score.LevelName.Set("LEVEL-" + i.ToString()); /* synclevelscore.score.PackName = synclevelscore.map.GetLatestString("PackName"); * synclevelscore.score.GameType = synclevelscore.map.GetLatestString("GameType"); * synclevelscore.score.LevelName = synclevelscore.map.GetLatestString("LevelName"); * synclevelscore.score.Hits = synclevelscore.map.GetLatestNumber("Hits"); * synclevelscore.score.MaxTurns = synclevelscore.map.GetLatestNumber("MaxTurns"); * synclevelscore.score.TimeUsed = synclevelscore.map.GetLatestNumber("TimeUsed"); * */ ScoreList.Add(synclevelscore); } } } }
/// <summary> /// gets the root game datamap /// </summary> /// <returns>Game datamap</returns> public static AGSGameDataMap GetGameData( ) { #if UNITY_ANDROID AndroidJavaObject jo = javaObject.Call <AndroidJavaObject>("getGameData"); if (jo != null) { return(new AGSGameDataMap(new AmazonJavaWrapper(jo))); } return(null); #elif UNITY_IOS if (null == gameDataMapInstance) { gameDataMapInstance = new AGSGameDataMap(); } return(gameDataMapInstance); #else return(null); #endif }
/// <summary> /// Draws an interface for this developer string. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // if the datamap is not available, display a message and leave. if(null == dataMap) { AmazonGUIHelpers.CenteredLabel(nullDataMapLabel); return; } // if the hash sets aren't initialize, attempt to initialize them. if(null == developerString) { InitializeDeveloperString(dataMap); } // if the hash sets are still null, display a message and leave. if(null == developerString) { AmazonGUIHelpers.CenteredLabel(nullDeveloperString); return; } if(GUILayout.Button(refreshDeveloperStringsButtonLabel)) { developerStringKeys = dataMap.getDeveloperStringKeys(); } if(null != developerStringKeys) { foreach(string key in developerStringKeys) { AmazonGUIHelpers.CenteredLabel(key); } } // Display the data available on the developer string AmazonGUIHelpers.CenteredLabel(string.Format(cloudValueLabel,developerString.getCloudValue())); AmazonGUIHelpers.CenteredLabel(string.Format(valueLabel,developerString.getValue())); AmazonGUIHelpers.CenteredLabel(string.Format(inConflictLabel,developerString.inConflict().ToString())); AmazonGUIHelpers.CenteredLabel(string.Format(isSetLabel,developerString.isSet().ToString())); // This button sets the developer string to the developerStringValue. if(GUILayout.Button(string.Format(setValueButtonLabel,developerStringValue))) { developerString.setValue(developerStringValue); // If there was a conflict, mark it was resolved, the value has been set. if(developerString.inConflict()) { developerString.markAsResolved(); } } }
/// <summary> /// Initializes the hash sets. /// </summary> /// <param name='dataMap'> /// Whispersync data map. /// </param> void InitializeHashSets(AGSGameDataMap dataMap) { // bail out if the data map was not valid. if(null == dataMap) { return; } // Initialize the list of hash sets with all functions on the data map that return a hash set. hashSets = new List<AmazonGameCircleExampleWSHashSet>(); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetHighestNumberKeys",dataMap.GetHighestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLowestNumberKeys",dataMap.GetLowestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestNumberKeys",dataMap.GetLatestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetHighNumberListKeys",dataMap.GetHighNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLowNumberListKeys",dataMap.GetLowNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestNumberListKeys",dataMap.GetLatestNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestStringKeys",dataMap.GetLatestStringKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestStringListKeys",dataMap.GetLatestStringListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetStringSetKeys",dataMap.GetStringSetKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetMapKeys",dataMap.GetMapKeys)); }
/// <summary> /// Initializes the syncable number list. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void InitSyncableNumberList(AGSGameDataMap dataMap) { // initialize the list based on what type of list it is. switch (listType) { case AvailableListType.HighNumber: syncableNumberList = dataMap.GetHighNumberList(ListName()); break; case AvailableListType.LatestNumber: syncableNumberList = dataMap.GetLatestNumberList(ListName()); break; case AvailableListType.LowNumber: syncableNumberList = dataMap.GetLowNumberList(ListName()); break; } // cache the size and if the list has been set. maxSize = syncableNumberList.GetMaxSize(); isSet = syncableNumberList.IsSet(); }
/// <summary> /// Initializes the hash sets. /// </summary> /// <param name='dataMap'> /// Whispersync data map. /// </param> void InitializeHashSets(AGSGameDataMap dataMap) { // bail out if the data map was not valid. if (null == dataMap) { return; } // Initialize the list of hash sets with all functions on the data map that return a hash set. hashSets = new List <AmazonGameCircleExampleWSHashSet>(); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetHighestNumberKeys", dataMap.GetHighestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLowestNumberKeys", dataMap.GetLowestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestNumberKeys", dataMap.GetLatestNumberKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetHighNumberListKeys", dataMap.GetHighNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLowNumberListKeys", dataMap.GetLowNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestNumberListKeys", dataMap.GetLatestNumberListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestStringKeys", dataMap.GetLatestStringKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetLatestStringListKeys", dataMap.GetLatestStringListKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetStringSetKeys", dataMap.GetStringSetKeys)); hashSets.Add(new AmazonGameCircleExampleWSHashSet("GetMapKeys", dataMap.GetMapKeys)); }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // put a visual box around this syncable number GUILayout.BeginVertical(GUI.skin.box); // foldouts keep things clean, they let the interface remain // hidden until needed foldoutOpen = AmazonGUIHelpers.FoldoutWithLabel(foldoutOpen, SyncableVariableName()); // Hide the menu if the foldout is not open. if (foldoutOpen) { // If the value has not been retrieved from Whispersync yet, retrieve it. if (!ValueAvailable()) { RetrieveAccumulatingNumberValue(dataMap); } // Show the value. AmazonGUIHelpers.CenteredLabel(ValueLabel()); // This button increments the value. if (GUILayout.Button(incrementButtonLabel)) { IncrementValue(dataMap); } // This button decrements the value. if (GUILayout.Button(decrementButtonLabel)) { DecrementValue(dataMap); } } // Always make sure to match begin and end GUILayout functions. GUILayout.EndVertical(); }
/// <summary> /// Initializes the data map if available. /// </summary> void InitializeDataMapIfAvailable() { // if the data map was already retrieved, nothing to do here. if (null != dataMap) { return; } dataMap = AGSWhispersyncClient.GetGameData(); // if the data map was retrieved for the first time, do // any first-time initialization behavior, such as subscribing // to callbacks. if (null != dataMap) { // subscribe to the new cloud data event. AGSWhispersyncClient.OnNewCloudDataEvent += OnNewCloudData; AGSWhispersyncClient.OnDataUploadedToCloudEvent += OnDataUploadedToCloud; AGSWhispersyncClient.OnThrottledEvent += OnThrottled; AGSWhispersyncClient.OnDiskWriteCompleteEvent += OnDiskWriteComplete; AGSWhispersyncClient.OnFirstSynchronizeEvent += OnFirstSynchronize; AGSWhispersyncClient.OnAlreadySynchronizedEvent += OnAlreadySynchronized; AGSWhispersyncClient.OnSyncFailedEvent += OnSyncFailed; } }
/// <summary> /// Retrieves the accumulating number value from Whispersync. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void RetrieveAccumulatingNumberValue(AGSGameDataMap dataMap) { // Retrieve the accumulating number value from Whispersync, based on its type. AGSSyncableAccumulatingNumber accumulatingNumber = dataMap.GetAccumulatingNumber(SyncableVariableName()); switch (type) { case AvailableAccumulatingNumberType.Double: valueAsDouble = accumulatingNumber.AsDouble(); break; case AvailableAccumulatingNumberType.Int: valueAsInt = accumulatingNumber.AsInt(); break; case AvailableAccumulatingNumberType.Long: valueAsLong = accumulatingNumber.AsLong(); break; case AvailableAccumulatingNumberType.String: valueAsString = accumulatingNumber.AsString(); break; } }
/// <summary> /// Increments the accumulating number value. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void IncrementValue(AGSGameDataMap dataMap) { // Increments the accumulating number value based on its type. AGSSyncableAccumulatingNumber accumulatingNumber = dataMap.GetAccumulatingNumber(SyncableVariableName()); switch(type) { case AvailableAccumulatingNumberType.Double: accumulatingNumber.Increment(doubleIncrementValue); break; case AvailableAccumulatingNumberType.Int: accumulatingNumber.Increment(intIncrementValue); break; case AvailableAccumulatingNumberType.Long: accumulatingNumber.Increment(longIncrementValue); break; case AvailableAccumulatingNumberType.String: accumulatingNumber.Increment(stringIncrementValue); break; } // after the increment is complete, update the value locally. RetrieveAccumulatingNumberValue(dataMap); }
/// <summary> /// gets the root game datamap /// </summary> /// <returns>Game datamap</returns> public static AGSGameDataMap GetGameData( ) { #if UNITY_ANDROID AndroidJavaObject jo = javaObject.Call<AndroidJavaObject>( "getGameData" ); if(jo != null){ return new AGSGameDataMap(new AmazonJavaWrapper(jo)); } return null; #elif UNITY_IOS if(null == gameDataMapInstance) { gameDataMapInstance = new AGSGameDataMap(); } return gameDataMapInstance; #else return null; #endif }
/// <summary> /// Initializes the data map if available. /// </summary> void InitializeDataMapIfAvailable() { // if the data map was already retrieved, nothing to do here. if(null != dataMap) { return; } dataMap = AGSWhispersyncClient.GetGameData(); // if the data map was retrieved for the first time, do // any first-time initialization behavior, such as subscribing // to callbacks. if(null != dataMap) { // subscribe to the new cloud data event. AGSWhispersyncClient.OnNewCloudDataEvent += OnNewCloudData; AGSWhispersyncClient.OnDataUploadedToCloudEvent += OnDataUploadedToCloud; AGSWhispersyncClient.OnThrottledEvent += OnThrottled; AGSWhispersyncClient.OnDiskWriteCompleteEvent += OnDiskWriteComplete; AGSWhispersyncClient.OnFirstSynchronizeEvent += OnFirstSynchronize; AGSWhispersyncClient.OnAlreadySynchronizedEvent += OnAlreadySynchronized; AGSWhispersyncClient.OnSyncFailedEvent += OnSyncFailed; } }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // put a visual box around this syncable number GUILayout.BeginVertical(GUI.skin.box); // foldouts keep things clean, they let the interface remain // hidden until needed foldoutOpen = AmazonGUIHelpers.FoldoutWithLabel(foldoutOpen,SyncableVariableName()); // Hide the menu if the foldout is not open. if(foldoutOpen) { // If the value has not been retrieved from Whispersync yet, retrieve it. if(!ValueAvailable()) { RetrieveAccumulatingNumberValue(dataMap); } // Show the value. AmazonGUIHelpers.CenteredLabel(ValueLabel()); // This button increments the value. if(GUILayout.Button(incrementButtonLabel)) { IncrementValue(dataMap); } // This button decrements the value. if(GUILayout.Button(decrementButtonLabel)) { DecrementValue(dataMap); } } // Always make sure to match begin and end GUILayout functions. GUILayout.EndVertical(); }
/// <summary> /// Initializes the developer string. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> private void InitializeDeveloperString(AGSGameDataMap dataMap) { developerString = dataMap.getDeveloperString(developerStringKey); }
// Use this for initialization void Start() { didScore15 = false; didScore30 = false; didScore50 = false; didScore75 = false; didScore100 = false; guiSkin.button.fontSize = Mathf.Max (Screen.width, Screen.height) / 25; AGSClient.ServiceReadyEvent += serviceReadyHandler; AGSClient.ServiceNotReadyEvent += serviceNotReadyHandler; bool usesLeaderboards = true; bool usesAchievements = true; bool usesWhispersync = true; AGSClient.Init (usesLeaderboards, usesAchievements, usesWhispersync); isServiceReady = AGSClient.IsServiceReady(); // Hook up feedback functions AGSLeaderboardsClient.SubmitScoreSucceededEvent += submitScoreSucceeded; AGSLeaderboardsClient.SubmitScoreFailedEvent += submitScoreFailed; AGSAchievementsClient.UpdateAchievementSucceededEvent += updateAchievementSucceeded; AGSAchievementsClient.UpdateAchievementFailedEvent += updateAchievementFailed; // Whispersync dataMap = AGSWhispersyncClient.GetGameData(); if(dataMap != null){ gamesPlayed = dataMap.GetAccumulatingNumber("gamesPlayed"); } }
/// <summary> /// Draws an interface to interact with a number list. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // make sure necessary variables are available before drawing anything. if (null == dataMap) { AmazonGUIHelpers.CenteredLabel(notInitializedLabel); return; } // make sure the number list is initialized before using it. if (null == syncableNumberList) { InitSyncableNumberList(dataMap); } if (null == syncableNumberList) { AmazonGUIHelpers.CenteredLabel(notInitializedLabel); return; } // putting a box around the list helps visually separate the lists in the menu. GUILayout.BeginVertical(GUI.skin.box); // foldouts help keep menus clean. foldout = AmazonGUIHelpers.FoldoutWithLabel(foldout, ListName()); if (foldout) { // this button refreshes the list, and retrieves elements in it. if (GUILayout.Button(refreshSyncableNumberElementsButtonLabel)) { RefreshList(); } // This label displays if this list has been set. AmazonGUIHelpers.CenteredLabel(string.Format(isListSetLabel, isSet)); // This label displays the max size (if the size has been retrieved). if (maxSize.HasValue) { maxSize = (int)AmazonGUIHelpers.DisplayCenteredSlider((float)maxSize.Value, minMaxSize, maxMaxSize, maxSizeLabel); if (GUILayout.Button(updateMaxSizeButtonLabel)) { syncableNumberList.SetMaxSize(maxSize.Value); } } // if the list is empty, display a message if (null == syncableNumberElementsCache || 0 == syncableNumberElementsCache.Length) { AmazonGUIHelpers.CenteredLabel(emptyListLabel); } // display each element in the list. else { foreach (AmazonGameCircleExampleWSNumberListElementCache cachedElement in syncableNumberElementsCache) { cachedElement.DrawElement(); } } // this button adds some values to the list, increments those values, and refreshes the list. // automatically incrementing values every time they are added allows this menu // to remain simple, without value selection logic. if (GUILayout.Button(addValuesButtonLabel)) { AddValuesToList(); // increment between adding values to make sure the metadata entries are different. IncrementValues(); AddValuesToListWithMetadata(); IncrementValues(); RefreshList(); } } GUILayout.EndVertical(); }
/// <summary> /// Draws an interface to interact with a number list. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // make sure necessary variables are available before drawing anything. if(null == dataMap) { AmazonGUIHelpers.CenteredLabel(notInitializedLabel); return; } // make sure the number list is initialized before using it. if(null == syncableNumberList) { InitSyncableNumberList(dataMap); } if(null == syncableNumberList) { AmazonGUIHelpers.CenteredLabel(notInitializedLabel); return; } // putting a box around the list helps visually separate the lists in the menu. GUILayout.BeginVertical(GUI.skin.box); // foldouts help keep menus clean. foldout = AmazonGUIHelpers.FoldoutWithLabel(foldout,ListName()); if(foldout) { // this button refreshes the list, and retrieves elements in it. if(GUILayout.Button(refreshSyncableNumberElementsButtonLabel)) { RefreshList(); } // This label displays if this list has been set. AmazonGUIHelpers.CenteredLabel(string.Format(isListSetLabel,isSet)); // This label displays the max size (if the size has been retrieved). if(maxSize.HasValue) { maxSize = (int)AmazonGUIHelpers.DisplayCenteredSlider((float)maxSize.Value,minMaxSize,maxMaxSize,maxSizeLabel); if(GUILayout.Button(updateMaxSizeButtonLabel)) { syncableNumberList.SetMaxSize(maxSize.Value); } } // if the list is empty, display a message if(null == syncableNumberElementsCache || 0 == syncableNumberElementsCache.Length) { AmazonGUIHelpers.CenteredLabel(emptyListLabel); } // display each element in the list. else { foreach(AmazonGameCircleExampleWSNumberListElementCache cachedElement in syncableNumberElementsCache) { cachedElement.DrawElement(); } } // this button adds some values to the list, increments those values, and refreshes the list. // automatically incrementing values every time they are added allows this menu // to remain simple, without value selection logic. if(GUILayout.Button(addValuesButtonLabel)) { AddValuesToList(); // increment between adding values to make sure the metadata entries are different. IncrementValues(); AddValuesToListWithMetadata(); IncrementValues(); RefreshList(); } } GUILayout.EndVertical(); }
/// <summary> /// Gets a GameCircle syncable number out of the data map. /// The SyncableNumber retrieved is based on the behavior of this syncable number helper. /// </summary> /// <returns> /// The syncable number. /// </returns> /// <param name='dataMap'> /// GameCircle data map. /// </param> AGSSyncableNumber GetSyncableNumber(AGSGameDataMap dataMap) { if(null == dataMap) { return null; } // using the behavior and type is a convenient way to create variable names. string variableName = BehaviorAndTypeAsString(); switch(behavior) { case SyncableNumberBehavior.Highest: return dataMap.GetHighestNumber(variableName); case SyncableNumberBehavior.Lowest: return dataMap.GetLowestNumber(variableName); case SyncableNumberBehavior.Latest: return dataMap.GetLatestNumber(variableName); default: AGSClient.LogGameCircleWarning(unhandledSyncableNumberTypeError); return null; } }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // put a visual box around this syncable number GUILayout.BeginVertical(GUI.skin.box); // foldouts keep things clean, they let the interface remain // hidden until needed foldoutOpen = AmazonGUIHelpers.FoldoutWithLabel(foldoutOpen,BehaviorAndTypeAsString()); if(foldoutOpen) { // draw the slider for this element, so a user can select a new number. DrawSlider(); // The getValue button will retrieve the current save value for this number. // This syncable number's save name is Behavior:Type. if(GUILayout.Button(string.Format(getValueLabel,BehaviorAndTypeAsString()))) { using(AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)) { if(null != syncableNumber) { GetSyncableValue(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // The setValue button will save this number with Whispersync. // This syncable number's save name is Behavior:Type. if(GUILayout.Button(string.Format(setValueLabel,BehaviorAndTypeAsString()))) { using(AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if(null != syncableNumber) { SetSyncableValue(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // this button sets the syncable value, with some metadata. if(GUILayout.Button(string.Format(setWithMetadataValueLabel,BehaviorAndTypeAsString()))) { using(AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if(null != syncableNumber) { SetSyncableValueWithMetadata(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // This button retrieves the metadata associated with this number. if(GUILayout.Button(string.Format(getMetadataButtonLabel,BehaviorAndTypeAsString()))) { using(AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if(null != syncableNumber) { metadataDictionary = GetMetadata(syncableNumber); } } } DisplayMetadata(); } GUILayout.EndVertical(); }
/// <summary> /// Retrieves the accumulating number value from Whispersync. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void RetrieveAccumulatingNumberValue(AGSGameDataMap dataMap) { // Retrieve the accumulating number value from Whispersync, based on its type. AGSSyncableAccumulatingNumber accumulatingNumber = dataMap.GetAccumulatingNumber(SyncableVariableName()); switch(type) { case AvailableAccumulatingNumberType.Double: valueAsDouble = accumulatingNumber.AsDouble(); break; case AvailableAccumulatingNumberType.Int: valueAsInt = accumulatingNumber.AsInt(); break; case AvailableAccumulatingNumberType.Long: valueAsLong = accumulatingNumber.AsLong(); break; case AvailableAccumulatingNumberType.String: valueAsString = accumulatingNumber.AsString(); break; } }
/// <summary> /// Initializes the syncable number list. /// </summary> /// <param name='dataMap'> /// Data map. /// </param> void InitSyncableNumberList(AGSGameDataMap dataMap) { // initialize the list based on what type of list it is. switch(listType) { case AvailableListType.HighNumber: syncableNumberList = dataMap.GetHighNumberList(ListName()); break; case AvailableListType.LatestNumber: syncableNumberList = dataMap.GetLatestNumberList(ListName()); break; case AvailableListType.LowNumber: syncableNumberList = dataMap.GetLowNumberList(ListName()); break; } // cache the size and if the list has been set. maxSize = syncableNumberList.GetMaxSize(); isSet = syncableNumberList.IsSet(); }
/// <summary> /// Draws an interface for this syncable number helper. /// </summary> /// <param name='dataMap'> /// The GameCircle Data map. /// </param> public void DrawGUI(AGSGameDataMap dataMap) { // put a visual box around this syncable number GUILayout.BeginVertical(GUI.skin.box); // foldouts keep things clean, they let the interface remain // hidden until needed foldoutOpen = AmazonGUIHelpers.FoldoutWithLabel(foldoutOpen, BehaviorAndTypeAsString()); if (foldoutOpen) { // draw the slider for this element, so a user can select a new number. DrawSlider(); // The getValue button will retrieve the current save value for this number. // This syncable number's save name is Behavior:Type. if (GUILayout.Button(string.Format(getValueLabel, BehaviorAndTypeAsString()))) { using (AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)) { if (null != syncableNumber) { GetSyncableValue(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // The setValue button will save this number with Whispersync. // This syncable number's save name is Behavior:Type. if (GUILayout.Button(string.Format(setValueLabel, BehaviorAndTypeAsString()))) { using (AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if (null != syncableNumber) { SetSyncableValue(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // this button sets the syncable value, with some metadata. if (GUILayout.Button(string.Format(setWithMetadataValueLabel, BehaviorAndTypeAsString()))) { using (AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if (null != syncableNumber) { SetSyncableValueWithMetadata(syncableNumber); } } } // a blank label to space things out a bit. GUILayout.Label(GUIContent.none); // This button retrieves the metadata associated with this number. if (GUILayout.Button(string.Format(getMetadataButtonLabel, BehaviorAndTypeAsString()))) { using (AGSSyncableNumber syncableNumber = GetSyncableNumber(dataMap)){ if (null != syncableNumber) { metadataDictionary = GetMetadata(syncableNumber); } } } DisplayMetadata(); } GUILayout.EndVertical(); }