summaryrefslogtreecommitdiff
path: root/Source/modules/asura-framework/scripts/entity.lua
blob: ea8e14df839ecc62e47acc8822cc2a3cae8bc1d9 (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
--
-- 实体,作为scene中的实体存在。Scene中唯一管理的就是实体entity,游戏里的所有component都依附于entity存在,包括camera组件。
--
module "AsuraEngine" 
require "transform"

AsuraEngine.Entity = AsuraEngine.Asset.Extend("Entity")

local Entity = AsuraEngine.Entity

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

function Entity:AddChild(entity) 
	table.insert(self.child, entity)
end

function Entity: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 Entity:GetComponent(name)
	return self.components[name]
end

function Entity:GetComponentByType(type)

end

function Entity:OnEnable()
	
end

function Entity: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 Entity:OnUpdate(dt)
	for name, component in self.components do 
		if component.OnUpdate ~= nil then 
			component:OnUpdate(dt)
		end
	end
end

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

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

function Entity:GetTrasform()
	return self.transform
end

function Entity:GetPosition()

end

function Entity:GetScale()

end

function Entity:GetRotation()

end

function Entity:SetTrasform(transform)

end

function Entity:SetPosition()

end

function Entity:SetScale()

end

function Entity:SetRotation()

end

--写asset
function Entity:ToAsset()

end

return Entity