Skip to content

Commit

Permalink
Added legacy package support, v1.2.0 bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jzapdot committed Oct 4, 2019
2 parents 0314c3e + d84b8e5 commit 32544e5
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 167 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.DS_Store
*.DS_Store

[Bb]uilds/
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace JCMG.PackageTools.Editor
[CustomPropertyDrawer(typeof(PackageManifestConfig.Dependency))]
internal sealed class DependencyPropertyDrawer : PropertyDrawer
{
private const string PackageNamePropertyName = "packageName";
private const string PackageVersionPropertyName = "packageVersion";
private const string PACKAGE_NAME_PROPERTY_NAME = "packageName";
private const string PACKAGE_VERSION_PROPERTY_NAME = "packageVersion";

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Expand All @@ -44,8 +44,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
position = new Vector2(position.x, packageRect.y + packageRect.height)
};

EditorGUI.PropertyField(packageRect, property.FindPropertyRelative(PackageNamePropertyName));
EditorGUI.PropertyField(packageVersionRect, property.FindPropertyRelative(PackageVersionPropertyName));
EditorGUI.PropertyField(packageRect, property.FindPropertyRelative(PACKAGE_NAME_PROPERTY_NAME));
EditorGUI.PropertyField(packageVersionRect, property.FindPropertyRelative(PACKAGE_VERSION_PROPERTY_NAME));
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
Expand Down
66 changes: 35 additions & 31 deletions Unity/Assets/JCMG/PackageTools/Scripts/Editor/EditorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using UnityEngine;

