Skip to content

Instantly share code, notes, and snippets.

@ITEnot
Created December 12, 2021 15:39
Show Gist options
  • Save ITEnot/d851e4a3e38a08f7ddb85e46042ea764 to your computer and use it in GitHub Desktop.
Save ITEnot/d851e4a3e38a08f7ddb85e46042ea764 to your computer and use it in GitHub Desktop.
class A{
enum ObjectMeshType{SQUARE, SPHERE}
public ObjectMeshType CurrentType;
public MeshFilter MeshFilter;
void Save(){
ASaveLoadStruct structToSave = new ASaveLoadStruct();
structToSave.Type = CurrentType;
string FormattedJson = JsonUtility.ToJson(structToSave);
File.WriteAllText(path, FormattedJson);
}
void Load(){
string SavedJson = File.ReadAllText(path);
ASaveLoadStruct structFromSave = JsonUtility.FromJson<SavedJson>();
this.CurrentType = structFromSave.Type;
InitializeAfterLoad();
}
void InitializeAfterLoad(){
if(CurrentType == ObjectMeshType.SQUARE){
MeshFilter.mesh = SquareMesh;
}
if(CurrentType == ObjectMeshType.SPHERE){
MeshFilter.mesh = SphereMesh;
}
}
[Serializable]
public struct ASaveLoadStruct{
public enum Type;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment