/// <summary> /// Retrieves an existing record from the Spark service by ID. /// </summary> /// <returns>The record's data.</returns> /// <param name="id">Identifier.</param> /// <param name="type">SparkType being retrieved.</param> /// <param name="error">Error.</param> /// <param name="result">Result.</param> public IEnumerator GetRecord(string id, SparkType type, Action <SparkMessage> error, Action <Dictionary <string, object> > result) { var url = string.Format("{0}/{1}", type.GetEndpoint(), id); var send = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, result); yield return(StartCoroutine(send)); }
/// <summary> /// Returns the API Resource Name for this SparkType. /// </summary> /// <param name="type">The SparkType.</param> /// <returns>URL Endpoint string.</returns> public static string GetEndpoint(this SparkType type) { switch (type) { case SparkType.Membership: return("memberships"); case SparkType.Room: return("rooms"); case SparkType.Person: return("people"); case SparkType.Team: return("teams"); case SparkType.TeamMembership: return("team/memberships"); case SparkType.Message: return("messages"); case SparkType.Webhook: return("webhooks"); default: throw new System.Exception("SparkType must have a registered endpoint"); } }
/// <summary> /// Creates the record. /// </summary> /// <returns>The record.</returns> /// <param name="data">Data.</param> /// <param name="type">Type.</param> /// <param name="error">Error.</param> /// <param name="result">Result.</param> public IEnumerator CreateRecord(Dictionary<string, object> data, SparkType type, Action<SparkMessage> error, Action<Dictionary<string, object>> result) { // Create request. var recordDetails = System.Text.Encoding.UTF8.GetBytes(Json.Serialize(data)); var url = type.GetEndpoint(); var send = SendRequest(url, UnityWebRequest.kHttpVerbPOST, recordDetails, error, result); yield return StartCoroutine(send); }
/// <summary> /// Create a new Webhook locally. /// </summary> /// <param name="name">A user-friendly name for this Webhook.</param> /// <param name="target">The URL that receives POST requests for each event.</param> /// <param name="resource">The resource type for the Webhook. Creating a webhook requires 'read' scope on the resource the webhook is for.</param> /// <param name="webhookEvent">The event type for the Webhook.</param> /// <param name="filter">The filter that defines the webhook scope.</param> /// <param name="secret">Secret used to generate payload signature.</param> public Webhook(string name, Uri target, SparkType resource, string webhookEvent, string filter = null, string secret = null) { Name = name; Target = target; Resource = resource; Event = webhookEvent; Filter = filter; Secret = secret; }
/// <summary> /// Updates the record. /// </summary> /// <returns>The record.</returns> /// <param name="id">Identifier.</param> /// <param name="data">Data.</param> /// <param name="type">Type.</param> /// <param name="error">Error.</param> /// <param name="result">Result.</param> public IEnumerator UpdateRecord(string id, Dictionary <string, object> data, SparkType type, Action <SparkMessage> error, Action <Dictionary <string, object> > result) { // Update Record. var recordDetails = System.Text.Encoding.UTF8.GetBytes(Json.Serialize(data)); var url = type.GetEndpoint() + "/" + id; var send = SendRequest(url, UnityWebRequest.kHttpVerbPUT, recordDetails, error, result); yield return(StartCoroutine(send)); }
/// <summary> /// Deletes the record from Spark. /// </summary> /// <returns>The record.</returns> /// <param name="id">Identifier.</param> /// <param name="type">Type.</param> /// <param name="error">Error.</param> /// <param name="success">Success.</param> public IEnumerator DeleteRecord(string id, SparkType type, Action<SparkMessage> error, Action<bool> success) { // Create Request. var url = type.GetEndpoint() + "/" + id; var send = SendRequest(url, UnityWebRequest.kHttpVerbDELETE, null, error, result => { success(true); }); yield return StartCoroutine(send); }
/// <summary> /// Deletes the record from Spark. /// </summary> /// <returns>The record.</returns> /// <param name="id">Identifier.</param> /// <param name="type">Type.</param> /// <param name="error">Error.</param> /// <param name="success">Success.</param> public IEnumerator DeleteRecord(string id, SparkType type, Action <SparkMessage> error, Action <bool> success) { // Create Request. var url = type.GetEndpoint() + "/" + id; var send = SendRequest(url, UnityWebRequest.kHttpVerbDELETE, null, error, result => { success(true); }); yield return(StartCoroutine(send)); }
/// <summary> /// Retrieves multiple records from the Spark service. /// </summary> /// <param name="constraints">Any constraints on the results returned. See ApiConstrains.json for SparkType specific options.</param> /// <param name="type">The SparkType to retrieve.</param> /// <param name="error">Error from Spark, if any.</param> /// <param name="result">List of de-serialised results as dictionaries.</param> public IEnumerator ListRecords(Dictionary <string, string> constraints, SparkType type, Action <SparkMessage> error, Action <List <object> > result) { string queryString = System.Text.Encoding.UTF8.GetString(UnityWebRequest.SerializeSimpleForm(constraints)); string url = string.Format("{0}?{1}", type.GetEndpoint(), queryString); var operation = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, data => { var items = data["items"] as List <object>; result(items); }); yield return(StartCoroutine(operation)); }
/// <summary> Create spark visual effect and start play sound spark /// <param name = "pos"> Create position visual effect</param> /// </summary> public void CreateSparkEffect(Vector2 pos, SparkType sparkType = SparkType.DefaultSpark) { List <ParticleSystem> sparks = null; ParticleSystem sparkPrefab = null; List <AudioClipPreset> sounds = null; switch (sparkType) { case SparkType.RaySpark: { sparks = RaySparks; sparkPrefab = B.Resource.Prefabs.RaySparkPrefab; sounds = RaySparkSounds; break; } default: { sparks = Sparks; sparkPrefab = B.Resource.Prefabs.SparkPrefab; sounds = SparkSounds; break; } } ParticleSystem spark = null; for (int i = 0; i < sparks.Count; i++) { if (!sparks[i].gameObject.activeInHierarchy) { spark = sparks[i]; } } if (spark == null) { spark = Instantiate(sparkPrefab, transform); sparks.Add(spark); } spark.SetActive(true); spark.transform.position = pos; SparkSoundIndex = SparkSoundIndex >= sounds.Count - 1 ? 0 : SparkSoundIndex + 1; SoundController.PlaySound(sounds[SparkSoundIndex]); StartCoroutine(HideObjectWithDellay(spark.gameObject, SparkHideTime)); }
public void MoveProperties(float hitstun, float blockstun, float pushback, float damage, int moveTypeInt, int hitTypeInt, int sparkTypeInt, float superBuilt = 3f) { enforceHitStun = hitstun; enforceBlockStun = blockstun; enforcePushBack = pushback; enforceDamage = damage; accumulateSuper = superBuilt; switch (moveTypeInt) { case 0: moveType = MoveType.low; break; case 1: moveType = MoveType.mid; break; default: moveType = MoveType.high; break; } switch (hitTypeInt) { case 0: hitType = HitType.normal; break; case 1: hitType = HitType.sweep; break; case 2: hitType = HitType.normalKnockDown; break; case 3: hitType = HitType.shoryuken; break; case 4: hitType = HitType.hurricaneKick; break; case 5: hitType = HitType.rekka; break; case 6: hitType = HitType.dashLow; break; case 7: hitType = HitType.akumaHurricaneKick; break; case 8: hitType = HitType.bisonSweep; break; default: hitType = HitType.otherKnockDown; break; } switch (sparkTypeInt) { case 0: sparkType = SparkType.normal; break; case 1: sparkType = SparkType.big; break; default: sparkType = SparkType.shoryuken; break; } }
/// <summary> /// Returns a list of a given SparkObject type matching the API constraints offered. /// </summary> /// <param name="constraints">Dictionary of URL constraints the request takes.</param> /// <param name="type">The SparkType being searched.</param> /// <param name="error">The error from Spark, if any.</param> /// <param name="result">The resultant list of the given SparkObject typeparamref name="T".</param> /// <typeparam name="T">The SparkObject child being searched for.</param> protected static IEnumerator ListObjects <T>(Dictionary <string, string> constraints, SparkType type, Action <SparkMessage> error, Action <List <T> > result) where T : SparkObject { var listRoutine = Request.Instance.ListRecords(constraints, type, error, success => { List <T> retrivedObjects = new List <T>(); foreach (var sparkObject in success) { var details = sparkObject as Dictionary <string, object>; var newSparkObject = (T)Activator.CreateInstance(typeof(T), details["id"] as string); newSparkObject.LoadDict(details); retrivedObjects.Add(newSparkObject); } result(retrivedObjects); }); yield return(Request.Instance.StartCoroutine(listRoutine)); }
/// <summary> /// Retrieves multiple records from the Spark service. /// </summary> /// <param name="constraints">Any constraints on the results returned. See ApiConstrains.json for SparkType specific options.</param> /// <param name="type">The SparkType to retrieve.</param> /// <param name="error">Error from Spark, if any.</param> /// <param name="result">List of de-serialised results as dictionaries.</param> public IEnumerator ListRecords(Dictionary<string, string> constraints, SparkType type, Action<SparkMessage> error, Action<List<object>> result) { string queryString = System.Text.Encoding.UTF8.GetString(UnityWebRequest.SerializeSimpleForm(constraints)); string url = string.Format("{0}?{1}", type.GetEndpoint(), queryString); var operation = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, data => { var items = data["items"] as List<object>; result(items); }); yield return StartCoroutine(operation); }
/// <summary> /// Retrieves an existing record from the Spark service by ID. /// </summary> /// <returns>The record's data.</returns> /// <param name="id">Identifier.</param> /// <param name="type">SparkType being retrieved.</param> /// <param name="error">Error.</param> /// <param name="result">Result.</param> public IEnumerator GetRecord(string id, SparkType type, Action<SparkMessage> error, Action<Dictionary<string, object>> result) { var url = string.Format("{0}/{1}", type.GetEndpoint(), id); var send = SendRequest(url, UnityWebRequest.kHttpVerbGET, null, error, result); yield return StartCoroutine(send); }