Created
June 28, 2020 09:41
-
-
Save frostyandy2k/4e56798aa843dfb334db0ad9019d936e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ScriptableObjectLoader : EditorWindow | |
{ | |
private static readonly int TYPE = 0; | |
private static readonly int NAME = 1; | |
private static readonly int IMAGE_PATH = 2; | |
[MenuItem("Tools/Load Scriptable Object Data")] | |
public static LoadScriptableObjectsFromFile() | |
{ | |
string path = "Assets/Cores/SomeCoolValuesForOurSO.csv"; | |
using (var reader = new StreamReader(path)) | |
{ | |
// first line is the table header, we can skip or do something with it | |
reader.ReadLine(); | |
while (!reader.EndOfStream) | |
{ | |
var line = reader.ReadLine(); | |
var values = line.Split(','); | |
//Create new instance of the specific type read from file | |
// Note: you can also use the type system CreateInstance<MySOType>() | |
var newScriptableObject = (MySOType)ScriptableObject.CreateInstance(values[TYPE]); | |
newScriptableObject.name = values[NAME]; | |
// Create the asset on the file system | |
AssetDatabase.CreateAsset(newScriptableObject, "Assets/MyDynamicallyCreatedSOFolder/" + values[NAME] + ".asset"); | |
newScriptableObject.sprite = AssetDatabase.LoadAssetAtPath<Sprite>(values[IMAGE_PATH]); | |
// optional | |
// AssetDatabase.SaveAssets(); | |
// AssetDatabase.Refresh(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment