Esempio n. 1
0
        /// <summary>
        /// 添加原始项目
        /// </summary>
        /// <param name="hash"></param>
        /// <param name="value"></param>
        internal static bool Add(int hash, GameObject value, byte type)
        {
            bool contains = originalPrefabs.ContainsKey(hash);

            if (!contains) //不能重复添加
            {
                if (type > SegmentSize)
                {
                    type = SegmentSize;
                }
                LuaHelper.AddComponent(value, typeof(ReferGameObjects));
                originalPrefabs[hash] = value;
                prefabFreeQueue[hash] = new Queue <ReferGameObjects>();   //空闲队列
                prefabsType[hash]     = type;
                prefabRefCaches[hash] = new HashSet <ReferGameObjects>(); //引用列表

                if (type <= SegmentSize)
                {
                    for (int i = segment.Count; i <= type; i++)
                    {
                        segment.Add(new List <int>());
                    }

                    segment[type].Add(hash);
                }

#if UNITY_EDITOR
                LuaHelper.RefreshShader(value);
#endif
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
    static public void SetAssetBundlesName()
    {
        Object[] selection = Selection.objects;

        AssetImporter import = null;

        foreach (Object s in selection)
        {
            import = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s));
            import.assetBundleName = s.name + "." + Common.ASSETBUNDLE_SUFFIX;
            if (s.name.Contains(" "))
            {
                Debug.LogWarning(s.name + " contains space");
            }
            Debug.Log(s.name);
            if (s is GameObject)
            {
                GameObject     tar  = s as GameObject;
                ReferenceCount refe = LuaHelper.AddComponent(tar, typeof(ReferenceCount)) as ReferenceCount;
                refe.assetBundleName = s.name.ToLower();
            }
        }
    }
Esempio n. 3
0
    public static void ClearAssetBundlesName()
    {
        Object[] selection = Selection.objects;

        AssetImporter import = null;

        foreach (Object s in selection)
        {
            import = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s));
            import.assetBundleName = null;
            Debug.Log(s.name + " clear");
            if (s is GameObject)
            {
                GameObject     tar  = s as GameObject;
                ReferenceCount refe = LuaHelper.AddComponent(tar, typeof(ReferenceCount)) as ReferenceCount;
                if (refe != null)
                {
                    refe.assetBundleName = string.Empty;
                    EditorUtility.SetDirty(s);
                }
            }
        }
    }
Esempio n. 4
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;
            string        name        = "";
            string        cacheAbName = "";
            StringBuilder tipsInfo    = new StringBuilder();

            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    string folder = GetLabelsByPath(path);
                    Object s      = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                    name = s.name.ToLower();
                    if (string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        name = CUtils.GetRightFileName(name);

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

                        cacheAbName = import.assetBundleName;
                    }
                    else
                    {
                        string[] names = name.Split('-');
                        name = names[0];
                        if (string.IsNullOrEmpty(folder))
                        {
                            import.assetBundleName = CUtils.GetRightFileName(name);
                        }
                        else
                        {
                            import.assetBundleName = string.Format("{0}/{1}", folder, CUtils.GetRightFileName(name));
                        }

                        import.assetBundleVariant = names[1];

                        cacheAbName = import.assetBundleName + "." + import.assetBundleVariant;
                    }

                    tipsInfo.AppendLine(cacheAbName + " path = " + path);

                    if (s is GameObject)
                    {
                        GameObject     tar  = s as GameObject;
                        ReferenceCount refe = LuaHelper.AddComponent(tar, typeof(ReferenceCount)) as ReferenceCount;
                        if (refe != null)
                        {
                            refe.assetbundle = cacheAbName;
                            // refe.assetHashCode = LuaHelper.StringToHash(cacheAbName);
                            EditorUtility.SetDirty(s);
                        }
                    }

                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                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!");
        }
Esempio n. 5
0
        /// <summary>
        /// 设置assetbundleName
        /// </summary>
        /// <param name="s"></param>
        public static void SetAssetBundleName(Object s, bool replace = false)
        {
            string        abPath  = AssetDatabase.GetAssetPath(s);
            AssetImporter import  = AssetImporter.GetAtPath(abPath);
            string        folder  = GetLabelsByPath(abPath);
            string        objName = s.name.ToLower();

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

            string name = CUtils.GetRightFileName(objName);

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

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

            bool isScene = abPath.EndsWith(".unity");

            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)
                    {
                        // refe.assetHashCode = LuaHelper.StringToHash(import.assetBundleName);
                        refe.assetbundle = import.assetBundleName;
                        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)
                {
                    refe.assetbundle = import.assetBundleName;
                    // refe.assetHashCode = LuaHelper.StringToHash(import.assetBundleName);
                    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}", GetGameObjectPathInScene(rf.transform, string.Empty));
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 设置assetbundleName
        /// </summary>
        /// <param name="s"></param>
        public static void SetAssetBundleName(Object s, bool replace = false, bool variant = false)
        {
            string abPath = AssetDatabase.GetAssetPath(s);
            AssetImporter
                   import  = AssetImporter.GetAtPath(abPath);
            string folder  = 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)
            {
                DirectoryInfo filePath  = new DirectoryInfo(abPath);
                var           m_variant = 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)
                    {
                        refe.assetbundle =
                            import.assetBundleName;
                        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)
                {
                    refe.assetbundle = import.assetBundleName;
                    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}", GetGameObjectPathInScene(rf.transform, string.Empty));
                    }
                }
            }
        }