Exemplo n.º 1
0
        private static void BuildSceneTree(ActorNode node)
        {
            var children = node.Actor.GetChildren();

            for (int i = 0; i < children.Length; i++)
            {
                var childNode = BuildActorNode(children[i]);
                if (childNode != null)
                {
                    childNode.ParentNode = node;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds the actor node. Warning! Don't create duplicated nodes.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <returns>Created node or null if failed.</returns>
        public static ActorNode BuildActorNode(Actor actor)
        {
            ActorNode result = null;
            Type      customType;

            try
            {
                // Try to pick custom node type for that actor object
                if (CustomNodesTypes.TryGetValue(actor.GetType(), out customType))
                {
                    // Use custom type
                    _sharedArgsContainer[0] = actor;
                    result = (ActorNode)Activator.CreateInstance(customType, _sharedArgsContainer);
                }
                else
                {
                    // Use default type for actors
                    result = new ActorNode(actor);
                }

                // Build children
                var childrenCount = actor.ChildrenCount;
                for (int i = 0; i < childrenCount; i++)
                {
                    var child = actor.GetChild(i);
                    if (child == null)
                    {
                        continue;
                    }

                    var childNode = BuildActorNode(child);
                    if (childNode != null)
                    {
                        childNode.ParentNode = result;
                    }
                }
            }
            catch (Exception ex)
            {
                // Error
                Editor.LogWarning($"Failed to create scene graph node for actor {actor.Name} (type: {actor.GetType()}).");
                if (CustomNodesTypes.TryGetValue(actor.GetType(), out customType))
                {
                    Editor.LogWarning($"Custom node type: {customType}");
                }
                Editor.LogWarning(ex);
            }

            return(result);
        }
Exemplo n.º 3
0
        private static void BuildSceneTree(ActorNode node)
        {
            var childrenCount = node.Actor.ChildrenCount;

            for (int i = 0; i < childrenCount; i++)
            {
                var child     = node.Actor.GetChild(i);
                var childNode = BuildActorNode(child);
                if (childNode != null)
                {
                    childNode.ParentNode = node;
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Called when actor child nodes get released.
 /// </summary>
 /// <param name="node">The node.</param>
 public virtual void OnActorChildNodesDispose(ActorNode node)
 {
     ActorChildNodesDispose?.Invoke(node);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Builds the actor node. Warning! Don't create duplicated nodes.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <returns>Created node or null if failed.</returns>
        public static ActorNode BuildActorNode(Actor actor)
        {
            ActorNode result = null;
            Type      customType;

            try
            {
                // Try to pick custom node type for that actor object
                var type = actor.GetType();
                if (CustomNodesTypes.TryGetValue(type, out customType))
                {
                    // Use custom type
                    _sharedArgsContainer[0] = actor;
                    result = (ActorNode)Activator.CreateInstance(customType, _sharedArgsContainer);
                }
                else
                {
                    // Check if the actor type inherits from one of the custom types but doesn't provide own node type
                    foreach (var e in CustomNodesTypes)
                    {
                        if (e.Key.IsAssignableFrom(type))
                        {
                            // Use custom type
                            _sharedArgsContainer[0] = actor;
                            result = (ActorNode)Activator.CreateInstance(e.Value, _sharedArgsContainer);
                            break;
                        }
                    }

                    // Use default type for actors
                    if (result == null)
                    {
                        result = new ActorNode(actor);
                    }
                }

                // Build children
                var childrenCount = actor.ChildrenCount;
                for (int i = 0; i < childrenCount; i++)
                {
                    var child = actor.GetChild(i);
                    if (child == null)
                    {
                        continue;
                    }

                    var childNode = BuildActorNode(child);
                    if (childNode != null)
                    {
                        childNode.ParentNode = result;
                    }
                }
            }
            catch (Exception ex)
            {
                // Error
                Editor.LogWarning($"Failed to create scene graph node for actor {actor.Name} (type: {actor.GetType()}).");
                if (CustomNodesTypes.TryGetValue(actor.GetType(), out customType))
                {
                    Editor.LogWarning($"Custom node type: {customType}");
                }
                Editor.LogWarning(ex);
            }

            return(result);
        }