Last active
January 31, 2019 08:38
-
-
Save quizcanners/5c9d2ababdcc61006d38f1fa0a22c8f6 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
// An example snippet for: https://www.quizcanners.com/single-post/2018/04/20/Story-Trigger-Data-Interface-iSTD | |
public stdEncoder Encode() => new stdEncoder() | |
.Add("mrkP", mapMarkerPosition); | |
.Add("mrkC", mapMarkerColor); | |
public bool Decode (string tag, string data){ | |
switch (tag){ | |
case "mrkP": mapMarkerPosition = data.ToVactor2(); break; | |
case "mrkC": mapMarkerColor = data.ToColor(); break; | |
default: return false; | |
} | |
return true; | |
} | |
// In case class structure changed, but you want to preserve backwards compatibility: | |
// In Encode() fucntion: | |
if (mapMarker.enabled){ | |
cody.Add("mrkP", mapMarker.position); | |
cody.Add("mrkC", mapMarker.color); | |
} | |
// In Decode Function | |
case "mrkP": | |
mapMarker.enabled = true; | |
mapMarker.position = data.ToVector2(); | |
case "mrkC": | |
mapMarker.color = data.ToColor(); | |
UpdateMarkers(); | |
break; | |
// But if BackwardsCompatibility is not needed you should add Encode()/Decode() functions and iSTD interface to MapMarker class | |
// and replace the functions above with something like: | |
public stdEncoder Encode() => new stdEncoder() | |
.Add("mrk", mapMarker); // This will call Encode() in the mapMarker, and will get position and color; | |
public bool Decode (string tag, string data){ | |
switch (tag){ | |
case "mrk": mapMarker.Decode(data); break; | |
default: return false; | |
} | |
return true; | |
} | |
// This way you can manually save any data for any class, without creating any additional Serializable classes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment