Ejemplo n.º 1
0
        /// <summary>
        /// Updates the name of the asset bundles.
        /// </summary>
        /// <param name="allAssets">All assets.</param>
        public static void UpdateAssetBundlesName(string[] allAssets)
        {
            string info = string.Format("Update AssetBundles Name To {0}", isMd5 == true ? "Md5" : " Prefab.Name");

            EditorUtility.DisplayProgressBar("UpdateAssetBundlesName", info, 0);
            AssetImporter
                          import   = null;
            float         i        = 0;
            float         allLen   = allAssets.Length;
            StringBuilder tipsInfo = new StringBuilder();

            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    string folder = EditorUtils.GetLabelsByPath(path);
                    Object s      = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                    SetAssetBundleName(s, true);
                    tipsInfo.AppendLine(s.name + " path = " + path);
                }
                else
                {
                    //Debug.LogWarning(path + " import not exist");
                }
                EditorUtility.DisplayProgressBar("UpdateAssetBundlesName", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }

            EditorUtility.ClearProgressBar();
            Debug.Log(tipsInfo.ToString() + " Complete!");
        }
Ejemplo n.º 2
0
        public static void DeleteAssetBundlesName()
        {
            string        assetBundleName = "";
            List <ABInfo> del             = new List <ABInfo>();

            Object[] selection = Selection.objects; //EditorUtils.SelectObjects();

            foreach (Object s in selection)
            {
                string abPath = AssetDatabase.GetAssetPath(s);
                string folder = EditorUtils.GetLabelsByPath(abPath);
                string name   = CUtils.GetRightFileName(s.name.ToLower());

                if (string.IsNullOrEmpty(folder))
                {
                    assetBundleName = name + "." + Common.ASSETBUNDLE_SUFFIX;
                }
                else
                {
                    assetBundleName = string.Format("{0}/{1}.{2}", folder, name, Common.ASSETBUNDLE_SUFFIX);
                }

                if (s.name.Contains(" "))
                {
                    Debug.LogWarning(s.name + " contains space");
                }
                Debug.Log("delete : " + s.name + " md5 = " + assetBundleName);
                del.Add(new ABInfo(assetBundleName, 0, 0, 0));
            }

            SplitPackage.DeleteStreamingFiles(del); //删除选中对象的ab
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置assetbundleName
        /// </summary>
        /// <param name="s"></param>
        public static void SetAssetBundleName(Object s, bool replace = false, bool variant = false, string variantName = null)
        {
            string abPath = AssetDatabase.GetAssetPath(s);
            AssetImporter
                   import  = AssetImporter.GetAtPath(abPath);
            string folder  = EditorUtils.GetLabelsByPath(abPath);
            string objName = s.name.ToLower();

            if (replace)
            {
                objName = HugulaEditorSetting.instance.GetAssetBundleNameByReplaceIgnore(objName);
                // Debug.LogFormat ("{0} replace {1}", s.name, objName);
            }

            bool   isScene = abPath.EndsWith(".unity");
            string name    = CUtils.GetRightFileName(objName);

            var suffix = Common.CHECK_ASSETBUNDLE_SUFFIX;

            // if (variant) // variant
            // {
            //     suffix = "";
            // }

            if (string.IsNullOrEmpty(folder))
            {
                import.assetBundleName = name + suffix;
            }
            else
            {
                import.assetBundleName = string.Format("{0}/{1}{2}", folder, name, suffix);
            }

            if (variant)
            {
                string m_variant;
                if (abPath.IndexOf("Assets/TapEnjoy/WarX/Effect/Prefabs/high") == 0)
                {
                    m_variant = "high";
                }
                else if (abPath.IndexOf("Assets/TapEnjoy/WarX/Effect/Prefabs/medium") == 0)
                {
                    m_variant = "medium";
                }
                else if (abPath.IndexOf("Assets/TapEnjoy/WarX/Effect/Prefabs/low") == 0)
                {
                    m_variant = "low";
                }
                else
                {
                    DirectoryInfo filePath = new DirectoryInfo(abPath);
                    m_variant = variantName != null ? variantName : filePath.Parent.Name.ToLower();
                }

                import.assetBundleVariant = m_variant;
                HugulaSetting.instance.AddVariant(m_variant);
                if (m_variant.Equals(Common.ASSETBUNDLE_SUFFIX))
                {
                    Debug.LogWarningFormat("{0} variant folder name Equals {1}", abPath, Common.ASSETBUNDLE_SUFFIX);
                }
                if (m_variant == Common.DOT_BYTES.Replace(".", ""))
                {
                    Debug.LogWarningFormat("{0} variant folder name Equals {1}", abPath, Common.DOT_BYTES);
                }
            }

            if (s.name.Contains(" "))
            {
                Debug.LogWarning(s.name + " contains space");
            }

            Debug.Log(import.assetBundleName + ",variant=" + import.assetBundleVariant);

            // if (s is GameObject)
            // {
            //     GameObject tar = s as GameObject;
            //     if (tar.transform.parent == null)
            //     {
            //         ReferenceCount refe = LuaHelper.AddComponent(tar, typeof(ReferenceCount)) as ReferenceCount;
            //         if (refe != null)
            //         {
            //             if (string.IsNullOrEmpty(import.assetBundleVariant))
            //                 refe.assetbundle = import.assetBundleName;
            //             else
            //                 refe.assetbundle = import.assetBundleName + "." + import.assetBundleVariant;

            //             EditorUtility.SetDirty(s);
            //         }
            //     }
            // }
            // else if (isScene) //如果是场景需要添加引用计数脚本
            // { //UnityEngine.SceneAsset
            //     var sce = s; // as SceneAsset;
            //     Debug.Log(sce);
            //     AssetDatabase.OpenAsset(sce);
            //     GameObject gobj = GameObject.Find(sce.name);
            //     if (gobj == null) gobj = new GameObject(sce.name);
            //     ReferenceCount refe = LuaHelper.AddComponent(gobj, typeof(ReferenceCount)) as ReferenceCount;
            //     if (refe != null)
            //     {
            //         if (string.IsNullOrEmpty(import.assetBundleVariant))
            //             refe.assetbundle = import.assetBundleName;
            //         else
            //             refe.assetbundle = import.assetBundleName + "." + import.assetBundleVariant;

            //         EditorUtility.SetDirty(sce);
            //     }

            //     var refers = GameObject.FindObjectsOfType<ReferenceCount>();
            //     foreach (var rf in refers)
            //     {
            //         if (rf != refe)
            //         {
            //             Debug.LogWarningFormat("you should not add ReferenceCount in {0}", EditorUtils.GetGameObjectPathInScene(rf.transform, string.Empty));
            //         }
            //     }
            // }
        }