コード例 #1
0
        private void InitiateBuySelected(bool firstAttempt)
        {
            AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset();

            if (firstAsset == null)
            {
                EditorUtility.DisplayDialog("No asset selected", "Please select asset before buying a package", "ok");
            }
            else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.AnonymousUser)
            {
                if (AssetStoreClient.LoggedIn())
                {
                    AssetStoreAssetSelection.RefreshFromServer(delegate
                    {
                        this.InitiateBuySelected(false);
                    });
                }
                else if (firstAttempt)
                {
                    this.LoginAndInitiateBuySelected();
                }
            }
            else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.ServiceDisabled)
            {
                if (firstAsset.previewInfo == null)
                {
                    return;
                }
                AssetStore.Open(string.Format("content/{0}/directpurchase", firstAsset.packageID));
            }
            else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.BasketNotEmpty)
            {
                if (firstAsset.previewInfo == null)
                {
                    return;
                }
                if (firstAttempt)
                {
                    AssetStoreAssetSelection.RefreshFromServer(delegate
                    {
                        this.InitiateBuySelected(false);
                    });
                }
                else
                {
                    AssetStore.Open(string.Format("content/{0}/basketpurchase", firstAsset.packageID));
                }
            }
            else
            {
                AssetStoreInstaBuyWindow.ShowAssetStoreInstaBuyWindow(firstAsset, AssetStoreAssetInspector.s_PurchaseMessage, AssetStoreAssetInspector.s_PaymentMethodCard, AssetStoreAssetInspector.s_PaymentMethodExpire, AssetStoreAssetInspector.s_PriceText);
            }
        }
