Class: Cukunity::Unity::GameObject
- Inherits:
-
JSONContainer
- Object
- JSONContainer
- Cukunity::Unity::GameObject
- Defined in:
- lib/cukunity/unity/gameobject.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#scene ⇒ Object
readonly
Returns the value of attribute scene.
Attributes inherited from JSONContainer
Instance Method Summary collapse
- #children ⇒ Object
- #component(*args) ⇒ Object
- #components(options = {}) ⇒ Object
- #has_component?(*args) ⇒ Boolean
- #hints(options = {}) ⇒ Object
-
#initialize(json, scene, parent = nil) ⇒ GameObject
constructor
A new instance of GameObject.
Methods inherited from JSONContainer
#has_key?, #keys, #method_missing, #to_s, #value_of
Methods included from Cukunity::Utils
#check_timeout, #merge_options, #restrict_options, #to_options, #wait_connectivity
Constructor Details
#initialize(json, scene, parent = nil) ⇒ GameObject
Returns a new instance of GameObject.
7 8 9 10 11 |
# File 'lib/cukunity/unity/gameobject.rb', line 7 def initialize(json, scene, parent = nil) super(json) @scene = scene @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cukunity::Unity::JSONContainer
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/cukunity/unity/gameobject.rb', line 5 def parent @parent end |
#scene ⇒ Object (readonly)
Returns the value of attribute scene.
4 5 6 |
# File 'lib/cukunity/unity/gameobject.rb', line 4 def scene @scene end |
Instance Method Details
#children ⇒ Object
13 14 15 16 17 |
# File 'lib/cukunity/unity/gameobject.rb', line 13 def children @children ||= (value_of('children') || []).map do |json| Unity::GameObject.new(json, @scene, self) end end |
#component(*args) ⇒ Object
19 20 21 |
# File 'lib/cukunity/unity/gameobject.rb', line 19 def component(*args) components(*args).first end |
#components(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cukunity/unity/gameobject.rb', line 27 def components( = {}) # memoize all components if @components.nil? @components = (value_of('components') || []).map do |json| Unity::Component.new(json, self) end @components += children.inject([]) do |components, child| components + child.components(:recursive => true) end end = (, { :recursive => false }) # select desired components @components.select do |component| acceptable_type = ([:type].nil? or [:type] == component.type) acceptable_type and ([:recursive] or component.gameobject == self) end end |
#has_component?(*args) ⇒ Boolean
23 24 25 |
# File 'lib/cukunity/unity/gameobject.rb', line 23 def has_component?(*args) !!component(*args) end |
#hints(options = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cukunity/unity/gameobject.rb', line 45 def hints( = {}) = (, { :recursive => false }) components((, :recursive)).inject([]) do |hints, component| hints + component.hints() end end |