Exemple #1
0
        private async Task UpdateGameSideReference([NotNull] AssetCompositeEditorViewModel editor, [NotNull] IGraphNode gameSideNode, ContentChangeType changeType, object oldValue, object newValue, NodeIndex index)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }

            if (!AssetRegistry.IsContentType(gameSideNode.Descriptor.GetInnerCollectionType()))
            {
                return;
            }

            // Grab the old referenced object if it's not null
            AttachedReference reference = null;

            if (!ReferenceEquals(oldValue, null))
            {
                reference = AttachedReferenceManager.GetAttachedReference(oldValue);
            }

            // Switch to game thread to actually update objects
            await editor.Controller.InvokeTask(() =>
            {
                // For references, push null instead of the real value, the editor asset loader will set the actual value later
                switch (changeType)
                {
                case ContentChangeType.ValueChange:
                    ((IMemberNode)gameSideNode).Update(null);
                    break;

                case ContentChangeType.CollectionUpdate:
                    ((IObjectNode)gameSideNode).Update(null, index);
                    break;

                case ContentChangeType.CollectionAdd:
                    ((IObjectNode)gameSideNode).Add(null, index);
                    break;

                case ContentChangeType.CollectionRemove:
                    var oldValueGameSide = gameSideNode.Retrieve(index);
                    ((IObjectNode)gameSideNode).Remove(oldValueGameSide, index);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(changeType), changeType, null);
                }

                if (oldValue == newValue)
                {
                    return(Task.CompletedTask);
                }

                // Unregister the previous value
                if (reference != null)
                {
                    return(editor.Controller.Loader.Manager.ClearContentReference(Owner.Id, reference.Id, gameSideNode, index));
                }
                return(Task.CompletedTask);
            });
        }
Exemple #2
0
        private static void FixupParentChild([NotNull] SceneViewModel childScene, AttachedReference parentReference)
        {
            if (parentReference == null)
            {
                // If this child does not have a parent, do nothing
                return;
            }

            var parent = childScene.Session.GetAssetById(parentReference.Id) as SceneViewModel;

            if (parent == null)
            {
                // Not a scene, let's clean the reference
                childScene.Parent = null;
                return;
            }

            if (!parent.isInitialized)
            {
                if (!parent.Asset.ChildrenIds.Contains(childScene.Id))
                {
                    // The parent doesn't know about this child, let's fix it
                    parent.childrenNode.Add(childScene.Id);
                }
                // child's Parent property will be fixed up during its parent initialization, nothing more to do
                return;
            }

            // The parent is already initialized but doesn't know about this child, let's add it
            childScene.parent = parent;
            parent.Children.Add(childScene);
        }
Exemple #3
0
        private bool HasSceneOrChildSceneReference(AttachedReference referencedSceneReference, Scene scene)
        {
            bool hasReference = referencedSceneReference != null && loadedScenes.ContainsKey(referencedSceneReference.Id);

            if (hasReference)
            {
                return(true);
            }

            // Recursive check for child scene references from this navigation mesh
            foreach (var childScene in scene.Children)
            {
                if (HasSceneOrChildSceneReference(referencedSceneReference, childScene))
                {
                    return(true);
                }
            }

            return(false);
        }
 public AttachedContentReference(AttachedReference attachedReference)
 {
     this.attachedReference = attachedReference;
 }