コード例 #2
0
        public void OnGUI()
        {
            if (AssetStoreLoginWindow.styles == null)
            {
                AssetStoreLoginWindow.styles = new AssetStoreLoginWindow.Styles();
            }
            AssetStoreLoginWindow.LoadLogos();
            if (AssetStoreClient.LoginInProgress() || AssetStoreClient.LoggedIn())
            {
                GUI.enabled = false;
            }
            GUILayout.BeginVertical();
            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(5f);
            GUILayout.Label(AssetStoreLoginWindow.s_AssetStoreLogo, GUIStyle.none, new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(false)
            });
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            GUILayout.Label(this.m_LoginReason, EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
            Rect lastRect = GUILayoutUtility.GetLastRect();

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Space(6f);
            Rect rect = new Rect(0.0f, 0.0f, 0.0f, 0.0f);

            if (this.m_LoginRemoteMessage != null)
            {
                Color color = GUI.color;
                GUI.color = Color.red;
                GUILayout.Label(this.m_LoginRemoteMessage, EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
                GUI.color = color;
                rect      = GUILayoutUtility.GetLastRect();
            }
            float height = (float)((double)lastRect.height + (double)rect.height + 110.0);

            if (Event.current.type == EventType.Repaint && (double)height != (double)this.position.height)
            {
                this.position = new Rect(this.position.x, this.position.y, this.position.width, height);
                this.Repaint();
            }
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUI.SetNextControlName("username");
            this.m_Username = EditorGUILayout.TextField("Username", this.m_Username, new GUILayoutOption[0]);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            this.m_Password = EditorGUILayout.PasswordField("Password", this.m_Password, new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(true)
            });
            if (GUILayout.Button(new GUIContent("Forgot?", "Reset your password"), AssetStoreLoginWindow.styles.link, new GUILayoutOption[1]
            {
                GUILayout.ExpandWidth(false)
            }))
            {
                Application.OpenURL("https://accounts.unity3d.com/password/new");
            }
            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
            GUILayout.EndHorizontal();
            bool rememberSession = AssetStoreClient.RememberSession;
            bool flag            = EditorGUILayout.Toggle("Remember me", rememberSession, new GUILayoutOption[0]);

            if (flag != rememberSession)
            {
                AssetStoreClient.RememberSession = flag;
            }
            GUILayout.EndVertical();
            GUILayout.Space(5f);
            GUILayout.EndHorizontal();
            GUILayout.Space(8f);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Create account"))
            {
                AssetStore.Open("createuser/");
                this.m_LoginRemoteMessage = "Cancelled - create user";
                this.Close();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel"))
            {
                this.m_LoginRemoteMessage = "Cancelled";
                this.Close();
            }
            GUILayout.Space(5f);
            if (GUILayout.Button("Login"))
            {
                this.DoLogin();
                this.Repaint();
            }
            GUILayout.Space(5f);
            GUILayout.EndHorizontal();
            GUILayout.Space(5f);
            GUILayout.EndVertical();
            if (Event.current.Equals((object)Event.KeyboardEvent("return")))
            {
                this.DoLogin();
                this.Repaint();
            }
            if (!(this.m_Username == string.Empty))
            {
                return;
            }
            EditorGUI.FocusTextInControl("username");
        }
コード例 #3
0
        /**
         * Initiate a purchase of the selected package from the asset store.
         * The package will be the one that contains the currently selected asset.
         *
         * Since not all users may have allowed for single click purchases this can result
         * in two scenarios:
         * 1. single click allowed and a native purchase acknowledgement dialog appears to
         *    finalize the purchase.
         * 2. single click is not allowed and the package is put to an asset store basket.
         *    Then the asset store window is displayed with the basket open.
         */
        void InitiateBuySelected(bool firstAttempt)
        {
            //Debug.Log("payavail " + paymentAvailability.ToString());
            // Ask the asset store if the use has allowed single click payments
            AssetStoreAsset asset = AssetStoreAssetSelection.GetFirstAsset();

            if (asset == null)
            {
                EditorUtility.DisplayDialog("No asset selected", "Please select asset before buying a package", "ok");
            }
            else if (paymentAvailability == PaymentAvailability.AnonymousUser)
            {
                // Maybe the asset store window did a login already and we have a session key
                // then we just need to fetch the new info
                if (AssetStoreClient.LoggedIn())
                {
                    AssetStoreAssetSelection.RefreshFromServer(delegate() {
                        InitiateBuySelected(false);
                    });
                }
                else if (firstAttempt)
                {
                    LoginAndInitiateBuySelected();
                }
            }
            else if (paymentAvailability == PaymentAvailability.ServiceDisabled)
            {
                // Use the asset store window to complete the purchase since single click is not possible
                if (asset.previewInfo == null)
                {
                    return;
                }
                AssetStore.Open(string.Format("content/{0}/directpurchase", asset.packageID));
            }
            else if (paymentAvailability == PaymentAvailability.BasketNotEmpty)
            {
                // Use the asset store window to complete the purchase since there is already \
                // something in the users basket
                if (asset.previewInfo == null)
                {
                    return;
                }

                // Maybe the basket has been emptied and this is a retry by the user
                if (firstAttempt)
                {
                    AssetStoreAssetSelection.RefreshFromServer(delegate() {
                        InitiateBuySelected(false);
                    });
                }
                else
                {
                    AssetStore.Open(string.Format("content/{0}/basketpurchase", asset.packageID));
                }
            }
            else
            {
                // Show single click window
                AssetStoreInstaBuyWindow.ShowAssetStoreInstaBuyWindow(asset,
                                                                      AssetStoreAssetInspector.s_PurchaseMessage,
                                                                      AssetStoreAssetInspector.s_PaymentMethodCard,
                                                                      AssetStoreAssetInspector.s_PaymentMethodExpire,
                                                                      AssetStoreAssetInspector.s_PriceText
                                                                      );
            }
        }
コード例 #4
0
        public void OnGUI()
        {
            if (styles == null)
            {
                styles = new Styles();
            }

            LoadLogos();

            if (AssetStoreClient.LoginInProgress() || AssetStoreClient.LoggedIn())
            {
                GUI.enabled = false;
            }

            GUILayout.BeginVertical();
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Space(5);
            GUILayout.Label(s_AssetStoreLogo, GUIStyle.none, GUILayout.ExpandWidth(false));
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Space(6);
            GUILayout.Label(m_LoginReason, EditorStyles.wordWrappedLabel);
            Rect lastReasonRect = GUILayoutUtility.GetLastRect();

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Space(6);
            Rect lastMessageRect = new Rect(0f, 0f, 0f, 0f);

            if (m_LoginRemoteMessage != null)
            {
                Color oldColor = GUI.color;
                GUI.color = Color.red;
                GUILayout.Label(m_LoginRemoteMessage, EditorStyles.wordWrappedLabel);
                GUI.color       = oldColor;
                lastMessageRect = GUILayoutUtility.GetLastRect();
            }
            float newHeight = lastReasonRect.height + lastMessageRect.height + kBaseHeight;

            if (Event.current.type == EventType.Repaint && newHeight != position.height)
            {
                // Debug.Log(newHeight.ToString() + " " + position.height + " " + lastReasonRect.height.ToString() + " " + lastMessageRect.height.ToString());
                position = new Rect(position.x, position.y, position.width, newHeight);
                Repaint();
            }
            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUI.SetNextControlName("username");
            m_Username = EditorGUILayout.TextField("Username", m_Username);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            m_Password = EditorGUILayout.PasswordField("Password", m_Password, GUILayout.ExpandWidth(true));
            if (GUILayout.Button(EditorGUIUtility.TrTextContent("Forgot?", "Reset your password"), styles.link, GUILayout.ExpandWidth(false)))
            {
                Application.OpenURL("https://accounts.unity3d.com/password/new");
            }

            EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
            GUILayout.EndHorizontal();

            bool oldRememberMe = AssetStoreClient.RememberSession;
            bool newRememberMe = EditorGUILayout.Toggle("Remember me", oldRememberMe);

            if (newRememberMe != oldRememberMe)
            {
                AssetStoreClient.RememberSession = newRememberMe;
            }

            GUILayout.EndVertical();
            GUILayout.Space(5);
            GUILayout.EndHorizontal();

            GUILayout.Space(8);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Create account"))
            {
                AssetStore.Open("createuser/");
                m_LoginRemoteMessage = "Cancelled - create user";
                Close();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel"))
            {
                m_LoginRemoteMessage = "Cancelled";
                Close();
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Login"))
            {
                DoLogin();
                Repaint();
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            GUILayout.EndVertical();

            if (Event.current.Equals(Event.KeyboardEvent("return")))
            {
                DoLogin();
                Repaint();
            }

            if (m_Username == "")
            {
                EditorGUI.FocusTextInControl("username");
            }
        }