Пример #1
0
        public static void Create(BuildCollection pCollection, bool pBuildAndRun, bool pBatchMode = false, bool pBuildAll = false, string pBuildTag = "")
        {
            UBSProcess p = ScriptableObject.CreateInstance <UBSProcess>();

            p.mBuildAndRun = pBuildAndRun;
            p.mBatchMode   = pBatchMode;
            p.mCollection  = pCollection;
            if (!pBuildAll)
            {
                p.mSelectedProcesses = p.mCollection.mProcesses.FindAll(obj => obj.mSelected);
            }
            else
            {
                p.mSelectedProcesses = p.mCollection.mProcesses;
            }
            p.mCurrentState = UBSState.invalid;

            if (!string.IsNullOrEmpty(pBuildTag))
            {
                foreach (var sp in p.mSelectedProcesses)
                {
                    sp.mOutputPath = AddBuildTag(sp.mOutputPath, pBuildTag);
                }
            }

            AssetDatabase.CreateAsset(p, GetProcessPath());
            AssetDatabase.SaveAssets();
        }
Пример #2
0
        public static void CreateBuildCollectionMenuCommand()
        {
            var asset = BuildCollection.CreateInstance <BuildCollection>();

            asset.hideFlags = HideFlags.None;
            var path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (String.IsNullOrEmpty(path))
            {
                path = "Assets";
            }

            var di = new FileInfo(path);

            if ((di.Attributes & FileAttributes.Directory) != 0)
            {
                path = path + "/New Build Collection.asset";
            }
            else
            {
                path = path.Substring(0, path.Length - di.Name.Length - 1) + "/New Build Collection.asset";
            }

            path = AssetDatabase.GenerateUniqueAssetPath(path);

            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.SaveAssets();
            Selection.activeObject = asset;
        }
        public static void ShowLastBuildCollection()
        {
            BuildCollection lastBuildcollection = GetLastBuildCollection();

            EditorGUIUtility.PingObject(lastBuildcollection);
            Selection.activeObject = lastBuildcollection;
        }
        public static void Init(BuildCollection pCollection)
        {
            var window = EditorWindow.GetWindow <UBSEditorWindow>("Build System", true);

            window.mData    = pCollection;
            window.position = new Rect(50, 50, kMinWidth + 50 + kListWidth, kMinHeight + 50);
        }
Пример #5
0
 public static void Init(BuildCollection pData, BuildProcess pProcess, bool pBuildAndRun = false)
 {
     foreach (var p in pData.mProcesses)
     {
         p.mSelected = (p == pProcess);
     }
     Init(pData, pBuildAndRun);
 }
Пример #6
0
        public BuildCollection CreateCurrentSceneClone()
        {
            var temp = BuildCollection.Instantiate(this);

            foreach (var i in temp.mProcesses)
            {
                i.mScenes = UnityEditor.SceneManagement.EditorSceneManager.GetAllScenes().Select(x => x.path).ToList();
            }
            UnityEditor.AssetDatabase.CreateAsset(temp, "Assets/temp_build.asset");
            return(temp);
        }
Пример #7
0
        public static int DrawBuildProcessEntry(BuildCollection data, BuildProcess e, bool odd, int selectedCount, bool editable)
        {
            GUILayout.BeginHorizontal(odd ? UBS.Styles.selectableListEntryOdd : UBS.Styles.selectableListEntry);
            {
                Texture2D platformIcon = GetPlatformIcon(e.mPlatform);
                GUILayout.Box(platformIcon, UBS.Styles.icon);
                GUILayout.Label(e.mName, odd ? UBS.Styles.selectableListEntryTextOdd : UBS.Styles.selectableListEntryText);
                GUILayout.FlexibleSpace();
                var sel = GUILayout.Toggle(e.mSelected, "");
                if (editable && sel != e.mSelected)
                {
                    e.mSelected = sel;
                    EditorUtility.SetDirty(data);
                }
                selectedCount += e.mSelected ? 1 : 0;
            }
            GUILayout.EndHorizontal();


            if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
            {
                Rect r = GUILayoutUtility.GetLastRect();
                if (r.Contains(Event.current.mousePosition))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent(e.mName), false, null);
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Open target folder"), false, () => {
                        DirectoryInfo di = new DirectoryInfo(UBS.Helpers.GetAbsolutePathRelativeToProject(e.mOutputPath));

                        string path;
                        if ((di.Attributes & FileAttributes.Directory) != 0)
                        {
                            path = di.FullName;
                        }
                        else
                        {
                            path = di.Parent.FullName;
                        }

                        EditorUtility.RevealInFinder(path);
                    });
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Build and run"), false, BuildAndRun, new BuildAndRunUserData(data, e));
                    menu.AddItem(new GUIContent("Build"), false, Build, new BuildAndRunUserData(data, e));

                    menu.ShowAsContext();
                }
            }


            return(selectedCount);
        }
        void OnDestroy()
        {
            if (mEditor != null)
            {
                mEditor.OnDestroy();
            }

            if (mData)
            {
                EditorUtility.SetDirty(mData);
            }

            AssetDatabase.SaveAssets();

            Undo.undoRedoPerformed -= OnUndoRedoPerformed;
            mData        = null;
            mInitialized = false;
        }
