| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 | #if !PHOTON_UNITY_NETWORKINGusing System;using Photon.Chat;using Photon.Chat.Demo;using Photon.Realtime;using UnityEditor;using UnityEngine;[InitializeOnLoad]public class ChatEditor : EditorWindow{    static ChatEditor()    {        EditorApplication.update += OnEditorUpdate;    }    private static void OnEditorUpdate()    {        EditorApplication.update -= OnEditorUpdate;        //ChatSettings settings = ChatSettings.Load();        //if (settings != null && !settings.WizardDone && string.IsNullOrEmpty(settings.AppId))        //{        //    OpenWizard();        //}    }    [MenuItem("Window/Photon Chat/Setup")]    public static void OpenWizard()    {        //currentSettings = ChatSettings.Load();        //currentSettings.WizardDone = true;        //EditorUtility.SetDirty(currentSettings);        ChatEditor editor = (ChatEditor)EditorWindow.GetWindow(typeof (ChatEditor), false, "Photon Chat");        editor.minSize = editor.preferredSize;    }    private ChatGui cGui;    internal string mailOrAppId;    internal bool showDashboardLink = false;    internal bool showRegistrationDone = false;    internal bool showRegistrationError = false;    private readonly Vector2 preferredSize = new Vector2(350, 400);    internal static string UrlCloudDashboard = "https://dashboard.photonengine.com/en-US/";    public string WelcomeText = "Thanks for importing Photon Chat.\nThis window should set you up.\n\nYou will need a free Photon Account to setup a Photon Chat application.\nOpen the Photon Dashboard (webpage) to access your account (see button below).\n\nCopy and paste a Chat AppId into the field below and click \"Setup\".";    //public string AlreadyRegisteredInfo = "The email is registered so we can't fetch your AppId (without password).\n\nPlease login online to get your AppId and paste it above.";    //public string RegisteredNewAccountInfo = "We created a (free) account and fetched you an AppId.\nWelcome. Your Photon Chat project is setup.";    //public string FailedToRegisterAccount = "This wizard failed to register an account right now. Please check your mail address or try via the Dashboard.";    //public string AppliedToSettingsInfo = "Your AppId is now applied to this project.";    public string SetupCompleteInfo = "<b>Done!</b>\nYour Chat AppId is now stored in the <b>Scripts</b> object, Chat App Settings.";    public string CloseWindowButton = "Close";    public string OpenCloudDashboardText = "Photon Dashboard Login";    public string OpenCloudDashboardTooltip = "Review Cloud App information and statistics.";    public void OnGUI()    {        if (this.cGui == null)        {            cGui = FindObjectOfType<ChatGui>();        }        GUI.skin.label.wordWrap = true;        GUI.skin.label.richText = true;        if (string.IsNullOrEmpty(mailOrAppId))        {            mailOrAppId = string.Empty;        }        GUILayout.Label("Chat Settings", EditorStyles.boldLabel);        GUILayout.Label(this.WelcomeText);        GUILayout.Space(15);        GUILayout.Label("Chat AppId");        string input = EditorGUILayout.TextField(this.mailOrAppId);        if (GUI.changed)        {            this.mailOrAppId = input.Trim();        }        //bool isMail = false;        bool minimumInput = false;        bool isAppId = false;        if (IsValidEmail(this.mailOrAppId))        {            // this should be a mail address            minimumInput = true;            //isMail = true;        }        else if (IsAppId(this.mailOrAppId))        {            // this should be an appId            minimumInput = true;            isAppId = true;        }        EditorGUI.BeginDisabledGroup(!minimumInput);        GUILayout.BeginHorizontal();        GUILayout.FlexibleSpace();        bool setupBtn = GUILayout.Button("Setup", GUILayout.Width(205));        GUILayout.FlexibleSpace();        GUILayout.EndHorizontal();        if (setupBtn)        {            this.showDashboardLink = false;            this.showRegistrationDone = false;            this.showRegistrationError = false;            //if (isMail)            //{            //    EditorUtility.DisplayProgressBar("Fetching Account", "Trying to register a Photon Cloud Account.", 0.5f);            //    AccountService service = new AccountService();            //    //service.RegisterByEmail(this.mailOrAppId, AccountService.Origin.Pun);            //    //EditorUtility.ClearProgressBar();            //    //if (service.ReturnCode == 0)            //    //{            //    //    currentSettings.AppId = service.AppId;            //    //    EditorUtility.SetDirty(currentSettings);            //    //    this.showRegistrationDone = true;            //    //    Selection.objects = new UnityEngine.Object[] { currentSettings };            //    //}            //    //else            //    //{            //    //    if (service.Message.Contains("registered"))            //    //    {            //    //        this.showDashboardLink = true;            //    //    }            //    //    else            //    //    {            //    //        this.showRegistrationError = true;            //    //    }            //    //}            //}            //else             if (isAppId)            {                //currentSettings.AppId = this.mailOrAppId;                //EditorUtility.SetDirty(currentSettings);                if (this.cGui != null)                {                    this.cGui.ChatAppSettings.AppIdChat = this.mailOrAppId;                    EditorUtility.SetDirty(this.cGui);                }                showRegistrationDone = true;            }            //EditorGUIUtility.PingObject(currentSettings);        }        EditorGUI.EndDisabledGroup();        GUILayout.BeginHorizontal();        GUILayout.FlexibleSpace();        if (GUILayout.Button(new GUIContent(OpenCloudDashboardText, OpenCloudDashboardTooltip), GUILayout.Width(205)))        {            EditorUtility.OpenWithDefaultApp(UrlCloudDashboard);        }        GUILayout.FlexibleSpace();        GUILayout.EndHorizontal();        //if (this.showDashboardLink)        //{        //    // button to open dashboard and get the AppId        //    GUILayout.Space(15);        //    GUILayout.Label(AlreadyRegisteredInfo);        //    GUILayout.BeginHorizontal();        //    GUILayout.FlexibleSpace();        //    if (GUILayout.Button(new GUIContent(OpenCloudDashboardText, OpenCloudDashboardTooltip), GUILayout.Width(205)))        //    {        //        EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.mailOrAppId));        //        this.mailOrAppId = string.Empty;        //        this.showDashboardLink = false;        //    }        //    GUILayout.FlexibleSpace();        //    GUILayout.EndHorizontal();        //}        //if (this.showRegistrationError)        //{        //    GUILayout.Space(15);        //    GUILayout.Label(FailedToRegisterAccount);        //    GUILayout.BeginHorizontal();        //    GUILayout.FlexibleSpace();        //    if (GUILayout.Button(new GUIContent(OpenCloudDashboardText, OpenCloudDashboardTooltip), GUILayout.Width(205)))        //    {        //        EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.mailOrAppId));        //        this.mailOrAppId = string.Empty;        //        this.showDashboardLink = false;        //    }        //    GUILayout.FlexibleSpace();        //    GUILayout.EndHorizontal();        //}        if (this.showRegistrationDone)        {            GUILayout.Space(15);            //GUILayout.Label("Registration done");            ////if (isMail)            ////{            ////    GUILayout.Label(RegisteredNewAccountInfo);            ////}            ////else            ////{            //    GUILayout.Label(AppliedToSettingsInfo);            ////}            // setup-complete info            GUILayout.Space(15);            GUILayout.Label(SetupCompleteInfo);            // close window (done)            GUILayout.BeginHorizontal();            GUILayout.FlexibleSpace();            if (GUILayout.Button(CloseWindowButton, GUILayout.Width(205)))            {                this.Close();            }            GUILayout.FlexibleSpace();            GUILayout.EndHorizontal();        }    }    public static bool IsAppId(string val)    {        if (string.IsNullOrEmpty(val) || val.Length < 16)        {            return false;        }        try        {            new Guid(val);        }        catch        {            return false;        }        return true;    }    // https://stackoverflow.com/a/1374644/1449056    private static bool IsValidEmail(string email)    {        if (string.IsNullOrEmpty(email) || !email.Contains("@"))        {            return false;        }        try        {            System.Net.Mail.MailAddress addr = new System.Net.Mail.MailAddress(email);            return email.Equals(addr.Address);        }        catch        {            return false;        }    }}#endif
 |