コード例 #1
0
        public HashSet <SwrveAssetsQueueItem> SetOfAssets()
        {
            HashSet <SwrveAssetsQueueItem> hashSet = new HashSet <SwrveAssetsQueueItem>();

            for (int i = 0; i < this.Formats.Count; i++)
            {
                SwrveMessageFormat swrveMessageFormat = this.Formats[i];
                for (int j = 0; j < swrveMessageFormat.Images.Count; j++)
                {
                    SwrveImage swrveImage = swrveMessageFormat.Images[j];
                    if (!string.IsNullOrEmpty(swrveImage.File))
                    {
                        hashSet.Add(new SwrveAssetsQueueItem(swrveImage.File, swrveImage.File, true));
                    }
                }
                for (int k = 0; k < swrveMessageFormat.Buttons.Count; k++)
                {
                    SwrveButton swrveButton = swrveMessageFormat.Buttons[k];
                    if (!string.IsNullOrEmpty(swrveButton.Image))
                    {
                        hashSet.Add(new SwrveAssetsQueueItem(swrveButton.Image, swrveButton.Image, true));
                    }
                }
            }
            return(hashSet);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <summary>
        /// Get all the assets in the in-app message.
        /// </summary>
        /// <returns>
        /// All the assets in the in-app message.
        /// </returns>
        public HashSet <SwrveAssetsQueueItem> SetOfAssets()
        {
            HashSet <SwrveAssetsQueueItem> messageAssets = new HashSet <SwrveAssetsQueueItem> ();

            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(new SwrveAssetsQueueItem(image.File, image.File, true));
                    }
                }

                for (int bi = 0; bi < format.Buttons.Count; bi++)
                {
                    SwrveButton button = format.Buttons[bi];
                    if (!string.IsNullOrEmpty(button.Image))
                    {
                        messageAssets.Add(new SwrveAssetsQueueItem(button.Image, button.Image, true));
                    }
                }
            }
            return(messageAssets);
        }
コード例 #4
0
        public static SwrveMessageFormat LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveMessage message, Dictionary <string, object> messageFormatData, Color?defaultBackgroundColor)
        {
            SwrveMessageFormat swrveMessageFormat = new SwrveMessageFormat(message);

            swrveMessageFormat.Name     = (string)messageFormatData["name"];
            swrveMessageFormat.Language = (string)messageFormatData["language"];
            if (messageFormatData.ContainsKey("scale"))
            {
                swrveMessageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1f);
            }
            if (messageFormatData.ContainsKey("orientation"))
            {
                swrveMessageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData["orientation"]);
            }
            swrveMessageFormat.BackgroundColor = defaultBackgroundColor;
            if (messageFormatData.ContainsKey("color"))
            {
                string text            = (string)messageFormatData["color"];
                Color? backgroundColor = swrveMessageFormat.BackgroundColor;
                if (text.Length == 8)
                {
                    byte a = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber);
                    byte r = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber);
                    byte g = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber);
                    byte b = byte.Parse(text.Substring(6, 2), NumberStyles.HexNumber);
                    backgroundColor = new Color32(r, g, b, a);
                }
                else if (text.Length == 6)
                {
                    byte r = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber);
                    byte g = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber);
                    byte b = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber);
                    backgroundColor = new Color32(r, g, b, byte.MaxValue);
                }
                swrveMessageFormat.BackgroundColor = backgroundColor;
            }
            Dictionary <string, object> dictionary = (Dictionary <string, object>)messageFormatData["size"];

            swrveMessageFormat.Size.X = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["w"], "value");
            swrveMessageFormat.Size.Y = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["h"], "value");
            IList <object> list = (List <object>)messageFormatData["buttons"];
            int            i    = 0;

            for (int count = list.Count; i < count; i++)
            {
                SwrveButton item = LoadButtonFromJSON(message, (Dictionary <string, object>)list[i]);
                swrveMessageFormat.Buttons.Add(item);
            }
            IList <object> list2 = (List <object>)messageFormatData["images"];
            int            j     = 0;

            for (int count2 = list2.Count; j < count2; j++)
            {
                SwrveImage item2 = LoadImageFromJSON(message, (Dictionary <string, object>)list2[j]);
                swrveMessageFormat.Images.Add(item2);
            }
            return(swrveMessageFormat);
        }
