summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-framework/scripts/entity.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-04-02 08:47:15 +0800
committerchai <chaifix@163.com>2019-04-02 08:47:15 +0800
commit250e30d73f09e9da2b5a81d0fbae63744ae12a73 (patch)
tree0f55daf334c073e1779d7a1284799a2056aad714 /source/libs/asura-lib-framework/scripts/entity.lua
parent66fe16dd5ed57ae958fc25158d0defae2e6fae6a (diff)
*misc
Diffstat (limited to 'source/libs/asura-lib-framework/scripts/entity.lua')
-rw-r--r--source/libs/asura-lib-framework/scripts/entity.lua114
1 files changed, 114 insertions, 0 deletions
diff --git a/source/libs/asura-lib-framework/scripts/entity.lua b/source/libs/asura-lib-framework/scripts/entity.lua
new file mode 100644
index 0000000..ea8e14d
--- /dev/null
+++ b/source/libs/asura-lib-framework/scripts/entity.lua
@@ -0,0 +1,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 \ No newline at end of file