public override void DrawCommandGUI() { Flowchart flowchart = FlowchartWindow.GetFlowchart(); if (flowchart == null) { return; } serializedObject.Update(); EditorGUILayout.PropertyField(textProp); EditorGUILayout.PropertyField(descriptionProp); BlockEditor.BlockField(targetBlockProp, new GUIContent("Target Block", "Block to call when option is selected"), new GUIContent("<None>"), flowchart); EditorGUILayout.PropertyField(hideIfVisitedProp); EditorGUILayout.PropertyField(interactableProp); EditorGUILayout.PropertyField(setMenuDialogProp); serializedObject.ApplyModifiedProperties(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { VariablePropertyAttribute variableProperty = attribute as VariablePropertyAttribute; if (variableProperty == null) { return; } EditorGUI.BeginProperty(position, label, property); // Filter the variables by the types listed in the VariableProperty attribute Func <Variable, bool> compare = v => { if (v == null) { return(false); } if (variableProperty.VariableTypes.Length == 0) { return(true); } return(variableProperty.VariableTypes.Contains <System.Type>(v.GetType())); }; VariableEditor.VariableField(property, label, FlowchartWindow.GetFlowchart(), compare, (s, t, u) => (EditorGUI.Popup(position, s, t, u))); EditorGUI.EndProperty(); }
public override void DrawCommandGUI() { Flowchart flowchart = FlowchartWindow.GetFlowchart(); if (flowchart == null) { return; } serializedObject.Update(); EditorGUILayout.PropertyField(durationProp); BlockEditor.BlockField(targetBlockProp, new GUIContent("Target Block", "Block to call when timer expires"), new GUIContent("<None>"), flowchart); serializedObject.ApplyModifiedProperties(); }
Command AddNewCommand() { Flowchart flowchart = FlowchartWindow.GetFlowchart(); if (flowchart == null) { return(null); } Block block = flowchart.selectedBlock; if (block == null) { return(null); } Command newCommand = Undo.AddComponent <Comment>(block.gameObject) as Command; newCommand.itemId = flowchart.NextItemId(); flowchart.ClearSelectedCommands(); flowchart.AddSelectedCommand(newCommand); return(newCommand); }
public void DrawItem(Rect position, int index) { Variable variable = this[index].objectReferenceValue as Variable; if (variable == null) { return; } float[] widths = { 80, 100, 140, 60 }; Rect[] rects = new Rect[4]; for (int i = 0; i < 4; ++i) { rects[i] = position; rects[i].width = widths[i] - 5; for (int j = 0; j < i; ++j) { rects[i].x += widths[j]; } } VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(variable.GetType()); if (variableInfo == null) { return; } Flowchart flowchart = FlowchartWindow.GetFlowchart(); if (flowchart == null) { return; } // Highlight if an active or selected command is referencing this variable bool highlight = false; if (flowchart.selectedBlock != null) { if (Application.isPlaying && flowchart.selectedBlock.IsExecuting()) { highlight = flowchart.selectedBlock.activeCommand.HasReference(variable); } else if (!Application.isPlaying && flowchart.selectedCommands.Count > 0) { foreach (Command selectedCommand in flowchart.selectedCommands) { if (selectedCommand == null) { continue; } if (selectedCommand.HasReference(variable)) { highlight = true; break; } } } } if (highlight) { GUI.backgroundColor = Color.green; GUI.Box(position, ""); } string key = variable.key; VariableScope scope = variable.scope; // To access properties in a monobehavior, you have to new a SerializedObject // http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html SerializedObject variableObject = new SerializedObject(this[index].objectReferenceValue); variableObject.Update(); GUI.Label(rects[0], variableInfo.VariableType); key = EditorGUI.TextField(rects[1], variable.key); SerializedProperty keyProp = variableObject.FindProperty("key"); keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable); SerializedProperty defaultProp = variableObject.FindProperty("value"); EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent("")); SerializedProperty scopeProp = variableObject.FindProperty("scope"); scope = (VariableScope)EditorGUI.EnumPopup(rects[3], variable.scope); scopeProp.enumValueIndex = (int)scope; variableObject.ApplyModifiedProperties(); GUI.backgroundColor = Color.white; }
public static void DrawView(View view, bool drawInterior) { float height = CalculateLocalViewSize(view); float widthA = height * (view.primaryAspectRatio.x / view.primaryAspectRatio.y); float widthB = height * (view.secondaryAspectRatio.x / view.secondaryAspectRatio.y); Color transparent = new Color(1, 1, 1, 0f); Color fill = viewColor; Color outline = viewColor; bool highlight = Selection.activeGameObject == view.gameObject; Flowchart flowchart = FlowchartWindow.GetFlowchart(); if (flowchart != null) { foreach (Command command in flowchart.selectedCommands) { MoveToView moveToViewCommand = command as MoveToView; if (moveToViewCommand != null && moveToViewCommand.targetView == view) { highlight = true; } else { FadeToView fadeToViewCommand = command as FadeToView; if (fadeToViewCommand != null && fadeToViewCommand.targetView == view) { highlight = true; } } } } if (highlight) { fill = outline = Color.green; fill.a = 0.1f; outline.a = 1f; } else { fill.a = 0.1f; outline.a = 0.5f; } if (drawInterior) { // Draw left box { Vector3[] verts = new Vector3[4]; verts[0] = view.transform.TransformPoint(new Vector3(-widthB, -height, 0)); verts[1] = view.transform.TransformPoint(new Vector3(-widthB, height, 0)); verts[2] = view.transform.TransformPoint(new Vector3(-widthA, height, 0)); verts[3] = view.transform.TransformPoint(new Vector3(-widthA, -height, 0)); Handles.DrawSolidRectangleWithOutline(verts, fill, transparent); } // Draw right box { Vector3[] verts = new Vector3[4]; verts[0] = view.transform.TransformPoint(new Vector3(widthA, -height, 0)); verts[1] = view.transform.TransformPoint(new Vector3(widthA, height, 0)); verts[2] = view.transform.TransformPoint(new Vector3(widthB, height, 0)); verts[3] = view.transform.TransformPoint(new Vector3(widthB, -height, 0)); Handles.DrawSolidRectangleWithOutline(verts, fill, transparent); } // Draw inner box { Vector3[] verts = new Vector3[4]; verts[0] = view.transform.TransformPoint(new Vector3(-widthA, -height, 0)); verts[1] = view.transform.TransformPoint(new Vector3(-widthA, height, 0)); verts[2] = view.transform.TransformPoint(new Vector3(widthA, height, 0)); verts[3] = view.transform.TransformPoint(new Vector3(widthA, -height, 0)); Handles.DrawSolidRectangleWithOutline(verts, transparent, outline); } } // Draw outer box { Vector3[] verts = new Vector3[4]; verts[0] = view.transform.TransformPoint(new Vector3(-widthB, -height, 0)); verts[1] = view.transform.TransformPoint(new Vector3(-widthB, height, 0)); verts[2] = view.transform.TransformPoint(new Vector3(widthB, height, 0)); verts[3] = view.transform.TransformPoint(new Vector3(widthB, -height, 0)); Handles.DrawSolidRectangleWithOutline(verts, transparent, outline); } }