void PerformPaste(Event e)
        {
            var copyText   = EditorGUIUtility.systemCopyBuffer;
            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(string[]));

            string[] copyNodeIds = (string[])serializer.Deserialize(new System.IO.StringReader(copyText));

            var   mouseWorld   = camera.ScreenToWorld(e.mousePosition);
            float offsetXDelta = 130;
            float offsetX      = 0;

            foreach (var id in copyNodeIds)
            {
                var sourceNode = graph.GetNode(id);
                var copiedNode = GraphOperations.DuplicateNode(graph, sourceNode);

                // Add the copied node to the asset file
                DungeonEditorHelper.AddToAsset(graph, copiedNode);

                // Update the bounds of the node to move it near the cursor
                var bounds = copiedNode.Bounds;
                bounds.x          = mouseWorld.x + offsetX;
                bounds.y          = mouseWorld.y;
                copiedNode.Bounds = bounds;

                offsetX += offsetXDelta;
            }
        }
Esempio n. 2
0
        void SetSpatialConstraintEditorAsset(SpatialConstraintAsset spatialAsset, SpatialConstraintsEditorAssignmentState state)
        {
            if (spatailWindowState.initialized &&
                spatailWindowState.spatialAsset == spatialAsset &&
                spatailWindowState.assignmentState == state)
            {
                // The states are the same. no need to assign
                return;
            }

            spatailWindowState.initialized     = true;
            spatailWindowState.spatialAsset    = spatialAsset;
            spatailWindowState.assignmentState = state;

            var existingWindow = DungeonEditorHelper.GetWindowIfOpen <SpatialConstraintsEditorWindow>();

            // Open a window only if we are assigning
            if (state == SpatialConstraintsEditorAssignmentState.Assigned && existingWindow == null)
            {
                existingWindow = EditorWindow.GetWindow <SpatialConstraintsEditorWindow>();
            }

            if (existingWindow != null)
            {
                existingWindow.Init(spatialAsset, state);
            }
        }
        void CreateLinkBetweenPins(GraphPin outputPin, GraphPin inputPin)
        {
            if (outputPin.PinType != GraphPinType.Output && inputPin.PinType != GraphPinType.Input)
            {
                Debug.LogError("Pin type mismatch");
                return;
            }

            // Make sure they are not from the same node
            if (outputPin.Node == inputPin.Node)
            {
                Debug.LogError("Linking pins from the same node");
                return;
            }

            // Create a link
            var link = GraphOperations.CreateLink <GraphLink>(graph, outputPin, inputPin);

            if (link != null)
            {
                DungeonEditorHelper.AddToAsset(graph, link);
                graph.NotifyStateChanged();
            }
            else
            {
                Debug.Log("GraphSchema: Link not allowed");
            }
        }
Esempio n. 4
0
        void BuildDungeon()
        {
            // Make sure we have a theme defined
            Dungeon dungeon = target as Dungeon;

            if (dungeon != null)
            {
                if (HasValidThemes(dungeon))
                {
                    // Create the splat maps for this dungeon, if necessary
                    var splatComponent = dungeon.GetComponent <DungeonSplatmap>();
                    SplatmapPropertyEditor.CreateSplatMapAsset(splatComponent);

                    // Build the dungeon
                    Undo.RecordObjects(new Object[] { dungeon, dungeon.ActiveModel }, "Dungeon Built");
                    dungeon.Build(new EditorDungeonSceneObjectInstantiator());
                    DungeonEditorHelper.MarkSceneDirty();

                    // Mark the splatmaps as dirty
                    if (splatComponent != null && splatComponent.splatmap != null)
                    {
                        EditorUtility.SetDirty(splatComponent.splatmap);
                    }
                }
                else
                {
                    Highlighter.Highlight("Inspector", "Dungeon Themes");

                    // Notify the user that atleast one theme needs to be set
                    EditorUtility.DisplayDialog("Dungeon Architect", "Please assign atleast one Dungeon Theme before building", "Ok");
                }
            }
        }
        void Advanced_OnCreateNodeIds()
        {
            var confirm = EditorUtility.DisplayDialog("Recreate Node Ids?",
                                                      "Are you sure you want to recreate node Ids?  You should do this after cloning a theme file", "Yes", "Cancel");

            if (confirm)
            {
                DungeonEditorHelper._Advanced_RecreateGraphNodeIds();
            }
        }
        /// <summary>
        /// Creates a new node in the specified screen coordinate
        /// </summary>
        /// <typeparam name="T">The type of node to created. Should be a subclass of GraphNode</typeparam>
        /// <param name="screenCoord">The screen coordinate to place the node at</param>
        /// <returns>The created graph node</returns>
        public T CreateNode <T>(Vector2 screenCoord) where T : GraphNode, new()
        {
            var node = GraphOperations.CreateNode <T>(graph);

            DungeonEditorHelper.AddToAsset(graph, node);
            var screenPosition = screenCoord - node.Bounds.size / 2;

            node.Position = camera.ScreenToWorld(screenPosition);
            BringToFront(node);
            return(node);
        }
Esempio n. 7
0
 void CreateSpatialConstraintAsset(VisualNode visualNode)
 {
     if (visualNode.spatialConstraint == null)
     {
         visualNode.spatialConstraint = CreateInstance <SpatialConstraintAsset>();
         visualNode.spatialConstraint.Init(visualNode);
         AssetDatabase.AddObjectToAsset(visualNode.spatialConstraint, graph);
         AssetDatabase.AddObjectToAsset(visualNode.spatialConstraint.Graph, graph);
         DungeonEditorHelper.CreateDefaultSpatialConstraintNodes(visualNode.spatialConstraint);
     }
 }
Esempio n. 8
0
        protected override void OnGuiChanged()
        {
            var themeEditorWindow = DungeonEditorHelper.GetWindowIfOpen <DungeonThemeEditorWindow>();

            if (themeEditorWindow != null)
            {
                var graphEditor = themeEditorWindow.GraphEditor;
                graphEditor.HandleGraphStateChanged();
                graphEditor.HandleNodePropertyChanged(target as GraphNode);
            }
        }
Esempio n. 9
0
        protected override void DestroyNode(GraphNode node)
        {
            if (node is VisualNode)
            {
                // Destroy the spatial constraint asset
                var visualNode = node as VisualNode;
                DungeonEditorHelper.DestroySpatialConstraintAsset(visualNode.spatialConstraint);
                visualNode.spatialConstraint = null;
            }

            base.DestroyNode(node);
        }
Esempio n. 10
0
        public virtual GraphNode CreateNode(Vector2 screenCoord, UnityEngine.Object hostAsset, System.Type nodeType)
        {
            var node = GraphOperations.CreateNode(graph, nodeType);

            DungeonEditorHelper.AddToAsset(hostAsset, node);

            var nodeScreenSize = node.Bounds.size / camera.ZoomLevel;
            var screenPosition = screenCoord - nodeScreenSize / 2;

            node.Position = camera.ScreenToWorld(screenPosition);
            BringToFront(node);

            events.OnNodeCreated.Notify(new GraphNodeEventArgs(node));
            return(node);
        }
Esempio n. 11
0
        public static void CreateSplatMapAsset(DungeonSplatmap splatComponent)
        {
            if (splatComponent == null)
            {
                // No splatmap attached to this dungeon configuration
                return;
            }

            // Check if the splatmap asset has been assigned
            if (splatComponent.splatmap == null)
            {
                // Create a new splatmap asset in the correct directory and assign it to the dungeon
                var defaultFileName = "DungeonSplatmap.asset";
                var scenePath       = DungeonEditorHelper.GetActiveScenePath();
                splatComponent.splatmap = DungeonEditorHelper.CreateAssetInBrowser <DungeonSplatAsset>(scenePath, defaultFileName);

                RegenerateSplatmaps(splatComponent);
            }
        }
        void BuildDungeon()
        {
            // Make sure we have a theme defined
            Dungeon dungeon = target as Dungeon;

            if (dungeon != null)
            {
                if (HasValidThemes(dungeon))
                {
                    // Build the dungeon
                    Undo.RecordObjects(new Object[] { dungeon, dungeon.ActiveModel }, "Dungeon Built");
                    dungeon.Build();
                    DungeonEditorHelper.MarkSceneDirty();
                }
                else
                {
                    Highlighter.Highlight("Inspector", "Dungeon Themes");

                    // Notify the user that atleast one theme needs to be set
                    EditorUtility.DisplayDialog("Dungeon Architect", "Please assign atleast one Dungeon Theme before building", "Ok");
                }
            }
        }