Created
May 23, 2018 16:05
-
-
Save paulhayes/f16339ea51df4e0c90919def4bc44a67 to your computer and use it in GitHub Desktop.
Simple abstract ScriptableObject Class to break settings assets into json file
This file contains hidden or 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
using System.IO; | |
using UnityEngine; | |
public abstract class ExternalScriptableObject : ScriptableObject | |
{ | |
void OnEnable() | |
{ | |
string filePath = Path.Combine(Application.dataPath, GetFileName()); | |
if( File.Exists(filePath) ){ | |
JsonUtility.FromJsonOverwrite( File.ReadAllText(filePath), this ); | |
} | |
} | |
public string GetFileName(){ | |
return name+".json"; | |
} | |
} |
This file contains hidden or 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
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Build; | |
using System.IO; | |
public class ExternalScriptableObjectPostprocessBuild : IPostprocessBuild | |
{ | |
public int callbackOrder { get { return 0; } } | |
public void OnPostprocessBuild(BuildTarget target, string path) | |
{ | |
var settingsObjects = Resources.FindObjectsOfTypeAll<ExternalScriptableObject>(); | |
foreach(var settings in settingsObjects){ | |
string dataDir = Path.Combine( Directory.GetParent(path).FullName,Path.GetFileNameWithoutExtension(path)+"_Data"); | |
Debug.LogFormat("{0} {1}",dataDir,Directory.Exists(dataDir)?"exists":"doesn't exist"); | |
string filePath = Path.Combine(dataDir,settings.GetFileName()); | |
File.WriteAllText( filePath, JsonUtility.ToJson( settings, true ) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment