Beispiel #1
0
        /// <summary>
        /// Create the game object from scene node and name.
        /// Used internally for cloning.
        /// </summary>
        /// <param name="name">GameObject name.</param>
        /// <param name="node">Scene node (will be cloned).</param>
        /// <param name="cloneNode">If true, will clone the scene node. If false, will take it as-is</param>
        internal GameObject(string name, Core.Graphics.Node node, bool cloneNode = true)
        {
            // clone scene node and set name
            _sceneNode = cloneNode ? node.Clone() : node;
            Name       = name;

            // increase instances counter
            Count++;
        }
Beispiel #2
0
        /// <summary>
        /// Create the game object from scene node and name.
        /// Used internally for cloning.
        /// </summary>
        /// <param name="name">GameObject name.</param>
        /// <param name="node">Scene node (will be cloned).</param>
        /// <param name="cloneNode">If true, will clone the scene node. If false, will take it as-is</param>
        internal GameObject(string name, Core.Graphics.Node node, bool cloneNode = true)
        {
            // clone scene node and set name
            _sceneNode = cloneNode ? node.Clone() : node;
            Name       = name;

            // count the event
            Core.Utils.CountAndAlert.Count(Core.Utils.CountAndAlert.PredefAlertTypes.AddedOrCreated);

            // increase instances counter
            Count++;
        }
Beispiel #3
0
        /// <summary>
        /// Destroy this Game Object.
        /// </summary>
        public void Destroy()
        {
            // already destroyed? do nothing
            if (_destroyed)
            {
                return;
            }

            // make disabled
            _enabled = false;

            // prepare children and component arrays
            PrepareChildrenAndComponentsArray();

            // destroy all components
            // note: we set parents to null because we want to first trigger parent event and then destroy.
            foreach (var component in _componentsArray)
            {
                component.SetParent(null);
                component.Destroy();
            }
            _componentsArray = null;

            // destroy all children (set the parent to null first to avoid cycle)
            foreach (var child in _childrenArray)
            {
                child._parent = null;
                child.Destroy();
            }
            _childrenArray = null;

            // clear internal and user data
            _internalData = null;
            UserData      = null;

            // remove from parent
            Parent = null;

            // destroy scene node
            if (_sceneNode.Parent != null)
            {
                _sceneNode.RemoveFromParent();
            }
            _sceneNode = null;

            // mark this object as destroyed
            _destroyed = true;
        }
Beispiel #4
0
        /// <summary>
        /// Create the game object.
        /// </summary>
        /// <param name="name">Object name.</param>
        /// <param name="nodeType">Optional scene node type (uses DefaultSceneNodeType if not provided).</param>
        public GameObject(string name = "", SceneNodeType?nodeType = null)
        {
            // set default scene node type
            nodeType = nodeType ?? DefaultSceneNodeType;

            // create the scene node
            switch (nodeType.Value)
            {
            // a simple scene node without culling
            case SceneNodeType.Simple:
                _sceneNode = new Core.Graphics.Node();
                break;

            // scene node with bounding-box culling
            case SceneNodeType.BoundingBoxCulling:
                _sceneNode = new Core.Graphics.BoundingBoxCullingNode();
                break;

            // scene node with bounding-sphere culling
            case SceneNodeType.BoundingSphereCulling:
                _sceneNode = new Core.Graphics.BoundingSphereCullingNode();
                break;

            // scene node optimized for particles
            case SceneNodeType.ParticlesNode:
                _sceneNode = new Core.Graphics.ParticleNode();
                break;

            // scene node with octree-based culling
            case SceneNodeType.OctreeCulling:
                _sceneNode = new Core.Graphics.OctreeCullingNode(OctreeSceneBoundaries, OctreeMaxDivisions);
                break;

            // unknown type
            default:
                throw new Exceptions.UnsupportedTypeException("Unknown or unsupported scene node type!");
            }

            // increase instances counter
            Count++;

            // count the event
            Core.Utils.CountAndAlert.Count(Core.Utils.CountAndAlert.PredefAlertTypes.AddedOrCreated);

            // set name (must come after creating scene node because it also set the node identifier)
            Name = name;
        }