Esempio n. 1
0
        /// <summary>
        /// Uploads an image to the user's social page on the given Provider with confirmation dialog.
        /// Supported platforms: Facebook, Twitter, Google+
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> the given image should be uploaded to.</param>
        /// <param name="message">Message to post with the image.</param>
        /// <param name="fileName">Name of image file with extension (jpeg/pgn).</param>
        /// <param name="imageBytes">Image bytes.</param>
        /// <param name="jpegQuality">Image quality, number from 0 to 100. 0 meaning compress for small size, 100 meaning compress for max quality.
        /// Some formats, like PNG which is lossless, will ignore the quality setting
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful upload.</param>
        /// <param name="customMessage">The message to show in the dialog</param>
        public static void UploadImageWithConfirmation(Provider provider, string message, string fileName, byte[] imageBytes,
                                                       int jpegQuality, string payload = "", Reward reward = null, string customMessage = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                string rewardId = reward != null ? reward.ID: "";
                instance._uploadImage(provider, message, fileName, imageBytes, jpegQuality,
                                      ProfilePayload.ToJSONObj(userPayload, rewardId).ToString(), true, customMessage);
            }

            else
            {
                // TODO: Support showConfirmation
                ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                targetProvider.UploadImage(imageBytes, fileName, message,
                                           /* success */ () => {
                    if (reward != null)
                    {
                        reward.Give();
                    }
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                },
                                           /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); },
                                           /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); }
                                           );
            }
        }
Esempio n. 2
0
//		public static void UploadImage(Provider provider, string message, string filename,
//		                               byte[] imageBytes, int quality, Reward reward) {
//			instance._uploadImage(provider, message, filename, imageBytes, quality, reward);
//		}
//

        /// <summary>
        /// Uploads an image to the user's social page on the given Provider.
        /// Supported platforms: Facebook
        ///
        /// NOTE: This operation requires a successful login.
        /// </summary>
        /// <param name="provider">The <c>Provider</c> the given image should be uploaded to.</param>
        /// <param name="tex2D">Texture2D for image.</param>
        /// <param name="fileName">Name of image file.</param>
        /// <param name="message">Message to post with the image.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful upload.</param>
        public static void UploadImage(Provider provider, Texture2D tex2D, string fileName, string message, string payload = "",
                                       Reward reward = null)
        {
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                ProfileEvents.OnSocialActionFailed(provider,
                                                   SocialActionType.UPLOAD_IMAGE,
                                                   "Image uploading is not supported with Texture for natively implemented social providers",
                                                   userPayload);
            }

            else
            {
                ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                targetProvider.UploadImage(tex2D.EncodeToPNG(), fileName, message,
                                           /* success */ () => {
                    ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload);
                    if (reward != null)
                    {
                        reward.Give();
                    }
                },
                                           /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); },
                                           /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); }
                                           );
            }
        }