コード例 #1
0
        public void SendMailWithAttachment(string _subject, string _body, bool _isHTMLBody,
                                           string _attachmentPath, string _mimeType, string[] _recipients, SharingCompletion _onCompletion)
        {
            DownloadAsset _request = new DownloadAsset(URL.FileURLWithPath(_attachmentPath), true);

#pragma warning disable
            _request.OnCompletion = (WWW _www, string _error) => {
                byte[] _attachmentByteArray = null;
                string _filename            = null;

                if (string.IsNullOrEmpty(_error))
                {
                    _attachmentByteArray = _www.bytes;
                    _filename            = Path.GetFileName(_attachmentPath);
                }
                else
                {
                    DebugUtility.Logger.LogWarning(Constants.kDebugTag, "[Sharing] The operation could not be completed. Error=" + _error);
                }

                SendMail(_subject, _body, _isHTMLBody, _attachmentByteArray,
                         _mimeType, _filename, _recipients, _onCompletion);
            };
#pragma warning restore
            _request.StartRequest();
        }
コード例 #2
0
        /// <summary>
        /// Adds specified file as an attachment of the email.
        /// </summary>
        /// <param name="_attachmentPath">Path of the file that has to be added as an attachment.</param>
        /// <param name="_MIMEType">The MIME type of the file attached in the email.</param>
        public void AddAttachmentAtPath(string _attachmentPath, string _MIMEType)
        {
            // Mark download in progress
            m_attachmentDownloadInProgress = true;

            // Start downloading
            DownloadAsset _request = new DownloadAsset(URL.FileURLWithPath(_attachmentPath), true);

#pragma warning disable
            _request.OnCompletion = (WWW _www, string _error) => {
                // Reset download progress
                m_attachmentDownloadInProgress = false;

                // Process data
                if (string.IsNullOrEmpty(_error))
                {
                    AddAttachment(_www.bytes, Path.GetFileName(_attachmentPath), _MIMEType);
                }
                else
                {
                    DebugUtility.Logger.LogWarning(Constants.kDebugTag, "[Sharing] The operation could not be completed. Error=" + _error);
                }
            };
#pragma warning restore

            _request.StartRequest();
        }
コード例 #3
0
        private static void CheckUpdates()
        {
            if (SessionState.GetBool(kNPUpdateChecker, false))
            {
                return;
            }

            DownloadAsset request = new DownloadAsset(new URL(kUrl), true);

            request.OnCompletion = (WWW _www, string _error) =>
            {
                if (string.IsNullOrEmpty(_error))
                {
                    string jsonString = _www.text;
                    if (!string.IsNullOrEmpty(jsonString))
                    {
                        IDictionary _dataDict = (IDictionary)JSONUtility.FromJSON(jsonString);
#if NATIVE_PLUGINS_LITE_VERSION
                        IDictionary versionInfo = _dataDict.GetIfAvailable <IDictionary>("info");
#else
                        IDictionary versionInfo = _dataDict.GetIfAvailable <IDictionary>("info");
#endif

                        if (versionInfo == null)
                        {
                            return;
                        }

                        string version     = versionInfo.GetIfAvailable <string>("version");
                        int    updateIndex = versionInfo.GetIfAvailable <int>("update-index");

                        string description = _dataDict.GetIfAvailable <string>("description");
                        IList  news        = _dataDict.GetIfAvailable <IList>("news");

                        int latestVersionNumber   = GetCovertedVersionValue(version);
                        int currentVersionNumber  = GetCovertedVersionValue(NPSettings.kProductVersion);
                        int notifiedVersionNumber = EditorPrefs.GetInt(Constants.kNotifiedVersionKey, currentVersionNumber);

                        if ((currentVersionNumber < latestVersionNumber) && ((latestVersionNumber + updateIndex) != notifiedVersionNumber))
                        {
                            EditorUtility.DisplayDialog("Cross Platform Native Plugins", description, "ok");
                            EditorPrefs.SetInt(Constants.kNotifiedVersionKey, latestVersionNumber + updateIndex);
                        }
                        EditorPrefs.SetString(Constants.kNativePluginsAssetStoreVersionKey, version);
                        EditorPrefs.SetString(Constants.kVBNewsKey, news.ToJSON());
                    }
                }
            };

            request.StartRequest();
        }
コード例 #4
0
        /// <summary>
        /// Loads the webpage contents from specified file.
        /// </summary>
        /// <param name="_filepath">Path of the target file to use as contents of the webpage.</param>
        /// <param name="_MIMEType">The MIME type of the content.</param>
        /// <param name="_textEncodingName">The content's character encoding name.</param>
        /// <param name="_baseURL">The base URL for the content.</param>
        public void LoadFile(string _filepath, string _MIMEType, string _textEncodingName, string _baseURL)
        {
            DownloadAsset _request = new DownloadAsset(new URLAddress(_filepath), true);

            _request.OnCompletion = (WWW _www, string _error) => {
                if (string.IsNullOrEmpty(_error))
                {
                    LoadData(_www.bytes, _MIMEType, _textEncodingName, _baseURL);
                }
                else
                {
                    OnDidFailLoadWithError(null, "[WebView] The operation could not be completed. Error = " + _error);
                    return;
                }
            };
            _request.StartRequest();
        }
