-
Notifications
You must be signed in to change notification settings - Fork 0
/
componentContainer.go
53 lines (43 loc) · 1.1 KB
/
componentContainer.go
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
package engine
// ComponentContainer is a wrap around container interface, that can be enabled or disabled
type ComponentContainer struct {
enabled bool
sceneObject *SceneObject
component Component
initialized bool
started bool
willBeRemoved bool
}
func (c *ComponentContainer) SetEnabled(enabled bool) {
if c.willBeRemoved || c.enabled == enabled {
return
}
c.enabled = enabled
if c.sceneObject.inCurrentScene {
instance.RequestRendering()
}
}
func (c *ComponentContainer) IsEnabled() bool {
return c.enabled
}
func (c *ComponentContainer) GetComponent() Component {
return c.component
}
func (c *ComponentContainer) IsDirty() bool {
return !c.initialized || !c.enabled || c.willBeRemoved
}
func (c *ComponentContainer) stop() {
if !c.enabled || !c.started {
return
}
instance.currentComponent = c.component
c.component.OnStop()
instance.currentComponent = nil
}
func NewComponentContainer(sceneObject *SceneObject, component Component) *ComponentContainer {
return &ComponentContainer{
enabled: true,
component: component,
sceneObject: sceneObject,
}
}