Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        internal static void Export()
        {
            ExportCommandInfo();
            ExportEventHandlerInfo();

            FlowchartWindow.ShowNotification("Exported Reference Documentation");
        }
Ejemplo n.º 4
0
        protected static void ExportReferenceDocs()
        {
            const string path = "./Docs";

            ExportCommandInfo(path);
            ExportEventHandlerInfo(path);

            FlowchartWindow.ShowNotification("Exported Reference Documentation");
        }
Ejemplo n.º 5
0
        protected static void DuplicateBlock(object obj)
        {
            var   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");

            var commandList = oldBlock.CommandList;

            foreach (var command in 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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        internal static void ConvertAllToGHMD()
        {
            var files = Directory.GetFiles(BaseDocPath, "*.md", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                ConvertFileToGHMD(file);
            }

            FlowchartWindow.ShowNotification("Converted " + files.Length.ToString() + " to Github MD");
        }
Ejemplo n.º 7
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");
        }
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button(new GUIContent("Delete Save Data", "Deletes the save data associated with the Save Data Key from PlayerPrefs")))
            {
                var saveMenu = target as SaveMenu;

                if (saveMenu != null)
                {
                    PlayerPrefs.DeleteKey(saveMenu.SaveDataKey);
                    FlowchartWindow.ShowNotification("Deleted Save Data");
                }
            }

            base.OnInspectorGUI();
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
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;

            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);
            }
        }
Ejemplo n.º 15
0
 protected virtual void ShowNotification(Localization localization)
 {
     FlowchartWindow.ShowNotification(localization.NotificationText);
     localization.NotificationText = "";
 }