Esempio n. 1
0
        public void Work()
        {
            var types = TypeManifest.Construct(
                new Type[]
            {
                typeof(int),
                typeof(bool),
                typeof(string),
            },
                new Type[]
            {
                typeof(RootModel),
                typeof(ChildModel)
            }
                );

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

            var sourceObject = new RootModel()
            {
                FirstValue = "Lol",
                AChild     = new ChildModel()
                {
                },
                BChild   = null,
                Children = new ChildModel[]
                {
                    new ChildModel(),
                    null
                },
                MoreChildren = new Dictionary <string, ChildModel>()
                {
                    ["alpha"] = new ChildModel()
                    {
                    },
                    ["beta"] = null
                }
            };

            var editorSession = new EditorSession(manifest, sourceObject, new JsonSerializer());

            DrawTree(editorSession.Root);

            editorSession.Root["BChild"].SetValue(new ChildModel());
            editorSession.Root["BChild"].ApplyModifiedProperties();

            DrawTree(editorSession.Root);
        }
Esempio n. 2
0
        private void DrawAssetSelection()
        {
            CurrentPackage = (ProjectImport)EditorGUILayout.ObjectField(CurrentPackage, typeof(ProjectImport), true,
                                                                        GUILayout.Width(180));
            if (CurrentPackage == null)
            {
                return;
            }

            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),
                        typeof(ItemInputNode),
                        typeof(ActivatableItemNode),
                        typeof(IterateNode),
                        typeof(GetStatNode),
                    });
                    var types = TypeManifest.Construct(
                        new Type[]
                    {
                        typeof(bool),
                        typeof(string),
                        typeof(int),
                        typeof(byte),
                        typeof(long),
                        typeof(short),
                        typeof(uint),
                        typeof(ulong),
                        typeof(ushort),
                        typeof(sbyte),
                        typeof(char),
                        typeof(float),
                        typeof(double),
                        typeof(decimal),
                        typeof(InputSocket),
                        typeof(LocalId),
                    },
                        new Type[]
                    {
                        typeof(SerializedGraph),
                        typeof(SerializedNode),
                        typeof(PackageNodeEditor),
                        typeof(PackageNodePosition),
                        typeof(ExtraData)
                    }
                        );

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

                    View.BeginSession(graphEditor, graphEditor.Root);
                }
            }
        }
Esempio n. 3
0
        public EditorSessionFrame(IResource resource)
        {
            Resource = resource;

            JObject editorTarget;

            using (var editorTargetData = Resource.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),
                typeof(ItemInputNode),
                typeof(ActivatableItemNode),
                typeof(IterateNode),
                typeof(GetStatNode),
            });
            var types = TypeManifest.Construct(
                new Type[]
            {
                typeof(bool),
                typeof(string),
                typeof(int),
                typeof(byte),
                typeof(long),
                typeof(short),
                typeof(uint),
                typeof(ulong),
                typeof(ushort),
                typeof(sbyte),
                typeof(char),
                typeof(float),
                typeof(double),
                typeof(decimal),
                typeof(InputSocket),
                typeof(LocalId),
            },
                new Type[]
            {
                typeof(SerializedGraph),
                typeof(SerializedNode),
                typeof(PackageNodeEditor),
                typeof(PackageNodePosition),
                typeof(ExtraData),

                typeof(ResourceTemplate),
                typeof(BuildingTemplate),
            }
                );

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

            string typeName = null;

            if (Resource.Tags.Contains("type-building"))
            {
                typeName = "BuildingTemplate";
            }
            else if (Resource.Tags.Contains("type-resource"))
            {
                typeName = "ResourceTemplate";
            }

            EditorSession = new EditorSession(manifest, editorTarget, typeName, Serializer);
        }