Пример #1
0
 /// <summary>
 /// Add a child in this <see cref="GameElement"/>.
 /// </summary>
 /// <param name="child">The child.</param>
 public void AddChild(GameElement child)
 {
     if (!HasChild(child))
     {
         child._parent = this;
         _childs.Add(child);
     }
 }
Пример #2
0
        /// <summary>
        /// Create a new <see cref="GameElement"/> with a name.
        /// </summary>
        /// <param name="name">The name of the new element.</param>
        public GameElement(string name)
        {
            _attachedComponents = new List <IComponent>();
            _childs             = new GameElementCollection();
            _name           = name;
            _worldTransform = new Transform();
            LocalTransform  = new Transform();

            GameElement.Add(_name, this);
        }
Пример #3
0
        /// <summary>
        /// Checks if the given <paramref name="child"/> is a child of
        /// this <see cref="GameElement"/>.
        /// </summary>
        /// <param name="child">The child to find.</param>
        public bool HasChild(GameElement child)
        {
            foreach (GameElement c in _childs)
            {
                if (c == child)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Register a new <see cref="GameElement"/> with the given name.
        /// </summary>
        /// <param name="name">The name of the <see cref="GameElement"/> to add.</param>
        /// <param name="gameElement">The instance</param>
        public static void Add(string name, GameElement gameElement)
        {
            if (_namesCounter.ContainsKey(gameElement.Name))
            {
                _namesCounter[gameElement.Name]++;
            }
            else
            {
                _namesCounter[gameElement.Name] = 0;
            }

            if (!Is(name))
            {
                _gameElements.Add(name, gameElement);
            }
            else
            {
                _gameElements.Add(name + "___" + _namesCounter[gameElement.Name], gameElement);
            }
        }
Пример #5
0
        /// <summary>
        /// Returns the child with the given <paramref name="name"/>.
        /// </summary>
        /// <param name="name">The name of the child to find.</param>
        public GameElement FindChild(string name)
        {
            foreach (GameElement c in _childs)
            {
                if (c.Name == name)
                {
                    return(c);
                }
                else
                {
                    GameElement ret = c.FindChild(name);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }

            return(null);
        }