public static void AddVariable(object obj, string suggestedName) { System.Type t = obj as System.Type; if (t == null) { return; } var flowchart = curFlowchart != null ? curFlowchart : FlowchartWindow.GetFlowchart(); Undo.RecordObject(flowchart, "Add Variable"); Variable newVariable = flowchart.gameObject.AddComponent(t) as Variable; newVariable.Key = flowchart.GetUniqueVariableKey(suggestedName); //if suggested exists, then insert, if not just add var existingVariable = flowchart.GetVariable(suggestedName); if (existingVariable != null) { flowchart.Variables.Insert(flowchart.Variables.IndexOf(existingVariable) + 1, newVariable); } else { flowchart.Variables.Add(newVariable); } // Because this is an async call, we need to force prefab instances to record changes PrefabUtility.RecordPrefabInstancePropertyModifications(flowchart); }
public override void DrawCommandGUI() { var 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); EditorGUILayout.PropertyField(hideThisOptionProp); 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) { var compatChecker = property.serializedObject.targetObject as ICollectionCompatible; if (compatChecker != null) { return(compatChecker.IsVarCompatibleWithCollection(v, variableProperty.compatibleVariableName)); } else { return(true); } } return(variableProperty.VariableTypes.Contains <System.Type>(v.GetType())); }; VariableEditor.VariableField(property, label, FlowchartWindow.GetFlowchart(), variableProperty.defaultText, compare, (s, t, u) => (EditorGUI.Popup(position, s, t, u))); EditorGUI.EndProperty(); }
public override void DrawCommandGUI() { var flowchart = FlowchartWindow.GetFlowchart(); if (flowchart == null) { return; } serializedObject.Update(); EditorGUILayout.PropertyField(textProp); EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.BeginHorizontal(); BlockEditor.BlockField(targetBlockProp, new GUIContent("Target Block", "Block to call when option is selected"), new GUIContent("<None>"), flowchart); const int popupWidth = 17; if (targetBlockProp.objectReferenceValue == null && GUILayout.Button("+", GUILayout.MaxWidth(popupWidth))) { var fw = EditorWindow.GetWindow <FlowchartWindow>(); var t = (Menu)target; var activeFlowchart = t.GetFlowchart(); var newBlock = fw.CreateBlockSuppressSelect(activeFlowchart, t.ParentBlock._NodeRect.position - Vector2.down * 60); targetBlockProp.objectReferenceValue = newBlock; activeFlowchart.SelectedBlock = t.ParentBlock; } EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(hideIfVisitedProp); EditorGUILayout.PropertyField(interactableProp); EditorGUILayout.PropertyField(setMenuDialogProp); EditorGUILayout.PropertyField(hideThisOptionProp); serializedObject.ApplyModifiedProperties(); }
public override void DrawCommandGUI() { var 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); } var block = flowchart.SelectedBlock; if (block == null) { return(null); } var 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; } int width = widthOfList; int totalRatio = DefaultWidth; float[] widths = { (80.0f / totalRatio) * width, (100.0f / totalRatio) * width, (140.0f / totalRatio) * width, (60.0f / totalRatio) * width }; 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; } var 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"); SerializedProperty defaultProp = variableObject.FindProperty("value"); SerializedProperty scopeProp = variableObject.FindProperty("scope"); keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable); bool isGlobal = scopeProp.enumValueIndex == (int)VariableScope.Global; if (isGlobal && Application.isPlaying) { var res = FungusManager.Instance.GlobalVariables.GetVariable(keyProp.stringValue); if (res != null) { SerializedObject globalValue = new SerializedObject(res); var globalValProp = globalValue.FindProperty("value"); var prevEnabled = GUI.enabled; GUI.enabled = false; EditorGUI.PropertyField(rects[2], globalValProp, new GUIContent("")); GUI.enabled = prevEnabled; } } else { EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent("")); } 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; var flowchart = FlowchartWindow.GetFlowchart(); if (flowchart != null) { var selectedCommands = flowchart.SelectedCommands; foreach (var command in 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); } }