mirror of
https://github.com/MrUnknownDE/examples-image-loading.git
synced 2026-04-19 06:43:50 +02:00
Moves demo to Examples folder
This commit is contained in:
@@ -3,14 +3,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEditor.VersionControl;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using VRC.PackageManagement.Core.Types.Packages;
|
||||
using YamlDotNet.Serialization.NodeTypeResolvers;
|
||||
|
||||
namespace VRC.PackageManagement.PackageMaker
|
||||
{
|
||||
@@ -22,6 +21,9 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
private TextField _packageIDField;
|
||||
private Button _actionButton;
|
||||
private EnumField _targetVRCPackageField;
|
||||
private TextField _authorNameField;
|
||||
private TextField _authorEmailField;
|
||||
private TextField _authorUrlField;
|
||||
private static string _projectDir;
|
||||
private PackageMakerWindowData _windowData;
|
||||
|
||||
@@ -33,6 +35,9 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
}
|
||||
_packageIDField.SetValueWithoutNotify(_windowData.packageID);
|
||||
_targetVRCPackageField.SetValueWithoutNotify(_windowData.relatedPackage);
|
||||
_authorEmailField.SetValueWithoutNotify(_windowData.authorEmail);
|
||||
_authorNameField.SetValueWithoutNotify(_windowData.authorName);
|
||||
_authorUrlField.SetValueWithoutNotify(_windowData.authorUrl);
|
||||
|
||||
RefreshActionButtonState();
|
||||
}
|
||||
@@ -53,27 +58,30 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
[MenuItem("Assets/Export VPM as UnityPackage")]
|
||||
private static void ExportAsUnityPackage ()
|
||||
{
|
||||
if (Selection.assetGUIDs.Length != 1)
|
||||
|
||||
var foldersToExport = new List<string>();
|
||||
StringBuilder exportFilename = new StringBuilder("exported");
|
||||
foreach (string guid in Selection.assetGUIDs)
|
||||
{
|
||||
Debug.LogWarning($"Cannot export selection, must be a single Folder.");
|
||||
return;
|
||||
}
|
||||
|
||||
string selectedFolder = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
|
||||
var manifestPath = Path.Combine(selectedFolder, VRCPackageManifest.Filename);
|
||||
var manifest = VRCPackageManifest.GetManifestAtPath(manifestPath);
|
||||
if (manifest == null)
|
||||
{
|
||||
Debug.LogWarning($"Could not read valid Package Manifest at {manifestPath}. You need to create this first.");
|
||||
return;
|
||||
string selectedFolder = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var manifestPath = Path.Combine(selectedFolder, VRCPackageManifest.Filename);
|
||||
var manifest = VRCPackageManifest.GetManifestAtPath(manifestPath);
|
||||
if (manifest == null)
|
||||
{
|
||||
Debug.LogWarning($"Could not read valid Package Manifest at {manifestPath}. You need to create this first to export a VPM Package.");
|
||||
continue;
|
||||
}
|
||||
exportFilename.Append($"-{manifest.Id}-{manifest.Version}");
|
||||
foldersToExport.Add(selectedFolder);
|
||||
}
|
||||
|
||||
exportFilename.Append(".unitypackage");
|
||||
var exportDir = Path.Combine(Directory.GetCurrentDirectory(), "Exports");
|
||||
Directory.CreateDirectory(exportDir);
|
||||
AssetDatabase.ExportPackage
|
||||
(
|
||||
selectedFolder,
|
||||
Path.Combine(exportDir, $"{manifest.Id}-{manifest.Version}.unitypackage"),
|
||||
foldersToExport.ToArray(),
|
||||
Path.Combine(exportDir, exportFilename.ToString()),
|
||||
ExportPackageOptions.Recurse | ExportPackageOptions.Interactive
|
||||
);
|
||||
}
|
||||
@@ -97,7 +105,9 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
{
|
||||
_actionButton.SetEnabled(
|
||||
StringIsValidAssetFolder(_windowData.targetAssetFolder) &&
|
||||
!string.IsNullOrWhiteSpace(_windowData.packageID)
|
||||
!string.IsNullOrWhiteSpace(_windowData.packageID) &&
|
||||
_authorNameField.value != null &&
|
||||
IsValidEmail(_authorEmailField.value)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,6 +128,7 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
// Create Target Asset folder and register for drag and drop events
|
||||
_rootView.Add(CreateTargetFolderElement());
|
||||
_rootView.Add(CreatePackageIDElement());
|
||||
_rootView.Add(CreateAuthorElement());
|
||||
_rootView.Add(CreateTargetVRCPackageElement());
|
||||
_rootView.Add(CreateActionButton());
|
||||
|
||||
@@ -202,6 +213,59 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
return box;
|
||||
}
|
||||
|
||||
private VisualElement CreateAuthorElement()
|
||||
{
|
||||
// Construct author fields
|
||||
_authorNameField = new TextField("Author Name");
|
||||
_authorEmailField = new TextField("Author Email");
|
||||
_authorUrlField = new TextField("Author URL (optional)");
|
||||
|
||||
// Save name to window data and toggle the Action Button if its status changed
|
||||
_authorNameField.RegisterValueChangedCallback((evt) =>
|
||||
{
|
||||
_windowData.authorName = evt.newValue;
|
||||
Debug.Log($"Window author name is {evt.newValue}");
|
||||
RefreshActionButtonState();
|
||||
});
|
||||
|
||||
// Save email to window data if valid and toggle the Action Button if its status changed
|
||||
_authorEmailField.RegisterValueChangedCallback((evt) =>
|
||||
{
|
||||
// Only save email if it appears valid
|
||||
if (IsValidEmail(evt.newValue))
|
||||
{
|
||||
_windowData.authorEmail = evt.newValue;
|
||||
}
|
||||
RefreshActionButtonState();
|
||||
});
|
||||
|
||||
// Save url to window data, doesn't affect action button state
|
||||
_authorUrlField.RegisterValueChangedCallback((evt) =>
|
||||
{
|
||||
_windowData.authorUrl = evt.newValue;
|
||||
});
|
||||
|
||||
// Add new fields to layout
|
||||
var box = new Box();
|
||||
box.Add(_authorNameField);
|
||||
box.Add(_authorEmailField);
|
||||
box.Add(_authorUrlField);
|
||||
return box;
|
||||
}
|
||||
|
||||
private bool IsValidEmail(string evtNewValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var addr = new System.Net.Mail.MailAddress(evtNewValue);
|
||||
return addr.Address == evtNewValue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Regex packageIdRegex = new Regex("[^a-z0-9.]");
|
||||
private void OnPackageIDChanged(ChangeEvent<string> evt)
|
||||
{
|
||||
@@ -331,13 +395,26 @@ namespace VRC.PackageManagement.PackageMaker
|
||||
}
|
||||
|
||||
string parentDir = new DirectoryInfo(targetDir)?.Parent.FullName;
|
||||
Core.Utilities.CreateStarterPackage(_windowData.packageID, parentDir, packageType);
|
||||
var packageDir = Core.Utilities.CreateStarterPackage(_windowData.packageID, parentDir, packageType);
|
||||
|
||||
// Modify manifest to add author
|
||||
// Todo: add support for passing author into CreateStarterPackage
|
||||
var manifest =
|
||||
VRCPackageManifest.GetManifestAtPath(Path.Combine(packageDir, VRCPackageManifest.Filename)) as
|
||||
VRCPackageManifest;
|
||||
manifest.author = new Author()
|
||||
{
|
||||
email = _windowData.authorEmail,
|
||||
name = _windowData.authorName,
|
||||
url = _windowData.authorUrl
|
||||
};
|
||||
manifest.Save();
|
||||
|
||||
var allFiles = GetAllFiles(corePath).ToList();
|
||||
MoveFilesToPackageDir(allFiles, corePath, targetDir);
|
||||
|
||||
// Clear target asset folder since it should no longer exist
|
||||
_windowData.targetAssetFolder = "";
|
||||
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetAllFiles(string path)
|
||||
|
||||
Reference in New Issue
Block a user