public void Unexpose(IExposedGuid obj, FieldInfo field)
        {
            if (entries == null)
            {
                return;
            }
            for (int i = 0; i < entries.Length; i++)         //trying to remove all instances
            {
                if (!IsExposed(obj, field))
                {
                    return;
                }

                Guid   objGuid   = obj.Guid;
                Type   type      = field.FieldType;
                string fieldName = field.Name;
                int    index     = entries.Find(e => e.guid == objGuid && e.fieldName == fieldName && e.type == type);

                ArrayTools.RemoveAt(ref entries, index);
                if (entries.Length == 0)
                {
                    entries = null;
                }
            }
        }
        public void ReadOverride(Graph graph, Dictionary <Entry, object> ovd)
        ///Reads the graph's exposed values defaults, storing them to ovd
        ///If ovd already contains exposed value, it won't be overwritten
        {
            Dictionary <Guid, IExposedGuid> guidLut = graph.CompileGraphGuidLut();

            ClearObsoleteEntries(graph);            //required to avoid errors on getting fields
            ClearObsoleteOverride(ovd);             //just in case

            if (entries == null || entries.Length == 0)
            {
                return;
            }
            for (int i = 0; i < entries.Length; i++)
            {
                if (ovd.ContainsKey(entries[i]))
                {
                    continue;                                              //already in list
                }
                IExposedGuid gen = guidLut[entries[i].guid];

                Type      genType = gen.GetType();
                FieldInfo field   = genType.GetField(entries[i].fieldName);

                object val = field.GetValue(gen);
                ovd.Add(entries[i], val);
            }
        }
        public void ClearObsoleteEntries(Graph graph)
        /// Removes THIS entries containing generators or fields that are not in graph anymore
        {
            if (entries == null || entries.Length == 0)
            {
                return;
            }
            for (int i = entries.Length - 1; i >= 0; i--)
            {
                //generator removed
                Guid guid = entries[i].guid;
                if (!graph.ContainsGenGuid(guid))
                {
                    ArrayTools.RemoveAt(ref entries, i);
                    continue;
                }

                //field removed (or target like adjust changed)
                IExposedGuid gen = graph.FindGenByGuid(guid);
                if (gen == null)
                {
                    ArrayTools.RemoveAt(ref entries, i);
                    continue;
                }
            }
        }
        public void ApplyOverride(Graph graph, Dictionary <Entry, object> ovd)
        ///Writes overridden value (ovd) to used graph
        {
            Dictionary <Guid, IExposedGuid> guidLut = graph.CompileGraphGuidLut();

            ClearObsoleteEntries(graph);             //required to avoid errors on getting fields

            if (entries == null || entries.Length == 0 || ovd == null || ovd.Count == 0)
            {
                return;
            }
            for (int i = 0; i < entries.Length; i++)
            {
                if (!ovd.ContainsKey(entries[i]))
                {
                    continue;                                               //exposed but not not overrided
                }
                IExposedGuid gen = guidLut[entries[i].guid];

                Type      genType = gen.GetType();
                FieldInfo field   = genType.GetField(entries[i].fieldName);

                object val = ovd[entries[i]];
                field.SetValue(gen, val);
            }
        }
        public bool IsExposed(IExposedGuid obj, FieldInfo field)
        {
            if (entries == null)
            {
                return(false);
            }

            Guid   objGuid   = obj.Guid;
            Type   type      = field.FieldType;
            string fieldName = field.Name;

            return(entries.Find(e => e.guid == objGuid && e.fieldName == fieldName && e.type == type) >= 0);
        }
