public RandomGraph(int n, GraphPermissions permissions, GraphBehaviour behaviour) : base(permissions, behaviour) { while (n-- > 0) { AddVertex(new ValueVertex <int>(n));//maybe abstract this away with a generic parameter } r = new Random(DateTime.Now.Millisecond); }
private WebJSON.Graph GetGraphJSON(GraphBehaviour gb) { if (gb == null) { return(null); } return(new WebJSON.Graph() { Name = gb.gameObject.name }); }
private void Start() { //合适的时机调用初始化节点反序列化功能的类 FlatNodeUtility.Init(); TextAsset textAsset = Resources.Load <TextAsset>("GraphRuntime/0"); if (textAsset == null) { return; } byte[] bytes = textAsset.bytes; ByteBuffer byteBuffer = new ByteBuffer(bytes); graphBehaviour = new GraphBehaviour(byteBuffer); graphBehaviour.Init(); //行为图的入口方法,可自行拓展 graphBehaviour.OnClick(); }
public static void DrawDsgVarValue(Rect rect, DsgVarComponent.DsgVarEditableEntry dsgVarEntry, DsgVarComponent.DsgVarEditableEntry.Value value, int?arrayIndex) { string stringVal; switch (value.type) { case DsgVarInfoEntry.DsgVarType.Boolean: value.AsBoolean = EditorGUI.Toggle(rect, value.AsBoolean); break; case DsgVarInfoEntry.DsgVarType.Int: value.AsInt = EditorGUI.IntField(rect, value.AsInt); break; case DsgVarInfoEntry.DsgVarType.UInt: stringVal = EditorGUI.TextField(rect, value.AsUInt.ToString()); if (UInt32.TryParse(stringVal, out uint r_uint)) { value.AsUInt = r_uint; } break; case DsgVarInfoEntry.DsgVarType.Caps: stringVal = EditorGUI.TextField(rect, value.AsCaps.ToString()); if (UInt32.TryParse(stringVal, out uint r_caps)) { value.AsCaps = r_caps; } break; case DsgVarInfoEntry.DsgVarType.Short: stringVal = EditorGUI.TextField(rect, value.AsShort.ToString()); if (Int16.TryParse(stringVal, out short r_short)) { value.AsShort = r_short; } break; case DsgVarInfoEntry.DsgVarType.UShort: stringVal = EditorGUI.TextField(rect, value.AsUShort.ToString()); if (UInt16.TryParse(stringVal, out ushort r_ushort)) { value.AsUShort = r_ushort; } break; case DsgVarInfoEntry.DsgVarType.Byte: stringVal = EditorGUI.TextField(rect, value.AsByte.ToString()); if (SByte.TryParse(stringVal, out sbyte r_sbyte)) { value.AsByte = r_sbyte; } break; case DsgVarInfoEntry.DsgVarType.UByte: stringVal = EditorGUI.TextField(rect, value.AsUByte.ToString()); if (Byte.TryParse(stringVal, out byte r_byte)) { value.AsUByte = r_byte; } break; case DsgVarInfoEntry.DsgVarType.Float: value.AsFloat = EditorGUI.FloatField(rect, value.AsFloat); break; case DsgVarInfoEntry.DsgVarType.Text: int?newTextID = DrawText(rect, value.AsText); if (newTextID.HasValue) { value.AsText = newTextID.Value; } //GUILayout.Label(MapLoader.Loader.localization.GetTextForHandleAndLanguageID((int)value.AsUInt, 0)); break; case DsgVarInfoEntry.DsgVarType.Vector: value.AsVector = EditorGUI.Vector3Field(rect, "", value.AsVector); break; case DsgVarInfoEntry.DsgVarType.Perso: if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { ROMPersoBehaviour currentPersoBehaviour = value.AsPersoROM != null ? value.AsPersoROM : null; ROMPersoBehaviour selectedPersoBehaviour = ((ROMPersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(ROMPersoBehaviour), true)); if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null) { value.AsPersoROM = selectedPersoBehaviour; } } else { PersoBehaviour currentPersoBehaviour = value.AsPerso != null ? value.AsPerso : null; PersoBehaviour selectedPersoBehaviour = ((PersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(PersoBehaviour), true)); if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null) { value.AsPerso = selectedPersoBehaviour; } } break; case DsgVarInfoEntry.DsgVarType.SuperObject: SuperObjectComponent currentGao = value.AsSuperObject != null ? value.AsSuperObject : null; SuperObjectComponent selectedGao = ((SuperObjectComponent)EditorGUI.ObjectField(rect, currentGao, typeof(SuperObjectComponent), true)); if (selectedGao != null && selectedGao.gameObject != null) { value.AsSuperObject = selectedGao; } break; case DsgVarInfoEntry.DsgVarType.WayPoint: WayPointBehaviour currentWaypointGao = value.AsWayPoint != null ? value.AsWayPoint : null; WayPointBehaviour selectedWaypointGao = ((WayPointBehaviour)EditorGUI.ObjectField(rect, currentWaypointGao, typeof(WayPointBehaviour), true)); if (selectedWaypointGao != null && selectedWaypointGao.gameObject != null) { value.AsWayPoint = selectedWaypointGao; } break; case DsgVarInfoEntry.DsgVarType.Graph: GraphBehaviour currentGraphGao = value.AsGraph != null ? value.AsGraph : null; GraphBehaviour selectedGraphGao = ((GraphBehaviour)EditorGUI.ObjectField(rect, currentGraphGao, typeof(GraphBehaviour), true)); if (selectedGraphGao != null && selectedGraphGao.gameObject != null) { value.AsGraph = selectedGraphGao; } break; case DsgVarInfoEntry.DsgVarType.ActionArray: case DsgVarInfoEntry.DsgVarType.FloatArray: case DsgVarInfoEntry.DsgVarType.Array11: case DsgVarInfoEntry.DsgVarType.GraphArray: case DsgVarInfoEntry.DsgVarType.Array9: case DsgVarInfoEntry.DsgVarType.IntegerArray: case DsgVarInfoEntry.DsgVarType.PersoArray: case DsgVarInfoEntry.DsgVarType.SoundEventArray: case DsgVarInfoEntry.DsgVarType.SuperObjectArray: case DsgVarInfoEntry.DsgVarType.TextArray: case DsgVarInfoEntry.DsgVarType.TextRefArray: case DsgVarInfoEntry.DsgVarType.VectorArray: case DsgVarInfoEntry.DsgVarType.WayPointArray: if (value.AsArray != null) { if (arrayIndex.HasValue) { if (value.AsArray[arrayIndex.Value] != null) { DrawDsgVarValue(rect, dsgVarEntry, value.AsArray[arrayIndex.Value], arrayIndex); } } else { EditorGUI.LabelField(rect, "Length: " + value.AsArray.Length); } } break; } }
public void Init() { if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader) { OpenSpace.Loader.R2ROMLoader l = MapLoader.Loader as OpenSpace.Loader.R2ROMLoader; foreach (OpenSpace.ROM.WayPoint wp in l.waypointsROM) { AddWaypoint(wp.GetGameObject()); } if (graphRoot == null && l.graphsROM.Count > 0) { graphRoot = new GameObject("Graphs"); graphRoot.transform.SetParent(transform); graphRoot.SetActive(false); } foreach (OpenSpace.ROM.Graph graph in l.graphsROM) { GameObject go_graph = new GameObject("Graph " + graph.Offset); go_graph.transform.SetParent(graphRoot.transform); GraphBehaviour gb = go_graph.AddComponent <GraphBehaviour>(); gb.graphROM = graph; graphROMDict[graph] = gb; for (int i = 0; i < graph.num_nodes; i++) { OpenSpace.ROM.GraphNode node = graph.nodes.Value.nodes[i].Value; if (node.waypoint.Value != null) { WayPointBehaviour wp = waypoints.FirstOrDefault(w => w.wpROM == node.waypoint.Value); if (wp != null) { gb.nodes.Add(wp); wp.nodesROM.Add(node); wp.name = "GraphNode[" + i + "].WayPoint (" + wp.wpROM.Offset + ")"; if (i == 0) { go_graph.transform.position = wp.transform.position; } wp.transform.SetParent(go_graph.transform); } } } } } else { MapLoader l = MapLoader.Loader; foreach (WayPoint wp in l.waypoints) { AddWaypoint(wp.Gao.GetComponent <WayPointBehaviour>()); } if (graphRoot == null && l.graphs.Count > 0) { graphRoot = new GameObject("Graphs"); graphRoot.transform.SetParent(transform); graphRoot.SetActive(false); } foreach (Graph graph in l.graphs) { GameObject go_graph = new GameObject(graph.name ?? "Graph " + graph.offset.ToString()); go_graph.transform.SetParent(graphRoot.transform); GraphBehaviour gb = go_graph.AddComponent <GraphBehaviour>(); gb.graph = graph; graphDict[graph] = gb; for (int i = 0; i < graph.nodes.Count; i++) { GraphNode node = graph.nodes[i]; if (node == null) { continue; } if (node.wayPoint != null) { WayPointBehaviour wp = waypoints.FirstOrDefault(w => w.wp == node.wayPoint); if (wp != null) { gb.nodes.Add(wp); wp.nodes.Add(node); wp.name = "GraphNode[" + i + "].WayPoint (" + wp.wp.offset + ")"; if (i == 0) { go_graph.transform.position = wp.transform.position; } wp.transform.SetParent(go_graph.transform); } } } } } List <WayPointBehaviour> isolateWaypoints = waypoints.Where(w => w.nodes.Count == 0 && w.nodesROM.Count == 0).ToList(); if (isolateWaypointRoot == null && isolateWaypoints.Count > 0) { isolateWaypointRoot = new GameObject("Isolate WayPoints"); isolateWaypointRoot.transform.SetParent(transform); isolateWaypointRoot.SetActive(false); } foreach (WayPointBehaviour wp in isolateWaypoints) { wp.name = "Isolate WayPoint @" + (wp.wpROM != null ? wp.wpROM.Offset : wp.wp.offset); wp.transform.SetParent(isolateWaypointRoot.transform); } foreach (WayPointBehaviour wp in waypoints) { wp.Init(); } UpdateViewGraphs(); //loaded = true; }
public override void OnInspectorGUI() { DrawDefaultInspector(); GraphBehaviour graphBehaviour = (GraphBehaviour)target; if (GUILayout.Button("Copy offsets to Cheat Engine table")) { //string text = ""; CETableBuilder cb = new CETableBuilder(); int nodeCount = 0; var nodes = new List <CETableBuilder.TableEntry>(); foreach (var node in graphBehaviour.graph.nodes) { var nodeProperties = new List <CETableBuilder.TableEntry>(); int arcCount = 0; foreach (var arc in node.arcList.list) { var arcProperties = new List <CETableBuilder.TableEntry> { new CETableBuilder.TableEntry("Capabilities", arc.offset + 16, CETableBuilder.CEVarType._4_Bytes, true), new CETableBuilder.TableEntry("Weight", arc.offset + 20, CETableBuilder.CEVarType._4_Bytes, true) }; nodeProperties.Add(new CETableBuilder.TableEntry() { Address = arc.offset, Name = $"Arc {arcCount}", Children = arcProperties, Type = CETableBuilder.CEVarType._4_Bytes }); arcCount++; } nodeProperties.Add(new CETableBuilder.TableEntry("Waypoint", node.offset + 12, CETableBuilder.CEVarType._4_Bytes, true) { Children = new List <CETableBuilder.TableEntry>() { new CETableBuilder.TableEntry("X", node.wayPoint.offset + 0, CETableBuilder.CEVarType.Float, false), new CETableBuilder.TableEntry("Y", node.wayPoint.offset + 4, CETableBuilder.CEVarType.Float, false), new CETableBuilder.TableEntry("Z", node.wayPoint.offset + 8, CETableBuilder.CEVarType.Float, false), new CETableBuilder.TableEntry("Radius", node.wayPoint.offset + 12, CETableBuilder.CEVarType.Float, false), } }); nodeProperties.Add(new CETableBuilder.TableEntry("Type of WP", node.offset + 16, CETableBuilder.CEVarType._4_Bytes, true)); nodeProperties.Add(new CETableBuilder.TableEntry("Type of WP Init", node.offset + 20, CETableBuilder.CEVarType._4_Bytes, true)); nodes.Add(new CETableBuilder.TableEntry { Address = node.offset, Name = $"Node {nodeCount}", Type = CETableBuilder.CEVarType._4_Bytes, Children = nodeProperties, }); nodeCount++; } cb.Entries = nodes; EditorGUIUtility.systemCopyBuffer = cb.Build(); } }
protected GraphObject(GraphPermissions permissions, GraphBehaviour behaviour) { this.permissions = permissions; this.behaviour = behaviour; }
public static void SetDefaultBehaviour(GraphPermissions permissions, GraphBehaviour behaviour) { defaultPermissions = permissions; defaultBehaviour = behaviour; }
static GraphObject() { defaultPermissions = GraphPermissions.None; defaultBehaviour = GraphBehaviour.ThrowUnpermittedBehaviour; }
public AdjacencyGraph(GraphPermissions permissions, GraphBehaviour behaviour) : base(permissions, behaviour) { vertices = new List <IVertex>(); }