Example #1
0
 /// <summary>
 /// Add a component to this GameObject instance, but only if in debug mode.
 /// If not in debug mode, will do nothing.
 /// </summary>
 /// <param name="component">Component to add.</param>
 public Components.BaseComponent AddComponentDebug(Components.BaseComponent component)
 {
     if (GeonBitMain.Instance.DebugMode)
     {
         AddComponent(component);
         component.AsDebug = true;
     }
     return(component);
 }
Example #2
0
        /// <summary>
        /// Remove a component from this GameObject instance.
        /// </summary>
        /// <param name="component"></param>
        public void RemoveComponent(Components.BaseComponent component)
        {
            // detach component
            component.SetParent(null);

            // check if need to clear an alias
            if (PhysicalBody == component)
            {
                PhysicalBody = null;
            }

            // need components array update
            _needComponentsArrayUpdate = true;

            // remove from list of components
            _components.Remove(component);
        }
Example #3
0
        /// <summary>
        /// Add a component to this GameObject instance.
        /// </summary>
        /// <param name="component">Component to add.</param>
        /// <param name="name">If provided, will also set the component name while adding it.</param>
        /// <returns>The newly added component.</returns>
        public Components.BaseComponent AddComponent(Components.BaseComponent component, string name = null)
        {
            // sanity check - make sure component don't have a parent
            if (component._GameObject != null)
            {
                throw new Exceptions.InvalidActionException("Cannot add the component to multiple game objects!");
            }

            // set component parent
            component.SetParent(this);

            // set as not debug mode by default
            component.AsDebug = false;

            // set physical body alias
            if (PhysicalBody == null && component.GetType() == typeof(Components.Physics.BasePhysicsComponent))
            {
                PhysicalBody = component as Components.Physics.BasePhysicsComponent;
            }

            // add to list of components
            _components.Add(component);

            // set name
            if (name != null)
            {
                component.Name = name;
            }

            // if we were already spawned, invoke component spawn immediately
            if (_wasSpawned)
            {
                component.Spawn();
            }

            // need components array update
            _needComponentsArrayUpdate = true;

            // return component
            return(component);
        }