namespace JCMG.PackageTools.Editor
Expand All @@ -32,54 +31,59 @@ namespace JCMG.PackageTools.Editor
internal static class EditorConstants
{
// Package Manifest
public const string DefaultPackageVersion = "1.0.0";
public const string DefaultUnityVersion = "2018.1";
public const string DEFAULT_PACKAGE_VERSION = "1.0.0";
public const string DEFAULT_UNITY_VERSION = "2018.1";

// File
public const string PackageJsonFilename = "package.json";
public const string WildcardFilter = "*";
public const string AssetExtension = ".asset";
public const string MetaFormat = "{0}.meta";
public const string GeneratedFolderName = "Generated";
public static readonly string ProjectPath =
public const string PACKAGE_JSON_FILENAME = "package.json";
public const string WILDCARD_FILTER = "*";
public const string ASSET_EXTENSION = ".asset";
public const string META_FORMAT = "{0}.meta";
public const string GENERATED_FOLDER_NAME = "Generated";
public const string UNITY_PACKAGE_NAME_FORMAT = "{0}_v{1}.unityPackage";
public const char EMPTY_SPACE = ' ';
public const char UNDERSCORE = '_';
public static readonly string PROJECT_PATH =
Application.dataPath.Remove(Application.dataPath.Length - 6, 6);

// Icons
public const string EditorFolderIcon = "Folder Icon";
public const string EditorFileIcon = "TextAsset Icon";
public const string EDITOR_FOLDER_ICON = "Folder Icon";
public const string EDITOR_FILE_ICON = "TextAsset Icon";

// Inspector
public const string PackageJsonHeader = "Package Json";
public const string PackageContentHeader = "Package Content and Export";
public const string PackageActionsHeader = "Actions";
public const string PACKAGE_JSON_HEADER = "Package Json";
public const string PACKAGE_CONTENT_HEADER = "Package Content and Export";
public const string PACKAGE_ACTIONS_HEADER = "Actions";

public const string SourcePathsHeaderLabel = "Source Paths";
public const string SourcePathElementLabelFormat = "Path {0}:";
public const string SOURCE_PATHS_HEADER_LABEL = "Source Paths";
public const string SOURCE_PATH_ELEMENT_LABEL_FORMAT = "Path {0}:";

public const string IgnorePathsHeaderLabel = "Exclude Paths";
public const string IGNORE_PATHS_HEADER_LABEL = "Exclude Paths";

public const string KeywordsHeaderLabel = "Keywords";
public const string KeywordElementLabelFormat = "Keyword {0}:";
public const string KEYWORDS_HEADER_LABEL = "Keywords";
public const string KEYWORD_ELEMENT_LABEL_FORMAT = "Keyword {0}:";

public const string DependencyHeaderLabel = "Dependencies";
public const string DependencyElementLabelFormat = "Dependency {0}:";
public const string DEPENDENCY_HEADER_LABEL = "Dependencies";
public const string DEPENDENCY_ELEMENT_LABEL_FORMAT = "Dependency {0}:";

public const string UpdatePackageButtonText = "Export Package Source";
public const string UPDATE_PACKAGE_BUTTON_TEXT = "Export Package Source";
public const string EXPORT_LEGACY_PACKAGE_BUTTON_TEXT = "Export as Legacy Package";

public static string SelectSourcePathFilePickerTitle = "Select Source Asset Path";
public const string SelectSourcePathPickerFolderTitle = "Select Source Folder Path";
public const string SelectPackageExportPathPickerTitle = "Select Package Export Folder";
public const string ProgressBarTitle = "Exporting Package Source";
public const string SELECT_SOURCE_PATH_FILE_PICKER_TITLE = "Select Source Asset Path";
public const string SELECT_SOURCE_PATH_PICKER_FOLDER_TITLE = "Select Source Folder Path";
public const string SELECT_PACKAGE_EXPORT_PATH_PICKER_TITLE = "Select Package Export Folder";
public const string PROGRESS_BAR_TITLE = "Exporting Package Source";
public const string PROGRESS_BAR_TITLE_LEGACY = "Exporting Legacy Package";
public const string COMPILING_PROGRESS_MESSAGE = "Compiling legacy package contents...";

public const float FolderPathPickerHeight = 26f;
public const float FolderPathPickerBuffer = 36f;
public const float FOLDER_PATH_PICKER_HEIGHT = 26f;
public const float FOLDER_PATH_PICKER_BUFFER = 36f;

// Logging
public const string PackageUpdateErrorFormat =
public const string PACKAGE_UPDATE_ERROR_FORMAT =
"[Package Tools] Failed to update package source for [{0}].";

public const string PackageUpdateSuccessFormat =
public const string PACKAGE_UPDATE_SUCCESS_FORMAT =
"[Package Tools] Successfully updated package source for [{0}].";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,49 @@ internal sealed class PackageManifestConfigInspector : UnityEditor.Editor
private ReorderableList _keywordReorderableList;
private ReorderableList _dependenciesReorderableList;

private const string SourcePathsPropertyName = "packageSourcePaths";
private const string ExcludePathsPropertyName = "packageIgnorePaths";
private const string DestinationPathPropertyName = "packageDestinationPath";
private const string NamePropertyName = "packageName";
private const string DisplayNameProperty = "displayName";
private const string PackageVersionPropertyName = "packageVersion";
private const string UnityVersionPropertyName = "unityVersion";
private const string DescriptionPropertyName = "description";
private const string CategoryPropertyName = "category";
private const string KeywordsPropertyName = "keywords";
private const string DependenciesPropertyName = "dependencies";
private const string IdPropertyName = "_id";
private const string SOURCE_PATHS_PROPERTY_NAME = "packageSourcePaths";
private const string EXCLUDE_PATHS_PROPERTY_NAME = "packageIgnorePaths";
private const string DESTINATION_PATH_PROPERTY_NAME = "packageDestinationPath";
private const string LEGACY_PACKAGE_PATH_PROPERTY_NAME = "legacyPackageDestinationPath";
private const string NAME_PROPERTY_NAME = "packageName";
private const string DISPLAY_NAME_PROPERTY = "displayName";
private const string PACKAGE_VERSION_PROPERTY_NAME = "packageVersion";
private const string UNITY_VERSION_PROPERTY_NAME = "unityVersion";
private const string DESCRIPTION_PROPERTY_NAME = "description";
private const string CATEGORY_PROPERTY_NAME = "category";
private const string KEYWORDS_PROPERTY_NAME = "keywords";
private const string DEPENDENCIES_PROPERTY_NAME = "dependencies";
private const string ID_PROPERTY_NAME = "_id";

private void OnEnable()
{
_sourcePathsReorderableList = new ReorderableList(
serializedObject,
serializedObject.FindProperty(SourcePathsPropertyName))
serializedObject.FindProperty(SOURCE_PATHS_PROPERTY_NAME))
{
drawHeaderCallback = DrawSourcePathHeader,
drawElementCallback = DrawSourcePathElement,
elementHeight = EditorConstants.FolderPathPickerHeight
elementHeight = EditorConstants.FOLDER_PATH_PICKER_HEIGHT
};

_excludePathsReorderableList = new ReorderableList(
serializedObject,
serializedObject.FindProperty(ExcludePathsPropertyName))
serializedObject.FindProperty(EXCLUDE_PATHS_PROPERTY_NAME))
{
drawHeaderCallback = DrawExcludePathHeader,
drawElementCallback = DrawExcludePathElement,
elementHeight = EditorConstants.FolderPathPickerHeight
elementHeight = EditorConstants.FOLDER_PATH_PICKER_HEIGHT
};

