Skip to content

Commit

Permalink
add lifetime sample
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSmile-0000011110110111 committed Jan 24, 2024
1 parent 730100c commit 0d0e65f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

#### v1.8.4 - Jan 24, 2024

- added asset lifetime sample script
- updated documentation

#### v1.8.3 - Jan 22, 2024

- Importer tests: disable some tests in 2021.3 because the method is not available
Expand Down
41 changes: 41 additions & 0 deletions Samples~/CreateAndDelete/CodeSmileAssetDatabaseExamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2021-2024 Steffen Itterheim
// Refer to included LICENSE file for terms and conditions.

using CodeSmileEditor;
using System;
using System.IO;
using UnityEditor;
using UnityEngine;

public static class CodeSmileAssetDatabaseExamples
{
private const String TestFolder = "Assets/_sub_folder_";

/// <summary>
/// For more usage examples please refer to the numerous Unit Tests:
/// Packages/CodeSmile AssetDatabase/Tests/Editor/*.cs
/// </summary>
/// <remarks>API reference: https://codesmile-0000011110110111.github.io/de.codesmile.assetdatabase</remarks>
[MenuItem("Window/CodeSmile/AssetDatabase Examples/Create and Delete Asset")]
private static void CreateAndDeleteAsset()
{
var path = $"{TestFolder}/TestAsset.asset";
var asset = new Asset(ScriptableObject.CreateInstance<TestAsset>(), path);

var instance = asset.MainObject;
var assetPath = asset.AssetPath;
Debug.Log($"Asset '{instance}' created at '{assetPath}'");

var message = asset.GetMain<TestAsset>().Message;
Debug.Log($"Asset says: '{message}'");

asset.Delete();
Debug.Log($"Asset deleted: {asset.IsDeleted}");

// a folder is an asset, too!
var folder = new Asset(TestFolder);
folder.Delete();

Debug.Log($"Testfolder removed: {!Directory.Exists(TestFolder)}");
}
}
11 changes: 11 additions & 0 deletions Samples~/CreateAndDelete/CodeSmileAssetDatabaseExamples.cs.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "CodeSmileEditor.AssetDatabase.Examples",
"rootNamespace": "",
"references": [
"GUID:38cc5939e6694a64d8d6ea3aaca03495"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

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

12 changes: 12 additions & 0 deletions Samples~/CreateAndDelete/TestAsset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2021-2024 Steffen Itterheim
// Refer to included LICENSE file for terms and conditions.

using System;
using UnityEngine;

public class TestAsset : ScriptableObject
{
public String Message = "To be, or not to be: that is not a question.";

private void OnEnable() => name = "Test ScriptableObject";
}
3 changes: 3 additions & 0 deletions Samples~/CreateAndDelete/TestAsset.cs.meta

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

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "de.codesmile.assetdatabase",
"displayName": "CodeSmile AssetDatabase",
"description": "Accessible 'clean code' version of Unity's ~20 year old AssetDatabase class and related functionality.\n\nPublished under multiple licenses:\n- GPL 3.0 for personal & educational use\n- Custom licensing for Asset Publishers & Sponsors (<a href=\"mailto:[email protected]\">contact me</a>)\n- Asset Store Terms and EULA for most other uses",
"version": "1.8.3",
"description": "The AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.\n\nAvailable under multiple licenses:\n- GPL 3.0 for personal & educational use\n- Asset Store Terms and EULA for commercial use",
"version": "1.8.4",
"unity": "2021.3",
"unityRelease": "3f1",
"author": {
Expand All @@ -16,5 +16,12 @@
"dependencies": {
"com.unity.test-framework": "1.4.1"
},
"relatedPackages": {}
"relatedPackages": {},
"samples": [
{
"displayName": "Create and Delete Asset",
"description": "Basic asset lifetime example.",
"path": "Samples~/CreateAndDelete"
}
]
}

0 comments on commit 0d0e65f

Please sign in to comment.