private void InitializeWindow() { diagramSO = new SerializedObject(diagram); nodesSP = diagramSO.FindProperty("nodes"); diagramEvent = new DiagramWindowEvent(); if (selectedNodeIndex >= diagram.nodes.Length) { selectedNodeIndex = -1; } windowNodes = new DiagramWindowNode[diagram.nodes.Length]; for (int i = 0; i < diagram.nodes.Length; i++) { if (diagram.nodes[i].Function == null || diagram.nodes[i].Function.type != FunctionType.Output) { windowNodes[i] = new DiagramWindowNode(i, diagram.nodes[i], nodesSP.GetArrayElementAtIndex(i), this); } else { windowNodes[i] = new DiagramWindowOutputNode(i, diagram.nodes[i], nodesSP.GetArrayElementAtIndex(i), this); } if (selectedNodeIndex == i) { windowNodes[i].IsFocused = true; } } ComputeCanvas(); transactions = new List <DiagramWindowTransaction>(); diagram.prepared = false; }
public override void OnNodeGUI(DiagramWindowEvent e) { // Draw the window with property label. Rect r = new Rect(1f, 20f, nodeRect.width - DOUBLE_PADDING, 20f); GUI.BeginGroup(nodeRect, output.name, IsFocused ? window.activeNodeStyle : window.normalNodeStyle); GUI.Label(r, node.GetPropertyName(0)); GUI.EndGroup(); // Draw the property connector. r.x = nodeRect.x - 17f; r.y = nodeRect.y + 21f; r.width = r.height = CONNECTOR_SIZE; if (e.IsTouchBeginInsideRect(r)) { window.StartTransaction(new ConnectionDragTransaction(this, 0, new Vector2(r.x, r.center.y) - window.scrollPosition)); e.Use(); } GUI.Box(r, typeBoxStrings[(int)node.Function.propertyTypes[0]], window.connectorBoxStyle); int argumentIndex = node.argumentIndices[0]; if (argumentIndex >= 0) { DrawConnection(argumentIndex, r); } }
private void InitializeStyles() { diagramEvent = new DiagramWindowEvent(); focusedConnectionColor = Color.white * (GUI.skin.name == "LightSkin" ? 0.25f : 0.75f); focusedConnectionColor.a = 1f; nameLabelStyle = new GUIStyle(GUI.skin.label); nameLabelStyle.alignment = TextAnchor.MiddleCenter; normalNodeStyle = new GUIStyle(GUI.skin.window); normalNodeStyle.font = GUI.skin.label.font; activeNodeStyle = new GUIStyle(normalNodeStyle); activeNodeStyle.normal = activeNodeStyle.onNormal; connectorBoxStyle = new GUIStyle(GUI.skin.box); connectorBoxStyle.contentOffset = Vector2.zero; connectorBoxStyle = new GUIStyle(GUI.skin.box); connectorBoxStyle.alignment = TextAnchor.LowerLeft; connectorBoxStyle.clipping = TextClipping.Overflow; connectorBoxStyle.fontSize = 8; connectorBoxStyle.contentOffset = new Vector2(-1f, 0f); connectorBoxStyle.wordWrap = false; fixedValueStyle = new GUIStyle(GUI.skin.label); fixedValueStyle.alignment = TextAnchor.LowerRight; fixedValueStyle.fontSize = 8; }
public virtual void OnNodeGUI(DiagramWindowEvent e) { // Draw the window with property labels. Rect r = new Rect(1f, 20f, nodeRect.width - DOUBLE_PADDING, 20f); GUI.BeginGroup(nodeRect, node.Name, IsFocused ? window.activeNodeStyle : window.normalNodeStyle); if (node.Function == null || node.Function.type != FunctionType.Input) { for (int i = 0, l = node.PropertyCount; i < l; i++) { GUI.Label(r, node.GetPropertyName(i)); r.y += 16f; } GUI.EndGroup(); // Draw the property connectors. float xOffset = nodeRect.x - 17f, yOffset = nodeRect.y + 21f; r.width = r.height = CONNECTOR_SIZE; for (int i = 0, l = node.PropertyCount; i < l; i++) { r.x = xOffset; r.y = yOffset; if (e.IsTouchBeginInsideRect(r)) { window.StartTransaction(new ConnectionDragTransaction(this, i, new Vector2(r.x, r.center.y) - window.scrollPosition)); e.Use(); } GUI.Box(r, node.Function == null ? " ?" : typeBoxStrings[(int)node.Function.propertyTypes[i]], window.connectorBoxStyle); int argumentIndex = node.argumentIndices[i]; if (argumentIndex >= 0) { DrawConnection(argumentIndex, r); } else { DrawFixedValue(i, r); } yOffset += CONNECTOR_OFFSET_Y; } } else { GUI.Label(r, node.GetPropertyName(0)); GUI.EndGroup(); } // Draw the result connector. if (node.Function == null) { GUI.Box(OutputConnectionRect, " ?", window.connectorBoxStyle); } else if (node.Function.returnType != ValueType.None) { GUI.Box(OutputConnectionRect, typeBoxStrings[(int)node.Function.returnType], window.connectorBoxStyle); } }
public bool OnGUI(DiagramWindowEvent e) { if (e.type == DiagramWindowEventType.TouchMove) { nodeToDrag.Position = nodeStartPosition + e.touchPosition - startPosition; e.Use(); return(true); } if (e.type == DiagramWindowEventType.Layout || e.type == DiagramWindowEventType.Repaint) { return(true); } // Any event other than Move, Layout, or Repaint terminates the drag. // The TouchEnd event isn't reliable enough to depend on, as it doesn't happen when releasing a node outside of the canvas. e.Use(); return(false); }
public bool OnGUI(DiagramWindowEvent e) { if (e.type == DiagramWindowEventType.TouchMove) { e.Use(); return(true); } if (e.type == DiagramWindowEventType.TouchEnd) { nodeToConnect.SetArgument(argumentIndex, e.targetWindowNode ?? e.targetOutputNode); e.Use(); return(false); } if (e.type == DiagramWindowEventType.Repaint) { Handles.DrawBezier(startPosition, e.touchPosition, startTangent, e.touchPosition, Color.grey, null, 2f); } return(true); }
public override void OnSelectedWindowGUI(DiagramWindowEvent e) { Rect r = SelectedWindowRect; GUI.BeginGroup(r, node.Name, window.normalNodeStyle); #if !UNITY_4_2 EditorGUIUtility.labelWidth = labelWidth; #endif r.x = panelPadding; r.y = panelPaddingTop; r.height = rowContentHeight; r.width = rowWidth; EditorGUI.PropertyField(r, spName); r.y += rowHeight; EditorGUI.PropertyField(r, spType); r.y += rowHeight; if (output.type == DiagramTextureType.NormalMap) { if (node.Diagram.isCubemap) { r.height = rowHeight * 3f; EditorGUI.HelpBox(r, "Normal maps are not supported for cubemap diagrams.", MessageType.Warning); } else { EditorGUI.PropertyField(r, spPrevieType, previewLabel); r.y += rowHeight; EditorGUI.PropertyField(r, spNormalFiltering, filteringLabel); r.y += rowHeight; EditorGUI.PropertyField(r, spStrength); } } else if (output.type == DiagramTextureType.ARGB) { EditorGUI.PropertyField(r, spPrevieType, previewLabel); } GUI.EndGroup(); }
public virtual void OnSelectedWindowGUI(DiagramWindowEvent e) { SerializedProperty fixedValuesSP = nodeSP.FindPropertyRelative("fixedValues"); float width = Mathf.Max(108f, Mathf.Max(propertyNameLabelWidth * 2f + 8f, nodeNameLabelWidth + 8f)); float labelWidth = (width - 8f) * 0.5f; Rect r = new Rect(window.position.width - width - 20f, 20f, width, (node.PropertyCount + 1) * 18f + 23f); GUI.BeginGroup(r, node.Name, window.normalNodeStyle); r.y = 20f; r.height = 16f; if (node.Function != null) { #if !UNITY_4_2 EditorGUIUtility.labelWidth = labelWidth; #endif for (int i = 0, l = fixedValuesSP.arraySize; i < l; i++) { r.x = 4f; if (node.argumentIndices[i] >= 0) { r.width = labelWidth; GUI.Label(r, node.GetPropertyName(i)); r.x = labelWidth + 4f; GUI.Label(r, "linked"); } else { SerializedProperty field = fixedValuesSP.GetArrayElementAtIndex(i). FindPropertyRelative(node.Function.propertyTypes[i].ToString()); r.width = width - 8f; if (field.propertyType == SerializedPropertyType.Vector3) { Rect subR = r; subR.width *= 0.5f; GUI.Label(subR, node.GetPropertyName(i)); subR.x += subR.width; subR.width = subR.width / 3f - 1f; EditorGUI.PropertyField(subR, field.FindPropertyRelative("x"), GUIContent.none); subR.x += subR.width + 1f; EditorGUI.PropertyField(subR, field.FindPropertyRelative("y"), GUIContent.none); subR.x += subR.width + 1f; EditorGUI.PropertyField(subR, field.FindPropertyRelative("z"), GUIContent.none); } else if (field.propertyType == SerializedPropertyType.Vector2) { Rect subR = r; subR.width *= 0.5f; GUI.Label(subR, node.GetPropertyName(i)); subR.x += subR.width; subR.width = subR.width / 2f - 1f; EditorGUI.PropertyField(subR, field.FindPropertyRelative("x"), GUIContent.none); subR.x += subR.width + 1f; EditorGUI.PropertyField(subR, field.FindPropertyRelative("y"), GUIContent.none); } else { EditorGUI.PropertyField(r, field, new GUIContent(node.GetPropertyName(i))); } } r.y += 18f; } } r.x = 4f; r.width = width - 8f; if (GUI.Button(r, "Delete")) { window.DeleteSelectedNode(); } GUI.EndGroup(); }