Exemplo n.º 1
0
        /// <summary>
        /// Initializes UI.
        /// </summary>
        void InitializeUI()
        {
            if (phase != Phase.Initialize)
            {
                return;
            }

            if (!DocumentActions.IsResourceReady() || !InstallPackageWindow.IsResourceReady() || !GitButton.IsResourceReady())
            {
                return;
            }

            root = UIUtils.GetRoot(this).Q("container");

            // Document actions.
            documentActions = new DocumentActions(root.Q("detailActions"));

            // Install package window.
            var installPackageWindow = new InstallPackageWindow();

            root.Add(installPackageWindow);

            // Add button to open InstallPackageWindow
            var addButton = root.Q("toolbarAddButton") ?? root.Q("moreAddOptionsButton");
            var gitButton = new GitButton(installPackageWindow.Open);

            addButton.parent.Insert(addButton.parent.IndexOf(addButton) + 1, gitButton);

#if UNITY_2018
            var space = new VisualElement();
            space.style.flexGrow = 1;
            addButton.parent.Insert(addButton.parent.IndexOf(addButton), space);
#endif

            // Update git packages on load packages
            var    packageList = Expose.FromObject(root.Q("packageList"));
            Action onLoad      = packageList["OnLoaded"].As <Action>();
            onLoad += OnPackageListLoaded;
            packageList["OnLoaded"] = Expose.FromObject(onLoad);

#if UNITY_2019_1_OR_NEWER
            var updateButton = root.Q("packageToolBar").Q <Button>("update");
#else
            OnPackageListLoaded();
            var updateButton = root.Q("updateCombo").Q <Button>("update");
#endif

            var detailView = Expose.FromObject(root.Q("detailsGroup"));

            // Override click action.
            Action actionUpdate = () =>
            {
#if UNITY_2019_1_OR_NEWER
                var exTargetPackage = detailView["TargetVersion"];
#else
                var exTargetPackage = detailView["SelectedPackage"];
#endif
                if (exTargetPackage["Origin"].As <int>() == 99)
                {
                    var    packageId       = exTargetPackage["Info"]["m_PackageId"].As <string>();
                    string packageIdPrefix = regInstallVersion.Replace(packageId, "");
                    string refName         = exTargetPackage["Version"].ToString().Replace("0.0.0-", "");
                    packageId = packageIdPrefix + "#" + refName;

                    var m = Regex.Match(packageId, "([^@]+)@(.*)");
                    if (m.Success)
                    {
                        var l = string.Format("\"{0}\": \"{1}\",", m.Groups [1].Value, m.Groups [2].Value);
                        Debug.Log(l);
                        var manifest     = MiniJSON.Json.Deserialize(System.IO.File.ReadAllText("Packages/manifest.json")) as Dictionary <string, object>;
                        var dependencies = manifest ["dependencies"] as Dictionary <string, object>;

                        dependencies.Remove(m.Groups [1].Value);
                        dependencies.Add(m.Groups [1].Value, m.Groups [2].Value);

                        System.IO.File.WriteAllText("Packages/manifest.json", MiniJSON.Json.Serialize(manifest));
                        UnityEditor.AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                    }
                }
                else
                {
                    detailView.Call("UpdateClick");
                }
            };
            Expose.FromObject(updateButton.clickable)["clicked"] = Expose.FromObject(actionUpdate);

            Settings.onChangedShowAllVersions = ReloadPackageCollection;

            phase = Phase.Idle;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes UI.
        /// </summary>
        void InitializeUI()
        {
            if (initialized || !InstallPackageWindow.IsResourceReady() || !GitButton.IsResourceReady())
            {
                return;
            }

            initialized = true;

            Debug.Log("[UpmGitExtension.InitializeUI]");
            root = UIUtils.GetRoot(this).Q <TemplateContainer>("");

            Debug.Log("[UpmGitExtension.InitializeUI] Setup internal bridge:");
            var internalBridge = Bridge.Instance;

            internalBridge.Setup(root);

            Debug.Log("[UpmGitExtension.InitializeUI] Setup host button:");
            var hostButton = root.Q <Button>("hostButton");

            if (hostButton == null)
            {
                hostButton = new Button(internalBridge.ViewRepoClick)
                {
                    name = "hostButton", tooltip = "View on browser"
                };
                hostButton.RemoveFromClassList("unity-button");
                hostButton.RemoveFromClassList("button");
                hostButton.AddToClassList("link");
                hostButton.style.marginRight = 2;
                hostButton.style.marginLeft  = 2;
                hostButton.style.width       = 16;
                hostButton.style.height      = 16;
                root.Q("detailVersion").parent.Add(hostButton);

#if !UNITY_2019_1_OR_NEWER
                hostButton.style.sliceBottom = 0;
                hostButton.style.sliceTop    = 0;
                hostButton.style.sliceRight  = 0;
                hostButton.style.sliceLeft   = 0;
#endif
            }

            // Install package window.
            Debug.Log("[UpmGitExtension.InitializeUI] Setup install window:");
            var installPackageWindow = new InstallPackageWindow();
            root.Add(installPackageWindow);

            // Add button to open InstallPackageWindow
            Debug.Log("[UpmGitExtension.InitializeUI] Add button to open install window:");
            var addButton = root.Q("toolbarAddMenu") ?? root.Q("toolbarAddButton") ?? root.Q("moreAddOptionsButton");
            var gitButton = new GitButton(installPackageWindow.Open);
            addButton.parent.Insert(0, gitButton);
            gitButton.style.borderRightWidth = 1;

#if UNITY_2018
            var space = new VisualElement();
            space.style.flexGrow = 1;
            addButton.parent.Insert(addButton.parent.IndexOf(addButton), space);

            Debug.Log("[UpmGitExtension.InitializeUI] Setup document actions:");
            root.Q <Button>("viewDocumentation").OverwriteCallback(internalBridge.ViewDocClick);
            root.Q <Button>("viewChangelog").OverwriteCallback(internalBridge.ViewChangelogClick);
            root.Q <Button>("viewLicenses").OverwriteCallback(internalBridge.ViewLicensesClick);
#endif

            Debug.Log("[UpmGitExtension.InitializeUI] Setup update button:");
            var updateButton = root.Q <Button>("update");
            updateButton.OverwriteCallback(internalBridge.UpdateClick);

            Debug.Log("[UpmGitExtension.InitializeUI] Setup remove button:");
            var removeButton = root.Q <Button>("remove");
            removeButton.OverwriteCallback(internalBridge.RemoveClick);

            internalBridge.UpdateGitPackages();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes UI.
        /// </summary>
        void InitializeUI()
        {
            if (phase != Phase.Initialize)
            {
                return;
            }

            if (!DocumentActions.IsResourceReady() || !InstallPackageWindow.IsResourceReady() || !GitButton.IsResourceReady())
            {
                return;
            }

            root = UIUtils.GetRoot(this).Q("container");

            // Document actions.
            documentActions = new DocumentActions(root.Q("detailActions"));

            // Install package window.
            var installPackageWindow = new InstallPackageWindow();

            root.Add(installPackageWindow);

            // Add button to open InstallPackageWindow
            var addButton = root.Q("toolbarAddButton") ?? root.Q("moreAddOptionsButton");
            var gitButton = new GitButton(installPackageWindow.Open);

            addButton.parent.Insert(addButton.parent.IndexOf(addButton) + 1, gitButton);

#if UNITY_2018
            var space = new VisualElement();
            space.style.flexGrow = 1;
            addButton.parent.Insert(addButton.parent.IndexOf(addButton), space);
#endif

            // Update git packages on load packages
            var    packageList = Expose.FromObject(root.Q("packageList"));
            Action onLoad      = packageList["OnLoaded"].As <Action>();
            onLoad += OnPackageListLoaded;
            packageList["OnLoaded"] = Expose.FromObject(onLoad);

#if UNITY_2019_1_OR_NEWER
            var updateButton = root.Q("packageToolBar").Q <Button>("update");
#else
            OnPackageListLoaded();
            var updateButton = root.Q("updateCombo").Q <Button>("update");
#endif

            var detailView = Expose.FromObject(root.Q("detailsGroup"));

            // Override click action.
            Action actionUpdate = () =>
            {
#if UNITY_2019_1_OR_NEWER
                var exTargetPackage = detailView["TargetVersion"];
#else
                var exTargetPackage = detailView["SelectedPackage"];
#endif
                if (exTargetPackage["Origin"].As <int>() == 99)
                {
                    var    packageId       = exTargetPackage["Info"]["m_PackageId"].As <string>();
                    string packageIdPrefix = regInstallVersion.Replace(packageId, "");
                    string refName         = exTargetPackage["Version"].ToString().Replace("0.0.0-", "");
                    exTargetPackage["_PackageId"] = Expose.FromObject(packageIdPrefix + "#" + refName);
                }

                detailView.Call("UpdateClick");
            };
            Expose.FromObject(updateButton.clickable)["clicked"] = Expose.FromObject(actionUpdate);

            phase = Phase.Idle;
        }