Example #1
0
	//
	public static void ShowBundle(BundleData newBundle)
	{
		// Show dummy object in inspector
		if(sbInspectorObj == null)
		{
			sbInspectorObj = ScriptableObject.CreateInstance<SceneBundleInpectorObj>();
			sbInspectorObj.hideFlags = HideFlags.DontSave;
		}

		if(abInpsectorObj == null)
		{
			abInpsectorObj = ScriptableObject.CreateInstance<AssetBundleInspectorObj>();
			abInpsectorObj.hideFlags = HideFlags.DontSave;
		}

		if(newBundle != null)
			Selection.activeObject = newBundle.sceneBundle? (Object)sbInspectorObj : (Object)abInpsectorObj;
		else
			Selection.activeObject = null;
		
		// Update bundle
		if(newBundle == currentBundle)
			return;
		
		currentBundle = newBundle;
		
		Refresh();
	}
Example #2
0
    /**
     * Detect if the bundle need update.
     */
    public static bool IsBundleNeedBunild(BundleData bundle)
    {
        string outputPath = GenerateOutputPathForBundle(bundle);
        if (!File.Exists(outputPath))
        {
            Debug.LogWarning("BundleData : " + bundle.name + " Not Exsit!  ");
            return true;
        }

        BundleBuildState bundleBuildState = BundleManager.GetBuildStateOfBundle(bundle.name);
        if (bundleBuildState == null)
        {
            Debug.LogWarning("BundleData : " + bundle.name + " Not Found!  ");
            return true;
        }
        DateTime lastBuildTime = File.GetLastWriteTime(outputPath);
        DateTime bundleChangeTime = bundleBuildState.changeTime == -1 ? DateTime.MaxValue : DateTime.FromBinary(bundleBuildState.changeTime);
        if (System.DateTime.Compare(lastBuildTime, bundleChangeTime) < 0)
        {
            Debug.LogWarning("BundleData : " + bundle.name + " bundleChangeTime > lastBuildTime ");
            return true;
        }

        string[] assetPaths = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray()), bundle.sceneBundle);
        string[] dependencies = AssetDatabase.GetDependencies(assetPaths);
        if (!EqualStrArray(dependencies, bundleBuildState.lastBuildDependencies))
        {
            Debug.LogWarning("BundleData : " + bundle.name + " Build depenedencies list changed: ");
            return true; // Build depenedencies list changed.
        }

        foreach (string file in dependencies)
        {
            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(file)) < 0)
            {
                Debug.LogWarning("BundleData : " + bundle.name + " file changed : " + file);
                return true;
            }
        }

        if (bundle.parent != "")
        {
            BundleData parentBundle = BundleManager.GetBundleData(bundle.parent);
            if (parentBundle != null)
            {
                if (IsBundleNeedBunild(parentBundle))
                    return true;
            }
            else
            {
                Debug.LogError("Cannot find bundle");
            }
        }

        return false;
    }
Example #3
0
 private static BundleData CreateBundleData(string path)
 {
     BundleData data = new BundleData();
     data.assetPath = path;
     data.name = Path.GetFileNameWithoutExtension(path);
     data.guid = AssetDatabase.AssetPathToGUID(path);
     data.depends = BuildHelp.GetDependencies(path);
     return data;
 }
Example #4
0
 private static void AddCommonDepends(BundleData bundleData)
 {
     bundleData.depends.Add("Assets/LocalResources/Shader.prefab");
 }
Example #5
0
 private static string GenerateOutputPathForBundle(BundleData bundle)
 {
     return Path.Combine(BuildConfiger.InterpretedOutputPath, (bundle.path == "" ? "" : bundle.path) + "/" + bundle.name + "." + BuildConfiger.BundleSuffix);
 }
Example #6
0
    internal static void RefreshBundleDependencies(BundleData bundle)
    {
        // Get all the includes files path
        string[] files = BuildHelper.GetAssetsFromPaths(GUIDsToPaths(bundle.includeGUIDs).ToArray(), bundle.sceneBundle);
        string[] dependGUIDs = PathsToGUIDs(AssetDatabase.GetDependencies(files));

        List<string> oldMetaList = bundle.dependGUIDs;
        bundle.dependGUIDs = new List<string>(dependGUIDs);
        bundle.dependGUIDs.RemoveAll(x => bundle.includeGUIDs.Contains(x));

        // Remove the old ones
        foreach (string guid in oldMetaList)
        {
            if (getInstance().dependRefDict.ContainsKey(guid))
                getInstance().dependRefDict[guid].Remove(bundle);
        }

        // Add new asset connection
        foreach (string guid in bundle.dependGUIDs)
        {
            if (!getInstance().dependRefDict.ContainsKey(guid))
            {
                List<BundleData> sharedBundleList = new List<BundleData>();
                sharedBundleList.Add(bundle);
                getInstance().dependRefDict.Add(guid, sharedBundleList);
            }
            else
            {
                getInstance().dependRefDict[guid].Add(bundle);
            }
        }
    }
Example #7
0
    Rect GUI_DrawItem(BundleData bundle, int indent)
    {
        bool isEditing = m_CurrentEditing == bundle.name;
        bool isRecieving = m_CurrentRecieving == bundle.name;
        bool isSelected = m_Selections.Contains(bundle.name);

        GUIStyle currentLableStyle = BMGUIStyles.GetCustomStyle("TreeItemUnSelect");
        if (isRecieving)
            currentLableStyle = BMGUIStyles.GetCustomStyle("receivingLable");
        else if (isSelected && !isEditing)
            currentLableStyle = HasFocuse() ? BMGUIStyles.GetCustomStyle("TreeItemSelectBlue") : BMGUIStyles.GetCustomStyle("TreeItemSelectGray");

        Rect itemRect = EditorGUILayout.BeginHorizontal(currentLableStyle);

        if (bundle.children.Count == 0)
        {
            GUILayout.Space(m_IndentWidth * indent + m_NoToggleIndent);
        }
        else
        {
            GUILayout.Space(m_IndentWidth * indent);
            bool fold = !GUILayout.Toggle(!IsFold(bundle.name), "", BMGUIStyles.GetCustomStyle("Foldout"));
            SetFold(bundle.name, fold);
        }

        GUILayout.Label(bundle.sceneBundle ? BMGUIStyles.GetIcon("sceneBundleIcon") : BMGUIStyles.GetIcon("assetBundleIcon"), BMGUIStyles.GetCustomStyle("BItemLabelNormal"), GUILayout.ExpandWidth(false));

        if (!isEditing)
        {
            GUILayout.Label(bundle.name, isSelected ? BMGUIStyles.GetCustomStyle("BItemLabelActive") : BMGUIStyles.GetCustomStyle("BItemLabelNormal"));
        }
        else
        {
            GUI.SetNextControlName(m_EditTextFeildName);
            m_EditString = GUILayout.TextField(m_EditString, BMGUIStyles.GetCustomStyle("TreeEditField"));
        }

        EditorGUILayout.EndHorizontal();

        return itemRect;
    }
Example #8
0
    public static void WriteDependencies2Json(string path)
    {
        List<BundleData> datas = new List<BundleData>();
        foreach (KeyValuePair<string, List<string>> kvp in dependencies)
        {
            BundleData data = new BundleData();
            string assetPath = AssetDatabase.GUIDToAssetPath(kvp.Key);
            data.name = assetPath.Replace("Assets/" + srcPath, "");
            string fullpath = string.Format("{0}/{1}/{2}", Application.dataPath, srcPath, data.name);
            data.md5 = Utils.md5file(fullpath);
            data.dependAssets = FindDependencies(kvp.Key);
            datas.Add(data);
        }

        FileStream fs = new FileStream(path, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);
        string jsonStr = JsonFormatter.PrettyPrint(LitJson.JsonMapper.ToJson(datas));
        sw.Write(jsonStr);
        sw.Flush();
        sw.Close();
        fs.Close();
    }
Example #9
0
    public static bool BuildSingleBundle( BundleData bundle)
    {
        

        UnityEngine.Object assetObj = null;
        string outputPath = GenerateOutputBundlePath(bundle.name);

        if (!LoadAssetObjectByAssetPath( bundle.assetPath, out assetObj))
        {
            return false;
        }

        uint crc = 0;
        long changTime = DateTime.Now.ToBinary();

        bool succeed = BuildAssetBundle(assetObj, outputPath, out crc);

        BundleBuildState bundleState = BundleManager.GetBuildStateNoNull(bundle.assetPath);
        if (succeed)
        {
            bundleState.crc = crc;
            bundleState.lastDependencies = bundle.depends.ToArray();
            FileInfo info = new FileInfo(outputPath);
            bundleState.size = info.Length;
            bundleState.changeTime = changTime;
        }
        else
        {
            bundleState.lastDependencies = null;
        }

        //  每次写入,文件过多会有性能问题
        //BMDataAccessor.SaveBundleBuildeStates();
        return succeed;
    }
Example #10
0
    public static bool BuildRootBundle( BundleData bundle)
    {
        if (!IsNeedBuild(bundle))
        {
            Debug.Log(string.Format("Bundle {0} Skiped!", bundle.name));
            return true;
        }

        PushCommontDepends();

        BuildPipeline.PushAssetDependencies();
        for (int i = 0; i < bundle.depends.Count; i++)
        {
            BundleData dependBundle = BundleManager.GetBundleData(bundle.depends[i]);
            if (!BuildSingleBundle(dependBundle))
            {
                Debug.Log(string.Format("Build {0} Fail!", dependBundle.name));
                goto ONE_POP;
            }
        }

        BuildPipeline.PushAssetDependencies();

        BundleData mainBundle = BundleManager.GetBundleData(bundle.assetPath);
        if ( !BuildSingleBundle(mainBundle))
        {
            goto TWO_POP;
        }

        goto SUCCEED;


    ONE_POP:
        Debug.Log( string.Format("{0} Depends Build Error! ", bundle.name));
        BuildPipeline.PopAssetDependencies();
        PopCommontDepends();
        return false;
    TWO_POP:
        Debug.Log(string.Format("{0} Self Build Error! ", bundle.name));
        BuildPipeline.PopAssetDependencies();
        BuildPipeline.PopAssetDependencies();
        PopCommontDepends();
        return false;
    SUCCEED:
        Debug.Log(string.Format("Build {0} Succeed!", bundle.name));
        BuildPipeline.PopAssetDependencies();
        BuildPipeline.PopAssetDependencies();
        PopCommontDepends();
        return true;
    }
Example #11
0
    private static bool IsNameDuplicatedAsset(BundleData bundle, string newAsset)
    {
        string newName = Path.GetFileNameWithoutExtension(newAsset);
        foreach (string guid in bundle.includeGUIDs)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            string file = Path.GetFileNameWithoutExtension(path);
            if (file == newName)
                return true;
        }

        return false;
    }
Example #12
0
    private static void InsertBundleToBundleList(BundleData bundle)
    {
        List<BundleData> bundleList = BMDataAccessor.Bundles;
        if (bundleList.Contains(bundle))
            return;

        if (bundle.parent == "")
        {
            int childBundleStartIndex = bundleList.FindIndex(x => x.parent != "");
            childBundleStartIndex = childBundleStartIndex == -1 ? bundleList.Count : childBundleStartIndex;
            bundleList.Insert(childBundleStartIndex, bundle);
        }
        else
            bundleList.Add(bundle);
    }
Example #13
0
 internal static void RemoveIncludeRef(string guid, BundleData bundle)
 {
     string path = AssetDatabase.GUIDToAssetPath(guid);
     foreach (string subPath in BuildHelper.GetAssetsFromPath(path, bundle.sceneBundle))
     {
         string subGuid = AssetDatabase.AssetPathToGUID(subPath);
         getInstance().includeRefDict[subGuid].Remove(bundle);
     }
 }
Example #14
0
    internal static void AddIncludeRef(string guid, BundleData bundle)
    {
        string path = AssetDatabase.GUIDToAssetPath(guid);
        foreach (string subPath in BuildHelper.GetAssetsFromPath(path, bundle.sceneBundle))
        {
            string subGuid = AssetDatabase.AssetPathToGUID(subPath);

            if (!getInstance().includeRefDict.ContainsKey(subGuid))
            {
                List<BundleData> sharedBundleList = new List<BundleData>() { bundle };
                getInstance().includeRefDict.Add(subGuid, sharedBundleList);
            }
            else if (!getInstance().includeRefDict[subGuid].Contains(bundle))
            {
                getInstance().includeRefDict[subGuid].Add(bundle);
            }
        }
    }
Example #15
0
 private static BundleDependsData CreateDependsData(BundleData data)
 {
     BundleDependsData dependsData = new BundleDependsData();
     dependsData.depends = new string[data.depends.Count];
     for (int i = 0; i < data.depends.Count; i++)
     {
         dependsData.depends[i] = Path.GetFileNameWithoutExtension(data.depends[i]);
     }
     dependsData.name = data.name;
     return dependsData;
 }
Example #16
0
    public static bool IsNeedBuild( BundleData bundle )
    {

        if (BuildManager.IsIgnoreState)
            return true;

        string outputPath = GenerateOutputBundlePath(bundle.name);
        if (!File.Exists(outputPath))
            return true;

        BundleBuildState bundleBuildState = BundleManager.GetBuildState(bundle.assetPath);

        if (bundleBuildState == null)
            return true;

        //  输出文件是否被修改
        DateTime lastBuildTime = File.GetLastWriteTime(outputPath);
        DateTime bundleChangeTime = bundleBuildState.changeTime == -1 ? DateTime.MaxValue : DateTime.FromBinary(bundleBuildState.changeTime);
        if ( System.DateTime.Compare(lastBuildTime, bundleChangeTime) < 0)
        {
            return true;
        }

        if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.assetPath)) < 0)
        {
            return true;
        }

        //  依赖是否改变
        if(!EqualStrArray(bundle.depends, bundleBuildState.lastDependencies))
        {
            return true;
        }


        string[] allResDepends = GetFilterCsDepends(bundle.assetPath);
        for (int i = 0; i < allResDepends.Length; i++)
        {
            var fullPaht = BundleHelp.AssetPath2FullPath(ref allResDepends[i]);

            DateTime test = File.GetLastWriteTime(fullPaht);

            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(fullPaht)) < 0)
            {
                return true;
            }

            if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(fullPaht + ".meta")) < 0)
            {
                return true;
            }
        }

        //  依赖文件是否被改变
        //for (int i = 0; i < bundle.depends.Count; i++)
        //{

        //    //  TODO:没有检测纹理之内的资源是否变化

        //    if (!File.Exists(GenerateOutputBundlePath(Path.GetFileNameWithoutExtension(bundle.depends[i]))))
        //        return true;

        //    if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.depends[i])) < 0)
        //    {
        //        return true;
        //    }

        //    //  meta change 
        //    //  Texture Format Change
        //    if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(bundle.depends[i] + ".meta")) < 0)
        //    {
        //        return true;
        //    }
        //}

        return false;
    }
Example #17
0
    internal static bool BuildBundleTree(BundleData bundle, List<string> requiredBuildList)
    {
        BuildPipeline.PushAssetDependencies();

        bool succ = BuildSingleBundle(bundle);
        if (!succ)
        {
            Debug.LogError(bundle.name + " build failed.");
            BuildPipeline.PopAssetDependencies();
            return false;
        }
        else
        {
            Debug.Log(bundle.name + " build succeed.");
        }

        foreach (string childName in bundle.children)
        {
            BundleData child = BundleManager.GetBundleData(childName);
            if (child == null)
            {
                Debug.LogError("Cannnot find bundle [" + childName + "]. Sth wrong with the bundle config data.");
                BuildPipeline.PopAssetDependencies();
                return false;
            }

            bool isDependingBundle = false;
            foreach (string requiredBundle in requiredBuildList)
            {
                if (BundleManager.IsBundleDependOn(requiredBundle, childName))
                {
                    isDependingBundle = true;
                    break;
                }
            }
            //ĬÈ϶¼ÊÇDeterministicBundle
            if (isDependingBundle)// || !BuildConfiger.DeterministicBundle)
            {
                succ = BuildBundleTree(child, requiredBuildList);
                if (!succ)
                {
                    BuildPipeline.PopAssetDependencies();
                    return false;
                }
            }
        }

        BuildPipeline.PopAssetDependencies();
        return true;
    }
Example #18
0
 static public void AddNewBundleData( BundleData data )
 {
     Instance.mBundleData.Add(data.assetPath, data);
 }
Example #19
0
    private static bool BuildSingleBundle(BundleData bundle)
    {
        // Prepare bundle output dictionary
        string outputPath = GenerateOutputPathForBundle(bundle);
        string bundleStoreDir = Path.GetDirectoryName(outputPath);
        if (!Directory.Exists(bundleStoreDir))
            Directory.CreateDirectory(bundleStoreDir);

        // Start build
        string[] assetPaths = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray()), bundle.sceneBundle);
        bool succeed = false;
        uint crc = 0;
        if (bundle.sceneBundle)
            succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
        else
            succeed = BuildAssetBundle(assetPaths, outputPath, out crc);

        // Remember the assets for next time build test
        BundleBuildState buildState = BundleManager.GetOrAddBuildStateOfBundle(bundle.name);
        if (succeed)
        {
            buildState.lastBuildDependencies = AssetDatabase.GetDependencies(assetPaths);
            buildState.version++;
            if (buildState.version == int.MaxValue)
                buildState.version = 0;

            buildState.crc = crc;
            FileInfo bundleFileInfo = new FileInfo(outputPath);
            buildState.size = bundleFileInfo.Length;
        }
        else
        {
            buildState.lastBuildDependencies = null;
        }

        BMDataAccessor.SaveBundleBuildeStates();
        return succeed;
    }
Example #20
0
        public void Process_AddBundle()
        {
            BundleData entry = new BundleData();
            UrlAliasInfo urlAliasInfo = new UrlAliasInfo();

            entry = (BundleData)Process_GetEntryAddValues(entry);

            entry.BundledItems = Process_GetBundledItems();

            urlAliasInfo = Process_Alias();

            try
            {
                if (hdn_publishaction.Value == Convert.ToInt32(EkEnumeration.AssetActionType.Save).ToString())
                {
                    m_refCatalog.AddAndSave(entry, urlAliasInfo);
                    Process_Taxonomy(entry.Id, entry.FolderId);
                    Process_Inventory(entry.Id);
                    Util_ResponseHandler("catalogentry.aspx?close=false&LangType=" + entry.LanguageId + "&id=" + entry.Id + "&type=update&back_file=cmsform.aspx&back_action=ViewStaged&back_folder_id=" + entry.FolderId + "&back_callerpage=content.aspx&back_origurl=action%3dViewContentByCategory%26id%3d" + entry.FolderId + "&back_LangType=" + entry.LanguageId + "&rnd=6"); // goes to edit screen.
                }
                else if (hdn_publishaction.Value == Convert.ToInt32(EkEnumeration.AssetActionType.Checkin).ToString())
                {
                    m_refCatalog.AddAndCheckIn(entry, urlAliasInfo);
                    Process_Taxonomy(entry.Id, entry.FolderId);
                    Process_Inventory(entry.Id);
                    Util_ResponseHandler((string)("../content.aspx?action=View&folder_id=" + entry.FolderId + "&id=" + entry.Id + "&LangType=" + entry.LanguageId + "&callerpage=content.aspx&origurl=action%3dViewContentByCategory%26id%3d" + entry.FolderId + "%26contentid%3d0%26form_id%3d0%26LangType%3d" + entry.LanguageId)); // goes to content view screen
                }
                else if (hdn_publishaction.Value == Convert.ToInt32(EkEnumeration.AssetActionType.Submit).ToString())
                {
                    m_refCatalog.AddAndPublish(entry, urlAliasInfo);
                    Process_Taxonomy(entry.Id, entry.FolderId);
                    Process_Inventory(entry.Id);
                    Util_ResponseHandler((string)("../content.aspx?action=ViewContentByCategory&id=" + this.m_iFolder.ToString())); // goes to folder
                }
            }
            catch (Exception ex)
            {
                Util_ResponseHandler((string)("../reterror.aspx?info=" + EkFunctions.UrlEncode(ex.Message) + "&LangType=" + entry.LanguageId));
            }
        }
Example #21
0
    /**
     * Create a new bundle.
     * @param name Name of the bundle name.
     * @param parent New parent's name. Set the parent to empty string if you want create a new root bundle.
     * @param sceneBundle Is the bundle a scene bundle?  
     */
    static public bool CreateNewBundle(string name, string parent, bool sceneBundle, string path = "")
    {
        var bundleDict = getInstance().bundleDict;

        if (bundleDict.ContainsKey(name))
            return false;

        BundleData newBundle = new BundleData();
        newBundle.name = name;
        newBundle.sceneBundle = sceneBundle;
        newBundle.path = path;
        if (parent != "")
        {
            if (!bundleDict.ContainsKey(parent))
                return false;
            else
                bundleDict[parent].children.Add(name);

            newBundle.parent = parent;
            newBundle.path = bundleDict[parent].path;
        }

        bundleDict.Add(name, newBundle);
        InsertBundleToBundleList(newBundle);

        BundleBuildState newBuildState = new BundleBuildState();
        newBuildState.bundleName = name;
        getInstance().statesDict.Add(name, newBuildState);
        BMDataAccessor.BuildStates.Add(newBuildState);

        UpdateBundleChangeTime(newBundle.name);

        BMDataAccessor.SaveBundleData();
        BMDataAccessor.SaveBundleBuildeStates();
        return true;
    }