Exemplo n.º 1
0
    private void CacheBundles()
    {
        Console.WriteLine("Caching bundles...");

        _bundlesCachePath = Path.Combine(_params.BundlesLocation, _bundlesDatabaseBuilder.Database.Id + "_cache");

        BuildUtils.PrepareCleanDirectory(_bundlesCachePath);

        // Note: All this flow break is required because WWW.LoadFromCacheOrDownload() is allowed only in play mode
        EditorUtility.SetDirty(this);

        EditorApplication.NewScene();
        var go             = new GameObject("AssetsBundleDatabaseCacher", typeof(AssetBundlesDatabaseCacher));
        var databaseCacher = go.GetComponent <AssetBundlesDatabaseCacher>();

        databaseCacher.Setup(_bundlesDatabaseBuilder.Database, Path.GetFullPath(_bundlesPath));

        // Application will only actually enter playmode after the call stack returns to the editor
        Application.runInBackground = true;
        EditorApplication.isPaused  = false;
        EditorApplication.isPlaying = true;

        EditorPrefs.SetBool("Builder.ContinuePending", true);
        _continueRequired = true;         // Prevents FinishAll() on Dispose
        throw new ContinueRequiredException();
    }
Exemplo n.º 2
0
    private void CreateLateResources(IList <UnityEngine.Object> objects)
    {
        const string lateResourcesDirectory = "Assets/Resources/Late";

        BuildUtils.PrepareCleanDirectory(lateResourcesDirectory);

        foreach (var obj in ScanningUtils.ItemsProcessor(objects,
                                                         "Creating late resources",
                                                         p => AssetDatabase.GetAssetPath(p)))
        {
            var lateResource = ScriptableObject.CreateInstance <LateResource>();
            lateResource.Target = obj;
            AssetDatabase.CreateAsset(lateResource, lateResourcesDirectory + "/" + AssetId.FromObject(obj) + ".asset");
        }
    }
Exemplo n.º 3
0
    public static void CopyDirectoryRecursiveIgnoreMeta(string source, string target)
    {
        BuildUtils.PrepareCleanDirectory(target);

        // HACK: Another unity non public useful method...
        var editorAssembly = Assembly.LoadFrom(UnityEditorInternal.InternalEditorUtility.GetEditorAssemblyPath());
        var editorType     = editorAssembly.GetType("UnityEditor.FileUtil");

        var method = editorType.GetMethod("CopyDirectoryRecursiveIgnoreMeta", BindingFlags.Static | BindingFlags.NonPublic);

        object[] options =
        {
            source,
            target
        };

        method.Invoke(null, options);
    }
Exemplo n.º 4
0
//    [MenuItem("Build Target/PreBuidTarget")]
//    static void PerformCopyToBuidTarget()
//    {
//        PreBuildTarget("OPPO", "Android");
//    }
//
//    [MenuItem("Build Target/ClearBuidTarget")]
//    static void ClearBuidTarget()
//    {
//        CleanAndroidBuildTarget();
//    }

    static void BuildTarget(string name, string target)
    {
        string app_name   = "JiangHu" + DateTime.Now.ToString("yyyyMMdd_") + name;
        string target_dir = string.Empty;            // Application.dataPath + "/TargetAndroid";

        string           target_name = string.Empty; // app_name + ".apk";
        BuildTargetGroup targetGroup = BuildTargetGroup.Android;
        BuildTarget      buildTarget = UnityEditor.BuildTarget.Android;

        string applicationPath = Application.dataPath.Replace("/Assets", "");

        if (target == "Android")
        {
            target_dir  = applicationPath + "/TargetAndroid";
            target_name = app_name + ".apk";
            targetGroup = BuildTargetGroup.Android;
        }
        else if (target == "IOS")
        {
            target_dir  = applicationPath + "/TargetIOS";
            target_name = app_name;
            targetGroup = BuildTargetGroup.iPhone;
            buildTarget = UnityEditor.BuildTarget.iPhone;
        }

        //FileInfo buildFile = new FileInfo(target_dir);
        //if (buildFile.Exists)
        //    buildFile.Delete();

        if (File.Exists(target_name))
        {
            File.Delete(target_name);
        }

        if (!Directory.Exists(target_dir))
        {
            Directory.CreateDirectory(target_dir);
        }
        string sourcePath = "";

        switch (name)
        {
        case "UC":
            PlayerSettings.bundleIdentifier = "com.fanhou.jianghu.uc";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_UC");
            sourcePath = UI_PATH_NAME;
            break;

        case "JIUYAO":
            PlayerSettings.bundleIdentifier = "com.fanhou.jianghu.jiuyao";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_JIUYAO");
            break;

        case "XIAOMI":
            PlayerSettings.bundleIdentifier = "Pushcraft.mi";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_XIAOMI");
            sourcePath = MI_PATH_NAME;
            break;

//            case "OPPO":
//                PlayerSettings.bundleIdentifier = "com.fanhou.jianghu.nearme";
//                PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_OPPO");
//                sourcePath=OPPO_PATH_NAME;
//                break;
        case "OPPO_0917":
            PlayerSettings.bundleIdentifier = "com.fanhou.jianghu.nearme.gamecenter";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_OPPO");
            sourcePath = OPPONEW_PATH_NAME;
            break;

        case "TencentTest":
            PlayerSettings.bundleIdentifier = "com.tencent.tmgp.yjws";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_TENCENT; TENCENT_TEST");
            PlayerSettings.keyaliasPass = "******";
            PlayerSettings.keystorePass = "******";
            sourcePath = TENCENT_TEST_PATH;
            break;

        case "TencentRelease":
            PlayerSettings.bundleIdentifier = "com.tencent.tmgp.yjws";
            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "ANDROID_TENCENT; TENCENT_RELEASE");
            PlayerSettings.keyaliasPass = "******";
            PlayerSettings.keystorePass = "******";
            sourcePath = TENCENT_RELEASE_PATH;
            break;

        default:
            break;
        }

        //string target_folder = EditorUtility.SaveFolderPanel("111", "", "2222");
        string target_fileName = EditorUtility.SaveFilePanel("BuildTarget", target_dir, target_name, "");

        if (string.IsNullOrEmpty(target_fileName))
        {
            return;
        }

        //拷贝相应平台的Plugins/Android到Plugins/Android
        BuildUtils.CopyDirectoryRecursiveIgnoreMeta(Path.Combine(PLATFORM_ANDROID_PATH, sourcePath), PLATFORM_PLUGINS_TARGET);
        AssetDatabase.Refresh();

        //开始Build场景
        GenericBuild(Scenes, target_fileName, buildTarget, BuildOptions.None);

        PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, "");

        BuildUtils.PrepareCleanDirectory(PLATFORM_PLUGINS_TARGET);
    }
Exemplo n.º 5
0
 public static void CleanAndroidBuildTarget()
 {
     PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, "");
     BuildUtils.PrepareCleanDirectory(PLATFORM_PLUGINS_TARGET);
     AssetDatabase.Refresh();
 }
Exemplo n.º 6
0
    private void PackBundles()
    {
        var referencedObjects = new HashSet <UnityEngine.Object>(_lateProcessor.ReferencedObjects);
        var packedObjects     = new HashSet <UnityEngine.Object>();

        var tempPath = Path.Combine(Path.GetTempPath(), "bundles_" + DateTime.UtcNow.Ticks.ToString());

        BuildUtils.PrepareCleanDirectory(tempPath);

        PushAssetDependencies();
        {
            foreach (var bundleInfo in ScanningUtils.ItemsProcessor(_bundles, "Packing asset bundles", p => Path.GetFileName(p.Name), true))
            {
                Console.WriteLine("Building bundle " + bundleInfo.Name + "...");

                string bundlePath = Path.Combine(tempPath, bundleInfo.Name);                //BuildUtils.GetPathHashString(bundleInfo.Name));

                if (bundleInfo.IsScene)
                {
                    var scenePaths = bundleInfo.AssetsPaths.ToArray();

                    PushAssetDependencies();
                    {
                        string buildResult = BuildPipeline.BuildStreamedSceneAssetBundle(scenePaths,
                                                                                         bundlePath,
                                                                                         _params.Target);
                        if (!String.IsNullOrEmpty(buildResult))
                        {
                            throw new UnityException(buildResult);
                        }
                    }
                    PopAssetDependencies();

                    // Find which assets were packed
                    var packedDependencies = new HashSet <UnityEngine.Object>();
                    foreach (var scenePath in scenePaths)
                    {
                        Debug.Log(scenePath);
                        EditorApplication.OpenScene(scenePath);
                        packedDependencies.UnionWith(ScanningUtils.ScanCurrentSceneAssets());
                        packedDependencies.ExceptWith(packedObjects);
                    }

                    bundleInfo.Dependencies = packedDependencies.ToList();

                    var hash = GetHashForBuildAssets(scenePaths.Concat(BuildUtils.GetAssetPathsForObjects(packedDependencies)));


                    int bundleLevel = _bundleLevelDataBase.GetBundleLevel(bundleInfo.Name);
                    bundleInfo.Data = _bundlesDatabaseBuilder.AddSceneBundle(bundleInfo.Name, hash, bundleLevel,
                                                                             scenePaths.Select(p => Path.GetFileNameWithoutExtension(p)).ToArray(),
                                                                             bundlePath);
                }
                else
                {
                    // Add only the main asset + any late referenced asset

                    var mainObjects     = bundleInfo.AssetsPaths.Select(p => AssetDatabase.LoadMainAssetAtPath(p));
                    var representations = bundleInfo.AssetsPaths.SelectMany(p => AssetDatabase.LoadAllAssetRepresentationsAtPath(p));
                    var objects         = mainObjects.Concat(representations.Where(o => referencedObjects.Contains(o))).ToArray();

                    var assetIds = objects.Select(o => AssetId.FromObject(o)).ToArray();


                    foreach (var obj in objects)
                    {
                        string assetPath = AssetDatabase.GetAssetPath(obj);
                        string guid      = AssetDatabase.AssetPathToGUID(assetPath);
                        Console.WriteLine("path: " + assetPath + "   guid:" + guid);
                    }


                    if (bundleInfo.Isolate)
                    {
                        PushAssetDependencies();
                    }
                    {
                        if (!BuildPipeline.BuildAssetBundleExplicitAssetNames(objects, assetIds, bundlePath,
                                                                              BuildAssetBundleOptions.CompleteAssets |
                                                                              BuildAssetBundleOptions.CollectDependencies |
                                                                              BuildAssetBundleOptions.DeterministicAssetBundle,
                                                                              _params.Target))
                        {
                            throw new UnityException("Error building bundle " + bundleInfo.Name);
                        }
                    }
                    if (bundleInfo.Isolate)
                    {
                        PopAssetDependencies();
                    }

                    // Find which assets were packed
                    var packedDependencies = new HashSet <UnityEngine.Object>(EditorUtility.CollectDependencies(objects.ToArray()));
                    packedDependencies.ExceptWith(packedObjects);
                    bundleInfo.Dependencies = packedDependencies.ToList();
                    if (!bundleInfo.Isolate)
                    {
                        packedObjects.UnionWith(packedDependencies);
                    }

                    var hash        = GetHashForBuildAssets(BuildUtils.GetAssetPathsForObjects(packedDependencies));
                    int bundleLevel = _bundleLevelDataBase.GetBundleLevel(bundleInfo.Name);
                    bundleInfo.Data = _bundlesDatabaseBuilder.AddBundle(bundleInfo.Name, hash, bundleLevel, bundlePath, assetIds.ToList());

                    foreach (var obj in objects)
                    {
                        referencedObjects.Remove(obj);
                    }
                }
            }
        }
        PopAssetDependencies();

        // Move to right destination
        Directory.CreateDirectory(_params.BundlesLocation);
        _bundlesPath = Path.Combine(_params.BundlesLocation, _bundlesDatabaseBuilder.Database.Id);
        FileUtil.DeleteFileOrDirectory(_bundlesPath);
        FileUtil.MoveFileOrDirectory(tempPath, _bundlesPath);

        // To create late reference for any late object not added to bundles
        _objectsToLateReference = referencedObjects.ToList();
    }