Example #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            VariablePropertyAttribute variableProperty = attribute as VariablePropertyAttribute;

            EditorGUI.BeginProperty(position, label, property);

            // Filter the variables by the types listed in the VariableProperty attribute
            Func <Variable, bool> compare = v =>
            {
                if (variableProperty.VariableTypes.Length == 0)
                {
                    return(true);
                }
                DebugLog.print(variableProperty.ToString());
                return(variableProperty.VariableTypes.Contains <System.Type>(v.GetType()));
            };

            VariableEditor.VariableField(property,
                                         label,
                                         FungusScriptWindow.GetFungusScript(),
                                         compare,
                                         (s, t, u) => (EditorGUI.Popup(position, s, t, u)));

            EditorGUI.EndProperty();
        }
        protected static void DuplicateSequence(object obj)
        {
            FungusScript fungusScript = GetFungusScript();
            Sequence     sequence     = obj as Sequence;

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

            Sequence oldSequence = sequence;

            Sequence newSequence = FungusScriptWindow.CreateSequence(fungusScript, newPosition);

            newSequence.sequenceName = fungusScript.GetUniqueSequenceKey(oldSequence.sequenceName + " (Copy)");

            Undo.RecordObject(newSequence, "Duplicate Sequence");

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

            if (oldSequence.eventHandler != null)
            {
                EventHandler eventHandler            = oldSequence.eventHandler;
                System.Type  type                    = eventHandler.GetType();
                EventHandler newEventHandler         = Undo.AddComponent(fungusScript.gameObject, type) as EventHandler;
                System.Reflection.FieldInfo[] fields = type.GetFields();
                foreach (System.Reflection.FieldInfo field in fields)
                {
                    field.SetValue(newEventHandler, field.GetValue(eventHandler));
                }
                newEventHandler.parentSequence = newSequence;
                newSequence.eventHandler       = newEventHandler;
            }
        }
Example #3
0
        public override void DrawCommandGUI()
        {
            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            serializedObject.Update();

            EditorGUILayout.PropertyField(durationProp);

            SequenceEditor.SequenceField(targetSequenceProp,
                                         new GUIContent("Target Sequence", "Sequence to call when timer expires"),
                                         new GUIContent("<None>"),
                                         fungusScript);

            serializedObject.ApplyModifiedProperties();
        }
        Command AddNewCommand()
        {
            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return(null);
            }

            Sequence sequence = fungusScript.selectedSequence;

            if (sequence == null)
            {
                return(null);
            }

            Command newCommand = sequence.gameObject.AddComponent <Note>() as Command;

            fungusScript.selectedCommand = newCommand;

            return(newCommand);
        }
Example #5
0
        Command AddNewCommand()
        {
            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return(null);
            }

            Sequence sequence = fungusScript.selectedSequence;

            if (sequence == null)
            {
                return(null);
            }

            Command newCommand = Undo.AddComponent <Comment>(sequence.gameObject) as Command;

            fungusScript.ClearSelectedCommands();
            fungusScript.AddSelectedCommand(newCommand);

            return(newCommand);
        }
Example #6
0
        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;
            }

            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            // Highlight if an active or selected command is referencing this variable
            bool highlight = false;

            if (fungusScript.selectedSequence != null)
            {
                if (Application.isPlaying && fungusScript.selectedSequence.IsExecuting())
                {
                    highlight = fungusScript.selectedSequence.activeCommand.HasReference(variable);
                }
                else if (!Application.isPlaying && fungusScript.selectedCommands.Count > 0)
                {
                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        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 = fungusScript.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;
        }
Example #7
0
        public void DrawItem(Rect position, int index)
        {
            Variable variable = this[index].objectReferenceValue as Variable;

            if (variable == null)
            {
                return;
            }

            float width1 = 100;
            float width3 = 50;
            float width2 = Mathf.Max(position.width - width1 - width3, 60);

            Rect keyRect = position;

            keyRect.width = width1;

            Rect valueRect = position;

            valueRect.x    += width1 + 5;
            valueRect.width = width2 - 5;

            Rect scopeRect = position;

            scopeRect.x    += width1 + width2 + 5;
            scopeRect.width = width3 - 5;

            string type = "";

            if (variable.GetType() == typeof(BooleanVariable))
            {
                type = "Boolean";
            }
            else if (variable.GetType() == typeof(IntegerVariable))
            {
                type = "Integer";
            }
            else if (variable.GetType() == typeof(FloatVariable))
            {
                type = "Float";
            }
            else if (variable.GetType() == typeof(StringVariable))
            {
                type = "String";
            }

            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            bool highlight = false;

            // Is an executing command referencing this variable?
            if (Application.isPlaying)
            {
                if (fungusScript.executingSequence != null &&
                    fungusScript.executingSequence.activeCommand != null)
                {
                    if (fungusScript.executingSequence.activeCommand.HasReference(variable))
                    {
                        highlight = true;
                    }
                }
            }
            else
            {
                // Is an expanded command referencing this variable?
                if (fungusScript.selectedSequence != null &&
                    fungusScript.selectedCommand != null)
                {
                    foreach (Command command in fungusScript.selectedSequence.commandList)
                    {
                        if (fungusScript.selectedCommand == command &&
                            command.HasReference(variable))
                        {
                            highlight = true;
                        }
                    }
                }
            }

            if (highlight)
            {
                GUI.backgroundColor = Color.green;
                GUI.Box(position, "");
            }

            string        key   = variable.key;
            VariableScope scope = variable.scope;

            if (Application.isPlaying)
            {
                GUI.Label(keyRect, variable.key);

                if (variable.GetType() == typeof(BooleanVariable))
                {
                    BooleanVariable v = variable as BooleanVariable;
                    v.Value = EditorGUI.Toggle(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(IntegerVariable))
                {
                    IntegerVariable v = variable as IntegerVariable;
                    v.Value = EditorGUI.IntField(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(FloatVariable))
                {
                    FloatVariable v = variable as FloatVariable;
                    v.Value = EditorGUI.FloatField(valueRect, v.Value);
                }
                else if (variable.GetType() == typeof(StringVariable))
                {
                    StringVariable v = variable as StringVariable;
                    v.Value = EditorGUI.TextField(valueRect, v.Value);
                }

                if (scope == VariableScope.Local)
                {
                    GUI.Label(scopeRect, "Local");
                }
                else if (scope == VariableScope.Global)
                {
                    GUI.Label(scopeRect, "Global");
                }
            }
            else
            {
                key = EditorGUI.TextField(keyRect, variable.key);
                GUI.Label(valueRect, type);
                scope = (VariableScope)EditorGUI.EnumPopup(scopeRect, variable.scope);

                // To access properties in a monobehavior, you have new a SerializedObject
                // http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html
                SerializedObject   variableObject = new SerializedObject(this[index].objectReferenceValue);
                SerializedProperty keyProp        = variableObject.FindProperty("key");
                SerializedProperty scopeProp      = variableObject.FindProperty("scope");

                variableObject.Update();
                keyProp.stringValue      = fungusScript.GetUniqueVariableKey(key, variable);
                scopeProp.enumValueIndex = (int)scope;
                variableObject.ApplyModifiedProperties();
            }

            GUI.backgroundColor = Color.white;
        }
Example #8
0
        public static void DrawView(View view)
        {
            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;

            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript != null)
            {
                foreach (Command command in fungusScript.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;
            }

            // 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);
            }
        }