_keywordReorderableList =new ReorderableList(
serializedObject,
serializedObject.FindProperty(KeywordsPropertyName))
serializedObject.FindProperty(KEYWORDS_PROPERTY_NAME))
{
drawHeaderCallback = DrawKeywordsHeader,
drawElementCallback = DrawKeywordElement
};

var dependencyProp = serializedObject.FindProperty(DependenciesPropertyName);
var dependencyProp = serializedObject.FindProperty(DEPENDENCIES_PROPERTY_NAME);
_dependenciesReorderableList = new ReorderableList(
serializedObject,
dependencyProp)
Expand All @@ -91,39 +92,51 @@ public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();

EditorGUILayout.LabelField(EditorConstants.PackageJsonHeader, EditorStyles.boldLabel);
EditorGUILayout.LabelField(EditorConstants.PACKAGE_JSON_HEADER, EditorStyles.boldLabel);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(serializedObject.FindProperty(IdPropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(ID_PROPERTY_NAME));
EditorGUI.EndDisabledGroup();

EditorGUILayout.PropertyField(serializedObject.FindProperty(NamePropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(DisplayNameProperty));
EditorGUILayout.PropertyField(serializedObject.FindProperty(PackageVersionPropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(NAME_PROPERTY_NAME));
EditorGUILayout.PropertyField(serializedObject.FindProperty(DISPLAY_NAME_PROPERTY));
EditorGUILayout.PropertyField(serializedObject.FindProperty(PACKAGE_VERSION_PROPERTY_NAME));

EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(serializedObject.FindProperty(UnityVersionPropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(UNITY_VERSION_PROPERTY_NAME));
EditorGUILayout.EndHorizontal();

EditorGUILayout.PropertyField(serializedObject.FindProperty(DescriptionPropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(CategoryPropertyName));
EditorGUILayout.PropertyField(serializedObject.FindProperty(DESCRIPTION_PROPERTY_NAME));
EditorGUILayout.PropertyField(serializedObject.FindProperty(CATEGORY_PROPERTY_NAME));

_keywordReorderableList.DoLayoutList();
_dependenciesReorderableList.DoLayoutList();

EditorGUILayout.Space();
EditorGUILayout.LabelField(EditorConstants.PackageContentHeader, EditorStyles.boldLabel);
EditorGUILayout.LabelField(EditorConstants.PACKAGE_CONTENT_HEADER, EditorStyles.boldLabel);

_sourcePathsReorderableList.DoLayoutList();
_excludePathsReorderableList.DoLayoutList();

// Package Source Export
EditorGUILayout.BeginHorizontal();
var destinationPathProperty = serializedObject.FindProperty(DestinationPathPropertyName);
var destinationPathProperty = serializedObject.FindProperty(DESTINATION_PATH_PROPERTY_NAME);
EditorGUILayout.PropertyField(
destinationPathProperty,
GUILayout.Height(EditorConstants.FolderPathPickerHeight));
GUILayout.Height(EditorConstants.FOLDER_PATH_PICKER_HEIGHT));
GUILayoutTools.DrawFolderPickerLayout(
destinationPathProperty,
EditorConstants.SelectPackageExportPathPickerTitle);
EditorConstants.SELECT_PACKAGE_EXPORT_PATH_PICKER_TITLE);
EditorGUILayout.EndHorizontal();

// Legacy Package Export
EditorGUILayout.BeginHorizontal();
var legacyPackagePathProperty = serializedObject.FindProperty(LEGACY_PACKAGE_PATH_PROPERTY_NAME);
EditorGUILayout.PropertyField(
legacyPackagePathProperty,
GUILayout.Height(EditorConstants.FOLDER_PATH_PICKER_HEIGHT));
GUILayoutTools.DrawFolderPickerLayout(
legacyPackagePathProperty,
EditorConstants.SELECT_PACKAGE_EXPORT_PATH_PICKER_TITLE);
EditorGUILayout.EndHorizontal();

if (EditorGUI.EndChangeCheck())
Expand All @@ -132,74 +145,79 @@ public override void OnInspectorGUI()
}

EditorGUILayout.Space();
EditorGUILayout.LabelField(EditorConstants.PackageActionsHeader, EditorStyles.boldLabel);
EditorGUILayout.LabelField(EditorConstants.PACKAGE_ACTIONS_HEADER, EditorStyles.boldLabel);

if (GUILayout.Button(EditorConstants.UpdatePackageButtonText))
if (GUILayout.Button(EditorConstants.UPDATE_PACKAGE_BUTTON_TEXT))
{
FileTools.CreateOrUpdatePackageSource((PackageManifestConfig)target);
}

if (GUILayout.Button(EditorConstants.EXPORT_LEGACY_PACKAGE_BUTTON_TEXT))
{
UnityFileTools.CompileLegacyPackage((PackageManifestConfig)target);
}
}

#region Source Paths ReorderableList

private void DrawSourcePathHeader(Rect rect)
{
EditorGUI.LabelField(rect, EditorConstants.SourcePathsHeaderLabel, EditorStyles.boldLabel);
EditorGUI.LabelField(rect, EditorConstants.SOURCE_PATHS_HEADER_LABEL, EditorStyles.boldLabel);
}

private void DrawSourcePathElement(Rect rect, int index, bool isActive, bool isFocused)
{
DrawPathElement(SourcePathsPropertyName, rect, index, isActive, isFocused);
DrawPathElement(SOURCE_PATHS_PROPERTY_NAME, rect, index, isActive, isFocused);
}

private void DrawExcludePathHeader(Rect rect)
{
EditorGUI.LabelField(rect, EditorConstants.IgnorePathsHeaderLabel, EditorStyles.boldLabel);
EditorGUI.LabelField(rect, EditorConstants.IGNORE_PATHS_HEADER_LABEL, EditorStyles.boldLabel);
}

private void DrawExcludePathElement(Rect rect, int index, bool isActive, bool isFocused)
{
DrawPathElement(ExcludePathsPropertyName, rect, index, isActive, isFocused);
DrawPathElement(EXCLUDE_PATHS_PROPERTY_NAME, rect, index, isActive, isFocused);
}

private void DrawPathElement(string propertyName, Rect rect, int index, bool isActive, bool isFocused)
{
rect.width -= EditorConstants.FolderPathPickerHeight * 2;
rect.height = EditorConstants.FolderPathPickerHeight;
rect.width -= EditorConstants.FOLDER_PATH_PICKER_HEIGHT * 2;
rect.height = EditorConstants.FOLDER_PATH_PICKER_HEIGHT;
var sourcePathRect = new Rect(rect);

var sourcePathProperty =
serializedObject.FindProperty(propertyName).GetArrayElementAtIndex(index);
EditorGUI.PropertyField(
sourcePathRect,
sourcePathProperty,
new GUIContent(string.Format(EditorConstants.SourcePathElementLabelFormat, index)));
new GUIContent(string.Format(EditorConstants.SOURCE_PATH_ELEMENT_LABEL_FORMAT, index)));

var filePickerRect = new Rect {
position = new Vector2(
sourcePathRect.width + EditorConstants.FolderPathPickerBuffer,
sourcePathRect.width + EditorConstants.FOLDER_PATH_PICKER_BUFFER,
sourcePathRect.position.y),
width = EditorConstants.FolderPathPickerHeight,
height = EditorConstants.FolderPathPickerHeight,
width = EditorConstants.FOLDER_PATH_PICKER_HEIGHT,
height = EditorConstants.FOLDER_PATH_PICKER_HEIGHT,
};

var folderPickerRect = new Rect {
position = new Vector2(
sourcePathRect.width + EditorConstants.FolderPathPickerHeight + EditorConstants.FolderPathPickerBuffer,
sourcePathRect.width + EditorConstants.FOLDER_PATH_PICKER_HEIGHT + EditorConstants.FOLDER_PATH_PICKER_BUFFER,
sourcePathRect.position.y),
width = EditorConstants.FolderPathPickerHeight,
height = EditorConstants.FolderPathPickerHeight,
width = EditorConstants.FOLDER_PATH_PICKER_HEIGHT,
height = EditorConstants.FOLDER_PATH_PICKER_HEIGHT,
};

GUILayoutTools.DrawFilePicker(
filePickerRect,
sourcePathProperty,
EditorConstants.SelectSourcePathFilePickerTitle);
EditorConstants.SELECT_SOURCE_PATH_FILE_PICKER_TITLE);

