Ejemplo n.º 1
0
        void OnGUI()
        {
            Color origColor = GUI.contentColor;

            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            GUILayout.Space((Screen.width * 0.5f) - 55.0f);
            GUI.contentColor = Color.green;
            GUILayout.Label("Bundling Configuration", EditorStyles.boldLabel);
            GUILayout.EndHorizontal();

            GUI.contentColor = origColor;

            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("Progress: {0}/{1}", _currItem, _itemCount), EditorStyles.boldLabel);
            GUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("Bundle Server Address:", _currItem, _itemCount), EditorStyles.boldLabel, new GUILayoutOption[] { GUILayout.Width(200) });
            string bundleServerPrev           = BuildSettings.BundleServerAddress;
            string updatedBundleServerAddress = GUILayout.TextField(BuildSettings.BundleServerAddress, 256, EditorStyles.boldLabel);

            if (bundleServerPrev != updatedBundleServerAddress)
            {
                string     host = string.Empty;
                System.Uri bsURI;
                if (System.Uri.TryCreate(updatedBundleServerAddress, System.UriKind.RelativeOrAbsolute, out bsURI))
                {
                    host = bsURI.Host;
                }
                BuildSettings.BundleServerAddress = "http://" + host + ":" + BuildSettings.BundleServerPort;
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            int prevBundleMode = (int)BuildSettings.DevBundleMode;

            BuildSettings.DevBundleMode = (EB.Assets.DevBundleType)GUILayout.SelectionGrid(prevBundleMode, _bundleModeSelections, 1);
            GUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            GUILayout.BeginVertical();
            string[]     buildOptionsNames  = System.Enum.GetNames(typeof(BuildOptions));
            System.Array buildOptionsValues = System.Enum.GetValues(typeof(BuildOptions));
            int          buildOptionsCount  = buildOptionsNames.Length;

            BuildOptions prevBuildOptions = BuildSettings.Options;

            for (int i = 0; i < buildOptionsCount; i++)
            {
                string       boName  = buildOptionsNames[i];
                BuildOptions boValue = (BuildOptions)buildOptionsValues.GetValue(i);

                bool wasSet = EB.Flag.IsSet(prevBuildOptions, boValue);
                bool nowSet = GUILayout.Toggle(wasSet, boName);
                if (wasSet != nowSet)
                {
                    BuildSettings.Options = EB.Flag.Set(BuildSettings.Options, boValue, nowSet);
                }
            }
            GUILayout.EndVertical();

            EditorGUILayout.Separator();

            GUILayout.BeginVertical();
            ArrayList prevDevLevel = BuildSettings.DevelopmentLevelsBuild;
            ArrayList available    = new ArrayList(BuildSettings.GetScenesFromEditorSettings());

            BuildSettings.DevelopmentLevelsBuild = SelectList(available, prevDevLevel, OnCheckboxItemGUI);
            GUILayout.EndVertical();

            bool levelsChanged = false;

            if (prevDevLevel.Count != BuildSettings.DevelopmentLevelsBuild.Count)
            {
                levelsChanged = true;
            }

            if ((BuildSettings.BundleServerAddress != bundleServerPrev) ||
                levelsChanged || (prevBundleMode != (int)BuildSettings.DevBundleMode))
            {
                BuildSettings.SaveSettings();
            }
        }
Ejemplo n.º 2
0
    public static void BuildPlayer(string apkPath, BuildOptions options)
    {
        BuildSettings.Options = options;
#if USE_XINKUAISDK
        PlayerSettings.Android.keystorePass = "******";
        PlayerSettings.Android.keyaliasName = "xinyou";
        PlayerSettings.Android.keyaliasPass = "******";
        PlayerSettings.Android.keystoreName = "Assets/Editor/Android/key.keystore";
#else
        PlayerSettings.Android.keystorePass = "******";
        PlayerSettings.Android.keyaliasName = "ebg";
        PlayerSettings.Android.keyaliasPass = "******";
        PlayerSettings.Android.keystoreName = "Assets/Editor/Android/android.keystore";
#endif
        EB.Debug.Log("Building to " + apkPath);

        string[] originalScenes = BuildSettings.GetScenesFromEditorSettings();
        string[] buildScenes    = originalScenes;

        if (BuildSettings.IsDevelopmentBuild)
        {
            if (BuildSettings.DevBundleMode == EB.Assets.DevBundleType.BundleServer)                    // only the basic levels are built in to the player, others are separate bundles for smaller packages while debugging
            {
                List <string> filteredScenes = new List <string>();
                foreach (string scene in originalScenes)
                {
                    string lowerScene = scene.ToLower();
                    foreach (string playerBuilt in BuildSettings.PlayerBuiltInScenes)
                    {
                        if (lowerScene.Contains(playerBuilt))
                        {
                            filteredScenes.Add(scene);
                            Debug.Log("Player Building scene: " + scene);
                            break;
                        }
                    }
                }
                buildScenes = filteredScenes.ToArray();
            }
        }

        try {
            if (BuildSettings.DevBundleMode != EB.Assets.DevBundleType.NoBundles)
            {
                Debug.Log("Moving Resources/Bundles out of Assets/ to build Player");
                BuildUtils.HideBundlesDirs();
            }

            BuildPipeline.BuildPlayer(buildScenes, apkPath, BuildTarget.Android, options);
        } finally {
            if (BuildSettings.DevBundleMode != EB.Assets.DevBundleType.NoBundles)
            {
                Debug.Log("Returning Resources/Bundles to Assets/ after building Player");
                BuildUtils.UnHideBundlesDirs();
            }
        }

        if (!File.Exists(apkPath))
        {
            throw new System.Exception("Failed to build apk!");
        }
    }
