Skip to content

Commit 7be3703

Browse files
committed
⚡ App Services improvements and data model get properties helper
1 parent 324fae0 commit 7be3703

File tree

6 files changed

+40
-55
lines changed

6 files changed

+40
-55
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Reflection;
2+
3+
namespace Unity3dAzure.AppServices
4+
{
5+
/// <summary>
6+
/// Helper methods to check and get object properties
7+
/// </summary>
8+
public class Model {
9+
public static bool HasProperty(object obj, string propertyName)
10+
{
11+
return GetProperty(obj, propertyName) != null;
12+
}
13+
14+
public static PropertyInfo GetProperty(object obj, string propertyName)
15+
{
16+
#if NETFX_CORE
17+
return obj.GetType().GetTypeInfo().GetDeclaredProperty(propertyName); // workaround for GetProperty on Windows
18+
#else
19+
return obj.GetType().GetProperty(propertyName);
20+
#endif
21+
}
22+
}
23+
}

Assets/AppServices/table/MobileServiceTable.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
using System.Collections.Generic;
55
using System;
66

7-
using RestSharp.Deserializers;
8-
using System.Reflection;
9-
107
namespace Unity3dAzure.AppServices
118
{
129
[CLSCompliant(false)]
@@ -56,9 +53,9 @@ public override string ToString()
5653
public void Update<T>(T item, Action<IRestResponse<T>> callback = null) where T : new()
5754
{
5855
// NB: Using Refelection to get 'id' property. Alternatively a DataModel Interface could be used to detect 'id' property
59-
if( HasProperty(item, "id") )
56+
if( Model.HasProperty(item, "id") )
6057
{
61-
var x = GetProperty(item, "id"); //item.GetType().GetProperty("id");
58+
var x = Model.GetProperty(item, "id"); //item.GetType().GetProperty("id");
6259
string id = x.GetValue(item, null) as string;
6360
string uri = URI_TABLES + _name + "/" + id;
6461
ZumoRequest request = new ZumoRequest(_client, uri, Method.PATCH);
@@ -87,20 +84,6 @@ public override string ToString()
8784
Debug.Log( "Lookup Request Uri: " + uri );
8885
_client.ExecuteAsync<T>(request, callback);
8986
}
90-
91-
protected static bool HasProperty(object obj, string propertyName)
92-
{
93-
return GetProperty(obj, propertyName) != null; // obj.GetType().GetProperty(propertyName) != null;
94-
}
95-
96-
protected static PropertyInfo GetProperty(object obj, string propertyName)
97-
{
98-
#if NETFX_CORE
99-
return obj.GetType().GetTypeInfo().GetDeclaredProperty(propertyName); // workaround for GetProperty on Windows
100-
#else
101-
return obj.GetType().GetProperty(propertyName);
102-
#endif
103-
}
10487

10588
}
10689
}

Assets/AppServices/table/query/CustomQuery.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Text;
3+
using UnityEngine;
34

45
namespace Unity3dAzure.AppServices
56
{
@@ -41,11 +42,7 @@ public override string ToString()
4142

4243
private string encode(string url)
4344
{
44-
StringBuilder sb = new StringBuilder(url);
45-
sb.Replace(" ", "%20"); // NB: replace " " with %20 and not with '+'
46-
sb.Replace("'", "%27");
47-
sb.Replace(":", "%3A");
48-
return sb.ToString();
45+
return WWW.EscapeURL(url.Replace("+", "%20")); // NB: replace space with '%20' and not '+'
4946
}
5047

5148
}

Assets/Scenes/InventoryDemo.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ RectTransform:
22552255
m_RootOrder: 0
22562256
m_AnchorMin: {x: 0, y: 1}
22572257
m_AnchorMax: {x: 1, y: 1}
2258-
m_AnchoredPosition: {x: 0, y: 460.00003}
2258+
m_AnchoredPosition: {x: 0, y: 0.000061035156}
22592259
m_SizeDelta: {x: 0, y: 460}
22602260
m_Pivot: {x: 0, y: 1}
22612261
--- !u!114 &986425711
@@ -2930,7 +2930,7 @@ MonoBehaviour:
29302930
m_HandleRect: {fileID: 1803301958}
29312931
m_Direction: 2
29322932
m_Value: 0
2933-
m_Size: 1
2933+
m_Size: 0.99999994
29342934
m_NumberOfSteps: 0
29352935
m_OnValueChanged:
29362936
m_PersistentCalls:

Assets/Scripts/InventoryDemo.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,14 @@ private void ReloadTableData()
257257
return;
258258
}
259259

260+
// Inventory data model properties
260261
string[] properties = { "strawberries", "melons", "lemons", "medicine" };
261262
foreach (string property in properties)
262263
{
263-
if (Utils.HasProperty (_inventory, property)) {
264-
var x = Utils.GetProperty(_inventory, property);
264+
if (Model.HasProperty (_inventory, property)) {
265+
var x = Model.GetProperty(_inventory, property);
265266
Nullable<int> value = x.GetValue(_inventory, null) as Nullable<int>;
266267
int amount = value ?? 0;
267-
Debug.Log ("Row "+ property + " Amount:" + amount);
268268
if (amount > 0) {
269269
InventoryItem item = new InventoryItem ();
270270
item.name = property;
@@ -333,21 +333,3 @@ public class InventoryItem {
333333
public int amount;
334334
}
335335

336-
/// <summary>
337-
/// Helper methods to check and get object properties
338-
/// </summary>
339-
public class Utils {
340-
public static bool HasProperty(object obj, string propertyName)
341-
{
342-
return GetProperty(obj, propertyName) != null;
343-
}
344-
345-
public static PropertyInfo GetProperty(object obj, string propertyName)
346-
{
347-
#if NETFX_CORE
348-
return obj.GetType().GetTypeInfo().GetDeclaredProperty(propertyName); // workaround for GetProperty on Windows
349-
#else
350-
return obj.GetType().GetProperty(propertyName);
351-
#endif
352-
}
353-
}

ProjectSettings/GraphicsSettings.asset

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ GraphicsSettings:
4444
useReflectionProbeBoxProjection: 0
4545
useReflectionProbeBlending: 0
4646
m_ShaderSettings_Tier2:
47-
useCascadedShadowMaps: 1
48-
standardShaderQuality: 2
49-
useReflectionProbeBoxProjection: 1
50-
useReflectionProbeBlending: 1
47+
useCascadedShadowMaps: 0
48+
standardShaderQuality: 1
49+
useReflectionProbeBoxProjection: 0
50+
useReflectionProbeBlending: 0
5151
m_ShaderSettings_Tier3:
52-
useCascadedShadowMaps: 1
53-
standardShaderQuality: 2
54-
useReflectionProbeBoxProjection: 1
55-
useReflectionProbeBlending: 1
52+
useCascadedShadowMaps: 0
53+
standardShaderQuality: 1
54+
useReflectionProbeBoxProjection: 0
55+
useReflectionProbeBlending: 0
5656
m_BuildTargetShaderSettings: []
5757
m_LightmapStripping: 0
5858
m_FogStripping: 0

0 commit comments

Comments
 (0)