Beispiel #1
0
        void Dispose(bool a_state)
        {
#if DEBUG_INFO
            Tools.VerifyObjectMemoryState(this, a_state);
#endif
            lock (GameObjects)
            {
                GameObjects.Remove(this);
            }

            lock (this)
            {
                m_update        = null;
                m_physicsUpdate = null;

                foreach (Component comp in m_components)
                {
                    lock (comp)
                    {
                        IDisposable disp = comp as IDisposable;

                        if (disp != null)
                        {
                            disp.Dispose();
                        }
                    }
                }

                m_components.Clear();

                m_transform = null;
            }
        }
Beispiel #2
0
        public void RemoveComponent <T> () where T : Component
        {
            lock (this)
            {
                for (int i = 0; i < m_components.Count; ++i)
                {
                    Component comp = m_components[i] as T;

                    if (comp != null)
                    {
                        lock (comp)
                        {
                            m_components.Remove(comp);

                            Behaviour behaviour = comp as Behaviour;
                            if (behaviour != null)
                            {
                                m_update        -= behaviour.Update;
                                m_physicsUpdate -= behaviour.PhysicsUpdate;
                                m_collision     -= behaviour.OnCollision;
                            }


                            IDisposable disposable = comp as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }

                        return;
                    }
                }
            }
        }
Beispiel #3
0
        internal void AddComponent(Component a_component)
        {
            lock (this)
            {
                if (a_component.GameObject != this)
                {
                    a_component.SetGameObject(this);
                }

                m_components.Add(a_component);

                if (a_component is Transform)
                {
                    m_transform = a_component as Transform;
                }
                else if (a_component is Behaviour)
                {
                    Behaviour behaviour = a_component as Behaviour;
                    if (behaviour.Start != null)
                    {
                        behaviour.Start.Invoke();
                    }

                    m_update        += behaviour.Update;
                    m_physicsUpdate += behaviour.PhysicsUpdate;
                    m_collision     += behaviour.OnCollision;
                }
            }
        }
Beispiel #4
0
        public void RemoveComponent <T> (T a_component) where T : Component
        {
            lock (this)
            {
                lock (a_component)
                {
                    m_components.Remove(a_component);

                    Behaviour behaviour = a_component as Behaviour;
                    if (behaviour != null)
                    {
                        m_update        -= behaviour.Update;
                        m_physicsUpdate -= behaviour.PhysicsUpdate;
                        m_collision     -= behaviour.OnCollision;
                    }
                }
            }
        }