コード例 #5
0
        /// <summary>
        /// Loads the webpage contents from specified file.
        /// </summary>
        /// <param name="_HTMLFilePath">Path of the target file, to use as contents of the webpage.</param>
        /// <param name="_baseURL">The base URL for the content.</param>
        public void LoadHTMLStringContentsOfFile(string _HTMLFilePath, string _baseURL)
        {
            DownloadAsset _request = new DownloadAsset(URLAddress.FileURLWithPath(_HTMLFilePath), true);

            _request.OnCompletion = (WWW _www, string _error) => {
                if (string.IsNullOrEmpty(_error))
                {
                    LoadHTMLString(_www.text, _baseURL);
                }
                else
                {
                    Console.LogError(Constants.kDebugTag, "[WebView] The operation could not be completed. Error=" + _error);
                    return;
                }
            };
            _request.StartRequest();
        }
コード例 #6
0
        public void ShareImageOnWhatsApp(string _imagePath, SharingCompletion _onCompletion)
        {
            DownloadAsset _request = new DownloadAsset(new URL(_imagePath), true);

            _request.OnCompletion = (WWW _www, string _error) => {
                if (string.IsNullOrEmpty(_error))
                {
                    ShareImageOnWhatsApp(_www.bytes, _onCompletion);
                }
                else
                {
                    DebugUtility.Logger.LogError(Constants.kDebugTag, "[Sharing] The operation could not be completed. Error=" + _error);
                    ShareImageOnWhatsApp((byte[])null, _onCompletion);
                    return;
                }
            };
            _request.StartRequest();
        }
コード例 #7
0
        public static void DownloadSDK(string _downloadLink, string _errorTitle, string _errorMessage)
        {
#if IO_UNSUPPORTED_PLATFORM
            Debug.LogWarning("[NPEditorUtility] Not supported.");
#else
            DownloadAsset _newRequest = new DownloadAsset(URL.URLWithString(_downloadLink), true);
#pragma warning disable CS0618 // Type or member is obsolete
            _newRequest.OnCompletion = (WWW _www, string _error) =>
            {
#pragma warning restore CS0618 // Type or member is obsolete

                if (_error != null)
                {
                    bool _openDownloadLink = EditorUtility.DisplayDialog(_errorTitle, _errorMessage, "Ok", "Cancel");

                    if (_openDownloadLink)
                    {
                        UnityEngine.Application.OpenURL(_downloadLink);
                    }
                }
                else
                {
                    const string _kTempFolderRelativePath = "Assets/Temp";
                    const string _kTempFileRelativePath   = _kTempFolderRelativePath + "/NewPackage.unitypackage";

                    if (!Directory.Exists(_kTempFolderRelativePath))
                    {
                        Directory.CreateDirectory(_kTempFolderRelativePath);
                    }

                    // Save the file into temp location and import it
                    File.WriteAllBytes(_kTempFileRelativePath, _www.bytes);
                    AssetDatabase.ImportPackage(_kTempFileRelativePath, true);

                    // Remove temp folder and refresh
                    Directory.Delete(_kTempFolderRelativePath, true);
                    File.Delete(_kTempFolderRelativePath + ".meta");
                    AssetDatabase.Refresh();
                }
            };
            _newRequest.StartRequest();
#endif
        }
コード例 #8
0
        public override void OnEnter()
        {
            if (attachmentOption != eAttachmentOption.None)
            {
                if (attachmentOption == eAttachmentOption.AttachScreenshot)
                {
                    TextureExtensions.TakeScreenshot((Texture2D _image) => {
                        m_imageData = _image.EncodeToPNG();

                        OnShareDataAvailable();
                    });

                    return;
                }
                else if (attachmentOption == eAttachmentOption.AttachImageAtPath)
                {
                    DownloadAsset _request = new DownloadAsset(new URLStruct(imagePath.Value), true);
                    _request.OnCompletion = (WWW _www, string _error) => {
                        if (_error == null)
                        {
                            m_imageData = _www.bytes;
                        }

                        OnShareDataAvailable();
                    };

                    return;
                }
                else
                {
                    m_imageData = ((Texture2D)image.Value).EncodeToPNG();

                    OnShareDataAvailable();
                    return;
                }
            }
            else
            {
                OnShareDataAvailable();
            }
        }
コード例 #9
0
        public void ShareImageAtPath(string _message, string _imagePath, eShareOptions[] _excludedOptions, SharingCompletion _onCompletion)
        {
            URL           _imagePathURL = URL.FileURLWithPath(_imagePath);
            DownloadAsset _newDownload  = new DownloadAsset(_imagePathURL, true);

            _newDownload.OnCompletion = (WWW _www, string _error) => {
                byte[] _imageData = null;

                if (string.IsNullOrEmpty(_error))
                {
                    _imageData = _www.bytes;
                }
                else
                {
                    DebugUtility.Logger.LogWarning(Constants.kDebugTag, "[Sharing] The operation could not be completed. Error=" + _error);
                }

                Share(_message, null, _imageData, _excludedOptions, _onCompletion);
            };
            _newDownload.StartRequest();
        }