Created
December 12, 2021 15:39
-
-
Save ITEnot/d851e4a3e38a08f7ddb85e46042ea764 to your computer and use it in GitHub Desktop.
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
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