Ejemplo n.º 3
0
    public static void BuildiOSPlayer(string profile, bool debug, BuildOptions options)
    {
        BuildSettings.Options = options;
        var path = GetBuildPath();

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        string[] originalScenes = BuildSettings.GetScenesFromEditorSettings();


        string[] buildScenes = originalScenes;

        if (BuildSettings.IsDevelopmentBuild)
        {
            if (BuildSettings.DevBundleMode == EB.Assets.DevBundleType.BundleServer)                    // only the basic levels are built in to the player, others are separate bundles for smaller packages while debugging
            {
                List <string> filteredScenes = new List <string>();
                foreach (string scene in originalScenes)
                {
                    string lowerScene = scene.ToLower();
                    foreach (string playerBuilt in BuildSettings.PlayerBuiltInScenes)
                    {
                        if (lowerScene.Contains(playerBuilt))
                        {
                            filteredScenes.Add(scene);
                            Debug.Log("Player Building scene: " + scene);
                            break;
                        }
                    }
                }
                buildScenes = filteredScenes.ToArray();
            }
        }
        else
        {
            List <string> tmp = new List <string>(originalScenes);
//NOTE: including the selector for now.
//			if (tmp[0].Contains("selector"))
//			{
//				Debug.Log("REMOVING SELECTOR SCENE");
//				tmp.RemoveAt(0);
//
//			}
            buildScenes = tmp.ToArray();
        }

        // copy profiles
        CopyProvisioningProfile(profile);

        Debug.Log("Building player with...");
        foreach (string s in buildScenes)
        {
            Debug.Log("\t" + s);
        }

        bool movedBundles = false;

        //bool isP4ConnectEnabled = P4Connect.Config.PerforceEnabled;
        try {
            if (BuildSettings.DevBundleMode != EB.Assets.DevBundleType.NoBundles)
            {
                Debug.Log("Moving Resources/Bundles out of Assets/ to build iOS Player ");
                movedBundles = true;

                //P4Connect.Config.PerforceEnabled = false;
                BuildUtils.HideBundlesDirs();
                //EditorUtility.UnloadUnusedAssets();

                if (!UnityEditor.VersionControl.Provider.isActive)
                {
                    // only do this on the build server (no UNITY P4 version control set up) because it will check out every file we just moved for delete (works fine with the 3rd party plugin)
                    Debug.Log("Refreshing Asset Database to remove references in Assets/Resources/Bundles");
                    AssetDatabase.Refresh();
                }
            }
            Debug.Log("***** BuildPipeline.BuildPlayer");
            BuildPipeline.BuildPlayer(buildScenes, path, BuildTarget.iOS, options);
            Debug.Log("***** BuildPipeline.BuildPlayer DONE");
        }
        finally
        {
            if (movedBundles)
            {
                Debug.Log("Moving Resources/Bundles back to Assets/ after building iOS Player");
                BuildUtils.UnHideBundlesDirs();
                //P4Connect.Config.PerforceEnabled = isP4ConnectEnabled;
                //EB.Perforce.Perforce.P4RevertUnchanged();
            }
        }
    }
Ejemplo n.º 4
0
    private static bool BuildScenesBundle(Hashtable bundle, string parent, BundleOptions options)
    {
        string folder    = EB.Dot.String("folder", bundle, string.Empty);
        string filter    = EB.Dot.String("filter", bundle, string.Empty);
        string id        = EB.Dot.String("id", bundle, string.Empty);
        bool   recursive = EB.Dot.Bool("recursive", bundle, true);

        bool result = false;

        string[] buildScenes     = BuildSettings.GetScenesFromEditorSettings();
        var      tmp             = new List <string>(buildScenes);
        var      buildSceneNames = EB.ArrayUtils.Map <string, string>(tmp, Path.GetFileNameWithoutExtension);

        if (!System.IO.Directory.Exists(folder))
        {
            Debug.LogWarning("BuildScenesBundle - Folder does not exist : " + folder);
            return(result);
        }

        string[] items = Directory.GetFiles(folder, "*.unity", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

        List <string> devLevels = new List <string>((string[])BuildSettings.DevelopmentLevelsBuild.ToArray(typeof(string)));

        devLevels = EB.ArrayUtils.Map <string, string>(devLevels,
                                                       delegate(string path)
        {
            string sceneName = Path.GetFileNameWithoutExtension(path).ToLower();
            foreach (string testName in BuildSettings.PlayerBuiltInScenes)
            {
                if (sceneName.Contains(testName))
                {
                    return(null);
                }
            }
            return(sceneName);
        });

        var filtered  = new List <string>();
        var arrayList = new ArrayList();

        foreach (string item in items)
        {
            Debug.Log("item: " + item + " " + (BuildSettings.IsDevelopmentBuild ? "YES" : "NO"));
            if (!string.IsNullOrEmpty(filter))
            {
                if (item.Contains(filter) == false)
                {
                    Debug.Log("Skipping scene because its in the build settings " + item);
                    continue;
                }
            }

            string sceneName      = Path.GetFileNameWithoutExtension(item);
            string sceneNameLower = sceneName.ToLower();

            if (BuildSettings.IsDevelopmentBuild && (BuildSettings.DevBundleMode == EB.Assets.DevBundleType.BundleServer) &&
                (BuildSettings.Target == BuildTarget.Android || BuildSettings.Target == BuildTarget.iOS))                       // build everything except the basic transition scenes as separate bundles for faster turn around when authoring/debugging.
            {
                if (!devLevels.Contains(sceneNameLower))
                {
                    continue;
                }
            }
            else if (buildSceneNames.Contains(sceneName))
            {
                Debug.Log("Skipping scene because its in the build settings " + item);
                continue;
            }

            filtered.Add(item);
            arrayList.Add(sceneName);
        }

        if (EB.Dot.Bool("single_bundle", bundle, false))
        {
            var bundle_name = string.Format("scene_{0}.assetbundle", id);
            var bundle_path = Path.Combine(_outFolder, bundle_name);

            var deps = AssetDatabase.GetDependencies(items);
            if ((options & BundleOptions.Force) != 0 || CheckDependancies(bundle_path, deps))
            {
                // build
                Debug.Log("Building " + items.Length + " scenes in one");
                BuildPipeline.PushAssetDependencies();
                BuildPipeline.BuildStreamedSceneAssetBundle(filtered.ToArray(), bundle_path, BuildSettings.Target);
                BuildPipeline.PopAssetDependencies();
                result = true;
            }
            long      ts            = File.GetLastWriteTime(bundle_path).Ticks;
            Hashtable sceneTSLookup = new Hashtable();
            foreach (string scene in arrayList)
            {
                sceneTSLookup[scene] = ts;
            }
            _scenes[id] = sceneTSLookup;
        }
        else
        {
            int itemsCount = filtered.Count;
            for (int i = 0; i < itemsCount; i++)
            {
                string shortname = (string)arrayList[i];
                string item      = filtered[i];

                var bundle_name = string.Format("scene_{0}.assetbundle", shortname);
                var bundle_path = Path.Combine(_outFolder, bundle_name);

                var deps = AssetDatabase.GetDependencies(new string[] { item });

                // check dependancies
                if ((options & BundleOptions.Force) != 0 || CheckDependancies(bundle_path, deps))
                {
                    // build
                    Debug.Log("Building scene " + shortname + " " + bundle_path);
                    BuildPipeline.PushAssetDependencies();

                    string error = null;
                    error = BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { item }, bundle_path, BuildSettings.Target);

                    if (!string.IsNullOrEmpty(error))
                    {
                        Debug.LogError("Error during BuildPipeline.BuildStreamedSceneAssetBundle " + item + " error: " + error);
                    }
                    else if (!File.Exists(bundle_path))
                    {
                        Debug.LogError("No Error returned, but no bundle created: " + bundle_path);
                    }
                    BuildPipeline.PopAssetDependencies();
                    EditorUtility.UnloadUnusedAssetsImmediate();

                    result = true;
                }

                long ts = File.GetLastWriteTime(bundle_path).Ticks;

                Hashtable sceneTSLookup = new Hashtable();
                sceneTSLookup[shortname] = ts;
                _scenes[shortname]       = sceneTSLookup;
            }
        }

        return(result);
    }