///<summary>Graph events BEFORE nodes</summary> static void HandlePreNodesGraphEvents(Graph graph, Vector2 canvasMousePos) { if (e.button == 2 && e.type == EventType.MouseDown /*|| e.type == EventType.MouseUp*/) { UndoUtility.RecordObjectComplete(graph, "Graph Pan"); } if (e.type == EventType.MouseUp || e.type == EventType.KeyUp) { SnapNodesToGrid(graph); } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.F && GUIUtility.keyboardControl == 0) { FocusSelection(); e.Use(); } if (e.type == EventType.MouseDown && e.button == 2 && e.clickCount == 2) { FocusPosition(ViewToCanvas(e.mousePosition)); } if (e.type == EventType.ScrollWheel && GraphEditorUtility.allowClick) { if (canvasRect.Contains(e.mousePosition)) { var zoomDelta = e.shift ? 0.1f : 0.25f; ZoomAt(e.mousePosition, -e.delta.y > 0 ? zoomDelta : -zoomDelta); } } if (e.type == EventType.MouseDrag && e.alt && e.button == 1) { ZoomAt(new Vector2(screenWidth / 2, screenHeight / 2), e.delta.x / 100); e.Use(); } if ((e.button == 2 && e.type == EventType.MouseDrag && canvasRect.Contains(e.mousePosition)) || ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.alt && e.isMouse)) { pan += e.delta; smoothPan = null; smoothZoomFactor = null; e.Use(); } if (e.type == EventType.MouseDown && e.button == 2) { mouse2Down = true; } if (e.type == EventType.MouseUp && e.button == 2) { mouse2Down = false; } if (e.alt || mouse2Down) { EditorGUIUtility.AddCursorRect(new Rect(0, 0, screenWidth, screenHeight), MouseCursor.Pan); } }
///---------------------------------------------------------------------------------------------- ///Self Serialize blackboard public void SelfSerialize() { if (haltForUndo /*|| ParadoxNotion.Services.Threader.applicationIsPlaying || Application.isPlaying*/) { return; } var newReferences = new List <UnityEngine.Object>(); var newSerialization = JSONSerializer.Serialize(typeof(BlackboardSource), _blackboard, newReferences); if (newSerialization != _serializedBlackboard || !newReferences.SequenceEqual(_objectReferences) || (_serializedVariables == null || _serializedVariables.Length != _blackboard.variables.Count)) { haltForUndo = true; UndoUtility.RecordObjectComplete(this, UndoUtility.GetLastOperationNameOr("Blackboard Change")); haltForUndo = false; _serializedVariables = new SerializationPair[_blackboard.variables.Count]; for (var i = 0; i < _blackboard.variables.Count; i++) { var serializedVariable = new SerializationPair(); serializedVariable._json = JSONSerializer.Serialize(typeof(Variable), _blackboard.variables.ElementAt(i).Value, serializedVariable._references); _serializedVariables[i] = serializedVariable; } _serializedBlackboard = newSerialization; _objectReferences = newReferences; } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); var def = (SignalDefinition)target; if (GUILayout.Button("Add Parameter")) { EditorUtils.ShowPreferedTypesSelectionMenu(typeof(object), (t) => { UndoUtility.RecordObjectComplete(def, "Add Parameter"); def.AddParameter(t.FriendlyName(), t); UndoUtility.SetDirty(def); }); } UndoUtility.CheckUndo(def, "Definition"); var options = new EditorUtils.ReorderableListOptions(); options.allowRemove = true; options.unityObjectContext = def; EditorUtils.ReorderableList(def.parameters, options, (i, picked) => { var parameter = def.parameters[i]; GUILayout.BeginHorizontal(); parameter.name = UnityEditor.EditorGUILayout.DelayedTextField(parameter.name, GUILayout.Width(150), GUILayout.ExpandWidth(true)); EditorUtils.ButtonTypePopup("", parameter.type, (t) => { parameter.type = t; }); GUILayout.EndHorizontal(); }); UndoUtility.CheckDirty(def); EditorUtils.EndOfInspector(); if (Event.current.isMouse) { Repaint(); } }