示例#1
0
        private void DrawAssetSelection()
        {
            CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true);
            if (CurrentPackage != null)
            {
                var explorer = CurrentPackage.Explorer;

                foreach (var resource in explorer.Resources)
                {
                    if (!resource.Name.EndsWith(".bhvr"))
                    {
                        continue;
                    }

                    if (GUILayout.Button(resource.ToString()))
                    {
                        CurrentResource = resource;
                        JObject editorTarget;
                        using (var editorTargetData = CurrentResource.LoadStream())
                            using (var sr = new StreamReader(editorTargetData))
                                using (var reader = new JsonTextReader(sr))
                                {
                                    editorTarget = JObject.Load(reader);
                                }

                        var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode), typeof(OutputValueNode) });
                        var types = TypeManifest.ConstructBaseTypes();

                        var manifest = new BehaviourManifest()
                        {
                            Nodes = nodes,
                            Types = types,
                        };
                        Debug.Log(editorTarget);
                        var graphEditor = new EditorSession(manifest, editorTarget, "SerializedGraph", Serializer);

                        View.BeginSession(graphEditor);
                    }
                }
            }
        }
示例#2
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(
                new Type[] {
                typeof(AddNode),
                typeof(RollNode),
                typeof(OutputValueNode),
                typeof(ItemInputNode),
                typeof(GetStatNode),
                typeof(IterateNode),
            }
                );
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var resource in ((IPackageExplorer)proj).Resources)
            {
                Console.WriteLine("\t" + resource.FullName);
            }

            var editorTargetResource = proj.Resources["Tutorial Gamerules/Main.bhvr"];
            var editorTargetData     = editorTargetResource.LoadStream();

            JObject editorTarget;

            var serializer = new JsonSerializer();

            using (var sr = new StreamReader(editorTargetData))
                using (var reader = new JsonTextReader(sr))
                {
                    editorTarget = JObject.Load(reader);
                }

            var editor = new EditorSession(manifest, editorTarget, "SerializedGraph", serializer);

            foreach (var node in editor.Root["Nodes"])
            {
                var nodeData = node["Data"];

                foreach (var field in nodeData)
                {
                    Console.WriteLine($"{field}");
                    if (field.Name == "MaxValue")
                    {
                        field.SetValue(field.GetValue <int> () + 10);
                        field.ApplyModifiedProperties();

                        field.SetValue(field.GetValue <int> ());
                        field.ApplyModifiedProperties();
                    }
                    else if (field.Name == "ValueB")
                    {
                        Console.WriteLine(field.GetValue <LocalPropertyId> ());
                    }
                }
            }

            using (var file = editorTargetResource.WriteStream())
                using (var jsonWriter = new JsonTextWriter(file)
                {
                    Formatting = Formatting.Indented
                })
                {
                    serializer.Serialize(jsonWriter, editorTarget);
                }

            Console.WriteLine(new DirectoryInfo("Content/Temp").FullName);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline()
            {
                Exporters = new List <ResourceExporter> ()
                {
                    new BhvrExporter()
                },
                BuildActions = new List <IBuildAction> ()
                {
                    consoleRenderer
                }
            };

            consoleRenderer.DrawProgressBar(32);
            proj.Export(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            var fireballAsset = exportedPackage.Resources["Fireball/Main.bhvr"];
            var data          = fireballAsset.LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph> (reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new DemoPlayer();

            IGraphInstance instancedItem = unpackedGraph.Create();

            instancedItem.Setup();
            instancedItem.SetInput(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 10;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance> (serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.SetInput(player);
            unpackedInstance.Setup();
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
示例#3
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var resource in ((IPackageExplorer)proj).Resources)
            {
                Console.WriteLine("\t" + resource.FullName);
            }

            var editorTargetResource = proj.Resources["Tutorial Gamerules/Main.bhvr"];
            var editorTargetData     = editorTargetResource.LoadStream();

            JObject editorTarget;

            var serializer = new JsonSerializer();

            using (var sr = new StreamReader(editorTargetData))
                using (var reader = new JsonTextReader(sr))
                {
                    editorTarget = JObject.Load(reader);
                }

            //var editNode = editorTarget.Nodes.First ();

            var editor = new EditorSession(manifest, editorTarget, "SerializedGraph");

            /*foreach (var field in editor.Root)
             * {
             *      Console.WriteLine ($"{field.Name}: {field.Json} ({field.Field.Type})");
             *      if (field.Name == "MaxValue")
             *      {
             *              var newObject = JToken.FromObject (field.Json.ToObject<int> () + 10);
             *              field.Json.Replace (newObject);
             *      }
             * }*/

            using (var file = editorTargetResource.WriteStream())
            {
                serializer.Serialize(new JsonTextWriter(file)
                {
                    Formatting = Formatting.Indented
                }, editorTarget);
            }


            Console.WriteLine(new DirectoryInfo("Content/Temp").FullName);

            var consoleRenderer = new BuildConsoleRenderer();

            var buildPipeline = new BuildPipeline()
            {
                Exporters = new List <ResourceExporter> ()
                {
                    new BhvrExporter()
                },
                BuildActions = new List <IBuildAction> ()
                {
                    consoleRenderer
                }
            };

            consoleRenderer.DrawProgressBar(32);
            proj.Export(buildPipeline, "Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            var fireballAsset = exportedPackage.Resources["Fireball/Main.bhvr"];
            var data          = fireballAsset.LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    packageItem = serializer.Deserialize <SerializedGraph> (reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance> (serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.Setup(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
示例#4
0
        public void OnGUI()
        {
            screenRect = new Rect(0, EditorGUIUtility.singleLineHeight + 1,
                                  position.width, position.height - (EditorGUIUtility.singleLineHeight + 1));

            currentEvent = Event.current;

            // HandleDragAndDrop (screenRect);


            DrawBackground(screenRect, dragging_Position);
            DrawTopBar();


            CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true);

            var explorer = CurrentPackage.Explorer;

            foreach (var resource in explorer.Resources)
            {
                if (!resource.Name.EndsWith(".bhvr"))
                {
                    continue;
                }

                if (GUILayout.Button(resource.ToString()))
                {
                    CurrentResource    = resource;
                    HasCurrentResource = true;
                    HasEditor          = false;
                }
            }

            if (HasCurrentResource && CurrentResource != null)
            {
                if (HasEditor == false)
                {
                    Debug.Log(CurrentResource);

                    var editorTargetData = CurrentResource.LoadStream();

                    using (var sr = new StreamReader(editorTargetData))
                        using (var reader = new JsonTextReader(sr))
                        {
                            editorTarget = JObject.Load(reader);
                            // editorTarget = serializer.Deserialize(reader);
                        }

                    var nodes = NodeManifest.Construct(new Type[] { typeof(AddNode), typeof(RollNode) });
                    var types = TypeManifest.ConstructBaseTypes();

                    var manifest = new BehaviourManifest()
                    {
                        Nodes = nodes,
                        Types = types,
                    };
                    Debug.Log(editorTarget);
                    graphEditor = new EditorSession(manifest, editorTarget, "SerializedGraph");
                    HasEditor   = true;
                }

                if (GUILayout.Button("Save"))
                {
                    using (var file = CurrentResource.WriteStream())
                    {
                        serializer.Serialize(new JsonTextWriter(file)
                        {
                            Formatting = Formatting.Indented
                        }, editorTarget);
                    }
                }

                foreach (var node in graphEditor.Root["Nodes"])
                {
                    var nodeEditor         = node["Editor"];
                    var nodeEditorPosition = nodeEditor["Position"];

                    var nodeRect = new Rect(
                        dragging_Position.x + nodeEditorPosition["x"].GetValue <int>(),
                        dragging_Position.y + nodeEditorPosition["y"].GetValue <int>(),
                        200,
                        160
                        );

                    bool startDrag = false;
                    if (Event.current.type == EventType.Repaint)
                    {
                        BehaviourGraphResources.Instance.NodeStyle.Draw(nodeRect,
                                                                        false, node.Name == selectedNode, false, false);
                    }

                    GUILayout.BeginArea(nodeRect);

                    var nodeData = node.Json["Data"];
                    var nodeType = node["Type"];

                    object fieldObject;
                    if (!node.ViewBag.TryGetValue("Generic", out fieldObject))
                    {
                        var fieldInformation = new FieldInformation();
                        fieldInformation.Type = nodeType.Json.ToObject <string>();

                        fieldObject = new EditorField(graphEditor, nodeData, node.Name,
                                                      fieldInformation);

                        node.ViewBag["Generic"] = fieldObject;
                    }
                    var field = (EditorField)fieldObject;


                    foreach (var childField in field)
                    {
                        DrawField(childField);
                    }

                    GUILayout.EndArea();

                    if (Event.current.type == EventType.MouseDown)
                    {
                        if (nodeRect.Contains(Event.current.mousePosition))
                        {
                            selectedNode          = node.Name;
                            dragging_IsDragging   = true;
                            dragging_NodeDragging = true;

                            GUI.UnfocusWindow();
                            GUI.FocusControl("");

                            Event.current.Use();
                        }
                    }
                }

                foreach (var node in graphEditor.Root["Nodes"])
                {
                    var nodeEditor         = node["Editor"];
                    var nodeEditorPosition = nodeEditor["Position"];

                    var nodePositionX = nodeEditorPosition["x"].GetValue <int>() + dragging_Position.x;
                    var nodePositionY = nodeEditorPosition["y"].GetValue <int>() + dragging_Position.y;

                    var nodeData = node.Json["Data"];
                    var nodeType = node["Type"];

                    object fieldObject;
                    if (!node.ViewBag.TryGetValue("Generic", out fieldObject))
                    {
                        var fieldInformation = new FieldInformation();
                        fieldInformation.Type = nodeType.Json.ToObject <string>();

                        fieldObject = new EditorField(graphEditor, nodeData, node.Name,
                                                      fieldInformation);

                        node.ViewBag["Generic"] = fieldObject;
                    }
                    var field = (EditorField)fieldObject;


                    foreach (var childField in field)
                    {
                        if (childField.Field.Type == "InputSocket")
                        {
                            object renderPosObject;
                            var    renderPos = new Rect();;
                            if (childField.ViewBag.TryGetValue("Position", out renderPosObject))
                            {
                                renderPos = (Rect)renderPosObject;
                            }
                            else
                            {
                                Debug.LogError(childField.Name + " has no position");
                            }

                            renderPos.x += nodePositionX;
                            renderPos.y += nodePositionY;

                            // EditorGUI.DrawRect(renderPos, Color.red);

                            Vector3 start    = new Vector3(renderPos.x, renderPos.y);
                            Vector3 end      = new Vector3(renderPos.x - 100, renderPos.y - 100);
                            Vector3 startDir = new Vector3(-1, 0);
                            Vector3 endDir   = new Vector3(1, 0);

                            DrawConnection(start, end, startDir, endDir);
                        }
                    }
                }
            }

            HandleInput();
        }
示例#5
0
        public void Start()
        {
            var nodes = NodeManifest.Construct(new Type[] { typeof(StatsNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Tutorial");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var asset in proj.Assets)
            {
                Console.WriteLine("\t" + asset.Archive.Name);
                foreach (var resource in asset.ProjectResources)
                {
                    Console.WriteLine("\t\t" + resource);
                }
            }

            proj.Export("Content/Temp");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Temp/Core.bpkg");

            foreach (var asset in exportedPackage.Assets)
            {
                Console.WriteLine(asset.Root);
                foreach (var resource in asset.PackageResources)
                {
                    Console.WriteLine("\t" + resource.ToString());
                }
            }

            var fireballAsset = exportedPackage.Assets["Fireball"];
            var data          = fireballAsset.GetResource("Main.bhvr").LoadStream();

            SerializedGraph packageItem;

            using (var sr = new StreamReader(data))
                using (var reader = new JsonTextReader(sr))
                {
                    var serializer = new JsonSerializer();
                    packageItem = serializer.Deserialize <SerializedGraph>(reader);
                }

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            var    packedInstance  = ((GraphInstance)instancedItem).Pack();
            string serializedGraph = packedInstance.AsJson();

            Console.WriteLine(serializedGraph);

            var deserialized     = JsonConvert.DeserializeObject <SerializedGraphInstance>(serializedGraph);
            var unpackedInstance = deserialized.Unpack(unpackedGraph);

            unpackedInstance.Setup(player);
            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            unpackedInstance.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }
示例#6
0
        public void Start()
        {
            IntEventField left  = new IntEventField(1);
            IntEventField right = new IntEventField(3);

            left += (int newValue) =>
            {
                Console.WriteLine("New Value: " + newValue);
            };

            left.Value += 5;

            Console.WriteLine($"{left.Value} + {right.Value} = " + (left + right).Calculate());

            IntEventField one = new IntEventField(1);

            IntEventField test = new IntEventField(left + right + one);

            left.Value++;
            right.Value++;

            Console.WriteLine($"{left.Value} + {right.Value} + {one.Value} = " + test.Value);


            var nodes = NodeManifest.Construct(new Type[] { typeof(StatsNode), typeof(RollNode) });
            var types = TypeManifest.ConstructBaseTypes();

            var manifest = new BehaviourManifest()
            {
                Nodes = nodes,
                Types = types
            };

            File.WriteAllText("Content/RPGCoreMath.bmfst", manifest.ToString());

            Console.WriteLine("Importing Graph...");

            var proj = ProjectExplorer.Load("Content/Core");

            Console.WriteLine(proj.Name);
            Console.WriteLine("\t\"" + proj.Name + "\"");
            foreach (var asset in proj.Assets)
            {
                Console.WriteLine("\t" + asset.Archive.Name);
                foreach (var resource in asset.Resources)
                {
                    Console.WriteLine("\t\t" + resource);
                }
            }

            proj.Export("Content/Core.bpkg");

            Console.WriteLine("Exported package...");
            var exportedPackage = PackageExplorer.Load("Content/Core.bpkg");

            foreach (var asset in exportedPackage.Assets)
            {
                Console.WriteLine(asset.Root);
                foreach (var resource in asset.Resources)
                {
                    Console.WriteLine("\t" + resource.ToString());
                }
            }

            var packageItem = JsonConvert.DeserializeObject <PackageBehaviour> (File.ReadAllText("Content/Core/Longsword/Main.bhvr"));

            Console.WriteLine("Imported: " + packageItem.Name);
            var unpackedGraph = packageItem.Unpack();

            Console.WriteLine("Running Simulation...");

            var player = new Actor();

            IBehaviour instancedItem = unpackedGraph.Setup(player);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
            instancedItem.Remove();

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(100);
                player.Health.Value -= 20;
            }
        }