Exemple #1
0
        private void CreatePackageGUI()
        {
            if (PackageGuiUtility.SourcePathGui())
            {
                Refresh();
            }

            var packageName           = serializedObject.FindProperty("packageManifest.name");
            var packageDisplayName    = serializedObject.FindProperty("packageManifest.displayName");
            var packageVersion        = serializedObject.FindProperty("packageManifest.version");
            var packageDescription    = serializedObject.FindProperty("packageManifest.description");
            var packageUnity          = serializedObject.FindProperty("packageManifest.unity");
            var packageUnityRelease   = serializedObject.FindProperty("packageManifest.unityRelease");
            var packageRepositoryName = serializedObject.FindProperty("packageManifest.repositoryName");

            var packageAuthorName    = serializedObject.FindProperty("packageManifest.author.name");
            var packageAuthorEmail   = serializedObject.FindProperty("packageManifest.author.email");
            var packageAuthorUrl     = serializedObject.FindProperty("packageManifest.author.url");
            var packageAuthorGithub  = serializedObject.FindProperty("packageManifest.author.twitter");
            var packageAuthorTwitter = serializedObject.FindProperty("packageManifest.author.github");

            GUILayout.BeginVertical("box");

            EditorGUILayout.LabelField("Package", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(packageName);
            if (EditorGUI.EndChangeCheck())
            {
                //Enforce lowercase constraint
                packageName.stringValue = packageName.stringValue.ToLowerInvariant();
            }

            EditorGUILayout.PropertyField(packageRepositoryName);
            EditorGUILayout.PropertyField(packageDisplayName);
            EditorGUILayout.PropertyField(packageVersion);
            EditorGUILayout.PropertyField(packageDescription);
            EditorGUILayout.PropertyField(packageUnity);
            EditorGUILayout.PropertyField(packageUnityRelease);

            EditorGUILayout.LabelField("Author", EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(packageAuthorName);
            EditorGUILayout.PropertyField(packageAuthorEmail);
            EditorGUILayout.PropertyField(packageAuthorUrl);
            EditorGUILayout.PropertyField(packageAuthorTwitter);
            EditorGUILayout.PropertyField(packageAuthorGithub);

            GUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Create Embeded"))
            {
                CreateEmbeded();
            }

            if (GUILayout.Button("Create at Source Path"))
            {
                CreateInSources();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }
Exemple #2
0
        private void EmbedPackageGUI()
        {
            if (PackageGuiUtility.SourcePathGui())
            {
                Refresh();
            }

            EditorGUI.BeginChangeCheck();
            displayName = EditorGUILayout.Toggle("ShowDisplayName", displayName);
            if (EditorGUI.EndChangeCheck())
            {
                SortPackageList();
            }

            bool refreshAssets = false;

            scrollPt = EditorGUILayout.BeginScrollView(scrollPt, GUILayout.ExpandHeight(false));
            foreach (var sourcePkg in sourcePackages)
            {
                EditorGUILayout.BeginHorizontal("box");

                if (displayName)
                {
                    EditorGUILayout.LabelField(sourcePkg.packageInfo?.displayName);
                }
                else
                {
                    EditorGUILayout.LabelField(sourcePkg.packageInfo?.name);
                }

                if (sourcePkg.status == SourcePackageInfo.Status.Error)
                {
                    EditorGUILayout.LabelField("Error", GUILayout.Width(60));
                }
                else if (sourcePkg.status == SourcePackageInfo.Status.Embeded)
                {
                    EditorGUILayout.LabelField("Embeded", GUILayout.Width(60));
                }
                else if (GUILayout.Button("Embed", GUILayout.Width(60)))
                {
                    try
                    {
                        //Create a softlink to the source package in our local package directory
                        var source = sourcePkg.directoryInfo.FullName;
                        var dest   = $"{Application.dataPath}/../Packages/{sourcePkg.directoryInfo.Name}";
                        if (!ShellUtility.CreateSymbolicLink(source, dest))
                        {
                            EditorApplication.Beep();
                            EditorUtility.DisplayDialog("Package Embed", "Failed to create symbolic link. Package was not embedded.",
                                                        "OK");
                        }
                        else
                        {
                            refreshAssets = true;
                            EditorUtility.DisplayDialog("Package Embed", "Done",
                                                        "OK");
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            //Doing this outside of the foreach loop to avoid layout and enum errors
            if (refreshAssets)
            {
                AssetDatabase.Refresh();
                GUIUtility.ExitGUI();
            }

            RefreshGUI();
        }