Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(versionumber): the updateversionfrompackagejson function should not use a static path #103

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions package/Editor/Plugins/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Linq;

namespace Scenario
{
public class PluginSettings : EditorWindow
{
private static string assemblyDefinitionFileName = "com.scenarioinc.scenario.editor";
private string apiKey;
private string secretKey;
private string saveFolder;
Expand All @@ -18,7 +20,7 @@ public class PluginSettings : EditorWindow
private readonly string[] imageFormats = { "JPEG", "PNG" };
private readonly string[] imageFormatExtensions = { "jpeg", "png" };

private static string vnumber = "";
private static string vnumber => GetVersionFromPackageJson();
private static string version => $"Scenario Beta Version {vnumber}";

[System.Serializable]
Expand All @@ -27,14 +29,35 @@ private class PackageInfo
public string version;
}

[MenuItem("Scenario/Update Version")]
public static void UpdateVersionFromPackageJson()
/// <summary>
/// Get the correct version number from the package JSON
/// </summary>
/// <returns>The version of the plugin, as a string</returns>
private static string GetVersionFromPackageJson()
{
string packageJsonPath = "Assets/Scenario/package.json";
string packageJsonContent = File.ReadAllText(packageJsonPath);
vnumber = JsonUtility.FromJson<PackageInfo>(packageJsonContent).version;
//Find the assembly Definition which should be at package/Editor/ folder because it's a unique file.
string[] guids = AssetDatabase.FindAssets($"{assemblyDefinitionFileName} t:assemblydefinitionasset");

if (guids.Length > 1)
{
Debug.LogError($"it seems that you have multiple file '{assemblyDefinitionFileName}.asmdef'. Please delete one");
return "0";
}

EditorWindow.GetWindow<PluginSettings>().Repaint();
if (guids.Length == 0)
{
Debug.LogError($"It seems that you don't have the file '{assemblyDefinitionFileName}.asmdef'. Please redownload the plugin from the asset store.");
return "0";
}

//find the folder of that file
string folderPath = AssetDatabase.GUIDToAssetPath(guids[0]);
folderPath = folderPath.Remove(folderPath.IndexOf($"Editor/{assemblyDefinitionFileName}.asmdef"));

//find the package.json inside this folder
string packageJsonPath = $"{folderPath}/package.json";
string packageJsonContent = File.ReadAllText(packageJsonPath);
return JsonUtility.FromJson<PackageInfo>(packageJsonContent).version;
}

public static string EncodedAuth
Expand Down Expand Up @@ -62,15 +85,15 @@ public static void ShowWindow()

private void OnEnable()
{
UpdateVersionFromPackageJson();
GetVersionFromPackageJson();
LoadSettings();
}

private void OnGUI()
{
Color backgroundColor = new Color32(18, 18, 18, 255);
EditorGUI.DrawRect(new Rect(0, 0, Screen.width, Screen.height), backgroundColor);

GUILayout.Space(10);

apiKey = EditorGUILayout.TextField("API Key", apiKey);
Expand Down
Loading