Class: Cukunity::Unity::Component

Inherits:
JSONContainer show all
Defined in:
lib/cukunity/unity/component.rb

Instance Attribute Summary collapse

Attributes inherited from JSONContainer

#json

Instance Method Summary collapse

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, gameobject) ⇒ Component

Returns a new instance of Component.



6
7
8
9
# File 'lib/cukunity/unity/component.rb', line 6

def initialize(json, gameobject)
  super(json)
  @gameobject = gameobject 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cukunity::Unity::JSONContainer

Instance Attribute Details

#gameobjectObject (readonly)

Returns the value of attribute gameobject.



4
5
6
# File 'lib/cukunity/unity/component.rb', line 4

def gameobject
  @gameobject
end

Instance Method Details

#has_hint?(*args) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/cukunity/unity/component.rb', line 15

def has_hint?(*args)
  !hint(*args).nil?
end

#hint(*args) ⇒ Object



11
12
13
# File 'lib/cukunity/unity/component.rb', line 11

def hint(*args)
  hints(*args).first
end

#hints(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cukunity/unity/component.rb', line 19

def hints(options = {})
  # memoize all hints
  if @hints.nil?
    @hints = (value_of('.hints') || []).inject([]) do |hints, json|
      type = json[0]
      values = json[1]
      hints + values.map do |json|
        Unity::Hint.new(json, type, self)
      end
    end
  end
  options = merge_options(options, { :type => nil })
  return @hints if options[:type].nil?
  # select desired hints
  @hints.select do |hint|
    options[:type].to_s == hint.type
  end
end