Esempio n. 1
0
        /// <summary>
        /// Spawns the specified actor.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <param name="parent">The parent.</param>
        public void Spawn(Actor actor, Actor parent)
        {
            if (actor == null)
            {
                throw new ArgumentNullException(nameof(actor));
            }

            // Link it
            actor.Parent = parent ?? throw new ArgumentNullException(nameof(parent));

            // Peek spawned node
            var actorNode = SceneGraphFactory.FindNode(actor.ID) as ActorNode ?? SceneGraphFactory.BuildActorNode(actor);

            if (actorNode == null)
            {
                throw new InvalidOperationException("Failed to create scene node for the spawned actor.");
            }

            var parentNode = SceneGraphFactory.FindNode(parent.ID) as ActorNode;

            actorNode.ParentNode = parentNode ?? throw new InvalidOperationException("Missing scene graph node for the spawned parent actor.");

            // Call post spawn action (can possibly setup custom default values)
            actorNode.PostSpawn();

            // Create undo action
            var action = new CustomDeleteActorsAction(new List <SceneGraphNode>(1)
            {
                actorNode
            }, true);

            Undo.AddAction(action);
        }
Esempio n. 2
0
        private void OnActorSpawned(Actor actor)
        {
            // Skip for not loaded scenes (spawning actors during scene loading in script Start function)
            var sceneNode = GetActorNode(actor.Scene);

            if (sceneNode == null)
            {
                return;
            }

            // Skip for missing parent
            var parent = actor.Parent;

            if (parent == null)
            {
                return;
            }

            var parentNode = GetActorNode(parent);

            if (parentNode == null)
            {
                // Missing parent node when adding child actor to not spawned or unlinked actor
                return;
            }

            var node = SceneGraphFactory.BuildActorNode(actor);

            if (node != null)
            {
                node.TreeNode.UnlockChildrenRecursive();
                node.ParentNode = parentNode;
            }
        }
Esempio n. 3
0
        private void OnActorParentChanged(Actor actor, Actor prevParent)
        {
            ActorNode node       = null;
            var       parentNode = GetActorNode(actor.Parent);

            // Try use previous parent actor to find actor node
            var prevParentNode = GetActorNode(prevParent);

            if (prevParentNode != null)
            {
                // If should be one of the children
                node = prevParentNode.FindChildActor(actor);

                // Search whole tree if node was not found
                if (node == null)
                {
                    node = GetActorNode(actor);
                }
            }
            else if (parentNode != null)
            {
                // Create new node for that actor (user may unlink it from the scene before and now link it)
                node = SceneGraphFactory.BuildActorNode(actor);
            }
            if (node == null)
            {
                return;
            }

            // Get the new parent node (may be missing)
            if (parentNode != null)
            {
                // Change parent
                node.TreeNode.UnlockChildrenRecursive();
                node.ParentNode = parentNode;
            }
            else
            {
                // Check if actor is selected in editor
                if (Editor.SceneEditing.Selection.Contains(node))
                {
                    Editor.SceneEditing.Deselect();
                }

                // Remove node (user may unlink actor from the scene but not destroy the actor)
                node.Dispose();
            }
        }
Esempio n. 4
0
        private void OnActorParentChanged(Actor actor, Actor prevParent)
        {
            ActorNode node = null;

            // Try use previous parent actor to find actor node
            var prevParentNode = GetActorNode(prevParent);

            if (prevParentNode != null)
            {
                // If should be one of the children
                node = prevParentNode.FindChildActor(actor);

                // Search whole tree if node was not found
                if (node == null)
                {
                    node = GetActorNode(actor);
                }
            }
            else
            {
                // Create new node for that actor (user may unlink it from the scene before and now link it)
                node = SceneGraphFactory.BuildActorNode(actor);
            }
            if (node == null)
            {
                return;
            }

            // Get the new parent node (may be missing)
            var parentNode = GetActorNode(actor.Parent);

            if (parentNode != null)
            {
                // Change parent
                node.ParentNode = parentNode;
            }
            else
            {
                // Remove node (user may unlink actor from the scene but not destroy the actor)
                node.Dispose();
            }
        }