Exemplo n.º 6
0
		public static void ShowWindow (Graph graph, IExposedGuid gen, IOutlet<object> layer, FieldInfo field, Vector2 pos)
		{
			ExposeWindow window = ScriptableObject.CreateInstance(typeof(ExposeWindow)) as ExposeWindow;

			if (layer != null  &&  layer is IExposedGuid expLayer) window.obj = expLayer;
			else window.obj = gen;

			window.graph = graph;
			window.field = field;
			window.customName = field.Name.Nicify();
			window.ShowUtility();

			Vector2 windowSize = new Vector2(300, 100);
			window.position = new Rect(
				pos - windowSize/2,
				windowSize);
		}
        public void Expose(IExposedGuid obj, FieldInfo field, string name = null)
        {
            if (entries == null)
            {
                entries = new Entry[0];
            }

            if (IsExposed(obj, field))
            {
                Unexpose(obj, field);
            }

            Entry entry = new Entry()
            {
                guid      = obj.Guid,
                type      = field.FieldType,
                fieldName = field.Name,
                guiName   = name != null ? name : field.Name.Nicify()
            };

            ArrayTools.Add(ref entries, entry);
        }
Exemplo n.º 8
0
        public void DrawGUI()
        {
            using (Cell.LinePx(32))
                Draw.Label("WARNING: Keeping this asset selected in \nInspector can slow down editor GUI performance.", style: UI.current.styles.helpBox);
            Cell.EmptyLinePx(5);

            using (Cell.LinePx(24)) if (Draw.Button("Open Editor"))
                {
                    GraphWindow.Show(graph);
                }
            using (Cell.LinePx(20)) if (Draw.Button("Open in New Tab"))
                {
                    GraphWindow.ShowInNewTab(graph);
                }

            //seed
            Cell.EmptyLinePx(5);
            using (Cell.LineStd)
            {
                int newSeed = Draw.Field(graph.random.Seed, "Seed");                         //
                if (newSeed != graph.random.Seed)
                {
                    graph.random.Seed = newSeed;
                    //Graph.OnChange.Raise(graph);
                }
            }

            using (Cell.LineStd) Draw.DualLabel("Nodes", graph.generators.Length.ToString());
            using (Cell.LineStd) Draw.DualLabel("MapMagic ver", graph.serializedVersion.ToString());
            Cell.EmptyLinePx(5);


            //global values

            /*using (Cell.LineStd)
             *      using (new Draw.FoldoutGroup (ref showShared, "Global Values"))
             *              if (showShared)
             *      {
             *              List<string> changedNames = new List<string>();
             *              List<object> changedVals = new List<object>();
             *
             *              (Type type, string name)[] typeNames = graph.sharedVals.GetTypeNames();
             *              for (int i=0; i<typeNames.Length; i++)
             *                      using (Cell.LineStd) GeneratorDraw.DrawGlobalVar(typeNames[i].type, typeNames[i].name);
             *
             *              if (Cell.current.valChanged)
             *              {
             *                      GraphWindow.current.mapMagic.ClearAllNodes();
             *                      GraphWindow.current.mapMagic.StartGenerate();
             *              }
             *      }*/

            //exposed values
            using (Cell.LineStd)
                using (new Draw.FoldoutGroup(ref showExposed, "Exposed Values"))
                    if (showExposed)
                    {
                        graph.exposed.ClearObsoleteEntries(graph);

                        if (graph.exposed.entries != null)
                        {
                            for (int e = 0; e < graph.exposed.entries.Length; e++)
                            {
                                Exposed.Entry entry = graph.exposed.entries[e];
                                IExposedGuid  gen   = graph.FindGenByGuid(entry.guid);
                                FieldInfo     field = gen.GetType().GetField(entry.fieldName);

                                using (Cell.LineStd)
                                {
                                    if (field == null)
                                    {
                                        Draw.DualLabel(entry.guiName, "unknown");
                                    }

                                    else
                                    {
                                        Draw.ClassField(
                                            field: field,
                                            type: entry.type,
                                            obj: gen,
                                            name: entry.guiName);
                                    }
                                }

                                if (Cell.current.valChanged)
                                {
                                    GraphWindow.RefreshMapMagic();
                                }
                            }
                        }
                    }

            //dependent graphs
            using (Cell.LineStd)
                using (new Draw.FoldoutGroup(ref showDependent, "Dependent Graphs"))
                    if (showDependent)
                    {
                        using (Cell.LinePx(0))
                            DrawDependentGraphs(graph);
                    }
        }