예제 #1
0
        private void DrawActionList(SerializedProperty property, List <Type> actionTypes)
        {
            if (actionTypes.Count > 0)
            {
                EditorGUILayout.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]            = 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);
                    AssetDatabaseUtility.ImportAsset(AssetDatabase.GetAssetPath(BuildSettings.instance));

                    index = 0;
                }

                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.HelpBox("No Build Actions found.", MessageType.Info);
            }
        }
예제 #2
0
        private void DrawPlatforms(SerializedProperty property)
        {
            for (int i = 0; i < list.arraySize; i++)
            {
                SerializedProperty listEntry = list.GetArrayElementAtIndex(i);

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

                SerializedObject serializedBuildPlatform = new SerializedObject(buildPlatform);

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

                UnityBuildGUIUtility.DropdownHeader(buildPlatform.platformName, ref show, false, GUILayout.ExpandWidth(true));

                listEntry.isExpanded = show;

                if (GUILayout.Button("X", UnityBuildGUIUtility.helpButtonStyle))
                {
                    List <BuildPlatform> buildPlatforms = BuildSettings.platformList.platforms;

                    // Destroy underlying object.
                    ScriptableObject.DestroyImmediate(buildPlatforms[i], true);
                    AssetDatabaseUtility.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 && buildPlatform.enabled)
                {
                    EditorGUILayout.BeginVertical(UnityBuildGUIUtility.dropdownContentStyle);
                    buildPlatform.Draw(serializedBuildPlatform);
                    EditorGUILayout.EndVertical();
                }
            }
        }
예제 #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            EditorGUILayout.BeginHorizontal();
            property.serializedObject.Update();

            bool show = property.isExpanded;

            UnityBuildGUIUtility.DropdownHeader("Build Platforms", ref show, false, GUILayout.ExpandWidth(true));
            property.isExpanded = show;

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

            platformList = fieldInfo.GetValue(property.serializedObject.targetObject) as BuildPlatformList;
            PopulateAvailablePlatforms();
            list = property.FindPropertyRelative("platforms");
            list.serializedObject.Update();

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

                DrawPlatforms(property);

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

                // Draw all available platforms.
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                index = EditorGUILayout.Popup(index, availablePlatformNameList.ToArray(), UnityBuildGUIUtility.popupStyle, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(250));
                if (GUILayout.Button("Add Platform", GUILayout.ExpandWidth(false), GUILayout.MaxWidth(150)))
                {
                    BuildPlatform addedBuildPlatform = ScriptableObject.CreateInstance(availablePlatformTypeList[index]) as BuildPlatform;
                    platformList.platforms.Add(addedBuildPlatform);

                    AssetDatabase.AddObjectToAsset(addedBuildPlatform, BuildSettings.instance);
                    AssetDatabaseUtility.ImportAsset(AssetDatabase.GetAssetPath(BuildSettings.instance));

                    platformList.platforms[platformList.platforms.Count - 1].enabled = true;

                    for (int i = platformList.platforms.Count - 1; i >= 0; i--)
                    {
                        if (!platformList.platforms[i].enabled)
                        {
                            platformList.platforms.RemoveAt(i);
                        }
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }

            EditorGUI.EndProperty();
        }
예제 #4
0
        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);
                    AssetDatabaseUtility.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();
                }
            }
        }