public static Vector4 ToVector4(JSONObject obj) {
			float x = obj["x"] ? obj["x"].f : 0;
			float y = obj["y"] ? obj["y"].f : 0;
			float z = obj["z"] ? obj["z"].f : 0;
			float w = obj["w"] ? obj["w"].f : 0;
			return new Vector4(x, y, z, w);
		}
		public static Matrix4x4 ToMatrix4x4(JSONObject obj) {
			Matrix4x4 result = new Matrix4x4();
			if(obj["m00"]) result.m00 = obj["m00"].f;
			if(obj["m01"]) result.m01 = obj["m01"].f;
			if(obj["m02"]) result.m02 = obj["m02"].f;
			if(obj["m03"]) result.m03 = obj["m03"].f;
			if(obj["m10"]) result.m10 = obj["m10"].f;
			if(obj["m11"]) result.m11 = obj["m11"].f;
			if(obj["m12"]) result.m12 = obj["m12"].f;
			if(obj["m13"]) result.m13 = obj["m13"].f;
			if(obj["m20"]) result.m20 = obj["m20"].f;
			if(obj["m21"]) result.m21 = obj["m21"].f;
			if(obj["m22"]) result.m22 = obj["m22"].f;
			if(obj["m23"]) result.m23 = obj["m23"].f;
			if(obj["m30"]) result.m30 = obj["m30"].f;
			if(obj["m31"]) result.m31 = obj["m31"].f;
			if(obj["m32"]) result.m32 = obj["m32"].f;
			if(obj["m33"]) result.m33 = obj["m33"].f;
			return result;
		}
		public static Keyframe ToKeyframe(JSONObject obj){
			Keyframe k = new Keyframe(obj.HasField("time")? obj.GetField("time").f : 0, obj.HasField("value")? obj.GetField("value").f : 0);
			if(obj.HasField("inTangent")) k.inTangent = obj.GetField("inTangent").f;
			if(obj.HasField("outTangent")) k.outTangent = obj.GetField("outTangent").f;
			if(obj.HasField("tangentMode")) k.tangentMode = (int)obj.GetField("tangentMode").f;
			
			return k;
		}
		public static AnimationCurve ToAnimationCurve(JSONObject obj){
			AnimationCurve a = new AnimationCurve();
			if(obj.HasField("keys")){
				JSONObject keys = obj.GetField("keys");
				for(int i =0; i < keys.list.Count;i++){
					a.AddKey(ToKeyframe(keys[i]));
				}
			}
			if(obj.HasField("preWrapMode"))
				a.preWrapMode = (WrapMode)((int)obj.GetField("preWrapMode").n);
			if(obj.HasField("postWrapMode"))
				a.postWrapMode = (WrapMode)((int)obj.GetField("postWrapMode").n);
			return a;
		}
		public static RectOffset ToRectOffset(JSONObject obj) {
			RectOffset r = new RectOffset();
			for(int i = 0; i < obj.Count; i++) {
				switch(obj.keys[i]) {
				case "bottom": r.bottom = (int)obj[i].n; break;
				case "left": r.left = (int)obj[i].n; break;
				case "right": r.right =	(int)obj[i].n; break;
				case "top": r.top = (int)obj[i].n; break;
				}
			}
			return r;
		}
		public void Absorb(JSONObject obj) {
			list.AddRange(obj.list);
			keys.AddRange(obj.keys);
			str = obj.str;
			n = obj.n;
			b = obj.b;
			type = obj.type;
		}
