예제 #1
0
        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();
        }
예제 #3
0
        protected static void DuplicateBlock(object obj)
        {
            Flowchart flowchart = GetFlowchart();
            Block     block     = obj as Block;

            Vector2 newPosition = new Vector2(block.nodeRect.position.x +
                                              block.nodeRect.width + 20,
                                              block.nodeRect.y);

            Block oldBlock = block;

            Block newBlock = FlowchartWindow.CreateBlock(flowchart, newPosition);

            newBlock.blockName = flowchart.GetUniqueBlockKey(oldBlock.blockName + " (Copy)");

            Undo.RecordObject(newBlock, "Duplicate Block");

            foreach (Command command in oldBlock.commandList)
            {
                if (ComponentUtility.CopyComponent(command))
                {
                    if (ComponentUtility.PasteComponentAsNew(flowchart.gameObject))
                    {
                        Command[] commands      = flowchart.GetComponents <Command>();
                        Command   pastedCommand = commands.Last <Command>();
                        if (pastedCommand != null)
                        {
                            pastedCommand.itemId = flowchart.NextItemId();
                            newBlock.commandList.Add(pastedCommand);
                        }
                    }

                    // This stops the user pasting the command manually into another game object.
                    ComponentUtility.CopyComponent(flowchart.transform);
                }
            }

            if (oldBlock.eventHandler != null)
            {
                if (ComponentUtility.CopyComponent(oldBlock.eventHandler))
                {
                    if (ComponentUtility.PasteComponentAsNew(flowchart.gameObject))
                    {
                        EventHandler[] eventHandlers      = flowchart.GetComponents <EventHandler>();
                        EventHandler   pastedEventHandler = eventHandlers.Last <EventHandler>();
                        if (pastedEventHandler != null)
                        {
                            pastedEventHandler.parentBlock = newBlock;
                            newBlock.eventHandler          = pastedEventHandler;
                        }
                    }
                }
            }
        }
예제 #4
0
        protected static void ExportReferenceDocs()
        {
            string path = EditorUtility.SaveFolderPanel("Export Reference Docs", "", "");

            if (path.Length == 0)
            {
                return;
            }

            ExportCommandInfo(path);
            ExportEventHandlerInfo(path);

            FlowchartWindow.ShowNotification("Exported Reference Documentation");
        }
        protected static void DuplicateBlock(object obj)
        {
            Flowchart flowchart = GetFlowchart();
            Block     block     = obj as Block;

            Vector2 newPosition = new Vector2(block.nodeRect.position.x +
                                              block.nodeRect.width + 20,
                                              block.nodeRect.y);

            Block oldBlock = block;

            Block newBlock = FlowchartWindow.CreateBlock(flowchart, newPosition);

            newBlock.blockName = flowchart.GetUniqueBlockKey(oldBlock.blockName + " (Copy)");

            Undo.RecordObject(newBlock, "Duplicate Block");

            foreach (Command command in oldBlock.commandList)
            {
                System.Type type       = command.GetType();
                Command     newCommand = Undo.AddComponent(flowchart.gameObject, type) as Command;
                System.Reflection.FieldInfo[] fields = type.GetFields();
                foreach (System.Reflection.FieldInfo field in fields)
                {
                    field.SetValue(newCommand, field.GetValue(command));
                }
                newCommand.itemId = flowchart.NextItemId();
                newBlock.commandList.Add(newCommand);
            }

            if (oldBlock.eventHandler != null)
            {
                EventHandler eventHandler            = oldBlock.eventHandler;
                System.Type  type                    = eventHandler.GetType();
                EventHandler newEventHandler         = Undo.AddComponent(flowchart.gameObject, type) as EventHandler;
                System.Reflection.FieldInfo[] fields = type.GetFields();
                foreach (System.Reflection.FieldInfo field in fields)
                {
                    field.SetValue(newEventHandler, field.GetValue(eventHandler));
                }
                newEventHandler.parentBlock = newBlock;
                newBlock.eventHandler       = newEventHandler;
            }
        }
예제 #6
0
        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();
        }
예제 #7
0
        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;
        }
예제 #9
0
 protected virtual void ShowNotification(Localization localization)
 {
     FlowchartWindow.ShowNotification(localization.notificationText);
     localization.notificationText = "";
 }
예제 #10
0
        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);
            }
        }