public override void DrawCommandGUI() { serializedObject.Update(); bool showPortraits = false; CommandEditor.ObjectField <Character>(characterProp, new GUIContent("Character", "Character that is speaking"), new GUIContent("<None>"), Character.activeCharacters); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); characterProp.objectReferenceValue = (Character)EditorGUILayout.ObjectField(characterProp.objectReferenceValue, typeof(Character), true); EditorGUILayout.EndHorizontal(); Say t = target as Say; // Only show portrait selection if... if (t.character != null && // Character is selected t.character.portraits != null && // Character has a portraits field t.character.portraits.Count > 0) // Selected Character has at least 1 portrait { showPortraits = true; } if (showPortraits) { CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing speaking character"), new GUIContent("<None>"), t.character.portraits); } else { if (!t.extendPrevious) { t.portrait = null; } } EditorGUILayout.PropertyField(storyTextProp); EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(extendPreviousProp); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "View available tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); if (showTagHelp) { DrawTagHelpLabel(); } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the text is displayed")); EditorGUILayout.PropertyField(showAlwaysProp); if (showAlwaysProp.boolValue == false) { EditorGUILayout.PropertyField(showCountProp); } GUIStyle centeredLabel = new GUIStyle(EditorStyles.label); centeredLabel.alignment = TextAnchor.MiddleCenter; GUIStyle leftButton = new GUIStyle(EditorStyles.miniButtonLeft); leftButton.fontSize = 10; leftButton.font = EditorStyles.toolbarButton.font; GUIStyle rightButton = new GUIStyle(EditorStyles.miniButtonRight); rightButton.fontSize = 10; rightButton.font = EditorStyles.toolbarButton.font; EditorGUILayout.PropertyField(fadeWhenDoneProp); EditorGUILayout.PropertyField(waitForClickProp); EditorGUILayout.PropertyField(stopVoiceoverProp); EditorGUILayout.PropertyField(setSayDialogProp); if (showPortraits && t.portrait != null) { Texture2D characterTexture = t.portrait.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); if (characterTexture != null) { GUI.DrawTexture(previewRect, characterTexture, ScaleMode.ScaleToFit, true, aspect); } } serializedObject.ApplyModifiedProperties(); }
public override void DrawCommandGUI() { serializedObject.Update(); Say t = target as Say; CommandEditor.ObjectField <Character>(characterProp, new GUIContent("Character", "Character to display in dialog"), new GUIContent("<None>"), Character.activeCharacters); CommandEditor.ObjectField <SayDialog>(sayDialogProp, new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"), new GUIContent("<Default>"), SayDialog.activeDialogs); bool showPortraits = false; // Only show portrait selection if... if (t.character != null && // Character is selected t.character.portraits != null && // Character has a portraits field t.character.portraits.Count > 0) // Selected Character has at least 1 portrait { showPortraits = true; } if (showPortraits) { CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing speaking character"), new GUIContent("<None>"), t.character.portraits); } else { t.portrait = null; } EditorGUILayout.PropertyField(storyTextProp); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); if (showTagHelp) { DrawTagHelpLabel(); } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed")); EditorGUILayout.PropertyField(showAlwaysProp); if (showAlwaysProp.boolValue == false) { EditorGUILayout.PropertyField(showCountProp); } EditorGUILayout.PropertyField(waitForInputProp); if (showPortraits && t.portrait != null) { Texture2D characterTexture = t.portrait.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; characterEditor.DrawPreview(previewRect, characterTexture); DestroyImmediate(characterEditor); } serializedObject.ApplyModifiedProperties(); }
public void DrawItem(Rect position, int index) { Command command = this[index].objectReferenceValue as Command; if (command == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType()); if (commandInfoAttr == null) { return; } FungusScript fungusScript = command.GetFungusScript(); if (fungusScript == null) { return; } bool isComment = (command.GetType() == typeof(Comment)); bool isLabel = (command.GetType() == typeof(Label)); bool error = false; string summary = command.GetSummary(); if (summary == null) { summary = ""; } else { summary = summary.Replace("\n", "").Replace("\r", ""); } if (summary.StartsWith("Error:")) { error = true; } if (isComment || isLabel) { summary = "<b> " + summary + "</b>"; } else { summary = "<i>" + summary + "</i>"; } bool commandIsSelected = false; foreach (Command selectedCommand in fungusScript.selectedCommands) { if (selectedCommand == command) { commandIsSelected = true; break; } } string commandName = commandInfoAttr.CommandName; GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box); commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground; commandLabelStyle.border.top = 1; commandLabelStyle.border.bottom = 1; commandLabelStyle.border.left = 1; commandLabelStyle.border.right = 1; commandLabelStyle.alignment = TextAnchor.MiddleLeft; commandLabelStyle.richText = true; commandLabelStyle.fontSize = 11; commandLabelStyle.padding.top -= 1; float indentSize = 20; for (int i = 0; i < command.indentLevel; ++i) { Rect indentRect = position; indentRect.x += i * indentSize - 21; indentRect.width = indentSize + 1; indentRect.y -= 2; indentRect.height += 5; GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f); GUI.Box(indentRect, "", commandLabelStyle); } float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f); float indentWidth = command.indentLevel * indentSize; Rect commandLabelRect = position; commandLabelRect.x += indentWidth - 21; commandLabelRect.y -= 2; commandLabelRect.width -= (indentSize * command.indentLevel - 22); commandLabelRect.height += 5; // Select command via left click if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition)) { if (fungusScript.selectedCommands.Contains(command) && Event.current.button == 0) { // Left click on an already selected command fungusScript.selectedCommands.Remove(command); } else { // Left click and no command key if (!EditorGUI.actionKey && Event.current.button == 0) { fungusScript.ClearSelectedCommands(); } fungusScript.AddSelectedCommand(command); } GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } Color commandLabelColor = Color.white; if (fungusScript.colorCommands) { commandLabelColor = command.GetButtonColor(); } if (commandIsSelected) { commandLabelColor = Color.green; } else if (!command.enabled) { commandLabelColor = Color.grey; } else if (error) { // TODO: Show warning icon } GUI.backgroundColor = commandLabelColor; if (isComment || isLabel) { GUI.Label(commandLabelRect, "", commandLabelStyle); } else { GUI.Label(commandLabelRect, commandName, commandLabelStyle); } if (command.IsExecuting()) { Rect iconRect = new Rect(commandLabelRect); iconRect.x += iconRect.width - commandLabelRect.width - 20; iconRect.width = 20; iconRect.height = 20; GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle()); } Rect summaryRect = new Rect(commandLabelRect); if (!isComment && !isLabel) { summaryRect.x += commandNameWidth; summaryRect.width -= commandNameWidth; summaryRect.width -= 5; } GUIStyle summaryStyle = new GUIStyle(); summaryStyle.fontSize = 10; summaryStyle.padding.top += 5; summaryStyle.richText = true; summaryStyle.wordWrap = false; summaryStyle.clipping = TextClipping.Clip; GUI.Label(summaryRect, summary, summaryStyle); if (error) { GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector); Rect errorRect = new Rect(summaryRect); errorRect.x += errorRect.width - 20; errorRect.y += 2; errorRect.width = 20; GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background); summaryRect.width -= 20; } GUI.backgroundColor = Color.white; }
public override void DrawCommandGUI() { serializedObject.Update(); Portrait t = target as Portrait; if (Stage.activeStages.Count > 1) { CommandEditor.ObjectField <Stage>(stageProp, new GUIContent("Portrait Stage", "Stage to display the character portraits on"), new GUIContent("<Default>"), Stage.activeStages); } else { t.stage = null; } // Format Enum names string[] displayLabels = StringFormatter.FormatEnumNames(t.display, "<None>"); displayProp.enumValueIndex = EditorGUILayout.Popup("Display", (int)displayProp.enumValueIndex, displayLabels); string characterLabel = "Character"; if (t.display == DisplayType.Replace) { CommandEditor.ObjectField <Character>(replacedCharacterProp, new GUIContent("Replace", "Character to replace"), new GUIContent("<None>"), Character.activeCharacters); characterLabel = "With"; } CommandEditor.ObjectField <Character>(characterProp, new GUIContent(characterLabel, "Character to display"), new GUIContent("<None>"), Character.activeCharacters); bool showOptionalFields = true; Stage s = t.stage; // Only show optional portrait fields once required fields have been filled... if (t.character != null) // Character is selected { if (t.character.portraits == null || // Character has a portraits field t.character.portraits.Count <= 0) // Character has at least one portrait { EditorGUILayout.HelpBox("This character has no portraits. Please add portraits to the character's prefab before using this command.", MessageType.Error); showOptionalFields = false; } if (t.stage == null) // If default portrait stage selected { if (t.stage == null) // If no default specified, try to get any portrait stage in the scene { s = GameObject.FindObjectOfType <Stage>(); } } if (s == null) { EditorGUILayout.HelpBox("No portrait stage has been set.", MessageType.Error); showOptionalFields = false; } } if (t.display != DisplayType.None && t.character != null && showOptionalFields) { if (t.display != DisplayType.Hide && t.display != DisplayType.MoveToFront) { // PORTRAIT CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing character"), new GUIContent("<Previous>"), t.character.portraits); if (t.character.portraitsFace != FacingDirection.None) { // FACING // Display the values of the facing enum as <-- and --> arrows to avoid confusion with position field string[] facingArrows = new string[] { "<Previous>", "<--", "-->", }; facingProp.enumValueIndex = EditorGUILayout.Popup("Facing", (int)facingProp.enumValueIndex, facingArrows); } else { t.facing = FacingDirection.None; } } else { t.portrait = null; t.facing = FacingDirection.None; } string toPositionPrefix = ""; if (t.move) { // MOVE EditorGUILayout.PropertyField(moveProp); } if (t.move) { if (t.display != DisplayType.Hide) { // START FROM OFFSET EditorGUILayout.PropertyField(shiftIntoPlaceProp); } } if (t.move) { if (t.display != DisplayType.Hide) { if (t.shiftIntoPlace) { t.fromPosition = null; // OFFSET // Format Enum names string[] offsetLabels = StringFormatter.FormatEnumNames(t.offset, "<Previous>"); offsetProp.enumValueIndex = EditorGUILayout.Popup("From Offset", (int)offsetProp.enumValueIndex, offsetLabels); } else { t.offset = PositionOffset.None; // FROM POSITION CommandEditor.ObjectField <RectTransform>(fromPositionProp, new GUIContent("From Position", "Move the portrait to this position"), new GUIContent("<Previous>"), s.positions); } } toPositionPrefix = "To "; } else { t.shiftIntoPlace = false; t.fromPosition = null; toPositionPrefix = "At "; } if (t.display == DisplayType.Show || (t.display == DisplayType.Hide && t.move)) { // TO POSITION CommandEditor.ObjectField <RectTransform>(toPositionProp, new GUIContent(toPositionPrefix + "Position", "Move the portrait to this position"), new GUIContent("<Previous>"), s.positions); } else { t.toPosition = null; } if (!t.move && t.display != DisplayType.MoveToFront) { // MOVE EditorGUILayout.PropertyField(moveProp); } if (t.display != DisplayType.MoveToFront) { EditorGUILayout.Separator(); // USE DEFAULT SETTINGS EditorGUILayout.PropertyField(useDefaultSettingsProp); if (!t.useDefaultSettings) { // FADE DURATION EditorGUILayout.PropertyField(fadeDurationProp); if (t.move) { // MOVE SPEED EditorGUILayout.PropertyField(moveSpeedProp); } if (t.shiftIntoPlace) { // SHIFT OFFSET EditorGUILayout.PropertyField(shiftOffsetProp); } } } else { t.move = false; t.useDefaultSettings = true; EditorGUILayout.Separator(); } EditorGUILayout.PropertyField(waitUntilFinishedProp); if (t.portrait != null && t.display != DisplayType.Hide) { Texture2D characterTexture = t.portrait.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); if (characterTexture != null) { GUI.DrawTexture(previewRect, characterTexture, ScaleMode.ScaleToFit, true, aspect); } } if (t.display != DisplayType.Hide) { string portraitName = "<Previous>"; if (t.portrait != null) { portraitName = t.portrait.name; } string portraitSummary = " " + portraitName; int toolbarInt = 1; string[] toolbarStrings = { "<--", portraitSummary, "-->" }; toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.MinHeight(20)); int portraitIndex = -1; if (toolbarInt != 1) { for (int i = 0; i < t.character.portraits.Count; i++) { if (portraitName == t.character.portraits[i].name) { portraitIndex = i; } } } if (toolbarInt == 0) { if (portraitIndex > 0) { t.portrait = t.character.portraits[--portraitIndex]; } else { t.portrait = null; } } if (toolbarInt == 2) { if (portraitIndex < t.character.portraits.Count - 1) { t.portrait = t.character.portraits[++portraitIndex]; } } } } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); FungusScript t = target as FungusScript; t.UpdateHideFlags(); if (Application.isPlaying) { if (t.executingSequence == null) { t.selectedCommand = null; } else { t.selectedCommand = t.executingSequence.activeCommand; } } EditorGUILayout.PropertyField(stepTimeProp, new GUIContent("Step Time", "Minimum time to execute each step")); SequenceEditor.SequenceField(startSequenceProp, new GUIContent("Start Sequence", "Sequence to be executed when controller starts."), new GUIContent("<None>"), t); if (t.startSequence == null) { GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = new Color(1, 0, 0); EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); } EditorGUILayout.PropertyField(executeOnStartProp, new GUIContent("Execute On Start", "Execute this Fungus Script when the scene starts.")); EditorGUILayout.PropertyField(colorCommandsProp, new GUIContent("Color Commands", "Display commands using colors in editor window.")); EditorGUILayout.PropertyField(showSequenceObjectsProp, new GUIContent("Show Sequence Objects", "Display the child Sequence game objects in the hierarchy view.")); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Editor")) { EditorWindow.GetWindow(typeof(FungusScriptWindow), false, "Fungus Script"); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.Separator(); if (t.selectedCommand != null) { CommandEditor commandEditor = Editor.CreateEditor(t.selectedCommand) as CommandEditor; commandEditor.DrawCommandInspectorGUI(); DestroyImmediate(commandEditor); } EditorGUILayout.Separator(); DrawVariablesGUI(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { BlockInspector blockInspector = target as BlockInspector; Block block = blockInspector.block; if (block == null) { return; } Flowchart flowchart = block.GetFlowchart(); BlockEditor blockEditor = Editor.CreateEditor(block) as BlockEditor; blockEditor.DrawBlockName(flowchart); // Using a custom rect area to get the correct 5px indent for the scroll views Rect blockRect = new Rect(5, topPanelHeight, Screen.width - 6, Screen.height - 70); GUILayout.BeginArea(blockRect); blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.blockViewHeight)); blockEditor.DrawBlockGUI(flowchart); GUILayout.EndScrollView(); Command inspectCommand = null; if (flowchart.selectedCommands.Count == 1) { inspectCommand = flowchart.selectedCommands[0]; } if (Application.isPlaying && inspectCommand != null && inspectCommand.parentBlock != block) { GUILayout.EndArea(); Repaint(); DestroyImmediate(blockEditor); return; } ResizeScrollView(flowchart); GUILayout.Space(7); blockEditor.DrawButtonToolbar(); commandScrollPos = GUILayout.BeginScrollView(commandScrollPos); if (inspectCommand != null) { CommandEditor commandEditor = Editor.CreateEditor(inspectCommand) as CommandEditor; commandEditor.DrawCommandInspectorGUI(); DestroyImmediate(commandEditor); } GUILayout.EndScrollView(); GUILayout.EndArea(); // Draw the resize bar after everything else has finished drawing // This is mainly to avoid incorrect indenting. Rect resizeRect = new Rect(0, topPanelHeight + flowchart.blockViewHeight + 1, Screen.width, 4f); GUI.color = new Color(0.64f, 0.64f, 0.64f); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.height = 1; GUI.color = new Color32(132, 132, 132, 255); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.y += 3; GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); GUI.color = Color.white; Repaint(); DestroyImmediate(blockEditor); }
public void DrawSequenceGUI(FungusScript fungusScript) { if (fungusScript.selectedSequence == null) { return; } serializedObject.Update(); Sequence sequence = fungusScript.selectedSequence; EditorGUI.BeginChangeCheck(); string sequenceName = EditorGUILayout.TextField(new GUIContent("Name", "Name of sequence object"), sequence.gameObject.name); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sequence.gameObject, "Set Sequence Name"); sequence.gameObject.name = sequenceName; } EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.Separator(); UpdateIndentLevels(sequence); ReorderableListGUI.Title("Command Sequence"); SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); ReorderableListControl.DrawControlFromState(adaptor, null, 0); if (Application.isPlaying) { serializedObject.ApplyModifiedProperties(); return; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (fungusScript.copyCommand != null) { if (GUILayout.Button("Paste")) { fungusScript.selectedCommand = CommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence); } } EditorGUILayout.EndHorizontal(); if (fungusScript.selectedCommand != null) { CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(fungusScript.selectedCommand.GetType()); if (infoAttr != null) { EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info); } } serializedObject.ApplyModifiedProperties(); }
public void DrawItem(Rect position, int index) { Command command = this[index].objectReferenceValue as Command; if (command == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType()); if (commandInfoAttr == null) { return; } FungusScript fungusScript = command.GetFungusScript(); if (fungusScript == null) { return; } bool error = false; string summary = command.GetSummary().Replace("\n", "").Replace("\r", ""); if (summary.Length > 80) { summary = summary.Substring(0, 80) + "..."; } if (summary.StartsWith("Error:")) { error = true; } bool selected = (Application.isPlaying && command.IsExecuting()) || (!Application.isPlaying && fungusScript.selectedCommand == command); float indentSize = 20; for (int i = 0; i < command.indentLevel; ++i) { Rect indentRect = position; indentRect.x += i * indentSize; indentRect.width = indentSize + 1; indentRect.y -= 2; indentRect.height += 5; GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.5f); GUI.Box(indentRect, ""); } string commandName = commandInfoAttr.CommandName; GUIStyle commandLabelStyle = new GUIStyle(EditorStyles.miniButtonLeft); float buttonWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 100f); float indentWidth = command.indentLevel * indentSize; Rect buttonRect = position; buttonRect.x += indentWidth; buttonRect.width = buttonWidth; buttonRect.y -= 2; buttonRect.height += 6; Rect summaryRect = buttonRect; summaryRect.x += buttonWidth - 1; summaryRect.width = position.width - buttonWidth - indentWidth - 15; if (!Application.isPlaying && Event.current.type == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition)) { fungusScript.selectedCommand = command; GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } Color buttonBackgroundColor = Color.white; if (fungusScript.colorCommands) { buttonBackgroundColor = command.GetButtonColor(); } Color summaryBackgroundColor = Color.white; if (selected) { summaryBackgroundColor = Color.green; buttonBackgroundColor = Color.green; } else if (!command.enabled) { buttonBackgroundColor = Color.grey; summaryBackgroundColor = Color.grey; } else if (error) { summaryBackgroundColor = Color.red; } GUI.backgroundColor = buttonBackgroundColor; GUI.Label(buttonRect, commandName, commandLabelStyle); GUIStyle summaryStyle = new GUIStyle(EditorStyles.miniButtonRight); summaryStyle.alignment = TextAnchor.MiddleLeft; if (error && !selected) { summaryStyle.normal.textColor = Color.white; } GUI.backgroundColor = summaryBackgroundColor; GUI.Box(summaryRect, summary, summaryStyle); GUI.backgroundColor = Color.white; Rect menuRect = summaryRect; menuRect.x += menuRect.width + 2; menuRect.y = position.y + 1; menuRect.width = 18; menuRect.height = position.height; GUIStyle menuButtonStyle = new GUIStyle(EditorStyles.popup); if (GUI.Button(menuRect, new GUIContent("", "Select command type"), menuButtonStyle)) { ShowCommandMenu(index, fungusScript.selectedSequence); } }
public virtual void DrawCommandInspectorGUI() { Command t = target as Command; if (t == null) { return; } FungusScript fungusScript = t.GetFungusScript(); if (fungusScript == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(t.GetType()); if (commandInfoAttr == null) { return; } GUILayout.BeginVertical(GUI.skin.box); GUI.backgroundColor = Color.green; GUILayout.BeginHorizontal(GUI.skin.button); string commandName = commandInfoAttr.CommandName; GUIStyle commandStyle = new GUIStyle(EditorStyles.miniButton); if (t.enabled) { if (fungusScript.colorCommands) { GUI.backgroundColor = t.GetButtonColor(); } else { GUI.backgroundColor = Color.white; } } else { GUI.backgroundColor = Color.grey; } bool enabled = t.enabled; if (GUILayout.Button(commandName, commandStyle, GUILayout.MinWidth(80), GUILayout.ExpandWidth(true))) { enabled = !enabled; } GUI.backgroundColor = Color.white; enabled = GUILayout.Toggle(enabled, new GUIContent()); if (t.enabled != enabled) { Undo.RecordObject(t, "Set Enabled"); t.enabled = enabled; } if (fungusScript != null) { if (GUILayout.Button("Copy", EditorStyles.miniButton)) { fungusScript.copyCommand = t; } } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; EditorGUILayout.Separator(); DrawCommandGUI(); EditorGUILayout.Separator(); if (t.errorMessage.Length > 0) { GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = new Color(1, 0, 0); EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); } GUILayout.EndVertical(); }
public virtual void DrawCommandInspectorGUI() { Command t = target as Command; if (t == null) { return; } Flowchart flowchart = t.GetFlowchart(); if (flowchart == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(t.GetType()); if (commandInfoAttr == null) { return; } GUILayout.BeginVertical(GUI.skin.box); if (t.enabled) { if (flowchart.colorCommands) { GUI.backgroundColor = t.GetButtonColor(); } else { GUI.backgroundColor = Color.white; } } else { GUI.backgroundColor = Color.grey; } GUILayout.BeginHorizontal(GUI.skin.button); string commandName = commandInfoAttr.CommandName; GUILayout.Label(commandName, GUILayout.MinWidth(80), GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); GUILayout.Label(new GUIContent("(" + t.itemId + ")")); GUILayout.Space(10); GUI.backgroundColor = Color.white; bool enabled = t.enabled; enabled = GUILayout.Toggle(enabled, new GUIContent()); if (t.enabled != enabled) { Undo.RecordObject(t, "Set Enabled"); t.enabled = enabled; } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; EditorGUILayout.Separator(); DrawCommandGUI(); EditorGUILayout.Separator(); if (t.errorMessage.Length > 0) { GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = new Color(1, 0, 0); EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); } GUILayout.EndVertical(); // Display help text CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(t.GetType()); if (infoAttr != null) { EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info, true); } }
public void DrawItem(Rect position, int index) { Command command = this[index].objectReferenceValue as Command; if (command == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType()); if (commandInfoAttr == null) { return; } Flowchart flowchart = command.GetFlowchart(); if (flowchart == null) { return; } bool isComment = command.GetType() == typeof(Comment); bool isLabel = (command.GetType() == typeof(Label)); bool error = false; string summary = command.GetSummary(); if (summary == null) { summary = ""; } else { summary = summary.Replace("\n", "").Replace("\r", ""); } if (summary.StartsWith("Error:")) { error = true; } if (isComment || isLabel) { summary = "<b> " + summary + "</b>"; } else { summary = "<i>" + summary + "</i>"; } bool commandIsSelected = false; foreach (Command selectedCommand in flowchart.selectedCommands) { if (selectedCommand == command) { commandIsSelected = true; break; } } string commandName = commandInfoAttr.CommandName; GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box); commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground; int borderSize = 5; commandLabelStyle.border.top = borderSize; commandLabelStyle.border.bottom = borderSize; commandLabelStyle.border.left = borderSize; commandLabelStyle.border.right = borderSize; commandLabelStyle.alignment = TextAnchor.MiddleLeft; commandLabelStyle.richText = true; commandLabelStyle.fontSize = 11; commandLabelStyle.padding.top -= 1; float indentSize = 20; for (int i = 0; i < command.indentLevel; ++i) { Rect indentRect = position; indentRect.x += i * indentSize - 21; indentRect.width = indentSize + 1; indentRect.y -= 2; indentRect.height += 5; GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f); GUI.Box(indentRect, "", commandLabelStyle); } float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f); float indentWidth = command.indentLevel * indentSize; Rect commandLabelRect = position; commandLabelRect.x += indentWidth - 21; commandLabelRect.y -= 2; commandLabelRect.width -= (indentSize * command.indentLevel - 22); commandLabelRect.height += 5; // There's a weird incompatibility between the Reorderable list control used for the command list and // the UnityEvent list control used in some commands. In play mode, if you click on the reordering grabber // for a command in the list it causes the UnityEvent list to spew null exception errors. // The workaround for now is to hide the reordering grabber from mouse clicks by extending the command // selection rectangle to cover it. We are planning to totally replace the command list display system. Rect clickRect = position; clickRect.x -= 20; clickRect.width += 20; // Select command via left click if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && clickRect.Contains(Event.current.mousePosition)) { if (flowchart.selectedCommands.Contains(command) && Event.current.button == 0) { // Left click on already selected command // Command key and shift key is not pressed if (!EditorGUI.actionKey && !Event.current.shift) { BlockEditor.actionList.Add(delegate { flowchart.selectedCommands.Remove(command); flowchart.ClearSelectedCommands(); }); } // Command key pressed if (EditorGUI.actionKey) { BlockEditor.actionList.Add(delegate { flowchart.selectedCommands.Remove(command); }); Event.current.Use(); } } else { bool shift = Event.current.shift; // Left click and no command key if (!shift && !EditorGUI.actionKey && Event.current.button == 0) { BlockEditor.actionList.Add(delegate { flowchart.ClearSelectedCommands(); }); Event.current.Use(); } BlockEditor.actionList.Add(delegate { flowchart.AddSelectedCommand(command); }); // Find first and last selected commands int firstSelectedIndex = -1; int lastSelectedIndex = -1; if (flowchart.selectedCommands.Count > 0) { if (flowchart.selectedBlock != null) { for (int i = 0; i < flowchart.selectedBlock.commandList.Count; i++) { Command commandInBlock = flowchart.selectedBlock.commandList[i]; foreach (Command selectedCommand in flowchart.selectedCommands) { if (commandInBlock == selectedCommand) { firstSelectedIndex = i; break; } } } for (int i = flowchart.selectedBlock.commandList.Count - 1; i >= 0; i--) { Command commandInBlock = flowchart.selectedBlock.commandList[i]; foreach (Command selectedCommand in flowchart.selectedCommands) { if (commandInBlock == selectedCommand) { lastSelectedIndex = i; break; } } } } } if (shift) { int currentIndex = command.commandIndex; if (firstSelectedIndex == -1 || lastSelectedIndex == -1) { // No selected command found - select entire list firstSelectedIndex = 0; lastSelectedIndex = currentIndex; } else { if (currentIndex < firstSelectedIndex) { firstSelectedIndex = currentIndex; } if (currentIndex > lastSelectedIndex) { lastSelectedIndex = currentIndex; } } for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i) { Command selectedCommand = flowchart.selectedBlock.commandList[i]; BlockEditor.actionList.Add(delegate { flowchart.AddSelectedCommand(selectedCommand); }); } } Event.current.Use(); } GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } Color commandLabelColor = Color.white; if (flowchart.colorCommands) { commandLabelColor = command.GetButtonColor(); } if (commandIsSelected) { commandLabelColor = Color.green; } else if (!command.enabled) { commandLabelColor = Color.grey; } else if (error) { // TODO: Show warning icon } GUI.backgroundColor = commandLabelColor; if (isComment) { GUI.Label(commandLabelRect, "", commandLabelStyle); } else { GUI.Label(commandLabelRect, commandName, commandLabelStyle); } if (command.executingIconTimer > Time.realtimeSinceStartup) { Rect iconRect = new Rect(commandLabelRect); iconRect.x += iconRect.width - commandLabelRect.width - 20; iconRect.width = 20; iconRect.height = 20; Color storeColor = GUI.color; float alpha = (command.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; alpha = Mathf.Clamp01(alpha); GUI.color = new Color(1f, 1f, 1f, alpha); GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle()); GUI.color = storeColor; } Rect summaryRect = new Rect(commandLabelRect); if (isComment) { summaryRect.x += 5; } else { summaryRect.x += commandNameWidth; summaryRect.width -= commandNameWidth; summaryRect.width -= 5; } GUIStyle summaryStyle = new GUIStyle(); summaryStyle.fontSize = 10; summaryStyle.padding.top += 5; summaryStyle.richText = true; summaryStyle.wordWrap = false; summaryStyle.clipping = TextClipping.Clip; commandLabelStyle.alignment = TextAnchor.MiddleLeft; GUI.Label(summaryRect, summary, summaryStyle); if (error) { GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector); Rect errorRect = new Rect(summaryRect); errorRect.x += errorRect.width - 20; errorRect.y += 2; errorRect.width = 20; GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background); summaryRect.width -= 20; } GUI.backgroundColor = Color.white; }
public override void DrawCommandGUI() { serializedObject.Update(); Say t = target as Say; SayDialog sd = t.sayDialog; if (t.sayDialog == null) // If default box selected { sd = t.GetFungusScript().defaultSay; // Try to get character's default say dialog box if (sd == null) // If no default specified, try to get any SayDialog in the scene { sd = GameObject.FindObjectOfType <SayDialog>(); } } bool showPortraits = false; CommandEditor.ObjectField <SayDialog>(sayDialogProp, new GUIContent("Say Dialog", "Say Dialog object to use to display the story text"), new GUIContent("<Default>"), SayDialog.activeDialogs); if (sd != null && sd.nameText != null) { CommandEditor.ObjectField <Character>(characterProp, new GUIContent("Character", "Character to display in dialog"), new GUIContent("<None>"), Character.activeCharacters); } else { t.character = null; } // Only show portrait selection if... if (t.character != null && // Character is selected t.character.portraits != null && // Character has a portraits field t.character.portraits.Count > 0) // Selected Character has at least 1 portrait { if (sd != null && sd.characterImage != null) // Check that selected say dialog has a character image { showPortraits = true; } } if (showPortraits) { CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing speaking character"), new GUIContent("<None>"), t.character.portraits); } else { if (!t.extendPrevious) { t.portrait = null; } } EditorGUILayout.PropertyField(storyTextProp); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(extendPreviousProp); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); if (showTagHelp) { DrawTagHelpLabel(); } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the say text is displayed")); EditorGUILayout.PropertyField(fadeInProp); EditorGUILayout.PropertyField(fadeOutProp); EditorGUILayout.PropertyField(showAlwaysProp); if (showAlwaysProp.boolValue == false) { EditorGUILayout.PropertyField(showCountProp); } if (showPortraits && t.portrait != null) { Texture2D characterTexture = t.portrait.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); if (characterTexture != null) { EditorGUI.DrawPreviewTexture(previewRect, characterTexture, spriteMaterial); } } serializedObject.ApplyModifiedProperties(); }
public override void DrawCommandGUI() { serializedObject.Update(); Choose t = target as Choose; CommandEditor.ObjectField <Character>(characterProp, new GUIContent("Character", "Character to display in dialog"), new GUIContent("<None>"), Character.activeCharacters); CommandEditor.ObjectField <ChooseDialog>(chooseDialogProp, new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"), new GUIContent("<Default>"), ChooseDialog.activeDialogs); bool showPortraits = false; // Only show portrait selection if... if (t.character != null && // Character is selected t.character.portraits != null && // Character has a portraits field t.character.portraits.Count > 0) // Selected Character has at least 1 portrait { showPortraits = true; } if (showPortraits) { CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing speaking character"), new GUIContent("<None>"), t.character.portraits); } else { t.portrait = null; } EditorGUILayout.PropertyField(chooseTextProp); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); if (showTagHelp) { SayEditor.DrawTagHelpLabel(); } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed")); EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit.")); /* * if (showPortraits && t.portrait != null) * { * Texture2D characterTexture = t.portrait.texture; * * float aspect = (float)characterTexture.width / (float)characterTexture.height; * * Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); * CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; * characterEditor.DrawPreview(previewRect, characterTexture); * DestroyImmediate(characterEditor); * } */ serializedObject.ApplyModifiedProperties(); }
public override void DrawCommandGUI() { serializedObject.Update(); Choose t = target as Choose; ChooseDialog cd = t.chooseDialog; if (t.chooseDialog == null) // If default box selected { cd = t.GetFungusScript().defaultChoose; // Try to get character's default choose dialog box if (cd == null) // If no default specified, Try to get any ChooseDialog in the scene { cd = GameObject.FindObjectOfType <ChooseDialog>(); } } CommandEditor.ObjectField <ChooseDialog>(chooseDialogProp, new GUIContent("Choose Dialog", "Choose Dialog object to use to display the multiple player choices"), new GUIContent("<Default>"), ChooseDialog.activeDialogs); if (cd != null && cd.nameText != null) { CommandEditor.ObjectField <Character>(characterProp, new GUIContent("Character", "Character to display in dialog"), new GUIContent("<None>"), Character.activeCharacters); } else { t.character = null; } bool showPortraits = false; // Only show portrait selection if... if (t.character != null && // Character is selected t.character.portraits != null && // Character has a portraits field t.character.portraits.Count > 0) // Selected Character has at least 1 portrait { if (cd != null && cd.characterImage != null) // Check that selected choose dialog has a character image { showPortraits = true; } } if (showPortraits) { CommandEditor.ObjectField <Sprite>(portraitProp, new GUIContent("Portrait", "Portrait representing speaking character"), new GUIContent("<None>"), t.character.portraits); } else { t.portrait = null; } EditorGUILayout.PropertyField(chooseTextProp); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Tag Help", "Show help info for tags"), new GUIStyle(EditorStyles.miniButton))) { showTagHelp = !showTagHelp; } EditorGUILayout.EndHorizontal(); if (showTagHelp) { SayEditor.DrawTagHelpLabel(); } EditorGUILayout.Separator(); EditorGUILayout.PropertyField(voiceOverClipProp, new GUIContent("Voice Over Clip", "Voice over audio to play when the choose text is displayed")); EditorGUILayout.PropertyField(timeoutDurationProp, new GUIContent("Timeout Duration", "Time limit for player to make a choice. Set to 0 for no limit.")); EditorGUILayout.PropertyField(fadeInProp); EditorGUILayout.PropertyField(fadeOutProp); if (showPortraits && t.portrait != null) { Texture2D characterTexture = t.portrait.texture; float aspect = (float)characterTexture.width / (float)characterTexture.height; Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true)); CharacterEditor characterEditor = Editor.CreateEditor(t.character) as CharacterEditor; characterEditor.DrawPreview(previewRect, characterTexture); DestroyImmediate(characterEditor); } serializedObject.ApplyModifiedProperties(); }