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(showNeedNameProp); EditorGUILayout.PropertyField(showAfterHowManyNumber); 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(voiceClipNameProp); EditorGUILayout.PropertyField(PreVoiceClipNameProp); 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); //char protrait popup menu if (t._Character != null) { EditorGUILayout.BeginVertical("box"); EditorGUILayout.ObjectField(t._Character.displayPortrait, typeof(DialogPortrait), true); if (DisplayPortraitInfo) { if (GUILayout.Button("Close Detail Info")) { DisplayPortraitInfo = false; } DrawGUI_PortraitData(); } else { if (GUILayout.Button("Show Detail Info")) { DisplayPortraitInfo = true; } } EditorGUILayout.EndVertical(); } EditorGUILayout.PropertyField(playTypeProp); EditorGUILayout.PropertyField(sayDialogAnimProp); EditorGUILayout.PropertyField(waitForVOProp); 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 void DrawItem(Rect position, int index, bool selected, bool focused) { Command command = this[index].objectReferenceValue as Command; if (command == null) { return; } CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType()); if (commandInfoAttr == null) { return; } var 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.CommandBackground; 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) { var 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 { string commandNameLabel; if (flowchart.ShowLineNumbers) { commandNameLabel = command.CommandIndex.ToString() + ": " + commandName; } else { commandNameLabel = commandName; } GUI.Label(commandLabelRect, commandNameLabel, 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) / FungusConstants.ExecutingIconFadeTime; alpha = Mathf.Clamp01(alpha); GUI.color = new Color(1f, 1f, 1f, alpha); GUI.Label(iconRect, FungusEditorResources.PlaySmall, new GUIStyle()); GUI.color = storeColor; } Rect summaryRect = new Rect(commandLabelRect); if (isComment) { summaryRect.x += 5; } else { summaryRect.x += commandNameWidth + 5; summaryRect.width -= commandNameWidth + 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 virtual void DrawCommandInspectorGUI() { Command t = target as Command; if (t == null) { return; } var 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 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(moveDurationProp); } 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(); }
// Update is called once per frame public override void DrawCommandGUI() { serializedObject.Update(); BillboardPrefab t = target as BillboardPrefab; if (shouldUpdatePrefab == true) { shouldUpdatePrefab = false; if (t._TargetPrefab != null) { listEmoji = t._TargetPrefab.GetEmojiListString().ToArray(); listBody = t._TargetPrefab.GetBodyListString().ToArray(); listEquip = t._TargetPrefab.GetEquipListString().ToArray(); } else { listEmoji = new string[] {} }; } EditorGUILayout.PropertyField(displayProp); if (t._Display != DisplayType.None) { if (t._Display != DisplayType.MoveToFront) { if (t._Display != DisplayType.Hide) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(targetPrefabProp, new GUIContent("角色立繪Prefab")); if (AdvKeyContent.GetCurrentInstance().GroupBillboardPrefab != null) { CommandEditor.ObjectField <UIBillboardController>(targetPrefabProp, new GUIContent("In folder (Prefabs/ADV)", "Dynamic Emoji Prefab (UIBillboardController)"), new GUIContent("<None>"), AdvKeyContent.GetCurrentInstance().GroupBillboardPrefab); } if (EditorGUI.EndChangeCheck()) { shouldUpdatePrefab = true; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(useEmojiProp, new GUIContent("使用表情")); int emojiIndex = EditorGUILayout.Popup(emojiId, listEmoji, EditorStyles.popup); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(useBodyProp, new GUIContent("使用衣服")); int bodyIndex = EditorGUILayout.Popup(bodyId, listBody, EditorStyles.popup); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(useEquipsProp, new GUIContent("使用裝備(我前面有箭頭)"), true); int equipIndex = EditorGUILayout.Popup(equipId, listEquip, EditorStyles.popup); EditorGUILayout.EndHorizontal(); if (emojiIndex != emojiId) { useEmojiProp.stringValue = listEmoji[emojiIndex]; } if (bodyIndex != bodyId) { useBodyProp.stringValue = listBody[bodyIndex]; } if (equipIndex != equipId) { t._UseEquips.Add(listEquip[equipIndex]); EditorUtility.SetDirty(t); } EditorGUILayout.PropertyField(flipFaceProp, new GUIContent("水平翻轉 ?")); EditorGUILayout.PropertyField(spriteDistanceProp, new GUIContent("立繪所在距離")); } if (t._Display == DisplayType.Hide) { EditorGUILayout.PropertyField(hideWhichProp, new GUIContent("隱藏哪個位置")); } if (t._Display == DisplayType.Show || t._Display == DisplayType.Replace || (t._Move && t._Display == DisplayType.Hide)) { EditorGUILayout.PropertyField(toPositionProp, new GUIContent("目標位置")); EditorGUILayout.PropertyField(positionShiftProp, new GUIContent("目標位置加上偏移")); EditorGUILayout.PropertyField(positionShiftValueProp, new GUIContent("偏移倍數")); } EditorGUILayout.LabelField("-- 移動設定 --", EditorStyles.boldLabel); EditorGUILayout.PropertyField(moveProp, new GUIContent("移動動畫 ?")); if (t._Move) { if (!t._ShiftIntoPlace) { EditorGUILayout.PropertyField(fromPositionProp, new GUIContent("從哪個相對位置滑入")); } } EditorGUILayout.PropertyField(useDefaultSettingsProp, new GUIContent("使用預設數值 ?")); if (!t._UseDefaultSettings) { if (t._Move) { if (t._Display != DisplayType.Hide) { EditorGUILayout.PropertyField(shiftIntoPlaceProp, new GUIContent("從目標位置附近滑入?")); if (t._ShiftIntoPlace) { EditorGUILayout.PropertyField(shiftOffsetProp, new GUIContent("從哪邊滑入(偏移量)")); } } } EditorGUILayout.PropertyField(fadeDurationProp, new GUIContent("淡出 / 淡入時間")); if (t._Move) { EditorGUILayout.PropertyField(moveDurationProp, new GUIContent("滑動時間")); } } EditorGUILayout.PropertyField(waitUntilFinishedProp); } else { EditorGUILayout.PropertyField(toPositionProp, new GUIContent("哪個位置")); } } //EditorGUILayout.PropertyField(serializedObject.FindProperty("myVariable"), new GUIContent("aDifferentLabel")); serializedObject.ApplyModifiedProperties(); } }