arcadia.core

log

Syntax

  • (log & args)

Description

Log message to the [Unity console](https://docs.unity3d.com/Manual/Console.html). Arguments are combined into a string.

Arguments

  • args

Examples

;; strings work
(log "Hello, Arcadia!")
;; strings work
(log "Hello, Arcadia!")
;; arguments are combined as in str
(let [n (rand)]
  (log "Want a number? " n ". Done!"))
;; arguments are combined as in str
(let [n (rand)]
  (log "Want a number? " n ". Done!"))
;; log can also be used as quick debug hook
(hook+ (object-named "Main Camera") :update log)

null-obj?

Syntax

  • (null-obj? x)

Description

Is `x` nil? This test is complicated by the fact that Unity uses a custom null object that evaluates to `true` in normal circumstances. `null-obj?` will return `true` if `x` is nil *or* Unity's null object.

Arguments

Examples

;; Unity interop calls will return Unity's null object
;; The Main Camera has no Rigidbody by default
(let [rb (.GetComponent
           (object-named "Main Camera")
           UnityEngine.Rigidbody)]
  rb              ;; => #unity/Object 0
  (boolean rb)    ;; => true
  (null-obj? rb)) ;; => true
;; arcadia functions use null-obj? internally to present
;; a more consistent view of the Unity scene graph
(cmpt (object-named "Main Camera") UnityEngine.Rigidbody) ;; => nil

obj-nil

Syntax

  • (obj-nil x)

Description

Inlined version of null-obj? Could be merged in the future.

Arguments

  • x

instantiate

Syntax

  • (instantiate original)
  • (instantiate original position)
  • (instantiate original position rotation)

Description

Clones the original object and returns the clone. The clone can optionally be given a new position or rotation as well. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/Instantiate.

Arguments

Examples

;; create a new camera identical to the default camera   
(let [new-camera (instantiate (object-named "Main Camera"))]
  new-camera          ;; => #unity/Object -6904
  (.name new-camera)) ;; "Main Camera(Clone)"
;; create a new camera at a new position
(instantiate (object-named "Main Camera")
             (v3 100 20 10))
;; create a new camera at a new position
;; looking at the origin
(instantiate (object-named "Main Camera")
             (v3 100 20 10)
             (qlookat (v3 100 20 10)
                      (v3 0)))

create-primitive

Syntax

  • (create-primitive prim)

Description

Creates a game object with a primitive mesh renderer and appropriate collider. `prim` can be a [PrimitiveType](http://docs.unity3d.com/ScriptReference/PrimitiveType.html "PrimitiveType") or one of :sphere :capsule :cylinder :cube :plane :quad. Wraps [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/CreatePrimitive.

Arguments

  • prim

Examples

;; create the default Unity cube
(create-primitive :cube)

destroy

Syntax

  • (destroy obj)
  • (destroy obj t)

Description

Removes a gameobject, component or asset. When called with `t`, the removal happens after `t` seconds. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/Destroy. The difference between destroy and destroy-immediate is still being worked out.

Arguments

Examples

;; remove the default camera
(destroy (object-named "Main Camera"))
;; remove every object with player in its name
(doseq [o (objects-named #".*player.*")]
  (destroy o))
;; remember that map is lazy, so the following will
;; not work as expected
(map destroy (objects-named #".*player.*"))
;; instead, force evaluation with dorun or do all
(dorun (map destroy (objects-named #".*player.*")))
;; mapv returns a vector, and also forces evaluation
(mapv destroy (objects-named #".*player.*"))

destroy-immediate

Syntax

  • (destroy-immediate obj)

Description

Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/DestroyImmediate. The difference between destroy and destroy-immediate is still being worked out.

Arguments


object-typed

Syntax

  • (object-typed t)

Description

Returns one object of Type `type`. The object selected seems to be the first object in the array returned by objects-typed. Wraps UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/FindObjectOfType.

Arguments

  • tType

Examples

;; any type that can be in the Unity scene graph works
(object-typed UnityEngine.GameObject)

objects-typed

Syntax

  • (objects-typed t)

Description

Returns an array of all active loaded objects of Type `type`. The order is consistent but undefined. UnityEngine.[Object](http://docs.unity3d.com/ScriptReference/Object.html "Object")/FindObjectsOfType.

Arguments

  • tType

Examples

;; components are returned directly
(objects-typed UnityEngine.Camera)
;; superclasses work too
(count (objects-typed UnityEngine.Camera))    ;; => 1
(count (objects-typed UnityEngine.Component)) ;; => 8
(count (objects-typed UnityEngine.Object))    ;; => 20

object-named

Syntax

  • (object-named name)

Description

Returns one [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") named `name`. Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/Find.

Arguments

Examples

;; get the default camera object
(object-named "Main Camera")

objects-named

Syntax

  • (objects-named name)

Description

Returns a sequence of all GameObjects named `name`.

Arguments

  • name

Examples

;; cube primitives are named Cube by default
(dotimes [_ 20]
  (create-primitive :cube))
(count (objects-named "Cube")) ;; # => 20
;; regular expressions work as well
(dotimes [_ 20]
  (let [cube (create-primitive :cube)]
    (set! (.name cube) (str (gensym "cube")))))
(count (objects-named #"cube.*")) ;; # => 20

object-tagged

Syntax

  • (object-tagged t)

Description

Returns one active [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") tagged `tag`. Tags are managed from the [Unity Tag Manager](https://docs.unity3d.com/Manual/class-TagManager.html). Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/FindWithTag.

Arguments


objects-tagged

Syntax

  • (objects-tagged t)

Description

Returns an array of active GameObjects tagged tag. Returns empty array if no [GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject") was found. Tags are managed from the [Unity Tag Manager](https://docs.unity3d.com/Manual/class-TagManager.html). Wraps UnityEngine.[GameObject](http://docs.unity3d.com/ScriptReference/GameObject.html "GameObject")/FindGameObjectsWithTag.

Arguments


IEntityComponent

Description

Common protocol for everything in Unity that supports attached components.

Functions

Implementations


cmpts

Syntax

  • (cmpts this t)

Description

Returns a vector of all components typed `t` attached to the object

Arguments

  • this
  • t

cmpt+

Syntax

  • (cmpt+ this t)

Description

Adds a component of type `t` to the object and returns the new instance

Arguments

  • this
  • t

cmpt-

Syntax

  • (cmpt- this t)

Description

Removes all components of type `t` from the object and returns the object

Arguments

  • this
  • t

cmpt

Syntax

  • (cmpt this t)

Description

Returns the first component typed `t` attached to the object

Arguments

  • this
  • t

ensure-cmpt

Syntax

  • (ensure-cmpt obj t)

Description

If `obj` has a component of type `t`, returns is. Otherwise, adds a component of type `t` and returns the new instance.

Arguments

  • obj
  • tType

ISceneGraph

Description

Common protocol for everything in Unity that is part of the scene graph hierarchy.


child-

Syntax

  • (child- this child)

Description

Move `child` from under `this` object ti the top of the hierarchy

Protocol

Arguments

  • this
  • child

parent

Syntax

  • (parent this)

Description

Returns the object that contains `this` object, or `nil` if it is at the top of the hierarchy.

Protocol

Arguments

  • this

child+

Syntax

  • (child+ this child)
  • (child+ this child transform-to)

Description

Moves `child` to under `this` object in the hierarchy, optionally recalculating its local transform.

Protocol

Arguments

  • this
  • child
  • transform-to

children

Syntax

  • (children this)

Description

Returns all objects under `this` object in the hierarchy.

Protocol

Arguments

  • this

gobj

Syntax

  • (gobj this)

Description

Protocol

Arguments

  • this

with-gobj

Syntax

  • (with-gobj [gob-name x] & body)

Arguments

  • gob-name
  • x
  • body

with-cmpt

Syntax

  • (with-cmpt gob cmpt-name-types & body)

Arguments

  • gob
  • cmpt-name-types
  • body

if-cmpt

Syntax

  • (if-cmpt gob [cmpt-name cmpt-type] then)
  • (if-cmpt gob [cmpt-name cmpt-type] then else)

Description

Execute body of code if `gob` has a component of type `cmpt-type`

Arguments

  • gob
  • cmpt-name
  • cmpt-type
  • then
  • else

gobj-seq

Syntax

  • (gobj-seq x)

Arguments

  • x

hook-types

Description

Map of keywords to hook component types


hook+

Syntax

  • (hook+ obj hook f)
  • (hook+ obj hook k f)

Description

Attach hook a Clojure function to a Unity message on `obj`. The funciton `f` will be invoked every time the message identified by `hook` is sent by Unity. `f` must have the same arity as the expected Unity message.

Arguments

  • obj
  • hook
  • f
  • k

hook-

Syntax

  • (hook- obj hook k)

Description

Remove all `hook` components attached to `obj`

Arguments

  • obj
  • hook
  • k

hook

Syntax

  • (hook obj hook)

Description

Return the `hook` component attached to `obj`. If there is more one component, then behavior is the same as `cmpt`.

Arguments

  • obj
  • hook

hooks

Syntax

  • (hooks obj hook)

Arguments

  • obj
  • hook

hook?

Syntax

  • (hook? t)
  • (hook? t hook)

Arguments

  • t
  • hook

state

Syntax

  • (state go)
  • (state go kw)

Description

Returns the state of object `go`.

Arguments

  • go
  • kw

set-state!

Syntax

  • (set-state! go kw v)

Description

Updates the state of object `go` with funciton `f`.

Arguments

  • go
  • kw
  • v

remove-state!

Syntax

  • (remove-state! go kw)

Description

Updates the state of object `go` with funciton `f`.

Arguments

  • go
  • kw

update-state!

Syntax

  • (update-state! go kw f & args)

Description

Updates the state of object `go` with funciton `f`.

Arguments

  • go
  • kw
  • f
  • args