res-avatar-unity/Packages/com.vrchat.core.vpm-resolver/Editor/PackageMaker/PackageMakerWindowData.cs
2023-07-15 19:51:23 -07:00

45 lines
1.3 KiB
C#

using System.IO;
using UnityEditor;
using UnityEngine;
using VRC.PackageManagement.PackageMaker;
public class PackageMakerWindowData : ScriptableObject
{
public static string defaultAssetPath = Path.Combine("Assets", "PackageMakerWindowData.asset");
public string targetAssetFolder;
public string packageID;
public PackageMakerWindow.VRCPackageEnum relatedPackage;
public static PackageMakerWindowData GetOrCreate()
{
var existingData = AssetDatabase.AssetPathToGUID(defaultAssetPath);
if (string.IsNullOrWhiteSpace(existingData))
{
return Create();
}
else
{
var saveData = AssetDatabase.LoadAssetAtPath<PackageMakerWindowData>(defaultAssetPath);
if (saveData == null)
{
Debug.LogError($"Could not load saved data but the save file exists. Resetting.");
return Create();
}
return saveData;
}
}
public static PackageMakerWindowData Create()
{
var saveData = CreateInstance<PackageMakerWindowData>();
AssetDatabase.CreateAsset(saveData, defaultAssetPath);
AssetDatabase.SaveAssets();
return saveData;
}
public void Save()
{
AssetDatabase.SaveAssets();
}
}