Module: Cukunity::Unity::ScreenHintMethods

Included in:
Hint
Defined in:
lib/cukunity/unity/screen_hint_methods.rb

Instance Method Summary collapse

Instance Method Details

#intersects?(arg) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cukunity/unity/screen_hint_methods.rb', line 36

def intersects?(arg)
  _rect2 =
    if arg.kind_of? Hash
      merge_options(arg, { :x => 0, :y => 0, :width => 0, :height => 0 })
    else
      arg.rect
    end
  _rect = self.rect
  # completely to the left?
  return false if (_rect[:x] + _rect[:width]) <= _rect2[:x] 
  # completely to the right?
  return false if _rect[:x] >= (_rect2[:x] + _rect2[:width])
  # completely above?
  return false if (_rect[:y] + _rect[:height]) <= _rect2[:y] 
  # completely below?
  return false if _rect[:y] >= (_rect2[:y] + _rect2[:height])
  # prove by contradiction
  true
end

#on_screen?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/cukunity/unity/screen_hint_methods.rb', line 31

def on_screen?
  return false unless component.enabled? and gameobject.active?
  intersects?(gameobject.scene.client.screen.json)
end

#rectObject



26
27
28
29
# File 'lib/cukunity/unity/screen_hint_methods.rb', line 26

def rect
  { :x => value_of('x'), :y => value_of('y'),
    :width => value_of('width'), :height => value_of('height') }
end

#screen_pos(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cukunity/unity/screen_hint_methods.rb', line 4

def screen_pos(options = {})
  options = merge_options(options, { :horizontal => :center, :vertical => :center })
  pos = {}
  case options[:horizontal]
  when :left
    pos[:x] = value_of('x').to_i
  when :right
    pos[:x] = (value_of('x') + value_of('width')).to_i
  else
    pos[:x] = (value_of('x') + value_of('width') / 2).to_i
  end
  case options[:vertical]
  when :bottom
    pos[:y] = value_of('y').to_i
  when :top
    pos[:y] = (value_of('y') + value_of('height')).to_i
  else
    pos[:y] = (value_of('y') + value_of('height') / 2).to_i
  end
  pos
end

#tap(options = {}) ⇒ Object



56
57
58
# File 'lib/cukunity/unity/screen_hint_methods.rb', line 56

def tap(options = {})
  gameobject.scene.client.screen.tap screen_pos(options), options
end