コード例 #5
0
        public void InitMessage(SwrveMessageFormat format, SwrveInAppMessageConfig inAppConfig, SwrveOrientation deviceOrientation, bool afterRotation = false)
        {
            this.format = format;
            format.Init(deviceOrientation);
            renderBackgroundColor = format.BackgroundColor.HasValue;

            if (!afterRotation)
            {
                if (animator != null)
                {
                    animator.InitMessage(format);
                }
                else
                {
                    format.InitAnimation(new Point(0, 0), new Point(0, 0));
                }
            }

            // Create widgets to render and use the cached personalization values
            widgetViews = new SwrveWidgetView[format.Images.Count + format.Buttons.Count];
            int eindex = 0;

            for (int ii = 0; ii < format.Images.Count; ii++)
            {
                SwrveImage      image = format.Images[ii];
                SwrveWidgetView renderer;
                if (image.Text != null)
                {
                    // Get cached resolved template
                    string resolvedTextTemplate = templatingResolver.TextResolution[image];
                    renderer = new SwrveMessagePersonalizedWidgetView(image, resolvedTextTemplate, inAppConfig);
                }
                else
                {
                    renderer = new SwrveImageView(image);
                }
                widgetViews[eindex++] = renderer;
            }
            for (int bi = 0; bi < format.Buttons.Count; bi++)
            {
                SwrveButton     button = format.Buttons[bi];
                SwrveWidgetView renderer;
                if (button.Text != null)
                {
                    string resolvedTextTemplate = templatingResolver.TextResolution[button];
                    renderer = new SwrveMessagePersonalizedWidgetView(button, resolvedTextTemplate, inAppConfig);
                }
                else
                {
                    renderer = new SwrveButtonView(button, inAppConfig.ButtonClickTintColor);
                }
                widgetViews[eindex++] = renderer;
            }
        }
コード例 #6
0
        protected static SwrveImage LoadImageFromJSON(SwrveMessage message, Dictionary <string, object> imageData)
        {
            SwrveImage swrveImage = new SwrveImage();

            swrveImage.Position.X = IntValueFromAttribute(imageData, "x");
            swrveImage.Position.Y = IntValueFromAttribute(imageData, "y");
            swrveImage.Size.X     = IntValueFromAttribute(imageData, "w");
            swrveImage.Size.Y     = IntValueFromAttribute(imageData, "h");
            swrveImage.File       = StringValueFromAttribute(imageData, "image");
            return(swrveImage);
        }
コード例 #7
0
 public void UnloadAssets()
 {
     for (int i = 0; i < Images.Count; i++)
     {
         SwrveImage swrveImage = Images[i];
         Object.Destroy(swrveImage.Texture);
         swrveImage.Texture = null;
     }
     for (int j = 0; j < Buttons.Count; j++)
     {
         SwrveButton swrveButton = Buttons[j];
         Object.Destroy(swrveButton.Texture);
         swrveButton.Texture = null;
     }
 }
コード例 #8
0
 public void UnloadAssets()
 {
     for (int i = 0; i < this.Images.Count; i++)
     {
         SwrveImage swrveImage = this.Images[i];
         UnityEngine.Object.Destroy(swrveImage.Texture);
         swrveImage.Texture = null;
     }
     for (int j = 0; j < this.Buttons.Count; j++)
     {
         SwrveButton swrveButton = this.Buttons[j];
         UnityEngine.Object.Destroy(swrveButton.Texture);
         swrveButton.Texture = null;
     }
 }
コード例 #9
0
        /// <summary>
        /// Remote the format assets from memory.
        /// </summary>
        public void UnloadAssets()
        {
            for (int ii = 0; ii < Images.Count; ii++)
            {
                SwrveImage image = Images[ii];
                Texture2D.Destroy(image.Texture);
                image.Texture = null;
            }

            for (int bi = 0; bi < Buttons.Count; bi++)
            {
                SwrveButton button = Buttons[bi];
                Texture2D.Destroy(button.Texture);
                button.Texture = null;
            }
        }
        public bool ResolveTemplating(SwrveMessage message, Dictionary <string, string> properties)
        {
            try {
                for (int fi = 0; fi < message.Formats.Count; fi++)
                {
                    SwrveMessageFormat format = message.Formats[fi];
                    for (int ii = 0; ii < format.Images.Count; ii++)
                    {
                        SwrveImage image = format.Images[ii];

                        if (!ResolveWidgetProperty(image, TextResolution, image.Text, properties))
                        {
                            return(false);
                        }
                    }

                    for (int bi = 0; bi < format.Buttons.Count; bi++)
                    {
                        SwrveButton button = format.Buttons[bi];

                        if (!ResolveWidgetProperty(button, TextResolution, button.Text, properties))
                        {
                            return(false);
                        }

                        // Need to personalize action
                        string personalizedButtonAction = button.Action;
                        if ((button.ActionType == SwrveActionType.Custom || button.ActionType == SwrveActionType.CopyToClipboard) && !string.IsNullOrEmpty(personalizedButtonAction))
                        {
                            if (!ResolveWidgetProperty(button, ActionResolution, personalizedButtonAction, properties))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            ActionResolution[button] = personalizedButtonAction;
                        }
                    }
                }
            } catch (SwrveSDKTextTemplatingException exp) {
                UnityEngine.Debug.LogError("Not showing campaign, error with personalization" + exp.Message);
                return(false);
            }
            return(true);
        }
