Skip to content

Add slide export functionality #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Editor/Inspectors/SlideDeckEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEditorInternal;
using System;
using Unity.Presentation.Utils;
using UnityEditor.Callbacks;

namespace Unity.Presentation.Inspectors
{
Expand Down Expand Up @@ -220,11 +221,27 @@ public override void OnInspectorGUI()
if (GUILayout.Button("Load This Slide Deck"))
{
Engine.Instance.LoadDeck(instance);
EditorWindow.GetWindow<PresentationWindow>();
}

scroll = DrawInspector(instance, scroll);
}

[OnOpenAsset(1)]
public static bool step1(int instanceID, int line)
{
SlideDeck deck = EditorUtility.InstanceIDToObject(instanceID) as SlideDeck;

if (deck)
{
Engine.Instance.LoadDeck(deck);
EditorWindow.GetWindow<PresentationWindow>();
return true;
}

return false;
}

#endregion
}
}
54 changes: 51 additions & 3 deletions Editor/PresentationWindow.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System;
using System.IO;
using Unity.Presentation.Inspectors;
using Unity.Presentation.Utils;

Expand Down Expand Up @@ -35,6 +33,7 @@ private class Styles
public readonly GUIContent TEXT_LOAD = new GUIContent("Load", "Load Presentation from disk");
public readonly GUIContent TEXT_SAVE = new GUIContent("Save", "Save Presentation to disk");
public readonly GUIContent TEXT_BUILD = new GUIContent("Build", "Build Standalone Presentation for selected platform");
public readonly GUIContent TEXT_EXPORT = new GUIContent("Exprt", "Export all slides to png image files");
public readonly GUIContent TEXT_PREV = new GUIContent("<<", "Go to the previous slide");
public readonly GUIContent TEXT_FROM_BEGINNING = new GUIContent("> B", "Start Presentation from the first slide");
public readonly GUIContent TEXT_STOP = new GUIContent("Stop", "Stop Presentation");
Expand Down Expand Up @@ -154,6 +153,7 @@ private void OnGUI()
else
{
var shouldBuild = false;
var shouldExport = false;
var bgcolor = GUI.backgroundColor;
var deck = engine.SlideDeck;

Expand All @@ -175,6 +175,10 @@ private void OnGUI()
{
shouldBuild = true;
}
if (GUILayout.Button(styles.TEXT_EXPORT, styles.BUTTON))
{
shouldExport = true;
}
GUI.enabled = true;

GUILayout.Label(GUIContent.none, GUILayout.ExpandWidth(true));
Expand Down Expand Up @@ -215,6 +219,50 @@ private void OnGUI()
{
EditorUtils.BuildPresentation(deck);
}

if (shouldExport)
{
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
var activeScene = SceneManager.GetActiveScene().path;

string exportFolder =
EditorUtility.OpenFolderPanel("Choose folder for export", Application.dataPath, "Exports");

if (!string.IsNullOrEmpty(exportFolder))
{
RenderTexture renderTexture = RenderTexture.GetTemporary(1920, 1080, 32, RenderTextureFormat.ARGB32);

for (var i = 0; i < deck.Slides.Count; i++)
{
var slide = deck.Slides[i];
EditorSceneManager.OpenScene(slide.ScenePath);

var sceneCam = Camera.main;
sceneCam.targetTexture = renderTexture;

RenderTexture.active = renderTexture;
sceneCam.Render();

var exportTexture = new Texture2D(renderTexture.width, renderTexture.height);
exportTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);

var slidePath =
string.Format("{0}/{1} - {2}.png", exportFolder, i + 1,
Path.GetFileNameWithoutExtension(slide.ScenePath));

File.WriteAllBytes(slidePath,
exportTexture.EncodeToPNG());

RenderTexture.active = null;
Object.DestroyImmediate(exportTexture);
}

RenderTexture.ReleaseTemporary(renderTexture);

if(!string.IsNullOrEmpty(activeScene))
EditorSceneManager.OpenScene(activeScene);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project allows you to build a full presentation in Unity and never leave it
1. Use Unity UI to design slides.
1. Make interactive slides (there are examples in the sample presentation).
1. Even load whole games as slides!
1. Export slides to .png files
1. ... and more!

## Getting started
Expand Down Expand Up @@ -55,7 +56,6 @@ If you check the demo Slide Deck you will see that slide scenes all have the sam

## TODO
1. Proper fullscreen.
1. Some way to export slides to more common formats (PNGs, PDF, PPT) when one is unable to run Unity during a presentation.
1. Better slide list interface.

## Known issues
Expand Down
9 changes: 0 additions & 9 deletions TextMesh Pro.meta

This file was deleted.

9 changes: 0 additions & 9 deletions TextMesh Pro/GUISkins.meta

This file was deleted.

Loading