Esempio 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;
        }
Esempio n. 2
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;
        }