/// <summary> /// Draws inspector for a Slide Deck. /// </summary> /// <param name="deck">Slide Deck to draw.</param> /// <param name="scroll">Current vertical scroll value.</param> /// <param name="shouldSelect">A function which returns if the current slide should be selected.</param> /// <param name="onPlayPress">A function called when "Play" button of a slide is pressed.</param> /// <returns>Current vertical scroll value.</returns> public static float DrawInspector(SlideDeck deck, float scroll, Func <SlideDeck, int, bool> shouldSelect = null, Action <SlideDeck, int> onPlayPress = null) { if (styles == null) { styles = new Styles(); } ReorderableList list; var key = deck.GetInstanceID() + "#" + (shouldSelect != null) + "#" + (onPlayPress != null); if (!lists.TryGetValue(key, out list)) { // Init a ReorderableList for the deck and cache it. list = new ReorderableList(deck.Slides, typeof(PresentationSlide), true, true, true, true); lists.Add(key, list); list.onChangedCallback += (l) => { // deck.Save(); }; list.drawHeaderCallback += (Rect rect) => GUI.Label(rect, deck.IsSavedOnDisk ? deck.Name + ".asset" : "<not saved>"); list.elementHeightCallback += (int index) => styles.ELEMENT_HEIGHT; list.drawElementBackgroundCallback += (Rect rect, int index, bool isActive, bool isFocused) => { if (Event.current.type == EventType.Repaint) { if (index < 0) { return; } var bgcolor = GUI.backgroundColor; var slide = deck.Slides[index]; if (shouldSelect != null && shouldSelect(deck, index)) { GUI.backgroundColor = styles.SELECTED_COLOR; rect.height += 3; styles.BG_SELECTED.Draw(rect, false, isActive, isActive, isFocused); } else if (slide.Visible || isFocused) { styles.BG.Draw(rect, false, isActive, isActive, isFocused); } else { GUI.backgroundColor = styles.INVISIBLE_COLOR; rect.height += 3; styles.BG_INVISIBLE.Draw(rect, false, isActive, isActive, isFocused); } GUI.backgroundColor = bgcolor; } }; list.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => { var changed = false; var color = GUI.color; var slide = deck.Slides[index]; // visible EditorGUI.BeginChangeCheck(); if (!slide.Visible) { GUI.color = styles.INACTIVE_COLOR; } var newVisible = GUI.Toggle( new Rect(rect.x, rect.y, styles.ICON.fixedWidth, rect.height), slide.Visible, styles.VISIBLE_ICON, styles.ICON); if (EditorGUI.EndChangeCheck()) { slide.Visible = newVisible; changed = true; } GUI.color = color; rect.x += styles.ICON.fixedWidth; // play mode EditorGUI.BeginChangeCheck(); if (!slide.StartInPlayMode) { GUI.color = styles.INACTIVE_COLOR; } var newPlaymode = GUI.Toggle( new Rect(rect.x, rect.y, styles.ICON.fixedWidth, rect.height), slide.StartInPlayMode, styles.PLAYMODE_ICON, styles.ICON); if (EditorGUI.EndChangeCheck()) { slide.StartInPlayMode = newPlaymode; changed = true; } GUI.color = color; rect.x += styles.ICON.fixedWidth; // scene var w = rect.width - styles.ICON.fixedWidth * 2; if (onPlayPress != null) { w -= styles.PLAY_BUTTON.fixedWidth + 6; } var scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(slide.ScenePath); EditorGUI.BeginChangeCheck(); var newScene = EditorGUI.ObjectField(new Rect(rect.x, rect.y + 2, w, rect.height - 4), scene, typeof(SceneAsset), false) as SceneAsset; if (EditorGUI.EndChangeCheck()) { slide.Scene = newScene; changed = true; } rect.x += w + 6; if (onPlayPress != null) { rect.y += 2; if (GUI.Button(rect, styles.PLAY_ICON, styles.PLAY_BUTTON)) { onPlayPress(deck, index); } } if (changed) { deck.Save(); } }; } scroll = EditorGUILayout.BeginScrollView(new Vector2(0, scroll), false, false, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)).y; var r = GUILayoutUtility.GetRect(0, list.GetHeight() + 20); list.DoList(r); var propsName = "presentation_" + deck.name + "_options"; var showOptions = EditorPrefs.GetBool(propsName, false); showOptions = GUIElements.Header(styles.TEXT_OPTIONS, showOptions); if (showOptions) { EditorGUI.indentLevel++; deck.BackgroundColor = EditorGUILayout.ColorField(styles.TEXT_BG_COLOR, deck.BackgroundColor, true, false, false, new ColorPickerHDRConfig(0, 1, 0, 1), GUILayout.ExpandWidth(true)); EditorGUI.indentLevel--; } EditorPrefs.SetBool(propsName, showOptions); EditorGUILayout.EndScrollView(); return(scroll); }