-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
44 lines (37 loc) · 1.19 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns source2016.core
(:use arcadia.core
arcadia.linear)
(:import [UnityEngine Rigidbody Vector3 GameObject Component]
ArcadiaState))
;; physics
(defn force! [pos f]
(doseq [^Rigidbody rb (objects-typed Rigidbody)]
(let [distance (Vector3/Distance (.. rb position)
pos)
amp (if (> distance 5)
0
(/ 1.0 distance))]
(.AddForceAtPosition rb
(v3* f amp)
pos
ForceMode/Impulse))))
(defn position [v]
(let [t (type v)]
(cond
(= t Vector3) v
(= t GameObject) (.. v transform position)
(isa? t Component) (.. v gameObject transform position))))
;; prototype components api
(defn ensure-component [go c]
(or (.GetComponent go c)
(.AddComponent go c)))
(defn state! [go s]
(let [^ArcadiaState c (ensure-component go ArcadiaState)]
(set! (.state c) s)))
(defn state [go]
(let [^ArcadiaState c (ensure-component go ArcadiaState)]
(.state c)))
(defn swap-state! [go f & args]
(state! go (apply f (state go) args)))
(defn hook! [go h f]
(set! (.fn (ensure-component go h)) f))