Exemplo n.º 1
0
 static public void BuildAssetBundles()
 {
     BuildScript.BuildAssetBundles();
 }
Exemplo n.º 2
0
 static public void BuildForLZ4Compression()
 {
     BuildScript.BuildAssetBundles(BuildAssetBundleOptions.ChunkBasedCompression);
 }
Exemplo n.º 3
0
 static public void BuildForUnCompression()
 {
     BuildScript.BuildAssetBundles(BuildAssetBundleOptions.UncompressedAssetBundle);
 }
    void OnGUI()
    {
        GUIStyle customLabel;

        customLabel             = new GUIStyle("Label");
        customLabel.fixedHeight = 50;

        GUI.Box(new Rect(0, 0, 50, 50), new GUIContent("", logotex), customLabel);


        GUILayout.BeginHorizontal();

        var customButton = new GUIStyle("Button");

        customButton.alignment = TextAnchor.MiddleCenter;
        GUILayout.FlexibleSpace();
        customButton.fontSize         = 10;
        customButton.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customButton.fontStyle        = FontStyle.Italic;
        customButton.fixedWidth       = 100;
        if (GUILayout.Button("Add VR Player", customButton))
        {
            var playerPrefabPath = "Assets/SteamVR/InteractionSystem/Core/Prefabs/Player.prefab";

            var file = new FileInfo(playerPrefabPath);

            string fullPath  = file.FullName.Replace(@"\", "/");
            string assetPath = "Assets" + fullPath.Replace(Application.dataPath, "");

            bool alreadyInScene = false;
            var  allRootGos     = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
            foreach (var go in allRootGos)
            {
                bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
                if (isPrefabInstance)
                {
                    UnityEngine.Object parentObject = EditorUtility.GetPrefabParent(go);
                    string             path         = AssetDatabase.GetAssetPath(parentObject);

                    if (assetPath.Equals(path))
                    {
                        alreadyInScene = true;
                        break;
                    }
                }
            }

            if (alreadyInScene)
            {
                EditorUtility.DisplayDialog("Player prefab already exists.",
                                            "\"Player\" prefab already in the scene.\n\nTo reset it you can try deleting it first then pressing this button again to create a new VR player object.", "OK");
            }
            else
            {
                UnityEngine.Object prefab = AssetDatabase.LoadMainAssetAtPath(assetPath);

                GameObject clone = PrefabUtility.InstantiatePrefab(prefab as GameObject) as GameObject;
            }
        }
        GUILayout.EndHorizontal();


        Rect r = (Rect)EditorGUILayout.BeginVertical(customLabel);

        customLabel                  = new GUIStyle("Label");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = Color.black;
        customLabel.fontStyle        = FontStyle.Bold;

        GUILayout.Label("Custom Prop Builder", customLabel);

        customLabel                  = new GUIStyle("Label");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 11;
        customLabel.normal.textColor = new Color(0.5f, 0.5f, 0.5f);
        customLabel.fontStyle        = FontStyle.Bold;

        GUILayout.Label(string.Format("Version: {0} (Lite)", BUILDER_VERSION /*Application.version*/), customLabel);

        EditorGUILayout.EndVertical();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 10;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;
        customLabel.fixedWidth       = 100;
        customLabel.normal.textColor = new Color(0.7f, 0.0f, 0.0f);

        //EditorGUILayout.LabelField("PATH WARNING!", customLabel, GUILayout.Width(100));

        if (!SystemInfo.operatingSystem.ToLower().Contains("windows 10"))
        {
            if (Application.dataPath.Length > 40)
            {
                if (GUILayout.Button("PATH WARNING!", customLabel))
                {
                    EditorUtility.DisplayDialog("Warning",
                                                string.Format(
                                                    "Your OS is: \"{0}\" which may experience issues with long paths." +
                                                    "\n\nIt would be wise to move this Builder project as close to \"C:\\\" as possible." +
                                                    "\n\nCurrent application datapath:\n{1}",
                                                    SystemInfo.operatingSystem, Application.dataPath
                                                    ),
                                                "Ok");

                    return;
                }
            }
        }

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = new Color(0.0f, 0.0f, 1.0f);
        customLabel.fontStyle        = FontStyle.Bold;

        EditorGUILayout.LabelField("Select the .blend file to process:");

        if (GUILayout.Button(new GUIContent("Import Prop Model", "Select .blend files containing valid models. Processes the model to generate a custom assetbundle compatible with AnimationPrepStudio runtime."), customLabel))
        {
            if (!string.IsNullOrEmpty(blenderAppPath) && !File.Exists(blenderAppPath))
            {
                EditorUtility.DisplayDialog("Blender Application Is Not Set",
                                            "Please browse for and select the installed Blender application. Must be version 2.79.", "OK");
                return;
            }

            FixPlayerSettings();

            AssetDatabase.RemoveUnusedAssetBundleNames();

            var modelPath = EditorUtility.OpenFilePanel("Load model", modelPathLast, "blend,fbx");

            if (!string.IsNullOrEmpty(modelPath))
            {
                modelPathLast = Path.GetDirectoryName(modelPath);
                if (Path.GetExtension(modelPath).Equals(".blend"))
                {
                    if (!RunBatch(AnimPrepAssetPostprocessor.assetBundleVariant, modelPath, blenderAppPath))
                    {
                        EditorUtility.DisplayDialog("No AssetCreator.exe Tool",
                                                    "Please ensure the AssetCreator.exe tool in located in the AnimPrep directory.", "OK");
                        return;
                    }

                    var baseName = Path.GetFileNameWithoutExtension(modelPath);

                    modelPath = Path.Combine(
                        Path.Combine(
                            Path.GetDirectoryName(modelPath), baseName.ToLower() + string.Format("_{0}", AnimPrepAssetPostprocessor.assetBundleVariant.ToLower())
                            ),
                        baseName + ".fbx"
                        );
                }

                var uploadFolder = Path.GetDirectoryName(modelPath);

                //var userName = Path.GetFileName (SystemInfo.deviceName);

                var uploadFolderTop = new DirectoryInfo(uploadFolder).Name;

                var uploadName = System.Guid.NewGuid().ToString();                  // Path.GetFileName (uploadFolder);

                var processingPath = AnimPrepAssetPostprocessor.processingFolder;   // Path.Combine(Application.dataPath, "MakeHumanModels");
                //processingPath = Path.Combine (processingPath, userName);
                processingPath = Path.Combine(processingPath, uploadName);

                System.IO.Directory.CreateDirectory(processingPath);


                DirectoryInfo dir        = new DirectoryInfo(uploadFolder);
                FileInfo[]    modelsInfo = dir.GetFiles("*.fbx");

                if (modelsInfo.Length == 0)
                {
                    Debug.LogError("modelsInfo was empty. No .fbx file could be loaded.");
                    return;
                }

                string uid = uploadName.Replace(AnimPrepAssetPostprocessor.templateSeperator.ToString(), "");                 // uploadFolderTop.Replace("$", "");


                //Copy all model files
                foreach (FileInfo f in modelsInfo)
                {
                    var to = Path.Combine(
                        processingPath,
                        AnimPrepAssetPostprocessor.assetBundleVariant +
                        AnimPrepAssetPostprocessor.templateSeperator +                        //"$"
                        uid +
                        AnimPrepAssetPostprocessor.templateSeperator +                        //"$"
                        f.Name
                        );
                    File.Copy(f.FullName, to);
                }

                //Copy all .json files
                FileInfo[] jsonInfo = dir.GetFiles("*.json");
                foreach (FileInfo f in jsonInfo)
                {
                    var to = Path.Combine(processingPath, f.Name);
                    File.Copy(f.FullName, to);
                }

                //Copy all images files
                var textures_path = Path.Combine(uploadFolder, "textures");
                if (Directory.Exists(textures_path))
                {
                    string[] extensions = new[] { ".png", ".jpg", ".tiff", ".bmp" };

                    DirectoryInfo dir_images = new DirectoryInfo(textures_path);

                    FileInfo[] texturesInfo =
                        dir_images.GetFiles()
                        .Where(f => extensions.Contains(f.Extension.ToLower()))
                        .ToArray();

                    foreach (FileInfo f in texturesInfo)
                    {
                        var to = Path.Combine(processingPath, f.Name);
                        FileUtil.CopyFileOrDirectory(f.FullName, to);
                    }
                }

                AnimPrepAssetPostprocessor.AssetBundleUserJson userPrefs = new AnimPrepAssetPostprocessor.AssetBundleUserJson()
                {
                    created = System.DateTime.UtcNow,
                    //user = userName,
                    //uploadFolder = uploadName,
                    characterFolder = Path.GetDirectoryName(modelPath)
                };

                string json     = JsonUtility.ToJson(userPrefs);
                var    jsonPath = Path.Combine(AnimPrepAssetPostprocessor.assetBundlesFolder, uid + ".json");
                using (StreamWriter sr = new StreamWriter(jsonPath)) {                  // Create the file.
                    sr.WriteLine(json);
                }


                AssetDatabase.Refresh();

                BuildScript.BuildAssetBundles();

                AssetDatabase.Refresh();
            }
        }

        EditorGUILayout.Space();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = new Color(0.0f, 0.5f, 0.0f);
        customLabel.fontStyle        = FontStyle.Bold;

        EditorGUILayout.LabelField("Save changes to assetbundles:");
        if (GUILayout.Button(new GUIContent("Re-Build Assetbundles", "After making any changes to avatars, this will update the changes to the local assetbundle files."), customLabel))
        {
            FixPlayerSettings();

            var allPaths = AssetDatabase.GetAllAssetPaths();
            foreach (var assetPath in allPaths)
            {
                if (assetPath.StartsWith(AnimPrepAssetPostprocessor.prefabsFolder))
                {
                    //ensure the prefab is enabled before saving as assetbundle

                    string     modelFileName = Path.GetFileNameWithoutExtension(assetPath);
                    GameObject modelAsset    = AssetDatabase.LoadAssetAtPath <GameObject> (assetPath);                 //LOADING AN ASSET
                    if (modelAsset == null)
                    {
                        continue;
                    }

                    if (!modelAsset.activeSelf)
                    {
                        GameObject model = (GameObject)PrefabUtility.InstantiatePrefab(modelAsset);
                        model.SetActive(true);
                        PrefabUtility.SaveAsPrefabAsset(model, assetPath);
                        GameObject.DestroyImmediate(model);
                    }
                }
            }


            var allShaderKeywordParams = GameObject.FindObjectsOfType <RendererShaderParams> ();

            foreach (var shaderKeywordParams in allShaderKeywordParams)
            {
                shaderKeywordParams.StoreParams();
            }

            var allRootGos = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
            foreach (var go in allRootGos)
            {
                bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
                if (isPrefabInstance)
                {
                    RendererShaderParams.StoreAllRenderers(go);

                    PrefabUtility.ReplacePrefab(go, PrefabUtility.GetPrefabParent(go), ReplacePrefabOptions.ConnectToPrefab);
                }
            }

            AssetDatabase.Refresh();
            BuildScript.BuildAssetBundles();
            AssetDatabase.Refresh();

            ShowAssetBundlesExplorer();
        }



        EditorGUILayout.Space();

        customLabel           = new GUIStyle("Button");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontSize  = 12;
        //customLabel.normal.textColor = new Color(0.0f,0.5f,0.0f);
        customLabel.fontStyle = FontStyle.Italic;

        EditorGUILayout.LabelField("Add processed models to scene:");

        if (GUILayout.Button(new GUIContent("Append Prefabs To Scene", "Places all prefabs into the current scene."), customLabel))
        {
            var info     = new DirectoryInfo(AnimPrepAssetPostprocessor.prefabsFolder);
            var fileInfo = info.GetFiles("*.prefab", SearchOption.TopDirectoryOnly);

            for (int i = 0; i < fileInfo.Length; i++)
            {
                var file = fileInfo[i];

                if (Path.GetExtension(file.FullName).Equals(".meta"))
                {
                    continue;
                }

                string fullPath  = file.FullName.Replace(@"\", "/");
                string assetPath = "Assets" + fullPath.Replace(Application.dataPath, "");

                bool alreadyInScene = false;
                var  allRootGos     = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
                foreach (var go in allRootGos)
                {
                    bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
                    if (isPrefabInstance)
                    {
                        UnityEngine.Object parentObject = EditorUtility.GetPrefabParent(go);
                        string             path         = AssetDatabase.GetAssetPath(parentObject);

                        if (assetPath.Equals(path))
                        {
                            alreadyInScene = true;
                            break;
                        }
                    }
                }
                if (alreadyInScene)
                {
                    continue;
                }

                UnityEngine.Object prefab = AssetDatabase.LoadMainAssetAtPath(assetPath);

                GameObject clone = PrefabUtility.InstantiatePrefab(prefab as GameObject) as GameObject;
            }
        }



        EditorGUILayout.Space();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 12;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;

        EditorGUILayout.LabelField("Show folder containing output files:");
        GUILayout.BeginHorizontal();

        if (GUILayout.Button(new GUIContent("Assetbundles", "Opens the folder containing the newly created Assetbundle files."), customLabel))
        {
            ShowAssetBundlesExplorer();
        }

        customLabel.normal.textColor = new Color(1.0f, 0.2f, 0.2f);
        if (GUILayout.Button(new GUIContent("VR_MocapAssets", "This is the destination folder where you should copy Assetbundles to for them to be included in AnimationPrepStudio runtime."), customLabel))
        {
            ShowMocapAssetsExplorer();
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.Space();



        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Blender Application (v2.79):", GUILayout.MinWidth(0));

        customLabel           = new GUIStyle("Label");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontStyle = FontStyle.BoldAndItalic;

        if (blenderAppExists)
        {
            customLabel.normal.textColor = new Color(0.0f, 0.5f, 0.0f);
            EditorGUILayout.LabelField("File Exists", customLabel, GUILayout.Width(100));
        }
        else
        {
            customLabel.normal.textColor = new Color(0.5f, 0.0f, 0.0f);
            EditorGUILayout.LabelField("File Missing!", customLabel, GUILayout.Width(100));

            customButton                  = new GUIStyle("Button");
            customButton.alignment        = TextAnchor.MiddleCenter;
            customButton.fontSize         = 10;
            customButton.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
            customButton.fontStyle        = FontStyle.Italic;
            customButton.fixedWidth       = 100;
            if (GUILayout.Button("Default", customButton))
            {
                blenderAppPath = blenderAppPathDefault;
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 10;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;
        customLabel.fixedWidth       = 100;

        blenderAppPath = GUILayout.TextField(blenderAppPath, GUILayout.MinWidth(0));
        if (GUILayout.Button(new GUIContent("Browse", "Select a valid Blender v2.79b installation path by locating and selecting the \"blender.exe\" runtime application file."), customLabel))
        {
            string modelPath = EditorUtility.OpenFilePanel("Blender Application (v2.79)", Path.GetDirectoryName(blenderAppPath), "exe");
            if (!string.IsNullOrEmpty(modelPath))
            {
                blenderAppPath = modelPath;
            }
        }
        GUILayout.EndHorizontal();
        EditorGUILayout.Space();

        customLabel           = new GUIStyle("Label");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontStyle = FontStyle.Italic;
        GUILayout.Label(string.Format("{0} - {1}", Application.unityVersion, SystemInfo.operatingSystem), customLabel);

        if (GUI.changed)
        {
            CheckBlenderAppExists();
        }

        this.Repaint();
    }
Exemplo n.º 5
0
 static public void BuildForLZMACompression()
 {
     BuildScript.BuildAssetBundles();
 }
Exemplo n.º 6
0
    void OnGUI()
    {
        GUIStyle styleCmdArea = new GUIStyle();

        styleCmdArea.normal.background = MakeTex(600, 80, Color.white);

        //	info area
        GUILayout.BeginArea(new Rect(10, 10, 600, 80), styleCmdArea);

        GUILayout.BeginHorizontal();
        GUILayout.Label("Platform:", GUILayout.Width(200));
        selectedPlatform = EditorGUILayout.Popup(selectedPlatform, listPlatform.ToArray());
        switch (selectedPlatform)
        {
        case 0:
            if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
            {
                EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
                LoadConfigXML(CommonPatcherData.cnfFN);
                LoadVersionXML();
            }
            else
            {
                GUILayout.EndHorizontal();
            }
            break;

        case 1:
            if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.StandaloneWindows)
            {
                EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.StandaloneWindows);
                LoadConfigXML(CommonPatcherData.cnfFN);
                LoadVersionXML();
            }
            else
            {
                GUILayout.EndHorizontal();
            }
            break;
        }

        GUILayout.BeginHorizontal();
        GUILayout.Label("Last Version : " + lastMajorVersion + "." + lastMinorVersion);
        GUILayout.Label(">>>");
        GUILayout.Label("New Version :");
        chkLastMajorVersion = GUILayout.TextField("" + chkLastMajorVersion);
        chkLastMinorVersion = GUILayout.TextField("" + chkLastMinorVersion);
        if (GUILayout.Button("Apply", GUILayout.Width(70)))
        {
            //	apply last version info and make folders and modify xml files.
            if (EditorUtility.DisplayDialog("You know that ?!", "This work just makes a folder for new version and change the text of last version. Later, you can make new resources for next patch when you press the button [Upload to repository].", "I see!!") == true)
            {
                SaveVersionXML();
            }
        }
        if (GUILayout.Button("Rollback", GUILayout.Width(70)))
        {
            string prevVersion = PatchVersion.getPreviousVersion(CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/" + CommonPatcherData.patchVersionFN);
            int    prevMajor   = Convert.ToInt32(prevVersion.Split('_')[1]);
            int    prevMinor   = Convert.ToInt32(prevVersion.Split('_')[2]);

            string curVersion = verDoc.SelectSingleNode("/VERSIONS/PATCH").Attributes["LastVersion"].Value;
            int    curMajor   = Convert.ToInt32(curVersion.Split('_')[1]);
            int    curMinor   = Convert.ToInt32(curVersion.Split('_')[2]);

            if (EditorUtility.DisplayDialog("Caution!!", "Your last version(VER " + curMajor.ToString("D2") + "." + curMinor.ToString("D3") + ") data will remove complete. Are you sure?", "YES", "NO") == true)
            {
                //	check last version
                Debug.Log("Rollback to previous Version >> " + prevVersion);

                //	modify patch.xml file
                verDoc.SelectSingleNode("/VERSIONS/PATCH").Attributes["LastVersion"].Value = prevVersion;
                PatchVersion.removeVersionNode(verDoc, curMajor, curMinor);
                XmlTool.writeXml(CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/" + CommonPatcherData.patchVersionFN, verDoc);

                //	remove assets.xml and files, and backup folder
                string _dn = CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/VER_" + curMajor.ToString("D2") + "/" + curMinor.ToString("D3");
                Directory.Delete(_dn, true);

                //	latest folder change
                Directory.Delete(CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/" + CommonPatcherData.lastVersionRepo, true);
                Directory.Move(CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/" + CommonPatcherData.lastVersionRepo + "_VER_" + curMajor.ToString("D2") + "_" + curMinor.ToString("D3"),
                               CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/" + CommonPatcherData.lastVersionRepo);

                lastMajorVersion    = prevMajor;
                chkLastMajorVersion = curMajor.ToString("D2");
                lastMinorVersion    = prevMinor;
                chkLastMinorVersion = curMinor.ToString("D3");
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Path :");
        CommonPatcherData.repoPath = GUILayout.TextField(CommonPatcherData.repoPath);
        //	read config file
        if (GUILayout.Button("Read", GUILayout.Width(100)))
        {
            LoadConfigXML(CommonPatcherData.cnfFN);
        }

        if (GUILayout.Button("Save", GUILayout.Width(100)))
        {
            cnfDoc.SelectSingleNode("/ToolConfig/Repository").Attributes ["path"].Value = CommonPatcherData.repoPath;
            SaveConfigXML(CommonPatcherData.cnfFN, cnfDoc);
            MakeLocalRepo();
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        //	command area
        GUILayout.BeginArea(new Rect(10, 100, 600, 140));
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Build AssetBundles", GUILayout.Width(150)))
        {
            ActiveABMWType = ABMWType.Build;
            BuildScript.BuildAssetBundles();
            return;
        }

        if (GUILayout.Button("unregisted assets", GUILayout.Width(150)))
        {
            ActiveABMWType = ABMWType.Unregisted;
            checkUnregistedAssets();
        }

        if (GUILayout.Button("All AssetBundles List", GUILayout.Width(150)))
        {
            ActiveABMWType = ABMWType.PatchInfo;
            checkRegistedAssets();
        }

        if (GUILayout.Button("Upload to repository", GUILayout.Width(150)))
        {
            if (EditorUtility.DisplayDialog("Upload !!", "Did you make a folder for new version?! If not, press the button [apply]. This will make a folder and change the version number for new version.", "I DID!!", "Ooops!") == true)
            {
                ActiveABMWType = ABMWType.Upload;
                BuildScript.BuildAssetBundles();

                //	compare all AssetBundles with "repoPath + lastVersionRepo"'s all files
                List <FileInfo> listNew     = new List <FileInfo>();
                List <FileInfo> listModify  = new List <FileInfo>();
                List <FileInfo> listRemoved = new List <FileInfo>();

                {
                    DirectoryInfo latestDir     = new DirectoryInfo(CommonPatcherData.repoPath + "/" + EditorUserBuildSettings.activeBuildTarget);
                    FileInfo []   latestABFiles = latestDir.GetFiles("*.*", SearchOption.AllDirectories);

                    DirectoryInfo buildDir   = new DirectoryInfo(BuildScript.GetAssetBundleBuildPath() + "/" + EditorUserBuildSettings.activeBuildTarget);
                    FileInfo []   newABFiles = buildDir.GetFiles("*.*", SearchOption.AllDirectories);

                    int newIndex = 0;
                    foreach (FileInfo fi in newABFiles)
                    {
                        int latestIndex = 0;
                        foreach (FileInfo latefi in latestABFiles)
                        {
                            int ret = compareFile(fi, latefi);
                            if (ret == 0)                              //	completely different
                            {
                            }
                            else if (ret == 1)                              //	same exactly
                            {
                                break;
                            }
                            else if (ret == 2)                               //	modified
                            {
                                listModify.Add(fi);
                                break;
                            }
                            latestIndex++;
                        }

                        if (latestIndex == latestABFiles.Length)
                        {
                            listNew.Add(fi);
                        }
                        newIndex++;
                    }

                    foreach (FileInfo latefiR in latestABFiles)
                    {
                        int chkIndex = 0;
                        foreach (FileInfo fiR in newABFiles)
                        {
                            if (fiR.Name == latefiR.Name)
                            {
                                break;
                            }
                            chkIndex++;
                        }
                        if (chkIndex == latestABFiles.Length)
                        {
                            listRemoved.Add(latefiR);
                        }
                    }
                }

                //	upload updated AssetBundles to the new repository.
                SaveAssetsXML(listNew, listModify, listRemoved);
            }
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        //	console area
        GUILayout.BeginArea(new Rect(10, 150, 600, 600));
        switch (ActiveABMWType)
        {
        case ABMWType.Build:

            break;

        case ABMWType.Unregisted:
            ListUnregistedAssets();
            break;

        case ABMWType.PatchInfo:
            ListRegistedAssets();
            break;

        case ABMWType.Upload:

            break;
        }
        GUILayout.EndArea();
    }
    void OnGUI()
    {
        var      customButton = new GUIStyle("Button");
        GUIStyle customLabel;

        customLabel             = new GUIStyle("Label");
        customLabel.fixedHeight = 50;

        GUI.Box(new Rect(0, 0, 50, 50), new GUIContent("", logotex), customLabel);

        Rect r = (Rect)EditorGUILayout.BeginVertical(customLabel);

        customLabel                  = new GUIStyle("Label");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = Color.black;
        customLabel.fontStyle        = FontStyle.Bold;

        GUILayout.Label("Custom Avatar Builder", customLabel);

        customLabel                  = new GUIStyle("Label");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 11;
        customLabel.normal.textColor = new Color(0.5f, 0.5f, 0.5f);
        customLabel.fontStyle        = FontStyle.Bold;

        GUILayout.Label(string.Format("Version: {0} (Lite)", Application.version), customLabel);

        EditorGUILayout.EndVertical();


        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 10;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;
        customLabel.fixedWidth       = 100;
        customLabel.normal.textColor = new Color(0.7f, 0.0f, 0.0f);

        //EditorGUILayout.LabelField("PATH WARNING!", customLabel, GUILayout.Width(100));

        if (!SystemInfo.operatingSystem.ToLower().Contains("windows 10"))
        {
            if (Application.dataPath.Length > 40)
            {
                if (GUILayout.Button("PATH WARNING!", customLabel))
                {
                    EditorUtility.DisplayDialog("Warning",
                                                string.Format(
                                                    "Your OS is: \"{0}\" which may experience issues with long paths." +
                                                    "\n\nIt would be wise to move this Builder project as close to \"C:\\\" as possible." +
                                                    "\n\nCurrent application datapath:\n{1}",
                                                    SystemInfo.operatingSystem, Application.dataPath
                                                    ),
                                                "Ok");

                    return;
                }
            }
        }

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = new Color(0.0f, 0.0f, 1.0f);
        customLabel.fontStyle        = FontStyle.Bold;


        EditorGUILayout.LabelField("Select the .blend file to process:");
        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 10;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;
        customLabel.fixedWidth       = 100;


        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = new Color(0.0f, 0.0f, 1.0f);
        customLabel.fontStyle        = FontStyle.Bold;


        if (GUILayout.Button("Import Avatar Model", customLabel))
        {
            if (characterType == (int)ArmatureLinker.CharacterType.DEFAULT)
            {
                var enumName = System.Enum.GetName(typeof(ArmatureLinker.CharacterType), ArmatureLinker.CharacterType.DEFAULT);
                Debug.LogError(string.Format("You must specify a character type (\"{0}\" is not a valid selection)", enumName));
                EditorUtility.DisplayDialog("Error",
                                            string.Format("Character type: \"{0}\" is not a valid selection!\n\nPlease select a desired character type first.", enumName),
                                            "Ok");

                return;
            }

            if (!string.IsNullOrEmpty(blenderAppPath) && !File.Exists(blenderAppPath))
            {
                EditorUtility.DisplayDialog("Blender Application Is Not Set",
                                            "Please browse for and select the installed Blender application. Must be version 2.79b.", "OK");
                return;
            }
            PlayerSettings.colorSpace = ColorSpace.Linear;

            AssetDatabase.RemoveUnusedAssetBundleNames();

            var modelPath = EditorUtility.OpenFilePanel(string.Format("Load {0} model", getCharacterTypesArray[characterType].ToLower()), modelPathLast, "blend");

            if (!string.IsNullOrEmpty(modelPath))
            {
                modelPathLast = Path.GetDirectoryName(modelPath);
                if (Path.GetExtension(modelPath).Equals(".blend"))
                {
                    if (!RunBatch(AnimPrepAssetPostprocessor.AssetBundleVariant, modelPath, blenderAppPath))
                    {
                        EditorUtility.DisplayDialog("No AssetCreator.exe Tool",
                                                    "Please ensure the AssetCreator.exe tool in located in the AnimPrep directory.", "OK");
                        return;
                    }

                    var baseName = Path.GetFileNameWithoutExtension(modelPath);

                    modelPath = Path.Combine(
                        Path.Combine(
                            Path.GetDirectoryName(modelPath), baseName.ToLower() + string.Format("_{0}", AnimPrepAssetPostprocessor.AssetBundleVariant.ToLower())
                            ),
                        baseName + ".fbx"
                        );
                }

                var uploadFolder = Path.GetDirectoryName(modelPath);

                //var userName = Path.GetFileName (SystemInfo.deviceName);

                var uploadFolderTop = new DirectoryInfo(uploadFolder).Name;

                var uploadName = System.Guid.NewGuid().ToString();                  // Path.GetFileName (uploadFolder);

                var processingPath = AnimPrepAssetPostprocessor.processingFolder;   // Path.Combine(Application.dataPath, "MakeHumanModels");
                //processingPath = Path.Combine (processingPath, userName);
                processingPath = Path.Combine(processingPath, uploadName);

                System.IO.Directory.CreateDirectory(processingPath);


                DirectoryInfo dir        = new DirectoryInfo(uploadFolder);
                FileInfo[]    modelsInfo = dir.GetFiles("*.fbx");

                if (modelsInfo.Length == 0)
                {
                    Debug.LogError("modelsInfo was empty. No .fbx file could be loaded.");
                    return;
                }

                string uid = uploadName.Replace(AnimPrepAssetPostprocessor.templateSeperator.ToString(), "");                 // uploadFolderTop.Replace("$", "");


                //Copy all model files
                foreach (FileInfo f in modelsInfo)
                {
                    var to = Path.Combine(
                        processingPath,
                        AnimPrepAssetPostprocessor.AssetBundleVariant +
                        AnimPrepAssetPostprocessor.templateSeperator +                        //"$"
                        uid +
                        AnimPrepAssetPostprocessor.templateSeperator +                        //"$"
                        f.Name
                        );
                    FileUtil.CopyFileOrDirectory(f.FullName, to);
                }

                //Copy all .json files
                FileInfo[] jsonInfo = dir.GetFiles("*.json");
                foreach (FileInfo f in jsonInfo)
                {
                    var to = Path.Combine(processingPath, f.Name);
                    FileUtil.CopyFileOrDirectory(f.FullName, to);
                }

                //Copy all images files
                var textures_path = Path.Combine(uploadFolder, "textures");
                if (Directory.Exists(textures_path))
                {
                    string[] extensions = new[] { ".png", ".jpg", ".tiff", ".bmp" };

                    DirectoryInfo dir_images = new DirectoryInfo(textures_path);

                    FileInfo[] texturesInfo =
                        dir_images.GetFiles()
                        .Where(f => extensions.Contains(f.Extension.ToLower()))
                        .ToArray();

                    foreach (FileInfo f in texturesInfo)
                    {
                        var to = Path.Combine(processingPath, f.Name);
                        FileUtil.CopyFileOrDirectory(f.FullName, to);
                    }
                }

                AnimPrepAssetPostprocessor.AssetBundleUserJson userPrefs = new AnimPrepAssetPostprocessor.AssetBundleUserJson()
                {
                    created    = System.DateTime.UtcNow,
                    variantTag = getCharacterTypesArray[characterType],                    //use the index of the users selection to get then enum name from the chracter types //  AnimPrepAssetPostprocessor.ReallusionAssetVariantTag,
                    //user = userName,
                    //uploadFolder = uploadName,
                    characterFolder = Path.GetDirectoryName(modelPath)
                };

                string json     = JsonUtility.ToJson(userPrefs);
                var    jsonPath = Path.Combine(AnimPrepAssetPostprocessor.assetBundlesFolder, uid + ".json");
                using (StreamWriter sr = new StreamWriter(jsonPath)) {                  // Create the file.
                    sr.WriteLine(json);
                }


                AssetDatabase.Refresh();

                BuildScript.BuildAssetBundles();

                AssetDatabase.Refresh();

                Debug.Log(string.Format("Created new {0} character!\nPress \"Append Prefabs To Scene\" button to see the newly created character.", getCharacterTypesArray[characterType].ToLower()));
            }
        }
        GUILayout.BeginHorizontal();


        characterType = EditorGUILayout.Popup("Character Type:", characterType, getCharacterTypesArray, GUILayout.MinWidth(100));


        GUILayout.EndHorizontal();

        EditorGUILayout.Space();



        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 14;
        customLabel.normal.textColor = new Color(0.0f, 0.5f, 0.0f);
        customLabel.fontStyle        = FontStyle.Bold;

        EditorGUILayout.LabelField("Save changes to assetbundles:");
        if (GUILayout.Button("Re-Build Assetbundles", customLabel))
        {
            var allPaths = AssetDatabase.GetAllAssetPaths();
            foreach (var assetPath in allPaths)
            {
                if (assetPath.StartsWith(AnimPrepAssetPostprocessor.prefabsFolder))
                {
                    //ensure the prefab is enabled before saving as assetbundle

                    string     modelFileName = Path.GetFileNameWithoutExtension(assetPath);
                    GameObject modelAsset    = AssetDatabase.LoadAssetAtPath <GameObject> (assetPath);                 //LOADING AN ASSET
                    if (modelAsset == null)
                    {
                        continue;
                    }

                    if (!modelAsset.activeSelf)
                    {
                        GameObject model = (GameObject)PrefabUtility.InstantiatePrefab(modelAsset);
                        model.SetActive(true);
                        PrefabUtility.SaveAsPrefabAsset(model, assetPath);
                        GameObject.DestroyImmediate(model);
                    }
                }
            }

            var allShaderKeywordParams = GameObject.FindObjectsOfType <RendererShaderParams> ();

            foreach (var shaderKeywordParams in allShaderKeywordParams)
            {
                shaderKeywordParams.StoreParams();
            }

            var allRootGos = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
            foreach (var go in allRootGos)
            {
                //bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
                bool isPrefabInstance = PrefabUtility.GetCorrespondingObjectFromOriginalSource(go) != null && PrefabUtility.GetCorrespondingObjectFromOriginalSource(go.transform) != null;
                if (isPrefabInstance)
                {
                    RendererShaderParams.StoreAllRenderers(go);

                    //PrefabUtility.ReplacePrefab(go, PrefabUtility.GetPrefabParent(go), ReplacePrefabOptions.ConnectToPrefab);
                    PrefabUtility.SaveAsPrefabAssetAndConnect(go, PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go), InteractionMode.AutomatedAction);
                }
            }

            AssetDatabase.Refresh();
            BuildScript.BuildAssetBundles();
            AssetDatabase.Refresh();

            ShowAssetBundlesExplorer();
        }



        EditorGUILayout.Space();

        customLabel           = new GUIStyle("Button");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontSize  = 12;
        //customLabel.normal.textColor = new Color(0.0f,0.5f,0.0f);
        customLabel.fontStyle = FontStyle.Italic;

        EditorGUILayout.LabelField("Add processed models to scene:");

        if (GUILayout.Button("Append Prefabs To Scene", customLabel))
        {
            //Vector3 offsetSpacing = Vector3.right * 1.5f;

            var info     = new DirectoryInfo(AnimPrepAssetPostprocessor.prefabsFolder);
            var fileInfo = info.GetFiles("*.prefab", SearchOption.TopDirectoryOnly);

            for (int i = 0; i < fileInfo.Length; i++)
            {
                var file = fileInfo[i];

                if (Path.GetExtension(file.FullName).Equals(".meta"))
                {
                    continue;
                }


                string fullPath  = file.FullName.Replace(@"\", "/");
                string assetPath = "Assets" + fullPath.Replace(Application.dataPath, "");


                bool alreadyInScene = false;
                var  allRootGos     = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
                foreach (var go in allRootGos)
                {
                    //bool isPrefabInstance = PrefabUtility.GetPrefabParent(go) != null && PrefabUtility.GetPrefabObject(go.transform) != null;
                    bool isPrefabInstance = PrefabUtility.GetCorrespondingObjectFromSource(go) != null && PrefabUtility.GetCorrespondingObjectFromSource(go.transform) != null;

                    if (isPrefabInstance)
                    {
                        //Object parentObject = EditorUtility.GetPrefabParent(go);
                        Object parentObject = PrefabUtility.GetCorrespondingObjectFromSource(go);
                        string path         = AssetDatabase.GetAssetPath(parentObject);

                        if (assetPath.Equals(path))
                        {
                            alreadyInScene = true;
                            break;
                        }
                    }
                }
                if (alreadyInScene)
                {
                    continue;
                }



                UnityEngine.Object prefab = AssetDatabase.LoadMainAssetAtPath(assetPath);

                GameObject clone = PrefabUtility.InstantiatePrefab(prefab as GameObject) as GameObject;

                //clone.transform.position = offsetSpacing * i;
            }
        }



        EditorGUILayout.Space();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 12;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;

        EditorGUILayout.LabelField("Show folder containing output files:");
        if (GUILayout.Button("Open Assetbundles Folder", customLabel))
        {
            ShowAssetBundlesExplorer();
        }


        EditorGUILayout.Space();



        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Blender Application (v2.79b):", GUILayout.MinWidth(0));

        customLabel           = new GUIStyle("Label");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontStyle = FontStyle.BoldAndItalic;

        if (blenderAppExists)
        {
            customLabel.normal.textColor = new Color(0.0f, 0.5f, 0.0f);
            EditorGUILayout.LabelField("File Exists", customLabel, GUILayout.Width(100));
        }
        else
        {
            customLabel.normal.textColor = new Color(0.5f, 0.0f, 0.0f);
            EditorGUILayout.LabelField("File Missing!", customLabel, GUILayout.Width(100));

            customButton                  = new GUIStyle("Button");
            customButton.alignment        = TextAnchor.MiddleCenter;
            customButton.fontSize         = 10;
            customButton.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
            customButton.fontStyle        = FontStyle.Italic;
            customButton.fixedWidth       = 100;
            if (GUILayout.Button("Default", customButton))
            {
                blenderAppPath = blenderAppPathDefault;
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        customLabel                  = new GUIStyle("Button");
        customLabel.alignment        = TextAnchor.MiddleCenter;
        customLabel.fontSize         = 10;
        customLabel.normal.textColor = new Color(0.2f, 0.2f, 0.2f);
        customLabel.fontStyle        = FontStyle.Italic;
        customLabel.fixedWidth       = 100;

        blenderAppPath = GUILayout.TextField(blenderAppPath, GUILayout.MinWidth(0));
        if (GUILayout.Button("Browse", customLabel))
        {
            string modelPath = EditorUtility.OpenFilePanel("Blender Application (v2.79b)", Path.GetDirectoryName(blenderAppPath), "exe");
            if (!string.IsNullOrEmpty(modelPath))
            {
                blenderAppPath = modelPath;
            }
        }
        GUILayout.EndHorizontal();
        EditorGUILayout.Space();

        customLabel           = new GUIStyle("Label");
        customLabel.alignment = TextAnchor.MiddleCenter;
        customLabel.fontStyle = FontStyle.Italic;
        GUILayout.Label(string.Format("{0} - {1}", Application.unityVersion, SystemInfo.operatingSystem), customLabel);

        if (GUI.changed)
        {
            CheckBlenderAppExists();
        }

        this.Repaint();
    }
Exemplo n.º 8
0
 //[MenuItem ("AssetBundles/Build AssetBundles")]
 static public void BuildAssetBundles()
 {
     BuildScript.BuildAssetBundles();
     //刷新编辑器
     AssetDatabase.Refresh();
 }
Exemplo n.º 9
0
    static void Build()
    {
        var globalSettings = GetGlobalSettings();

        // Use this for real release builds - more compression, but much slower build
        // var mainBundle = BuildOptions.None;
        // var assetBundle = BuildAssetBundleOptions.None;
        var mainBundle  = BuildOptions.CompressWithLz4;
        var assetBundle = BuildAssetBundleOptions.ChunkBasedCompression;

        int count  = UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings;
        var scenes = new string[]
        {
            // only main scene
            UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(0),
        };

        var target   = EditorUserBuildSettings.activeBuildTarget;
        var location = GetBuildDestination();

        //Back up initial graphics settings
        var graphicsSettingsPath = Path.Combine(Path.Combine(Directory.GetParent(Application.dataPath).ToString(), "ProjectSettings"), "GraphicsSettings.asset");
        var backup = File.ReadAllText(graphicsSettingsPath);

        //Change shader inclusion settings for specific target
        ChangeShaderInclusionSettings(globalSettings.shaderInclusionSettings, GlobalSettings.BundleBuildTarget(target));

        string oldText = "";

        try
        {
            //Build bundles
            BuildScript.BuildAssetBundles(
                globalSettings.assetBundleSettings,
                assetBundle,
                Path.Combine(Directory.GetParent(location).ToString(), "AssetBundles"),
                target
                );

            UpdateBuildInfo(out oldText);

            //Build player
            BuildPipeline.BuildPlayer(scenes, location, target, mainBundle);
        }
        catch (Exception e) { throw e; }
        finally
        {
            if (oldText != "")
            {
                ResetBuildInfo(oldText);
            }

            //Reset graphics settings to initial status
            File.WriteAllText(graphicsSettingsPath, backup);
        }

        var files       = new string[] { "Map.txt" };
        var source      = Application.dataPath + "/../";
        var destination = Directory.GetParent(location) + "/";

        foreach (var f in files)
        {
            string srcFilePath    = source + f;
            string destFolderPath = destination + f;
            if (File.Exists(srcFilePath) && Directory.Exists(destFolderPath))
            {
                FileUtil.CopyFileOrDirectory(srcFilePath, destFolderPath);
            }
        }
    }
Exemplo n.º 10
0
    public static void GenerateAssetBundlesUpdateFile(string[] allBundles)
    {
        string title = "Generate Update File ";
        string info  = "Compute crc32";

        EditorUtility.DisplayProgressBar(title, info, 0.1f);

        #region 读取首包
        CrcCheck.Clear();
        bool          firstExists = false;
        DirectoryInfo firstDir    = new DirectoryInfo(Application.dataPath);
        string        firstPath   = Path.Combine(firstDir.Parent.Parent.FullName, Common.FirstOutPath);
        string        readPath    = Path.Combine(firstPath, CUtils.GetAssetPath(""));
        readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME));
        Debug.Log(readPath);

        WWW abload = new WWW("file://" + readPath);
        if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null)
        {
            var       ab = abload.assetBundle;
            TextAsset ta = ab.LoadAllAssets <TextAsset>()[0];
            //ta.text
            Debug.Log(ta);
            string   context = ta.text;
            string[] split   = context.Split('\n');
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)");
            float j = 1;
            float l = split.Length;
            foreach (var line in split)
            {
                System.Text.RegularExpressions.Match match = regex.Match(line);
                if (match.Success)
                {
                    //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value);
                    CrcCheck.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value));
                }
                //Debug.Log(line);
                EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l);
                j++;
            }
            ab.Unload(true);
            firstExists = true;
        }
        else
        {
            Debug.LogWarning(abload.error + "no frist packeage in " + readPath);
        }
        abload.Dispose();
        #endregion

        #region 生成校验列表
        Dictionary <string, uint> updateList = new Dictionary <string, uint>();
        StringBuilder             sb         = new StringBuilder();
        sb.AppendLine("return {");

        var   selected = string.Empty;
        float i        = 0;
        float allLen   = allBundles.Length;

        //忽略列表
        Dictionary <string, bool> ignore = new Dictionary <string, bool>();
        ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true);
        ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true);

        foreach (var str in allBundles)
        {
            string url    = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str);
            uint   outCrc = 0;
            Debug.Log(str);
            string abName = str.Replace("\\", "/");
            string key    = CUtils.GetAssetBundleName(abName);
            if (!ignore.ContainsKey(key) && CrcCheck.CheckLocalFileWeakCrc(url, out outCrc) == false) //如果不一致需要更新
            {
                updateList.Add(abName, outCrc);                                                       //记录导出记录
                sb.AppendLine("[\"" + key + "\"] = " + outCrc + ",");
            }
            EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
            i++;
        }
        sb.AppendLine("}");
        //Debug.Log (sb.ToString ());
        CrcCheck.Clear();

        //输出到临时目录
        var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
        string tmpPath       = Path.Combine(Application.dataPath, TmpPath);
        ExportResources.CheckDirectory(tmpPath);
        string assetPath = "Assets/" + TmpPath + crc32filename + ".txt";
        EditorUtility.DisplayProgressBar("Generate file list", "write file to " + assetPath, 0.99f);

        string outPath = Path.Combine(tmpPath, crc32filename + ".txt");
        Debug.Log("write to path=" + outPath);
        using (StreamWriter sr = new StreamWriter(outPath, false))
        {
            sr.Write(sb.ToString());
        }
        //
        //打包到streaming path
        AssetDatabase.Refresh();
        string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); //(fileCrc32ListName + ".u3d");
        BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);
        string topath = Path.Combine(GetOutPutPath(), crc32outfilename);
        Debug.Log(info + " assetbunle build complate! " + topath);

        #endregion

        #region 生成版本号
        //生成版本号码
        string crc32Path = "file://" + Path.Combine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); //CUtils.GetAssetFullPath (fileCrc32ListName+".u3d");
        WWW    loaderVer = new WWW(crc32Path);
        if (!string.IsNullOrEmpty(loaderVer.error))
        {
            Debug.LogError(loaderVer.error);
            return;
        }
        uint crcVer = Crc32.Compute(loaderVer.bytes);
        loaderVer.Dispose();

        tmpPath = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath(""));
        outPath = Path.Combine(tmpPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));
        Debug.Log("verion to path=" + outPath);
        //json 化version{ code,crc32,version}
        StringBuilder verJson = new StringBuilder();
        verJson.Append("{");
        verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
        verJson.Append(@"""crc32"":" + crcVer.ToString() + ",");
        verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + "");
        verJson.Append("}");

        using (StreamWriter sr = new StreamWriter(outPath, false))
        {
            sr.Write(verJson.ToString());
        }

        Debug.Log(info + " Complete! ver=" + crcVer.ToString() + " path " + outPath);
        BuildScript.BuildAssetBundles();

        #endregion

        #region copy更新文件导出
        if (updateList.Count > 0)
        {
            info = "copy updated file ";
            string        updateOutPath = Path.Combine(firstPath, CUtils.GetAssetPath("") + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm"));
            DirectoryInfo outDic        = new DirectoryInfo(updateOutPath);
            if (outDic.Exists)
            {
                outDic.Delete();
            }
            outDic.Create();

            if (!firstExists)
            {
                updateList.Clear();               //如果没有首包,只导出校验文件。
            }
            updateList.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), 0);
            updateList.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), crcVer);

            string sourcePath;
            string outfilePath;
            i      = 1;
            allLen = updateList.Count;
            string key = "";
            foreach (var k in updateList)
            {
                key        = CUtils.GetAssetBundleName(k.Key);
                sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key);
                if (k.Value != 0)
                {
                    if (key.Equals(CUtils.platformFloder))
                    {
                        key = key + "_" + k.Value.ToString() + "." + Common.ASSETBUNDLE_SUFFIX;
                    }
                    else
                    {
                        key = CUtils.InsertAssetBundleName(key, "_" + k.Value.ToString());//
                    }
                }
                outfilePath = Path.Combine(updateOutPath, key);
                FileHelper.CheckCreateFilePathDirectory(outfilePath);
                File.Copy(sourcePath, outfilePath, true);// source code copy
                EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
        }
        #endregion

        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 11
0
    public static bool BuildGame(GameBuilderParameter para)
    {
        Debug.Log("Build Game Start and Para is:" + para);

        if (!para.BuildVersion.CheckConstraint())
        {
            Debug.LogError("BuildVersion not pass constraint! version:" + para.BuildVersion.GetVersionString());
            return(false);
        }

        try
        {
            if (para.BuildTarget == BuildTarget.iOS)
            {
                para.UseMono2X = false;
                Debug.Log("ios platform always use IL2ccpp. is not will compiler error");
            }

            // 处理热更url
            if (!HandleHotFix(para))
            {
                return(false);
            }
            Debug.Log("Clear " + Application.streamingAssetsPath);
            FileUtils.ClearDirectoryReadOnly(Application.streamingAssetsPath);
            FileUtils.ClearDirectory(Application.streamingAssetsPath);
            SetupSetting(para);

            // build lua bundle
            Debug.Log("Start MarkBundlesNames ");
            ToLuaMenu.MarkBundlesNames();
            Debug.Log("End MarkBundlesNames ");

            if (para.ApplyAllRule)
            {
                Debug.Log("Start ApplyAllRule ");
                AssetBundleRuleUtils.ApplyAll(null, true);
                Debug.Log("ApplyAllRule finish ");
            }

            string sourcePath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName());
            if (!para.IncreativeBuildAssetBundles)
            {
                Debug.Log("Clear Assetbundle dir:" + sourcePath);
                FileUtils.ClearDirectoryReadOnly(sourcePath);
                FileUtils.ClearDirectory(sourcePath);
                Debug.Log("finish Clear Assetbundle dir:");
            }

            Debug.Log("BuildAssetBundles to " + sourcePath);
            BuildScript.BuildAssetBundles(null, para.BundleCompress ? ToLuaMenu.GetBuildAssetBundleOptions(): BuildAssetBundleOptions.None);
            Debug.Log("BuildAssetBundles finish ");

            Debug.Log("Start CopyDirectory to Streaming");
            FileUtils.CopyDirectory(sourcePath, VersionConst.StreamingVersionPath);
            Debug.Log("Finish CopyDirectory to Streaming");

            // 这个放在下面,不然会被前面的删除掉
            if (para.CopyFmod)
            {
                // -音效引擎相关代码,放在打包资源之后因为会清理打包资源-//
                Debug.Log("CopyToStreamingAssets---------------------------------------");
                //EventManager.DoCopyToStreamingAssets();
                Debug.Log("MasterBankName---------------------------------------");
            }
            Debug.Log("GenHotFixFileListAndCheckConflict");
            AssetBundleRuleUtils.GenHotFixFileListAndCheckConflict();
            bool bOk = true;
            if (para.BuildMode == BuildMode.Patch || para.BuildMode == BuildMode.All)
            {
                Debug.Log("开始生成补丁");
                VersionPatchBuilder patchBuilder = new VersionPatchBuilder(para.BuildTarget, para.BuildVersion, para.BuildNumber);
                if (!patchBuilder.Build())
                {
                    bOk = false;
                }

                Debug.Log("结束生成补丁");
            }

            // 如果要求生成补丁,但补丁失败,则包也
            if (bOk && (para.BuildMode == BuildMode.Package || para.BuildMode == BuildMode.All))
            {
                Debug.Log("开始写入发布时版本信息:" + VersionConst.ReleasedVersionPath);
                // 写入发布版本信息
                SaveReleasedVersionFile(para.BuildVersion, VersionConst.ReleasedVersionPath);
                Debug.Log("结束写入发布时版本信息");

                Debug.Log("开始生成安装包");
                string[] levels = BuilderEditorUtils.GetBuildScenes();
                var      error  = BuildPipeline.BuildPlayer(levels
                                                            , para.OutputPath
                                                            , para.BuildTarget
                                                            , para.BuildOptions);
                if (!string.IsNullOrEmpty(error))
                {
                    Debug.LogError("Build failed: " + error);
                    bOk = false;
                }
                Debug.Log("结束生成安装包");
            }

            return(bOk);
        }
        catch (Exception e)
        {
            Debug.LogError("error BuildGame stderror exception: " + e.Message);
            return(false);
        }
    }
Exemplo n.º 12
0
    public static void BuildAssetBundle()
    {
        BuildScript.BuildAssetBundles();

        BuildScript.CopyRecorder();
    }
Exemplo n.º 13
0
 static public void BuildAssetBundles_LZMA()
 {
     BuildScript.BuildAssetBundles(BuildAssetBundleOptions.None);
 }
Exemplo n.º 14
0
    public void BuildAssetBundles()
    {
        var path = Path.Combine(Application.dataPath, "AssetBundles");

        BuildScript.BuildAssetBundles(assetBundleMgr.assetBundleSettings, BuildAssetBundleOptions.ChunkBasedCompression, path, buildTarget);
    }