From 03b3b8ae80559745f98ef94569b421adddeb441f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Mar 2019 23:46:59 +0800 Subject: *misc --- .../libs/asura-lib-framework/scripts/component.lua | 6 +- source/libs/asura-lib-framework/scripts/entity.lua | 114 ++++++++++++++++++++ .../scripts/filesystem/entity_loader.lua | 2 +- .../asura-lib-framework/scripts/gameobject.lua | 115 --------------------- .../scripts/graphics/animator.lua | 6 +- .../scripts/graphics/particle_system.lua | 4 +- source/libs/asura-lib-framework/scripts/scene.lua | 2 +- 7 files changed, 124 insertions(+), 125 deletions(-) create mode 100644 source/libs/asura-lib-framework/scripts/entity.lua delete mode 100644 source/libs/asura-lib-framework/scripts/gameobject.lua (limited to 'source/libs/asura-lib-framework/scripts') diff --git a/source/libs/asura-lib-framework/scripts/component.lua b/source/libs/asura-lib-framework/scripts/component.lua index 9306f3b..b560bd3 100644 --- a/source/libs/asura-lib-framework/scripts/component.lua +++ b/source/libs/asura-lib-framework/scripts/component.lua @@ -3,7 +3,7 @@ AsuraEngine.Component = AsuraEngine.Class("Component") local Component = AsuraEngine.Component -- Component要显示在inspector的变量 -Component.gameobject = AsuraEngine.Type.GameObject +Component.entity = AsuraEngine.Type.Entity function Component.Extend(cname) self.base(cname) @@ -11,8 +11,8 @@ function Component.Extend(cname) end -function Component:Ctor(gameobject) - self.gameobject = gameobject +function Component:Ctor(entity) + self.entity = entity end function Component:OnEvent(e) 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 diff --git a/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua index 57a890f..39ae0d9 100644 --- a/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua +++ b/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua @@ -1,4 +1,4 @@ -local loader = AsuraEngine.Loader.New("gameobject") +local loader = AsuraEngine.Loader.New("entity") function loader.OnLoad(asset) diff --git a/source/libs/asura-lib-framework/scripts/gameobject.lua b/source/libs/asura-lib-framework/scripts/gameobject.lua deleted file mode 100644 index a2d20ef..0000000 --- a/source/libs/asura-lib-framework/scripts/gameobject.lua +++ /dev/null @@ -1,115 +0,0 @@ --- --- 实体,作为scene中的实体存在。Scene中唯一管理的就是实体entity,游戏里的所有component都依附于entity存在,包括camera组件。 --- -require "transform" - -AsuraEngine.GameObject = AsuraEngine.Asset.Extend("GameObject") - -local GameObject = AsuraEngine.GameObject - -function GameObject:Ctor() - self.transform = AsuraEngine.Transform.New() - self.subentities = {} -- Extend 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 \ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/animator.lua b/source/libs/asura-lib-framework/scripts/graphics/animator.lua index c019dfa..fd2f979 100644 --- a/source/libs/asura-lib-framework/scripts/graphics/animator.lua +++ b/source/libs/asura-lib-framework/scripts/graphics/animator.lua @@ -8,9 +8,9 @@ local Animator = AsuraEngine.Animator Animator.spriteRenderer = AsuraEngine.Type.SpriteRenderer Animator.animation = AsuraEngine.Type.Animation -function Animator:Ctor(gameobject, animation) - self.base(gameobject) - self.spriteRenderer = gameobject:GetSpriteRenderer() +function Animator:Ctor(entity, animation) + self.base(entity) + self.spriteRenderer = entity:GetSpriteRenderer() self.animation = animation end diff --git a/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua b/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua index 8de3258..065a845 100644 --- a/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua +++ b/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua @@ -4,8 +4,8 @@ AsuraEngine.ParticleSystem = AsuraEngine.Component.Extend("ParticleSystem") local ParticleSystem = AsuraEngine.ParticleSystem -function ParticleSystem.Ctor(self, gameobject, def) - self.base(gameobject) +function ParticleSystem.Ctor(self, entity, def) + self.base(entity) self.spriteRenderer = AsuraEngine.SpriteRenderer.New() end diff --git a/source/libs/asura-lib-framework/scripts/scene.lua b/source/libs/asura-lib-framework/scripts/scene.lua index 3036ce1..11ac86c 100644 --- a/source/libs/asura-lib-framework/scripts/scene.lua +++ b/source/libs/asura-lib-framework/scripts/scene.lua @@ -6,7 +6,7 @@ AsuraEngine.Scene = AsuraEngine.Asset.Extend("Scene") local Scene = AsuraEngine.Scene function Scene.Ctor(self) - self.rootGameObjects = {} --当前场景的所有root gameobject + self.rootGameObjects = {} --当前场景的所有root entity self.super.Ctor(self) end -- cgit v1.1-26-g67d0