Example #7
0
		private void ParseData(JSONObject item) {
			
			var settings = this.socialModule.GetSettings<FBSettings>();
			var mainPhoto = settings.profileMainPhoto;

			var picture = item.GetField("picture");
			if (picture.isContainer == true) {

				picture = picture.GetField("data");
				if (picture.isContainer == true) {

					var url = picture.GetField("url").str;
					this.photoIsDefault = picture.GetField("is_silhouette").b;
					SocialSystem.LoadImage(mainPhoto == "photo_50", this.photo_50 = url, (texture, result) => this.photo_50_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));

				}

			}

			var items = item.GetField("devices");
			if (items != null && items.IsArray == true) {

				this.devices = new List<UserDevice>();
				foreach (var device in items.list) {

					this.devices.Add(new UserDevice(device));

				}

			}

			this.SetSex(item.GetField("gender").str);
			this.SetUserID(item.GetField("id").str);
			this.SetUserName(item.GetField("name").str);

			this.bdate = item.GetField("birthday").str;
			
			this.about = item.GetField("about").str;
			this.bio = item.GetField("bio").str;
			this.installed = item.GetField("installed").b;
			this.is_verified = item.GetField("is_verified").b;
			this.link = item.GetField("link").str;
			this.locale = item.GetField("locale").str;
			this.political = item.GetField("political").str;
			this.relationship_status = item.GetField("relationship_status").str;
			this.religion = item.GetField("religion").str;
			this.quotes = item.GetField("quotes").str;
			this.third_party_id = item.GetField("third_party_id").str;
			this.timezone = item.GetField("timezone").f;
			this.token_for_business = item.GetField("token_for_business").str;
			this.verified = item.GetField("verified").b;
			this.website = item.GetField("website").str;

			this.SetAuthenticated(true);
			this.SetState(UnityEngine.SocialPlatforms.UserState.Online);

		}
Example #8
0
		// Is avatar default?

		protected override void OnUserParse() {
			
			var data = new JSONObject(this.userData);
			this.ParseData(data);

		}
Example #9
0
		private void ParseData(JSONObject item) {
			
			this.SetSex((int)item.GetField("sex").n);
			this.SetUserID(item.GetField("uid").d.ToString());
			this.SetUserName(string.Format("{0} {1}", item.GetField("first_name").str, item.GetField("last_name").str));
			
			this.onlineState = (int)item.GetField("online").n;
			
			this.SetAuthenticated(true);
			this.SetState(UnityEngine.SocialPlatforms.UserState.Online);
			
			var settings = this.socialModule.GetSettings<VKSettings>();
			var mainPhoto = settings.profileMainPhoto;
			
			SocialSystem.LoadImage(mainPhoto == "photo_50", this.photo_50 = item.GetField("photo_50").str,				(texture, result) => this.photo_50_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_100", this.photo_100 = item.GetField("photo_100").str,				(texture, result) => this.photo_100_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_200_orig", this.photo_200_orig = item.GetField("photo_200_orig").str,	(texture, result) => this.photo_200_orig_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_200", this.photo_200 = item.GetField("photo_200").str,				(texture, result) => this.photo_200_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_400_orig", this.photo_400_orig = item.GetField("photo_400_orig").str,	(texture, result) => this.photo_400_orig_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_max", this.photo_max = item.GetField("photo_max").str,				(texture, result) => this.photo_max_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));
			SocialSystem.LoadImage(mainPhoto == "photo_max_orig", this.photo_max_orig = item.GetField("photo_max_orig").str,	(texture, result) => this.photo_max_orig_image = texture as Texture2D, (texture) => this.SetImage(texture as Texture2D));

		}
Example #10
0
		// site	returns a website address from a user profile.
		
		protected override void OnUserParse() {
			
			var data = new JSONObject(this.userData);
			
			var field = data.GetField("response");
			if (field.IsArray == true) {
				
				var item = field.list[0];
				
				this.ParseData(item);
				
			}
			
		}
		/// <summary>
		/// Merge object right into left recursively
		/// </summary>
		/// <param name="left">The left (base) object</param>
		/// <param name="right">The right (new) object</param>
		static void MergeRecur(JSONObject left, JSONObject right) {
			if(left.type == Type.NULL)
				left.Absorb(right);
			else if(left.type == Type.OBJECT && right.type == Type.OBJECT) {
				for(int i = 0; i < right.list.Count; i++) {
					string key = right.keys[i];
					if(right[i].isContainer) {
						if(left.HasField(key))
							MergeRecur(left[key], right[i]);
						else
							left.AddField(key, right[i]);
					} else {
						if(left.HasField(key))
							left.SetField(key, right[i]);
						else
							left.AddField(key, right[i]);
					}
				}
			} else if(left.type == Type.ARRAY && right.type == Type.ARRAY) {
				if(right.Count > left.Count) {
					Debug.LogError("Cannot merge arrays when right object has more elements");
					return;
				}
				for(int i = 0; i < right.list.Count; i++) {
					if(left[i].type == right[i].type) {			//Only overwrite with the same type
						if(left[i].isContainer)
							MergeRecur(left[i], right[i]);
						else {
							left[i] = right[i];
						}
					}
				}
			}
		}
		/*
		 * The Merge function is experimental. Use at your own risk.
		 */
		public void Merge(JSONObject obj) {
			MergeRecur(this, obj);
		}
		public void SetField(string name, JSONObject obj) {
			if(HasField(name)) {
				list.Remove(this[name]);
				keys.Remove(name);
			}
			AddField(name, obj);
		}
		public void AddField(string name, JSONObject obj) {
			if(obj) {		//Don't do anything if the object is null
				if(type != Type.OBJECT) {
					if(keys == null)
						keys = new List<string>();
					if(type == Type.ARRAY) {
						for(int i = 0; i < list.Count; i++)
							keys.Add(i + "");
					} else
						if(list == null)
							list = new List<JSONObject>();
					type = Type.OBJECT;		//Congratulations, son, you're an OBJECT now
				}
				keys.Add(name);
				list.Add(obj);
			}
		}
		public void Add(JSONObject obj) {
			if(obj) {		//Don't do anything if the object is null
				if(type != Type.ARRAY) {
					type = Type.ARRAY;		//Congratulations, son, you're an ARRAY now
					if(list == null)
						list = new List<JSONObject>();
				}
				list.Add(obj);
			}
		}
		public static Vector3 ToVector3(JSONObject obj) {
			float x = obj["x"] ? obj["x"].f : 0;
			float y = obj["y"] ? obj["y"].f : 0;
			float z = obj["z"] ? obj["z"].f : 0;
			return new Vector3(x, y, z);
		}
		public static Quaternion ToQuaternion(JSONObject obj) {
			float x = obj["x"] ? obj["x"].f : 0;
			float y = obj["y"] ? obj["y"].f : 0;
			float z = obj["z"] ? obj["z"].f : 0;
			float w = obj["w"] ? obj["w"].f : 0;
			return new Quaternion(x, y, z, w);
		}
		public static Color ToColor(JSONObject obj) {
			Color c = new Color();
			for(int i = 0; i < obj.Count; i++) {
				switch(obj.keys[i]) {
				case "r": c.r = obj[i].f; break;
				case "g": c.g = obj[i].f; break;
				case "b": c.b = obj[i].f; break;
				case "a": c.a = obj[i].f; break;
				}
			}
			return c;
		}
		/*
		 * Vector2
		 */
		public static Vector2 ToVector2(JSONObject obj) {
			float x = obj["x"] ? obj["x"].f : 0;
			float y = obj["y"] ? obj["y"].f : 0;
			return new Vector2(x, y);
		}
		public static LayerMask ToLayerMask(JSONObject obj) {
			LayerMask l = new LayerMask {value = (int)obj["value"].n};
			return l;
		}
Example #21
0
		public override List<ISocialUser> ParseUsers(string inputData) {
			
			var result = new List<ISocialUser>();

			var data = new JSONObject(inputData);

			var field = data.GetField("data");
			if (field.IsArray == true) {

				foreach (var item in field.list) {
					
					var user = new FBLocalUser();
					user.socialModule = this.socialModule;
					user.userData = item.ToString();
					user.ParseData(item);

					result.Add(user);
					
				}

			}

			return result;
			
		}
		public static Rect ToRect(JSONObject obj) {
			Rect r = new Rect();
			for(int i = 0; i < obj.Count; i++) {
				switch(obj.keys[i]) {
				case "x": r.x = obj[i].f; break;
				case "y": r.y = obj[i].f; break;
				case "height": r.height = obj[i].f; break;
				case "width": r.width = obj[i].f; break;
				}
			}
			return r;
		}
		public UserDevice(JSONObject json) {

			this.hardware = json.GetField("hardware").str;
			this.os = json.GetField("os").str;

		}
		public JSONObject(JSONObject[] objs) {
			type = Type.ARRAY;
			list = new List<JSONObject>(objs);
		}