Пример #9
0
 internal BuildAndRunUserData(BuildCollection bCollection, BuildProcess bProcess)
 {
     process    = bProcess;
     collection = bCollection;
 }
Пример #10
0
 public void Run(BuildCollection pCollection, bool pBuildAndRun)
 {
     scrollPosition01 = Vector2.zero;
     UBSProcess.Create(pCollection, pBuildAndRun);
 }
Пример #11
0
        public static void Init(BuildCollection pData, bool pBuildAndRun = false)
        {
            var window = CreateWindow();

            window.Run(pData, pBuildAndRun);
        }
Пример #12
0
        /// <summary>
        /// Builds a given build collection from command line. Call this method directly from the command line using Unity in headless mode.
        /// <https://docs.unity3d.com/Documentation/Manual/CommandLineArguments.html>
        ///
        /// Provide `collection` parameter to your command line build to specify the collection you want to build.
        /// All selected build processes within the collection will be build.
        ///
        /// Example: -collection=Assets/New\ BuildCollection.asset
        /// </summary>
        public static void BuildFromCommandLine()
        {
            bool batchMode = false;

            string[] arguments      = System.Environment.GetCommandLineArgs();
            string[] availableArgs  = { "-batchmode", "-collection=", "-android-sdk=", "-buildTag=", "-buildAll", "-commitID=", "-tagName=" };
            string   collectionPath = "";
            string   androidSdkPath = "";
            string   buildTag       = "";
            string   commitID       = "";
            string   tagName        = "";
            bool     buildAll       = false;

            foreach (var s in arguments)
            {
                if (s.StartsWith("-batchmode"))
                {
                    batchMode = true;
                    Debug.Log("UBS process started in batchmode!");
                }

                if (s.StartsWith("-collection="))
                {
                    collectionPath = s.Substring(availableArgs[1].Length);
                }

                if (s.StartsWith("-android-sdk="))
                {
                    androidSdkPath = s.Substring(availableArgs[2].Length);
                }

                if (s.StartsWith("-buildTag="))
                {
                    buildTag = s.Substring(availableArgs[3].Length);
                }

                if (s.StartsWith("-buildAll"))
                {
                    buildAll = true;
                    Debug.Log("Selection override: building whole collection!");
                }

                if (s.StartsWith("-commitID="))
                {
                    commitID = s.Substring(availableArgs[5].Length);
                }

                if (s.StartsWith("-tagName="))
                {
                    tagName = s.Substring(availableArgs[6].Length);
                }
            }
            if (collectionPath == null)
            {
                Debug.LogError("NO BUILD COLLECTION SET");
                return;
            }

            if (!string.IsNullOrEmpty(androidSdkPath))
            {
                EditorPrefs.SetString("AndroidSdkRoot", androidSdkPath);
                Debug.Log("Set Android SDK root to: " + androidSdkPath);
            }

            if (!string.IsNullOrEmpty(commitID))
            {
                EditorPrefs.SetString("commitID", commitID);
                Debug.Log("Set commitID to: " + commitID);
            }

            if (!string.IsNullOrEmpty(tagName))
            {
                EditorPrefs.SetString("tagName", tagName);
                Debug.Log("Set tagName to: " + tagName);
            }

            Debug.Log("Loading Build Collection: " + collectionPath);

            // Load Build Collection
            BuildCollection collection = AssetDatabase.LoadAssetAtPath(collectionPath, typeof(BuildCollection)) as BuildCollection;

            // Run Create Command
            Create(collection, false, batchMode, buildAll, buildTag);


            UBSProcess process = LoadUBSProcess();

            try
            {
                while (true)
                {
                    process.MoveNext();
                    Debug.Log("Wait..");
                    Debug.Log("Process state: " + process.CurrentState);
                    if (process.CurrentState == UBSState.done)
                    {
                        return;
                    }
                }
            }catch (Exception pException)
            {
                Debug.LogError("Build failed due to exception: ");
                Debug.LogException(pException);
                EditorApplication.Exit(1);
            }
        }
Пример #13
0
 public void Run(BuildCollection pCollection, bool pBuildAndRun)
 {
     UBSProcess.Create(pCollection, pBuildAndRun);
 }
Пример #14
0
        public void OnGUI(BuildProcess pProcess, BuildCollection pCollection)
        {
            if (pProcess == null)
            {
                return;
            }

            if (pProcess != mEditedBuildProcess)
            {
                if (mEditedBuildProcess != null)
                {
                    SaveScenesToStringList();
                }

                mEditedBuildProcess = pProcess;
                mCollection         = pCollection;

                LoadScenesFromStringList();
                OnEnable();

                // after switching to another process, we want to make sure to unfocus all possible controls
                // like textfields. This will remove an issue, where dangling focus between process switching could happen
                GUI.FocusControl("");
            }

            GUILayout.BeginVertical();

            GUILayout.Label("Build Process", Styles.detailsTitle);

            Styles.HorizontalSeparator();

            Undo.RecordObject(mCollection, "Edit Build Process Details");
            pProcess.mName = EditorGUILayout.TextField("Name", mEditedBuildProcess.mName);


            mEditedBuildProcess.mPlatform = (BuildTarget)EditorGUILayout.EnumPopup("Platform", mEditedBuildProcess.mPlatform);

            mEditedBuildProcess.mPretend = EditorGUILayout.Toggle(new GUIContent("Pretend Build", "Will not trigger a unity build, but run everything else. "), mEditedBuildProcess.mPretend);

            GUILayout.Space(5);
            mShowBuildOptions = EditorGUILayout.Foldout(mShowBuildOptions, "Build Options");
            GUILayout.BeginHorizontal();
            GUILayout.Space(25);

            if (mShowBuildOptions)
            {
                GUILayout.BeginVertical();

                foreach (var buildOption in mBuildOptions)
                {
                    bool selVal = (mEditedBuildProcess.mBuildOptions & buildOption) != 0;
                    {
                        bool resVal = EditorGUILayout.ToggleLeft(buildOption.ToString(), selVal);
                        if (resVal != selVal)
                        {
                            if (resVal)
                            {
                                mEditedBuildProcess.mBuildOptions = mEditedBuildProcess.mBuildOptions | buildOption;
                            }
                            else
                            {
                                mEditedBuildProcess.mBuildOptions = mEditedBuildProcess.mBuildOptions & ~buildOption;
                            }
                            UpdateSelectedOptions();
                        }
                    }
                }


                GUILayout.EndVertical();
            }
            else
            {
                GUILayout.Label(selectedOptionsString);
            }


            GUILayout.EndHorizontal();
            GUILayout.Space(5);

            DrawOutputPathSelector();

            ReorderableListGUI.Title("Included Scenes");
            ReorderableListGUI.ListField(mEditedBuildProcess.mSceneAssets, SceneDrawer);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Copy scenes from settings"))
            {
                CopyScenesFromSettings();
            }

            if (GUILayout.Button("Clear scenes"))
            {
                mEditedBuildProcess.mSceneAssets.Clear();
            }

            GUILayout.EndHorizontal();

            Styles.HorizontalSeparator();

            mDrawingBuildStepType = EBuildStepType.PreBuildStep;
            ReorderableListGUI.Title("Pre Build Steps");
            ReorderableListGUI.ListField(mEditedBuildProcess.mPreBuildSteps, StepDrawer);


            Styles.HorizontalSeparator();
            GUILayout.Label("Actual Unity Build", Styles.mediumHint);
            Styles.HorizontalSeparator();


            mDrawingBuildStepType = EBuildStepType.PostBuildStep;
            ReorderableListGUI.Title("Post Build Steps");
            ReorderableListGUI.ListField(mEditedBuildProcess.mPostBuildSteps, StepDrawer);


            GUILayout.EndVertical();
        }