Created
December 7, 2015 20:25
-
-
Save selfsame/0e031ffeb5e4a4fc5986 to your computer and use it in GitHub Desktop.
ArcadiaComponents.cs
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 clojure.lang; | |
| public class ArcadiaBehaviour : MonoBehaviour, ISerializationCallbackReceiver | |
| { | |
| private IFn _fn; | |
| public IFn fn | |
| { | |
| get { return _fn; } | |
| set | |
| { | |
| _fn = value; | |
| serializedVar = null; | |
| OnBeforeSerialize(); | |
| } | |
| } | |
| [SerializeField] | |
| public string serializedVar; | |
| // if fn is a var, store in serializedVar | |
| public void OnBeforeSerialize() | |
| { | |
| Var v = fn as Var; | |
| if(v != null) | |
| { | |
| serializedVar = v.Namespace.Name + "/" + v.Symbol.Name; | |
| } | |
| } | |
| // if serializedVar not null, set fn to var | |
| public void OnAfterDeserialize() | |
| { | |
| if(serializedVar != "") | |
| { | |
| Symbol sym = Symbol.intern(serializedVar); | |
| try { | |
| RT.var("clojure.core", "require").invoke(Symbol.intern(sym.Namespace)); | |
| fn = RT.var(sym.Namespace, sym.Name); | |
| } | |
| catch { | |
| try { | |
| string libName = sym.Namespace.Replace(".", "/").Replace("-", "_"); | |
| Debug.Log("Loading " + libName); | |
| RT.load(libName); | |
| fn = Var.intern(Symbol.intern(sym.Namespace), Symbol.intern(sym.Name)); | |
| } | |
| catch { | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment