com.soosvet_games.common_tools 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Runtime/Abstract/IObservable.cs +9 -0
- package/Runtime/Abstract/IObservable.cs.meta +3 -0
- package/Runtime/Abstract/IReadOnly.cs +7 -0
- package/Runtime/Abstract/IReadOnly.cs.meta +3 -0
- package/Runtime/Abstract/IValue.cs +7 -0
- package/Runtime/Abstract/IValue.cs.meta +3 -0
- package/Runtime/Abstract.meta +3 -0
- package/Runtime/{Extensions/AssetDatabaseExtensions.cs → Utils/AssetDatabaseUtils.cs} +15 -2
- package/Runtime/{Extensions/AssetDatabaseExtensions.cs.meta → Utils/AssetDatabaseUtils.cs.meta} +1 -1
- package/Runtime/Utils/ScriptUtils.cs +41 -0
- package/Runtime/Utils/ScriptUtils.cs.meta +11 -0
- package/Runtime/Utils.meta +8 -0
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#if UNITY_EDITOR
|
|
2
2
|
using System.IO;
|
|
3
|
+
using System.Linq;
|
|
3
4
|
using UnityEditor;
|
|
4
5
|
using UnityEngine;
|
|
5
6
|
|
|
6
|
-
namespace SoosvetGames.CommonTools
|
|
7
|
+
namespace SoosvetGames.CommonTools
|
|
7
8
|
{
|
|
8
|
-
public static class
|
|
9
|
+
public static class AssetDatabaseUtils
|
|
9
10
|
{
|
|
10
11
|
public static void ClearFolder( this DefaultAsset defaultAsset )
|
|
11
12
|
{
|
|
@@ -26,6 +27,18 @@ namespace SoosvetGames.CommonTools.Extensions
|
|
|
26
27
|
|
|
27
28
|
AssetDatabase.Refresh();
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
public static T LoadAsset< T >() where T : ScriptableObject
|
|
32
|
+
{
|
|
33
|
+
return LoadAssets< T >().FirstOrDefault();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static T[] LoadAssets< T >( bool orderByName = true ) where T : ScriptableObject
|
|
37
|
+
{
|
|
38
|
+
var result = AssetDatabase.FindAssets( $"t:{typeof(T).Name}" ).Select( ( guid ) => AssetDatabase.LoadAssetAtPath< T >( AssetDatabase.GUIDToAssetPath( guid ) ) );
|
|
39
|
+
|
|
40
|
+
return orderByName ? result.OrderBy( ( x ) => x.name ).ToArray() : result.ToArray();
|
|
41
|
+
}
|
|
29
42
|
}
|
|
30
43
|
}
|
|
31
44
|
#endif
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#if UNITY_EDITOR
|
|
2
|
+
using System.IO;
|
|
3
|
+
using System.Text;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
|
|
6
|
+
namespace SoosvetGames.CommonTools
|
|
7
|
+
{
|
|
8
|
+
public static class ScriptUtils
|
|
9
|
+
{
|
|
10
|
+
public static void Create(
|
|
11
|
+
string path,
|
|
12
|
+
string namespaceName,
|
|
13
|
+
string className,
|
|
14
|
+
string content
|
|
15
|
+
)
|
|
16
|
+
{
|
|
17
|
+
var file = CreateCustomClass( namespaceName, className, content );
|
|
18
|
+
var fullPath = path + $"/{className}.cs";
|
|
19
|
+
|
|
20
|
+
File.WriteAllText( fullPath, file );
|
|
21
|
+
AssetDatabase.ImportAsset( fullPath );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static string CreateCustomClass( string namespaceName, string className, string content )
|
|
25
|
+
{
|
|
26
|
+
StringBuilder builder = new();
|
|
27
|
+
builder.AppendLine( $"namespace {namespaceName}" );
|
|
28
|
+
builder.AppendLine( "{" );
|
|
29
|
+
builder.Append( "\t" ).AppendLine( $"public sealed class {className}" );
|
|
30
|
+
builder.Append( "\t" ).AppendLine( "{" );
|
|
31
|
+
|
|
32
|
+
builder.Append( content );
|
|
33
|
+
|
|
34
|
+
builder.Append( "\t" ).AppendLine( "}" );
|
|
35
|
+
builder.AppendLine( "}" );
|
|
36
|
+
|
|
37
|
+
return builder.ToString();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
#endif
|