Exemplo n.º 1
0
        void OnGUI()
        {
            // http://answers.unity3d.com/questions/1324195/detect-if-build-target-is-installed.html
            var moduleManager = System.Type.GetType("UnityEditor.Modules.ModuleManager,UnityEditor.dll");

            isPlatformSupportLoaded        = moduleManager.GetMethod("IsPlatformSupportLoaded", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            getTargetStringFromBuildTarget = moduleManager.GetMethod("GetTargetStringFromBuildTarget", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);

            GUILayout.Label("Unity plugin for STYLY", EditorStyles.boldLabel);
            GUIStyle style = new GUIStyle(GUI.skin.label);

            style.wordWrap = true;
            EditorGUILayout.LabelField("Right click on a prefab and select \"STYLY\"-\"Upload prefab or scene to STYLY\". Your prefab will appear in \"3D Model\"-\"My Models\" section in STYLY. ", style);

            GUILayout.BeginHorizontal("box");
            if (GUILayout.Button("Get STYLY API Key", GUILayout.Width(120)))
            {
                Application.OpenURL(Config.GetAPIKeyUrl);
            }
            if (GUILayout.Button("Get Started", GUILayout.Width(120)))
            {
                Application.OpenURL(Config.GetStartedUrl);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            GUIStyle      platformStyle      = new GUIStyle();
            GUIStyleState platformStyleState = new GUIStyleState();

            platformStyleState.textColor = Color.red;
            platformStyle.normal         = platformStyleState;
            bool allPlatformInstalled = true;

            foreach (var platform in Config.PlatformList)
            {
                var target = Config.PlatformBuildTargetDic[platform];
                if (!IsPlatformSupportLoaded(GetTargetStringFromBuildTarget(target)))
                {
                    EditorGUILayout.LabelField(target.ToString() + " module not installed.", platformStyle);
                    allPlatformInstalled = false;
                }
            }
            if (allPlatformInstalled == false)
            {
                EditorGUILayout.LabelField("STYLY Uploader requires above modules. Please install these modules.", platformStyle);

                GUILayout.BeginHorizontal("box");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("More Information", GUILayout.Width(120)))
                {
                    Application.OpenURL(Config.ModulesErrorUrl);
                }
                GUILayout.EndHorizontal();
            }

            if (!IsCacheServerEnabled())
            {
                EditorGUILayout.LabelField("Cache Server is strongly recommended.\n Change the setting at Edit-Preferences-CacheServer", platformStyle);
            }

            GUILayout.Space(20);
            EditorGUI.BeginChangeCheck();

            email = EditorGUILayout.TextField("Email", email);
            GUILayout.Space(5);
            api_key = EditorGUILayout.TextField("API Key", api_key);
            GUILayout.Space(30);

            // Validate AzCopy exec file presence
            // NOTE this will run even if the "enable" toggle wasn't pressed
            // In order to avoid freeze of Unity Editor, avoid calling DisplayDialog() at the initial several calls of OnGUI().
            if (onGUICallCounter > 5 && azcopyEnabled && !AzcopyExecutableFileInstaller.Validate())
            {
                azcopyEnabled = false;
                // mark as dirty to register this change
                GUI.changed = true;

                EditorUtility.DisplayDialog(
                    "AzCopy exec file not found",
                    "Please click the 'Enable AzCopy' checkbox to install AzCopy again.",
                    "OK");
            }

            // azcopy setting
            var azcopyEnabledNew = GUILayout.Toggle(azcopyEnabled, "Enable AzCopy");

            GUILayout.Space(5);
            EditorGUILayout.HelpBox("AzCopy can be used for faster upload", MessageType.Info);
            if (!azcopyEnabled && azcopyEnabledNew)
            {
                EditorUtility.DisplayProgressBar("Installing AzCopy", "", 0);

                if (AzcopyExecutableFileInstaller.Install(out var error))
                {
                    azcopyEnabled = true;

                    EditorUtility.DisplayDialog(
                        "AzCopy installation success",
                        "AzCopy was installed properly!",
                        "OK");
                }
                else
                {
                    Debug.LogError($"AzCopy was not installed: {error}");
                    EditorUtility.DisplayDialog(
                        "Failed installing AzCopy",
                        $"AzCopy was not installed.\n{error}",
                        "OK");
                }

                EditorUtility.ClearProgressBar();
            }
            else
            {
                // Disable AzCopy
                azcopyEnabled = azcopyEnabledNew;
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetString(SETTING_KEY_STYLY_EMAIL, email.Trim());
                EditorPrefs.SetString(SETTING_KEY_STYLY_API_KEY, api_key.Trim());
                Config.IsAzCopyEnabled = azcopyEnabled;
            }

            GUILayout.Space(20);
            this.Repaint();

            // about Styly
            GUILayout.BeginVertical();
            RenderFooter();
            GUILayout.EndVertical();

            onGUICallCounter++;
        }
Exemplo n.º 2
0
        public void CheckError()
        {
            // Validate AzCopy
            if (azcopyEnable && !AzcopyExecutableFileInstaller.Validate())
            {
                error = new Error("AzCopy enabled but exec file not found");
                return;
            }

            // unity version check
            bool isUnSupportedVersion = true;

            foreach (string version in Config.UNITY_VERSIONS)
            {
                if (Application.unityVersion.Contains(version))
                {
                    isUnSupportedVersion = false;
                }
            }
            if (isUnSupportedVersion)
            {
                Debug.Log("isUnSupportedVersion");
                this.error = new Error("Please use Unity " + string.Join(", ", Config.UNITY_VERSIONS) + ".");
                return;
            }

            if (this.email == null || this.email.Length == 0 ||
                this.asset == null || this.apiKey.Length == 0)
            {
                Debug.Log("You don't have a account settings. [STYLY/Asset Uploader Settings]");
                this.error = new Error("You don't have a account settings. [STYLY/Asset Uploader Settings]");
                return;
            }

            //もしSTYLYアセット対応拡張子ではなかったらエラー出して終了
            if (Array.IndexOf(Config.AcceptableExtentions, System.IO.Path.GetExtension(assetPath)) < 0)
            {
                Debug.Log("Unsupported format ");
                this.error = new Error("Unsupported format " + System.IO.Path.GetExtension(assetPath));
                return;
            }

            string assetType = this.asset.GetType().ToString();

            if ((!isAdministrator) && (assetType == "UnityEngine.GameObject"))
            {
                GameObject  assetObj        = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;
                Transform[] childTransforms = assetObj.GetComponentsInChildren <Transform>();
                foreach (Transform t in childTransforms)
                {
                    //禁止アセットのチェック
                    if (Config.ProhibitedTags.Contains(t.gameObject.tag))
                    {
                        this.error = new Error(string.Format("{0} can not be used as a tag.", t.tag));
                        return;
                    }
                    //禁止レイヤーのチェック
                    //Defaultレイヤー以外使用できない
                    if (t.gameObject.layer != 0)
                    {
                        this.error = new Error("Object needs to be in Default layer. You use " + LayerMask.LayerToName(t.gameObject.layer));
                        return;
                    }
                }
            }
        }