Пример #1
0
        public static AssetFileInfo GetAssetFileInfo(long guid)
        {
            if (assetFileInfos == null)
            {
                assetFileInfos = new Dictionary <long, AssetFileInfo>();
            }

            if (!assetFileInfos.TryGetValue(guid, out AssetFileInfo info))
            {
                info = new AssetFileInfo {
                    guid = guid
                };
                assetFileInfos.Add(guid, info);
            }

            return(info);
        }
        public static void ObjectAddToFileInfo(Object obj, SerializedObject serializedObject, AssetBundleFileInfo info)
        {
            if (obj == null)
            {
                return;
            }

            string name2 = obj.name;
            string type  = obj.GetType().ToString();

            if (type.StartsWith("UnityEngine.", System.StringComparison.Ordinal))
            {
                type = type.Substring(12);

                // 如果是内置的组件,就不当作是资源
                if (obj as Component)
                {
                    return;
                }
            }
            else if (string.Equals(type, "UnityEditor.Animations.AnimatorController", System.StringComparison.Ordinal))
            {
                type = "AnimatorController";
            }
            else if (string.Equals(type, "UnityEditorInternal.AnimatorController", System.StringComparison.Ordinal))
            {
                type = "AnimatorController";
            }
            else if (string.Equals(type == "UnityEditor.MonoScript", System.StringComparison.Ordinal))
            {
                MonoScript ms    = obj as MonoScript;
                string     type2 = ms.GetClass().ToString();
                if (type2.StartsWith("UnityEngine.", System.StringComparison.Ordinal))
                {
                    // 内置的脚本对象也不显示出来
                    return;
                }

                // 外部的组件脚本,保留下来
                type = "MonoScript";
            }
            else
            {
                // 外部的组件脚本,走上面的MonoScript
                if (obj as Component)
                {
                    return;
                }
                // 外部的序列化对象,已经被脚本给分析完毕了,不需要再添加进来
                if (obj as ScriptableObject)
                {
                    return;
                }

                Debug.LogError("What's this? " + type);
                return;
            }

            // 内建的资源排除掉
            string assetPath = AssetDatabase.GetAssetPath(obj);

            if (!string.IsNullOrEmpty(assetPath))
            {
                return;
            }

            long guid;

            if (info.isScene)
            {
                // 场景的话,没法根据PathID来确定唯一性,那么就认为每个场景用到的资源都不一样
                guid = (info.name + name2 + type).GetHashCode();
            }
            else
            {
                SerializedProperty pathIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");
#if UNITY_5 || UNITY_5_3_OR_NEWER
                guid = pathIdProp.longValue;
#else
                guid = pathIdProp.intValue;
#endif
            }

            if (info.IsAssetContain(guid))
            {
                return;
            }

            AssetFileInfo info2 = AssetBundleFilesAnalyze.GetAssetFileInfo(guid);
            info2.name = name2;
            info2.type = type;
            info2.includedBundles.Add(info);
            if (info2.detailHyperLink == null)
            {
                // 初次创建对象时链接为空
                info2.detailHyperLink = new OfficeOpenXml.ExcelHyperLink(System.String.Empty, info2.name);
                info2.propertys       = AnalyzeObject(obj, serializedObject, info.rootPath, info.name);
            }

            info.assets.Add(info2);
        }