Esempio n. 1
0
        private static void PerformPostBuild()
        {
            // Run post-build actions.
            BuildAction[] buildActions = BuildSettings.postBuildActions.buildActions;
            if (buildActions != null)
            {
                for (int i = 0; i < buildActions.Length; i++)
                {
                    BuildAction action = buildActions[i];

                    // Check if execute method has been overriden.
                    MethodInfo m = action.GetType().GetMethod("Execute");
                    if (m.GetBaseDefinition().DeclaringType != m.DeclaringType && action.actionType == BuildAction.ActionType.SingleRun)
                    {
                        if (action.actionEnabled)
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Performing Post-Build Action ({0}/{1}).", i + 1, buildActions.Length), action.actionName,
                                                                               true, null));

                            action.Execute();
                        }
                        else
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Skipping Post-Build Action ({0}/{1}).", i + 1, buildActions.Length), action.actionName,
                                                                               true, null));
                        }
                    }
                }
            }
        }
        public void OnPostprocessBuild(BuildTarget target, string path)
        {
            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                               BuildNotification.Category.Notification, "PostProcessBuild", "Running post process build actions",
                                                               true, null));

            BuildAction[] actions = BuildSettings.postProcessBuildActions.buildActions;
            if (actions != null)
            {
                for (int i = 0; i < actions.Length; i++)
                {
                    BuildAction action = actions[i];

                    if (action.actionEnabled)
                    {
                        BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                           BuildNotification.Category.Notification,
                                                                           string.Format("Performing Post-Process-Build Action ({0}/{1}).", i + 1, actions.Length),
                                                                           action.actionName,
                                                                           true, null));

                        action.PostProcessExecute(target, path);
                    }
                    else
                    {
                        BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                           BuildNotification.Category.Notification,
                                                                           string.Format("Skipping Post-Build Action ({0}/{1}).", i + 1, actions.Length),
                                                                           action.actionName,
                                                                           true, null));
                    }
                }
            }
        }
Esempio n. 3
0
        private static void PerformPreBuild(out DateTime buildTime)
        {
            buildTime = DateTime.Now;

            // Clear any old notifications.
            BuildNotificationList.instance.RefreshAll();

            // Generate version string.
            if (BuildSettings.productParameters.autoGenerate)
            {
                GenerateVersionString(BuildSettings.productParameters, buildTime);
            }

            // Run pre-build actions.
            BuildAction[] buildActions = BuildSettings.preBuildActions.buildActions;
            if (buildActions != null)
            {
                for (int i = 0; i < buildActions.Length; i++)
                {
                    BuildAction action = buildActions[i];

                    // Check if execute method has been overriden.
                    MethodInfo m = action.GetType().GetMethod("Execute");
                    if (m.GetBaseDefinition().DeclaringType != m.DeclaringType &&
                        action.actionType == BuildAction.ActionType.SingleRun)
                    {
                        if (action.actionEnabled)
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Performing Pre-Build Action ({0}/{1}).", i + 1, buildActions.Length),
                                                                               action.actionName,
                                                                               true, null));

                            action.Execute();
                        }
                        else
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Skipping Pre-Build Action ({0}/{1}).", i + 1, buildActions.Length),
                                                                               action.actionName,
                                                                               true, null));
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private static void PerformPostBuild(
            BuildReleaseType releaseType,
            BuildPlatform platform,
            BuildArchitecture architecture,
            BuildDistribution distribution,
            DateTime buildTime, ref BuildOptions options, string configKey, string buildPath)
        {
            BuildAction[] buildActions = BuildSettings.postBuildActions.buildActions;
            if (buildActions != null)
            {
                for (int i = 0; i < buildActions.Length; i++)
                {
                    BuildAction action = buildActions[i];

                    // Check if execute method has been overriden.
                    MethodInfo m = action.GetType().GetMethod("PerBuildExecute");
                    if (m.GetBaseDefinition().DeclaringType != m.DeclaringType &&
                        action.actionType == BuildAction.ActionType.PerPlatform)
                    {
                        // Check build filter and execute if true.
                        if (action.filter == null ||
                            action.filter.Evaluate(releaseType, platform, architecture, distribution, configKey) &&
                            action.actionEnabled)
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Performing Post-Build Action ({0}/{1}).", i + 1, buildActions.Length),
                                                                               string.Format("{0}: {1}", action.actionName, configKey),
                                                                               true, null));

                            action.PerBuildExecute(releaseType, platform, architecture, distribution, buildTime,
                                                   ref options, configKey, buildPath);
                        }
                        else
                        {
                            BuildNotificationList.instance.AddNotification(new BuildNotification(
                                                                               BuildNotification.Category.Notification,
                                                                               string.Format("Skipping Post-Build Action ({0}/{1}).", i + 1, buildActions.Length),
                                                                               string.Format("{0}: {1}", action.actionName, configKey),
                                                                               true, null));
                        }
                    }
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            EditorGUILayout.BeginHorizontal();
            bool show = property.isExpanded;

            UnityBuildGUIUtility.DropdownHeader(label.text, ref show, false, GUILayout.ExpandWidth(true));
            property.isExpanded = show;

            UnityBuildGUIUtility.HelpButton("Parameter-Details#build-actions");
            EditorGUILayout.EndHorizontal();

            list = property.FindPropertyRelative("buildActions");

            List <Type> actionTypes;

            if (property.name.ToUpper().Contains("PRE"))
            {
                actionTypes = BuildActionListUtility.preBuildActions;
            }
            else
            {
                actionTypes = BuildActionListUtility.postBuildActions;
            }

            if (show)
            {
                EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle);

                for (int i = 0; i < list.arraySize; i++)
                {
                    SerializedProperty listEntry = list.GetArrayElementAtIndex(i);

                    BuildAction buildAction = listEntry.objectReferenceValue as BuildAction;
                    if (buildAction == null)
                    {
                        list.DeleteArrayElementAtIndex(i);
                        --i;
                        continue;
                    }

                    SerializedObject serializedBuildAction = new SerializedObject(buildAction);

                    EditorGUILayout.BeginHorizontal();
                    show = listEntry.isExpanded;

                    buildAction.actionEnabled = EditorGUILayout.Toggle(buildAction.actionEnabled, GUILayout.Width(15));
                    EditorGUI.BeginDisabledGroup(!buildAction.actionEnabled);
                    UnityBuildGUIUtility.DropdownHeader(buildAction.actionName, ref show, false, GUILayout.ExpandWidth(true));
                    EditorGUI.EndDisabledGroup();
                    listEntry.isExpanded = show;

                    EditorGUI.BeginDisabledGroup(i == 0);
                    if (GUILayout.Button("↑↑", UnityBuildGUIUtility.helpButtonStyle))
                    {
                        list.MoveArrayElement(i, 0);
                    }
                    if (GUILayout.Button("↑", UnityBuildGUIUtility.helpButtonStyle))
                    {
                        list.MoveArrayElement(i, i - 1);
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUI.BeginDisabledGroup(i == list.arraySize - 1);
                    if (GUILayout.Button("↓", UnityBuildGUIUtility.helpButtonStyle))
                    {
                        list.MoveArrayElement(i, i + 1);
                    }
                    EditorGUI.EndDisabledGroup();

                    if (GUILayout.Button("X", UnityBuildGUIUtility.helpButtonStyle))
                    {
                        BuildAction[] buildActions;
                        if (property.name.ToUpper().Contains("PRE"))
                        {
                            buildActions = BuildSettings.preBuildActions.buildActions;
                        }
                        else
                        {
                            buildActions = BuildSettings.postBuildActions.buildActions;
                        }

                        // Destroy underlying object.
                        ScriptableObject.DestroyImmediate(buildActions[i], true);
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BuildSettings.instance));

                        // Remove object reference from list.
                        // TODO: Why do I need to call this twice? First call nulls reference, second one then deletes null entry.
                        list.DeleteArrayElementAtIndex(i);
                        list.DeleteArrayElementAtIndex(i);
                        show = false;
                    }

                    EditorGUILayout.EndHorizontal();

                    if (show && buildAction.actionEnabled)
                    {
                        EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle);
                        buildAction.Draw(serializedBuildAction);
                        EditorGUILayout.EndVertical();
                    }
                }

                if (list.arraySize > 0)
                {
                    GUILayout.Space(20);
                }

                if (actionTypes.Count > 0)
                {
                    GUILayout.BeginHorizontal();

                    string[] buildActionNameList = new string[actionTypes.Count];
                    for (int i = 0; i < buildActionNameList.Length; i++)
                    {
                        buildActionNameList[i] = actionTypes[i].Name;
                    }

                    index = EditorGUILayout.Popup(index, buildActionNameList, UnityBuildGUIUtility.popupStyle, GUILayout.ExpandWidth(true));
                    if (GUILayout.Button("Add Build Action", GUILayout.ExpandWidth(false), GUILayout.MaxWidth(150)) && index < actionTypes.Count)
                    {
                        Type addedType = actionTypes[index];

                        int addedIndex = list.arraySize;
                        list.InsertArrayElementAtIndex(addedIndex);
                        list.serializedObject.ApplyModifiedProperties();

                        BuildAction[] buildActions;
                        if (property.name.ToUpper().Contains("PRE"))
                        {
                            buildActions = BuildSettings.preBuildActions.buildActions;
                        }
                        else
                        {
                            buildActions = BuildSettings.postBuildActions.buildActions;
                        }

                        //buildActions[addedIndex] = Activator.CreateInstance(addedType) as BuildAction;
                        buildActions[addedIndex]            = ScriptableObject.CreateInstance(addedType) as BuildAction;
                        buildActions[addedIndex].name       = addedType.Name;
                        buildActions[addedIndex].actionName = addedType.Name;
                        buildActions[addedIndex].filter     = new BuildFilter();

                        AssetDatabase.AddObjectToAsset(buildActions[addedIndex], BuildSettings.instance);
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BuildSettings.instance));

                        index = 0;
                    }

                    GUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.HelpBox("No Build Actions found.", MessageType.Info);
                }

                EditorGUILayout.EndVertical();
            }

            EditorGUI.EndProperty();
        }
        private void DrawActions(SerializedProperty property)
        {
            for (int i = 0; i < list.arraySize; i++)
            {
                SerializedProperty listEntry = list.GetArrayElementAtIndex(i);

                BuildAction buildAction = listEntry.objectReferenceValue as BuildAction;
                if (buildAction == null)
                {
                    list.DeleteArrayElementAtIndex(i);
                    --i;
                    continue;
                }

                SerializedObject serializedBuildAction = new SerializedObject(buildAction);

                EditorGUILayout.BeginHorizontal();
                bool show = listEntry.isExpanded;

                buildAction.actionEnabled = EditorGUILayout.Toggle(buildAction.actionEnabled, GUILayout.Width(15));
                EditorGUI.BeginDisabledGroup(!buildAction.actionEnabled);
                UnityBuildGUIUtility.DropdownHeader(buildAction.actionName, ref show, false, GUILayout.ExpandWidth(true));
                EditorGUI.EndDisabledGroup();
                listEntry.isExpanded = show;

                EditorGUI.BeginDisabledGroup(i == 0);
                if (GUILayout.Button("↑↑", UnityBuildGUIUtility.helpButtonStyle))
                {
                    list.MoveArrayElement(i, 0);
                }
                if (GUILayout.Button("↑", UnityBuildGUIUtility.helpButtonStyle))
                {
                    list.MoveArrayElement(i, i - 1);
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(i == list.arraySize - 1);
                if (GUILayout.Button("↓", UnityBuildGUIUtility.helpButtonStyle))
                {
                    list.MoveArrayElement(i, i + 1);
                }
                EditorGUI.EndDisabledGroup();

                if (GUILayout.Button("X", UnityBuildGUIUtility.helpButtonStyle))
                {
                    BuildAction[] buildActions;
                    if (property.name.ToUpper().Contains("PRE"))
                    {
                        buildActions = BuildSettings.preBuildActions.buildActions;
                    }
                    else
                    {
                        buildActions = BuildSettings.postBuildActions.buildActions;
                    }

                    // Destroy underlying object.
                    ScriptableObject.DestroyImmediate(buildActions[i], true);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BuildSettings.instance));

                    // Remove object reference from list.
                    // TODO: Why do I need to call this twice? First call nulls reference, second one then deletes null entry.
                    list.DeleteArrayElementAtIndex(i);
                    list.DeleteArrayElementAtIndex(i);
                    show = false;
                }

                EditorGUILayout.EndHorizontal();

                if (show && buildAction.actionEnabled)
                {
                    EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle);
                    buildAction.Draw(serializedBuildAction);
                    EditorGUILayout.EndVertical();
                }
            }
        }