Skip to content

Commit

Permalink
📦 1.1.5 Release
Browse files Browse the repository at this point in the history
- Scriptable Asset Reference Fixes
- Asset Version Validator to check for the latest version in the settings for the asset.
- Project organisation of code editor folders.
  • Loading branch information
JonathanMCarter committed Jun 27, 2023
1 parent 40dde5c commit 5ee186a
Show file tree
Hide file tree
Showing 61 changed files with 997 additions and 199 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions Code/Editor/Asset Version Validator/VersionChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2018-Present Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using UnityEngine;
using UnityEngine.Networking;

namespace CarterGames.Assets.BuildVersions.Editor
{
/// <summary>
/// Handles checking for the latest version.
/// </summary>
public static class VersionChecker
{
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// The download URL for the latest version.
/// </summary>
public static string DownloadURL => VersionInfo.DownloadBaseUrl + Versions.Data.Version;


/// <summary>
/// Gets if the latest version is this version.
/// </summary>
public static bool IsLatestVersion => Versions.Data.Match(VersionInfo.ProjectVersionNumber);


/// <summary>
/// Gets the version data downloaded.
/// </summary>
public static VersionPacket Versions { get; private set; }


/// <summary>
/// The latest version string.
/// </summary>
public static string LatestVersionNumberString => Versions.Data.Version;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Events
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// Raises when the data has been downloaded.
/// </summary>
public static Action ResponseReceived { get; set; } = delegate { };

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Methods
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// Gets the latest version data when called.
/// </summary>
public static void GetLatestVersions()
{
RequestLatestVersionData();
}


/// <summary>
/// Makes the web request & handles the response.
/// </summary>
private static void RequestLatestVersionData()
{
var request = UnityWebRequest.Get(VersionInfo.ValidationUrl);
var async = request.SendWebRequest();

async.completed += (a) =>
{
if (request.result != UnityWebRequest.Result.Success) return;

Versions = JsonUtility.FromJson<VersionPacket>(request.downloadHandler.text);
ResponseReceived?.Invoke();
};
}
}
}
11 changes: 11 additions & 0 deletions Code/Editor/Asset Version Validator/VersionChecker.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions Code/Editor/Asset Version Validator/VersionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2018-Present Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using UnityEngine;

namespace CarterGames.Assets.BuildVersions.Editor
{
/// <summary>
/// A copy of the Json data for each entry stored on the server.
/// </summary>
[Serializable]
public class VersionData
{
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

[SerializeField] private string key;
[SerializeField] private string version;
[SerializeField] private string releaseDate;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Properties
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// The key for the entry.
/// </summary>
public string Key
{
get => key;
set => key = value;
}


/// <summary>
/// The version for the entry.
/// </summary>
public string Version
{
get => version;
set => version = value;
}


/// <summary>
/// The release date for the entry.
/// </summary>
public string ReleaseDate
{
get => releaseDate;
set => releaseDate = value;
}


/// <summary>
/// The version number for the entry.
/// </summary>
public VersionNumber VersionNumber => new VersionNumber(Version);

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Methods
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// Gets if the entry version number matches the entered string.
/// </summary>
/// <param name="toCompare">The version string to compare.</param>
/// <returns>If the entry is a match or not on all values (major/minor/patch).</returns>
public bool Match(string toCompare)
{
var aVN = VersionNumber;
var bVN = new VersionNumber(toCompare);

return aVN.Major.Equals(bVN.Major) && aVN.Minor.Equals(bVN.Minor) && aVN.Patch.Equals(bVN.Patch);
}
}
}
11 changes: 11 additions & 0 deletions Code/Editor/Asset Version Validator/VersionData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions Code/Editor/Asset Version Validator/VersionEditorGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018-Present Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using UnityEditor;
using UnityEngine;

namespace CarterGames.Assets.BuildVersions.Editor
{
/// <summary>
/// A helper class for using the version system on editor.
/// </summary>
public static class VersionEditorGUI
{
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Methods
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// Draws a check for updates button when called with dialogues to show the results.
/// </summary>
public static void DrawCheckForUpdatesButton()
{
if (!GUILayout.Button("Check For Updates", GUILayout.MaxWidth(135))) return;

VersionChecker.GetLatestVersions();

VersionChecker.ResponseReceived += () =>
{
if (!VersionChecker.IsLatestVersion)
{
if (EditorUtility.DisplayDialog("Update Checker",
$"You are using an older version of this package.\n\nCurrent: {VersionInfo.ProjectVersionNumber}\nLatest: {VersionChecker.LatestVersionNumberString}",
"Latest Release", "Continue"))
{
Application.OpenURL(VersionChecker.DownloadURL);
}
}
else
{
EditorUtility.DisplayDialog("Update Checker",
"You are using the latest version!",
"Continue");
}
};
}
}
}
11 changes: 11 additions & 0 deletions Code/Editor/Asset Version Validator/VersionEditorGUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions Code/Editor/Asset Version Validator/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018-Present Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace CarterGames.Assets.BuildVersions.Editor
{
/// <summary>
/// The info used in the version validation system.
/// </summary>
public static class VersionInfo
{
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// The Url to request the versions from.
/// </summary>
public const string ValidationUrl = "https://carter.games/validation/versions.json";


/// <summary>
/// The download Url for the latest version of this package.
/// </summary>
public const string DownloadBaseUrl = "https://github.com/CarterGames/BuildVersions/releases/tag/";


/// <summary>
/// The key of the package to get from the JSON blob.
/// </summary>
public const string Key = "Build Versions";


/// <summary>
/// The version string for the package.
/// </summary>
public static string ProjectVersionNumber => AssetVersionData.VersionNumber;
}
}
11 changes: 11 additions & 0 deletions Code/Editor/Asset Version Validator/VersionInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5ee186a

Please sign in to comment.