コード例 #11
0
        protected static SwrveImage LoadImageFromJSON(SwrveMessage message, Dictionary <string, object> imageData)
        {
            SwrveImage image = new SwrveImage();

            image.Position.X = IntValueFromAttribute(imageData, "x");
            image.Position.Y = IntValueFromAttribute(imageData, "y");

            image.Size.X = IntValueFromAttribute(imageData, "w");
            image.Size.Y = IntValueFromAttribute(imageData, "h");

            image.File = StringValueFromAttribute(imageData, "image");
            if (imageData.ContainsKey("text"))
            {
                image.Text = StringValueFromAttribute(imageData, "text");
            }

            return(image);
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        public static void DrawMessage(SwrveMessageFormat format, int centerx, int centery)
        {
            if (Animator != null)
            {
                AnimateMessage(format);
            }
            if (format.BackgroundColor.HasValue && GetBlankTexture() != null)
            {
                Color value = format.BackgroundColor.Value;
                value.a           *= format.Message.BackgroundAlpha;
                GUI.color          = value;
                WholeScreen.width  = Screen.width;
                WholeScreen.height = Screen.height;
                GUI.DrawTexture(WholeScreen, blankTexture, ScaleMode.StretchToFill, alphaBlend: true, 10f);
                GUI.color = Color.white;
            }
            bool rotate = format.Rotate;

            if (rotate)
            {
                Vector2 pivotPoint = new Vector2(centerx, centery);
                GUIUtility.RotateAroundPivot(90f, pivotPoint);
            }
            float num = format.Scale * format.Message.AnimationScale;

            GUI.color = Color.white;
            Point centeredPosition;

            for (int i = 0; i < format.Images.Count; i++)
            {
                SwrveImage swrveImage = format.Images[i];
                if (swrveImage.Texture != null)
                {
                    float num2 = num * swrveImage.AnimationScale;
                    centeredPosition       = swrveImage.GetCenteredPosition(swrveImage.Texture.width, swrveImage.Texture.height, num2, num);
                    centeredPosition.X    += centerx;
                    centeredPosition.Y    += centery;
                    swrveImage.Rect.x      = centeredPosition.X;
                    swrveImage.Rect.y      = centeredPosition.Y;
                    swrveImage.Rect.width  = (float)swrveImage.Texture.width * num2;
                    swrveImage.Rect.height = (float)swrveImage.Texture.height * num2;
                    GUI.DrawTexture(swrveImage.Rect, swrveImage.Texture, ScaleMode.StretchToFill, alphaBlend: true, 10f);
                }
                else
                {
                    GUI.Box(swrveImage.Rect, swrveImage.File);
                }
            }
            for (int j = 0; j < format.Buttons.Count; j++)
            {
                SwrveButton swrveButton = format.Buttons[j];
                if (swrveButton.Texture != null)
                {
                    float num2 = num * swrveButton.AnimationScale;
                    centeredPosition        = swrveButton.GetCenteredPosition(swrveButton.Texture.width, swrveButton.Texture.height, num2, num);
                    swrveButton.Rect.x      = centeredPosition.X + centerx;
                    swrveButton.Rect.y      = centeredPosition.Y + centery;
                    swrveButton.Rect.width  = (float)swrveButton.Texture.width * num2;
                    swrveButton.Rect.height = (float)swrveButton.Texture.height * num2;
                    if (rotate)
                    {
                        Point center = swrveButton.GetCenter(swrveButton.Texture.width, swrveButton.Texture.height, num2);
                        swrveButton.PointerRect.x      = (float)centerx - (float)swrveButton.Position.Y * num + (float)center.Y;
                        swrveButton.PointerRect.y      = (float)centery + (float)swrveButton.Position.X * num + (float)center.X;
                        swrveButton.PointerRect.width  = swrveButton.Rect.height;
                        swrveButton.PointerRect.height = swrveButton.Rect.width;
                    }
                    else
                    {
                        swrveButton.PointerRect = swrveButton.Rect;
                    }
                    if (Animator != null)
                    {
                        Animator.AnimateButtonPressed(swrveButton);
                    }
                    else
                    {
                        GUI.color = (swrveButton.Pressed ? ButtonPressedColor : Color.white);
                    }
                    GUI.DrawTexture(swrveButton.Rect, swrveButton.Texture, ScaleMode.StretchToFill, alphaBlend: true, 10f);
                }
                else
                {
                    GUI.Box(swrveButton.Rect, swrveButton.Image);
                }
                GUI.color = Color.white;
            }
            if ((Animator == null && format.Closing) || (Animator != null && Animator.IsMessageDismissed(format)))
            {
                format.Dismissed = true;
                format.UnloadAssets();
            }
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
 public SwrveImageView(SwrveImage image)
 {
     this.image = image;
 }