コード例 #1
0
        private void Apply()
        {
            var changedIndices = new List <int>();
            var changedScripts = new List <MonoScript>();

            for (int i = 0; i < m_AllScripts.Length; i++)
            {
                if (MonoImporter.GetExecutionOrder(m_AllScripts[i]) != m_AllOrders[i])
                {
                    changedIndices.Add(i);
                    changedScripts.Add(m_AllScripts[i]);
                }
            }

            bool editable = true;

            if (Provider.enabled)
            {
                var needToCheckout = new AssetList();
                foreach (var s in changedScripts)
                {
                    var asset = Provider.GetAssetByPath(AssetDatabase.GetAssetPath(s));
                    if (asset == null) // script might be outside of the project (e.g. in a package)
                    {
                        continue;
                    }
                    if (AssetDatabase.IsMetaFileOpenForEdit(s, StatusQueryOptions.UseCachedIfPossible))
                    {
                        continue; // might not need a checkout (not connected, etc.)
                    }
                    needToCheckout.Add(asset);
                }
                if (needToCheckout.Any())
                {
                    var task = Provider.Checkout(needToCheckout, CheckoutMode.Meta);
                    task.Wait();
                    editable = task.success;
                }
            }

            if (editable)
            {
                foreach (int index in changedIndices)
                {
                    MonoImporter.SetExecutionOrder(m_AllScripts[index], m_AllOrders[index]);
                }

                PopulateScriptArray();
            }
            else
            {
                Debug.LogError("Could not checkout scrips in version control for changing script execution order");
            }
        }
コード例 #2
0
        private string ValidateAssetInfo(AssetViewModel assetToExclude)
        {
            StringBuilder errorMessage = new StringBuilder();

            // validate required fields
            if (string.IsNullOrWhiteSpace(SelectedAssetID))
            {
                errorMessage.AppendLine("Asset ID is missing.");
            }

            if (Path.GetInvalidFileNameChars().Any(c => SelectedAssetID.Contains(c)))
            {
                errorMessage.AppendLine("Asset ID contains invalid characters.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetName))
            {
                errorMessage.AppendLine("Name is missing.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetAuthor))
            {
                errorMessage.AppendLine("Author is missing.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetCategory))
            {
                errorMessage.AppendLine("Category is missing.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetDownloadUrl))
            {
                errorMessage.AppendLine("Download Url or Google Drive ID is missing.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetImageUrl))
            {
                errorMessage.AppendLine("Preview Image Url is missing.");
            }

            if (string.IsNullOrWhiteSpace(SelectedAssetVersion))
            {
                SelectedAssetVersion = "1";
            }

            // validate ID is unique
            if (AssetList.Any(a => a != assetToExclude && a.Asset.ID == $"{SelectedAssetID}{SelectedIDExtension}"))
            {
                errorMessage.AppendLine($"Asset ID {SelectedAssetID}{SelectedIDExtension} is already in use. Change the ID to be unique.");
            }

            return(errorMessage.ToString());
        }
コード例 #3
0
        static void UpgradePrefabAsset(Asset asset,
                                       AssetList prefabsWithShapes,
                                       ICollection <Asset> upgradedAssets,
                                       AssetGroupViewData successes,
                                       AssetGroupViewData failures
                                       )
        {
            // exit if we have already upgraded the asset (e.g. it is a parent and we already upgraded it via a variant)
            if (upgradedAssets.Contains(asset))
            {
                return;
            }

            upgradedAssets.Add(asset);

            // exit if it is a prefab parent that doesn't actually have any shapes
            if (!prefabsWithShapes.Contains(asset))
            {
                return;
            }

            GameObject prefab = null;

            try { prefab = PrefabUtility.LoadPrefabContents(asset.path); }
            catch (Exception e)
            {
                failures.AddEntry(asset.path, $"{e.Message}\n\n{e.StackTrace}");
                return;
            }

            // if the prefab is a variant, ensure the prefab it inherits is upgraded first
            if (PrefabUtility.GetPrefabAssetType(prefab) == PrefabAssetType.Variant)
            {
                var sourcePrefab = PrefabUtility.GetCorrespondingObjectFromSource(prefab);
                var sourceAsset  = new Asset(AssetDatabase.GetAssetPath(sourcePrefab));
                UpgradePrefabAsset(sourceAsset, prefabsWithShapes, upgradedAssets, successes, failures);
            }

            // next upgrade any nested prefabs
            foreach (
                var rootAsset in prefab.GetComponentsInChildren <Transform>(true)
                .Select(PrefabUtility.GetNearestPrefabInstanceRoot)
                .Where(r => r != null && r != prefab)                               // skip if the child is not a nested prefab
                .Select(r => new Asset(AssetDatabase.GetAssetPath(r)))
                .Where(r => prefabsWithShapes.Any(a => a.assetPath == r.assetPath)) // skip if the nested prefab isn't one with a shape
                )
            {
                UpgradePrefabAsset(rootAsset, prefabsWithShapes, upgradedAssets, successes, failures);
            }

            bool success = true;

            try
            {
                UpgradePrefabInstance(prefab);
                PrefabUtility.SaveAsPrefabAsset(prefab, asset.path);
            }
            catch (Exception e)
            {
                failures.AddEntry(asset.path, $"{e.Message}\n\n{e.StackTrace}");
            }
            finally
            {
                PrefabUtility.UnloadPrefabContents(prefab);
            }
            if (success)
            {
                successes.AddEntry(asset.path, string.Empty);
            }
        }