Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Last active August 29, 2015 14:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsgardner/ea64001779a2221f26cf to your computer and use it in GitHub Desktop.
Save timsgardner/ea64001779a2221f26cf to your computer and use it in GitHub Desktop.
set-with!
;; funny little macro to make interop bit less painful
(set! *warn-on-reflection* true)
(defmacro set-with! [obj [sym prop] & body]
`(let [obj# ~obj
~sym (. obj# ~prop)]
(set! (. obj# ~prop) (do ~@body))))
;; use: ----------------------------------------
(use 'arcadia.core)
(import '[UnityEngine Transform GameObject Vector3])
(defn v+ ^Vector3 [^Vector3 v1 ^Vector3 v2]
(Vector3/op_Addition v1 v2))
(defn travel [^GameObject obj]
(doto (get-component obj Transform)
(set-with! [pos localPosition]
(v+ pos (Vector3. 1 2 3)))))
(defn travel-weirdly [^GameObject obj]
(let [^Transform trns (get-component obj Transform)]
(set-with! trns [pos localPosition]
(set-with! trns [eua localEulerAngles]
(v+ eua pos))
(v+ pos (Vector3. 1 2 3)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment