Added Unity project files

This commit is contained in:
2026-06-07 16:58:24 +01:00
parent 3cc05d260b
commit 23bbcab156
3942 changed files with 453676 additions and 0 deletions

View File

@ -0,0 +1,95 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace VRC.ExampleCentral.Editor
{
/// <summary>
/// Stores the GUID and Hash for each Asset in an Example
/// </summary>
[Serializable]
public class AssetInfo
{
public string GUID { get; private set; }
public string Hash { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="AssetInfo"/> class with the specified GUID and hash.
/// Used for deserialization, after the hash is computed.
/// </summary>
/// <param name="guid">The GUID of the asset.</param>
/// <param name="hash">The hash of the asset.</param>
public AssetInfo(string guid, string hash)
{
GUID = guid;
Hash = hash;
}
/// <summary>
/// Initializes a new instance of the <see cref="AssetInfo"/> class with the specified GUID.
/// The hash is computed based on the asset's content.
/// </summary>
/// <param name="guid">The GUID of the asset.</param>
public AssetInfo(string guid)
{
GUID = guid;
Hash = ComputeAssetHash(guid);
}
/// <summary>
/// Computes the hash of the asset based on its content.
/// </summary>
/// <param name="guid">The GUID of the asset.</param>
/// <returns>The computed hash of the asset.</returns>
private string ComputeAssetHash(string guid)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
string fullPath = Path.Combine(Application.dataPath, assetPath.Substring("Assets/".Length));
if (!File.Exists(fullPath))
return "File Not Found";
try
{
using FileStream stream = File.OpenRead(fullPath);
using SHA256 sha = SHA256.Create();
byte[] hashBytes = sha.ComputeHash(stream);
StringBuilder sb = new StringBuilder();
foreach (byte b in hashBytes)
sb.Append(b.ToString("X2"));
return sb.ToString();
}
catch (Exception ex)
{
Debug.LogError($"Error computing hash for {assetPath}: {ex.Message}");
return "Error";
}
}
/// <summary>
/// Serializes the asset to a string, using a pipe character as a separator.
/// </summary>
/// <returns>A string representation of the asset's guid and hash.</returns>
public string Serialize()
{
return $"{GUID}|{Hash}";
}
/// <summary>
/// Deserializes the asset information from a string.
/// </summary>
/// <param name="serializedData">The serialized data string.</param>
/// <returns>An instance of <see cref="AssetInfo"/>.</returns>
/// <exception cref="ArgumentException">Thrown when the serialized data format is invalid.</exception>
public static AssetInfo Deserialize(string serializedData)
{
var parts = serializedData.Split('|');
if (parts.Length != 2)
throw new ArgumentException("Invalid serialized data format");
return new AssetInfo(parts[0], parts[1]);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d95aa121fc5f5848b1a4a6b1eae7299
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
using System;
namespace VRC.ExampleCentral.Editor
{
/// <summary>
/// Stores a description of changes made to an Example
/// </summary>
[Serializable]
public class Changes
{
/// <summary>
/// SemVer-compatible version number (SemVer not currently enforced anywhere)
/// </summary>
public string Version;
/// <summary>
/// Plain text description of changes
/// </summary>
public string Value;
public Changes(string version, string value)
{
Version = version;
Value = value;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 305cd65774c510c409011962a5752a51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace VRC.ExampleCentral.Editor
{
public enum ExampleStatus
{
Local,
Draft,
Published
}
[Serializable]
public class ExampleData : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField]
public string author;
[SerializeField]
public string title;
[SerializeField]
public Texture2D thumbnail;
[SerializeField]
public string description;
[SerializeField]
public string version;
[SerializeField]
public string documentationLink;
[SerializeField]
public string vrcWorldId;
[SerializeField]
public List<string> tags = new();
[SerializeField]
public SceneAsset exampleScene;
[SerializeField]
private List<string> serializedAssets;
public List<AssetInfo> assets = new();
[SerializeField]
public string sanityId = $"drafts.{Guid.NewGuid().ToString()}";
[SerializeField]
public ExampleStatus ExampleStatus = ExampleStatus.Local;
[SerializeField]
public List<Changes> changes = new();
// Serialize the AssetInfo list to a list of strings
public void OnBeforeSerialize()
{
serializedAssets = assets.ConvertAll(asset => asset.Serialize());
}
// Deserialize the List<string> back to the AssetInfo list
public void OnAfterDeserialize()
{
assets = serializedAssets.ConvertAll(AssetInfo.Deserialize);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 02be9066d74f7884ab56988f40f56297
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: