mirror of
https://github.com/smyalygames/monopoly.git
synced 2026-01-06 19:58:49 +01:00
Added multiplayer plugin
This commit is contained in:
54
Assets/Mirror/Editor/ScriptableObjectUtility.cs
Normal file
54
Assets/Mirror/Editor/ScriptableObjectUtility.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.EditorScripts
|
||||
{
|
||||
public static class ScriptableObjectUtility
|
||||
{
|
||||
/// <summary>
|
||||
// This makes it easy to create, name and place unique new ScriptableObject asset files.
|
||||
/// </summary>
|
||||
public static T CreateAsset<T>(string defaultName) where T : ScriptableObject
|
||||
{
|
||||
string path = SavePanel(defaultName);
|
||||
// user click cancel
|
||||
if (string.IsNullOrEmpty(path)) { return null; }
|
||||
|
||||
T asset = ScriptableObject.CreateInstance<T>();
|
||||
|
||||
SaveAsset(path, asset);
|
||||
|
||||
return asset;
|
||||
}
|
||||
|
||||
static string SavePanel(string name)
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel(
|
||||
"Save ScriptableObject",
|
||||
"Assets/Mirror/",
|
||||
name + ".asset",
|
||||
"asset");
|
||||
|
||||
// user click cancel, return early
|
||||
if (string.IsNullOrEmpty(path)) { return path; }
|
||||
|
||||
// Unity only wants path from Assets
|
||||
if (path.StartsWith(Application.dataPath))
|
||||
{
|
||||
path = "Assets" + path.Substring(Application.dataPath.Length);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static void SaveAsset(string path, ScriptableObject asset)
|
||||
{
|
||||
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path);
|
||||
|
||||
AssetDatabase.CreateAsset(asset, assetPathAndName);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user