public static void AnimateMessage(SwrveMessageFormat format) { if (Animator != null) { Animator.AnimateMessage(format); } }
/// <summary> /// Get all the assets in the in-app message. /// </summary> /// <returns> /// All the assets in the in-app message. /// </returns> public List <string> ListOfAssets() { List <string> messageAssets = new List <string> (); for (int fi = 0; fi < Formats.Count; fi++) { SwrveMessageFormat format = Formats[fi]; for (int ii = 0; ii < format.Images.Count; ii++) { SwrveImage image = format.Images[ii]; if (!string.IsNullOrEmpty(image.File)) { messageAssets.Add(image.File); } } for (int bi = 0; bi < format.Buttons.Count; bi++) { SwrveButton button = format.Buttons[bi]; if (!string.IsNullOrEmpty(button.Image)) { messageAssets.Add(button.Image); } } } return(messageAssets); }
public static void InitMessage(SwrveMessageFormat format, SwrveOrientation deviceOrientation) { if (Animator != null) { Animator.InitMessage(format); } else { format.Init(deviceOrientation); format.InitAnimation(new Point(0, 0), new Point(0, 0)); } }
/// <summary> /// Notify that the message was shown to the user. This function /// has to be called only once when the message is displayed to /// the user. /// This is automatically called by the SDK and will only need /// to be manually called if you are implementing your own /// in-app message rendering code. /// </summary> public void MessageWasShownToUser(SwrveMessageFormat messageFormat) { base.WasShownToUser(); if (Messages.Count > 0) { if (!RandomOrder) { int nextMessage = (Next + 1) % Messages.Count; Next = nextMessage; SwrveLog.Log("Round Robin: Next message in campaign " + Id + " is " + nextMessage); } else { SwrveLog.Log("Next message in campaign " + Id + " is random"); } } }
/// <summary> /// Load an in-app message from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="messageData"> /// JSON object with the individual message data. /// </param> /// <returns> /// Parsed in-app message. /// </returns> public static SwrveMessage LoadFromJSON(SwrveSDK sdk, SwrveMessagesCampaign campaign, Dictionary <string, object> messageData) { SwrveMessage message = new SwrveMessage(sdk, campaign); message.Id = MiniJsonHelper.GetInt(messageData, "id"); message.Name = (string)messageData ["name"]; if (messageData.ContainsKey("priority")) { message.Priority = MiniJsonHelper.GetInt(messageData, "priority"); } Dictionary <string, object> template = (Dictionary <string, object>)messageData ["template"]; IList <object> jsonFormats = (List <object>)template ["formats"]; for (int i = 0, j = jsonFormats.Count; i < j; i++) { Dictionary <string, object> messageFormatData = (Dictionary <string, object>)jsonFormats [i]; SwrveMessageFormat messageFormat = SwrveMessageFormat.LoadFromJSON(sdk, message, messageFormatData); message.Formats.Add(messageFormat); } return(message); }
public static void DrawMessage(SwrveMessageFormat format, int centerx, int centery) { if (Animator != null) { AnimateMessage(format); } if (format.BackgroundColor.HasValue && GetBlankTexture() != null) { Color backgroundColor = format.BackgroundColor.Value; backgroundColor.a = backgroundColor.a * format.Message.BackgroundAlpha; GUI.color = backgroundColor; WholeScreen.width = Screen.width; WholeScreen.height = Screen.height; GUI.DrawTexture(WholeScreen, blankTexture, ScaleMode.StretchToFill, true, 10.0f); GUI.color = Color.white; } bool rotatedFormat = format.Rotate; // Rotate the inner message if necessary if (rotatedFormat) { Vector2 pivotPoint = new Vector2(centerx, centery); GUIUtility.RotateAroundPivot(90, pivotPoint); } float scale = format.Scale * format.Message.AnimationScale; GUI.color = Color.white; // Draw images for (int ii = 0; ii < format.Images.Count; ii++) { SwrveImage image = format.Images[ii]; if (image.Texture != null) { float computedSize = scale * image.AnimationScale; Point centerPoint = image.GetCenteredPosition(image.Texture.width, image.Texture.height, computedSize, scale); centerPoint.X += centerx; centerPoint.Y += centery; image.Rect.x = centerPoint.X; image.Rect.y = centerPoint.Y; image.Rect.width = image.Texture.width * computedSize; image.Rect.height = image.Texture.height * computedSize; GUI.DrawTexture(image.Rect, image.Texture, ScaleMode.StretchToFill, true, 10.0f); } else { GUI.Box(image.Rect, image.File); } } // Draw buttons for (int bi = 0; bi < format.Buttons.Count; bi++) { SwrveButton button = format.Buttons[bi]; if (button.Texture != null) { float computedSize = scale * button.AnimationScale; Point centerPoint = button.GetCenteredPosition(button.Texture.width, button.Texture.height, computedSize, scale); button.Rect.x = centerPoint.X + centerx; button.Rect.y = centerPoint.Y + centery; button.Rect.width = button.Texture.width * computedSize; button.Rect.height = button.Texture.height * computedSize; if (rotatedFormat) { // Rotate 90 degrees the hit area Point widgetCenter = button.GetCenter(button.Texture.width, button.Texture.height, computedSize); button.PointerRect.x = centerx - (button.Position.Y * scale) + widgetCenter.Y; button.PointerRect.y = centery + (button.Position.X * scale) + widgetCenter.X; button.PointerRect.width = button.Rect.height; button.PointerRect.height = button.Rect.width; } else { button.PointerRect = button.Rect; } if (Animator != null) { Animator.AnimateButtonPressed(button); } else { GUI.color = (button.Pressed) ? ButtonPressedColor : Color.white; } GUI.DrawTexture(button.Rect, button.Texture, ScaleMode.StretchToFill, true, 10.0f); } else { GUI.Box(button.Rect, button.Image); } GUI.color = Color.white; } // Do closing logic if ((Animator == null && format.Closing) || (Animator != null && Animator.IsMessageDismissed(format))) { format.Dismissed = true; format.UnloadAssets(); } }
/// <summary> /// Load an in-app message format from a JSON response. /// </summary> /// <param name="message"> /// Parent in-app message. /// </param> /// <param name="messageFormatData"> /// JSON object with the individual message format data. /// </param> /// <returns> /// Parsed in-app message format. /// </returns> public static SwrveMessageFormat LoadFromJSON(SwrveSDK sdk, SwrveMessage message, Dictionary <string, object> messageFormatData) { SwrveMessageFormat messageFormat = new SwrveMessageFormat(message); messageFormat.Name = (string)messageFormatData ["name"]; messageFormat.Language = (string)messageFormatData ["language"]; if (messageFormatData.ContainsKey("scale")) { messageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1); } if (messageFormatData.ContainsKey("orientation")) { messageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData ["orientation"]); } messageFormat.BackgroundColor = sdk.DefaultBackgroundColor; if (messageFormatData.ContainsKey("color")) { string strColor = (string)messageFormatData ["color"]; Color? c = messageFormat.BackgroundColor; if (strColor.Length == 8) { // RRGGBB byte a = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte r = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, a); } else if (strColor.Length == 6) { // AARRGGBB byte r = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, 255); } messageFormat.BackgroundColor = c; } Dictionary <string, object> sizeJson = (Dictionary <string, object>)messageFormatData ["size"]; messageFormat.Size.X = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["w"]), "value"); messageFormat.Size.Y = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["h"]), "value"); IList <object> jsonButtons = (List <object>)messageFormatData ["buttons"]; for (int i = 0, j = jsonButtons.Count; i < j; i++) { SwrveButton button = LoadButtonFromJSON(message, (Dictionary <string, object>)jsonButtons [i]); messageFormat.Buttons.Add(button); } IList <object> jsonImages = (List <object>)messageFormatData ["images"]; for (int ii = 0, ji = jsonImages.Count; ii < ji; ii++) { SwrveImage image = LoadImageFromJSON(message, (Dictionary <string, object>)jsonImages [ii]); messageFormat.Images.Add(image); } return(messageFormat); }