Ejemplo n.º 1
0
    static void OnPostHeaderGUI(Editor editor)
    {
        if (editor.target == null)
        {
            return;
        }
        string assetPath = AssetDatabase.GetAssetPath(editor.target).ToLower();

        if (IsValid(assetPath) == false)
        {
            return;
        }

        if (s_ToggleMixed == null)
        {
            s_ToggleMixed = new GUIStyle("ToggleMixed");
        }

        var asset = GetAssetFile(editor.target);

        GUILayout.BeginHorizontal();

        bool isSelectAsset = asset != null && list.Contains(asset.name);
        bool isSelectMixed = IsMixedSelect(editor.targets);

        if (isSelectMixed)
        {
            isSelectAsset = false;
        }


        bool isSelectGroup;

        if (isSelectMixed)
        {
            isSelectGroup = GUILayout.Toggle(isSelectAsset, "Asset", s_ToggleMixed, GUILayout.ExpandWidth(false));
        }
        else
        {
            isSelectGroup = GUILayout.Toggle(isSelectAsset, "Asset", GUILayout.ExpandWidth(false));
        }
        if (isSelectAsset && isSelectGroup == false)
        {
            RemoveFromList(editor.targets);
            asset = null;
        }
        else if (isSelectAsset == false && isSelectGroup)
        {
            AddToList(editor.targets);
        }

        if (asset != null && isSelectAsset && editor.targets.Length == 1)
        {
            asset.asset = assetPath;

            var assetName = EditorGUILayout.DelayedTextField(asset.name, GUILayout.ExpandWidth(true));
            if (assetName != asset.name)
            {
                list.Remove(asset);
                asset.name = assetName.ToLower();
                list.Add(asset);
                SaveAssetList();
            }
        }

        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (asset != null && list.Contains(asset.name))
        {
            isSelectAsset = string.IsNullOrEmpty(asset.bundle) == false;
            isSelectMixed = IsMixedGroup(editor.targets);
            if (isSelectMixed)
            {
                isSelectGroup = GUILayout.Toggle(isSelectAsset, "Bundle", s_ToggleMixed, GUILayout.ExpandWidth(false));
            }
            else
            {
                isSelectGroup = GUILayout.Toggle(isSelectAsset, "Bundle", GUILayout.ExpandWidth(false));
            }
            if (isSelectGroup == false && isSelectAsset)
            {
                SetAssetsBundle(editor.targets, null);
                SaveAssetList();
            }
            else
            {
                if (isSelectGroup)
                {
                    if (isSelectAsset == false)
                    {
                        string dir = Path.GetDirectoryName(asset.asset);
                        asset.bundle = dir.Substring(dir.LastIndexOf("\\", System.StringComparison.Ordinal) + 1);
                    }

                    var group = EditorGUILayout.DelayedTextField(asset.bundle, GUILayout.ExpandWidth(true));
                    if (isSelectAsset == false || group != asset.bundle)
                    {
                        //Debug.Log(check + "," + select + "," + asset.group + "," + group);
                        SetAssetsBundle(editor.targets, group);
                        SaveAssetList();
                    }
                }
            }
        }

        GUILayout.EndHorizontal();
    }
Ejemplo n.º 2
0
    static void SaveBuildList(string outputPath)
    {
        AssetList        buildList = new AssetList();
        HashSet <string> bundeList = new HashSet <string>();

        buildList.manifest = EditorUserBuildSettings.activeBuildTarget.ToString();
        bundeList.Add(buildList.manifest);

        foreach (var file in list.assets.Values)
        {
            if (file.asset.Contains("resources/") == false || string.IsNullOrEmpty(file.bundle) == false)
            {
                if (buildList.Contains(file.name) == false && buildList.assets.ContainsValue(file) == false)
                {
                    if (string.IsNullOrEmpty(file.bundle))
                    {
                        string fullPath = string.Format("{0}{1}", outputPath, file.asset);
                        byte[] bytes    = File.ReadAllBytes(fullPath);
                        file.size = bytes.Length;
                        file.md5  = MD5Hash.Get(bytes);
                    }
                    else
                    {
                        file.size = 0;
                        file.md5  = null;
                        bundeList.Add(file.bundle);
                    }
                    buildList.assets.Add(file.name, file);
                }
            }
            else
            {
                if (buildList.Contains(file.name) == false && buildList.assets.ContainsValue(file) == false)
                {
                    string fullPath = string.Format("{0}{1}", Application.dataPath.Replace("Assets", ""), file.asset);
                    byte[] bytes    = File.ReadAllBytes(fullPath);
                    file.size = bytes.Length;
                    file.md5  = MD5Hash.Get(bytes);
                    buildList.assets.Add(file.name, file);
                }
            }
        }
        foreach (var name in bundeList)
        {
            string    fullPath = string.Format("{0}{1}", outputPath, name);
            byte[]    bytes    = File.ReadAllBytes(fullPath);
            AssetFile file     = new AssetFile();
            file.name   = name;
            file.bundle = name;
            file.size   = bytes.Length;
            file.md5    = MD5Hash.Get(bytes);
            buildList.assets.Add(file.name, file);
        }

        string assetXmlFile = outputPath + "/" + AssetPath.ASSETSFILE;

        StreamWriter writerXml = new StreamWriter(assetXmlFile);

        writerXml.Write(buildList.ToXml());
        writerXml.Close();
        writerXml.Dispose();
    }
Ejemplo n.º 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);
            }
        }