summaryrefslogtreecommitdiff
path: root/Source/Asura.Framework/scripts/gameobject.lua
blob: cd984ee679db6ebd39068017ce7257d58b3bb4e0 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--
-- 实体,作为scene中的实体存在。Scene中唯一管理的就是实体entity,游戏里的所有component都依附于entity存在,包括camera组件。
--
require "transform"

AsuraEngine.GameObject = AsuraEngine.Asset.Sub("GameObject")

local GameObject = AsuraEngine.GameObject

function GameObject:Ctor() 
  self.transform = AsuraEngine.Transform.New()
  self.subentities = {} -- Sub node entities
end

function GameObject:AddChild(gameobject) 
  table.insert(self.child, gameobject)
end

function GameObject:AddComponent(type, name)
  local cname = type 
  if name == nil then 
    cname = name 
  end 
  local component = AsuraEngine.Component.GetComponent(type)
  self.components[cname] = compoennt
end

-- 根据组件名拿到组件
function GameObject:GetComponent(name)
  return self.components[name]
end

-- 根据组件类型拿到组件
function GameObject:GetComponentByType(tname)

end

function GameObject:OnEnable()
  
end

function GameObject:OnEvent(e)
  if self.components == nil or type(self.components) ~= "table" then 
    AsuraEditor.LogError("")
    return 
  end 
  for name, component in self.components do 
    if component.OnEvent ~= nil then 
      component:OnEvent(e)
    end  
  end 
end

function GameObject:OnUpdate(dt)
  for name, component in self.components do 
    if component.OnUpdate ~= nil then 
      component:OnUpdate(dt)
    end
  end
end

function GameObject:OnRender()
  for name, component in self.components do 
    if component.OnRender ~= nil then 
      component.OnRender()
    end
  end
end

function GameObject:OnDisable()
  for name, component in self.components do 
    if component.OnDisable ~= nil then 
      component.OnDisable()
    end
  end
end

function GameObject:GetTrasform()
  return self.transform
end

function GameObject:GetPosition()

end

function GameObject:GetScale()

end

function GameObject:GetRotation()

end

function GameObject:SetTrasform(transform)

end

function GameObject:SetPosition()

end

function GameObject:SetScale()

end

function GameObject:SetRotation()

end

--写asset
function GameObject:ToAsset()

end

return GameObject