GUILayoutTools.DrawFolderPicker(
folderPickerRect,
sourcePathProperty,
EditorConstants.SelectSourcePathPickerFolderTitle);
EditorConstants.SELECT_SOURCE_PATH_PICKER_FOLDER_TITLE);
}

#endregion
Expand All @@ -208,15 +226,15 @@ private void DrawPathElement(string propertyName, Rect rect, int index, bool isA

private void DrawKeywordsHeader(Rect rect)
{
EditorGUI.LabelField(rect, EditorConstants.KeywordsHeaderLabel, EditorStyles.boldLabel);
EditorGUI.LabelField(rect, EditorConstants.KEYWORDS_HEADER_LABEL, EditorStyles.boldLabel);
}

private void DrawKeywordElement(Rect rect, int index, bool isActive, bool isFocused)
{
EditorGUI.PropertyField(
rect,
serializedObject.FindProperty(KeywordsPropertyName).GetArrayElementAtIndex(index),
new GUIContent(string.Format(EditorConstants.KeywordElementLabelFormat, index)));
serializedObject.FindProperty(KEYWORDS_PROPERTY_NAME).GetArrayElementAtIndex(index),
new GUIContent(string.Format(EditorConstants.KEYWORD_ELEMENT_LABEL_FORMAT, index)));
}

#endregion
Expand All @@ -225,16 +243,16 @@ private void DrawKeywordElement(Rect rect, int index, bool isActive, bool isFocu

private void DrawDependencyHeader(Rect rect)
{
EditorGUI.LabelField(rect, EditorConstants.DependencyHeaderLabel, EditorStyles.boldLabel);
EditorGUI.LabelField(rect, EditorConstants.DEPENDENCY_HEADER_LABEL, EditorStyles.boldLabel);
}

private void DrawDependencyElement(Rect rect, int index, bool isActive, bool isFocused)
{
// TODO This needs to be replaced or a custom drawer made
EditorGUI.PropertyField(
rect,
serializedObject.FindProperty(DependenciesPropertyName).GetArrayElementAtIndex(index),
new GUIContent(string.Format(EditorConstants.DependencyElementLabelFormat, index))
serializedObject.FindProperty(DEPENDENCIES_PROPERTY_NAME).GetArrayElementAtIndex(index),
new GUIContent(string.Format(EditorConstants.DEPENDENCY_ELEMENT_LABEL_FORMAT, index))
);
}

Expand Down
Loading

0 comments on commit 32544e5

Please sign in to comment.