internal void EditEntry(DevLogEntry entry) { isNewEntry = false; windowScrollPos = Vector2.zero; status = entry.status; detailScrollPosition = Vector2.zero; shortText = entry.shortDescription; detailText = entry.longDescription; assets = entry.assets; isSocial = entry.isSocial; gitCommit = entry.commitHash; MetaDataItems items = EntryPanelSettings.GetSuggestedMetaDataItems(); for (int i = 0; i < items.Count; i++) { if (devLogWindow.currentEntry.metaData.Contains(items.GetItem(i).name)) { items.GetItem(i).IsSelected = true; } } List <string> mediaFilePaths = new List <string>(); for (int i = 0; i < ScreenCaptures.Count; i++) { DevLogScreenCapture capture = ScreenCaptures.captures[i]; if (devLogWindow.currentEntry.captures.Contains(capture)) { ScreenCaptures.captures[i].IsSelected = true; } } }
private void ImageSelectionGUI() { EditorGUILayout.BeginHorizontal(); for (int i = ScreenCaptures.captures.Count - 1; i >= 0; i--) { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); DevLogScreenCapture capture = ScreenCaptures.captures[i]; if (GUILayout.Button(capture.Texture, GUILayout.Width(100), GUILayout.Height(100))) { ScreenCaptures.captures[i].IsSelected = !ScreenCaptures.captures[i].IsSelected; } ScreenCaptures.captures[i].IsSelected = EditorGUILayout.Toggle(ScreenCaptures.captures[i].IsSelected); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("View")) { System.Diagnostics.Process.Start("Explorer.exe", string.Format("/open, \"{0}\"", capture.ImagePath)); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Captures a screenshot of the desired editor window. To get a list of all the /// windows available in the editor use: /// ``` /// EditorWindow[] allWindows = Resources.FindObjectsOfTypeAll<EditorWindow>(); /// foreach (EditorWindow window in allWindows) /// { /// Debug.Log(window); /// } ///``` /// </summary> /// <param name="windowName">The name of the window to be captured, for example: /// </param> public void CaptureWindowScreenshot(string windowName) { DevLogScreenCapture screenCapture = ScriptableObject.CreateInstance <DevLogScreenCapture>(); screenCapture.productName = Application.productName; screenCapture.version = Application.version; screenCapture.timestamp = DateTime.Now; screenCapture.sceneName = SceneManager.GetActiveScene().name; screenCapture.encoding = DevLogScreenCapture.ImageEncoding.png; screenCapture.windowName = windowName; screenCapture.name = Application.productName + " v" + Application.version + " " + SceneManager.GetActiveScene().name; screenCapture.AbsoluteSaveFolder = CapturesFolderPath(screenCapture); EditorWindow window; if (windowName.StartsWith("UnityEditor.")) { window = EditorWindow.GetWindow(typeof(UnityEditor.Editor).Assembly.GetType(windowName)); } else { Type type = AppDomain.CurrentDomain.GetAssemblies() .Where(a => !a.IsDynamic) .SelectMany(a => a.GetTypes()) .FirstOrDefault(t => t.FullName.Equals(windowName)); window = EditorWindow.GetWindow(type); } window.Focus(); EditorApplication.delayCall += () => { int width = (int)window.position.width; int height = (int)window.position.height; Vector2 position = window.position.position; position.y += 18; if (windowName.EndsWith("SceneView") || windowName.EndsWith("GameView")) { position.y += 18; height -= 18; } Color[] pixels = UnityEditorInternal.InternalEditorUtility.ReadScreenPixel(position, width, height); Texture2D windowTexture = new Texture2D(width, height, TextureFormat.RGB24, false); windowTexture.SetPixels(pixels); byte[] bytes = windowTexture.EncodeToPNG(); System.IO.File.WriteAllBytes(screenCapture.ImagePath, bytes); screenCapture.IsImageSaved = true; AddToLatestCaptures(screenCapture); // TODO This used to be in the window, but now it's not so how do we get focus back? // this.Focus(); }; }
/// <summary> /// Post to the DevLog and Twitter. /// </summary> /// <returns>The new DevLog entry.</returns> private DevLogEntry PostToDevLogAndTwitter() { string m_StatusText = ""; bool isTweeted = false; if (mediaPanel.hasSelectedImages) // Images to post { List <string> mediaFilePaths = new List <string>(); //TODO only allowed 4 still or 1 animated GIF for (int i = 0; i < mediaPanel.ScreenCaptures.Count; i++) { if (mediaPanel.ScreenCaptures.captures[i].IsSelected) { DevLogScreenCapture capture = mediaPanel.ScreenCaptures.captures[i]; mediaFilePaths.Add(capture.ImagePath); } } if (Twitter.PublishTweetWithMedia(TweetText, mediaFilePaths, out string response)) { m_StatusText = "Tweet with image(s) sent succesfully"; isTweeted = true; } else { Debug.LogError(response); m_StatusText = response; } } else { // No Images to post if (Twitter.PublishTweet(TweetText, out string response)) { m_StatusText = "Tweet sent succesfully"; isTweeted = true; } else { Debug.LogError(response); } } EditorGUILayout.LabelField(m_StatusText); if (isTweeted) { return(m_EntryPanel.AppendDevlogEntry(true)); } else { return(m_EntryPanel.AppendDevlogEntry()); } }
private void AddToLatestCaptures(DevLogScreenCapture screenCapture) { if (screenCapture == null) { return; } AssetDatabase.AddObjectToAsset(screenCapture, ScreenCaptures); screenCapture.IsSelected = true; ScreenCaptures.captures.Add(screenCapture); EditorUtility.SetDirty(ScreenCaptures); AssetDatabase.SaveAssets(); }
/// <summary> /// Create a new Discord message. /// </summary> /// <param name="username">The unsername to use when posting.</param> /// <param name="introText">The intro text that will appear before the first image, if there is one.</param> /// <param name="screenCaptures">The set of available and selected screen captures that may be shared as part of the message.</param> internal Message(string username, string introText, DevLogScreenCaptureCollection screenCaptures) { this.username = username; this.introText = introText; for (int i = 0; i < screenCaptures.Count; i++) { DevLogScreenCapture capture = screenCaptures.captures[i]; if (!capture.IsSelected) { continue; } ImageContent image = new ImageContent("File" + i, capture); files.Add(image); } }
public void UpdateDevLogEntry() { devLogWindow.currentEntry.status = status; devLogWindow.currentEntry.shortDescription = shortText; devLogWindow.currentEntry.assets = assets; devLogWindow.currentEntry.isSocial = isSocial; devLogWindow.currentEntry.commitHash = gitCommit; MetaDataItems items = EntryPanelSettings.GetSuggestedMetaDataItems(); for (int i = 0; i < items.Count; i++) { if (!items.GetItem(i).IsSelected) { devLogWindow.currentEntry.metaData.Remove(items.GetItem(i).name); } else if (items.GetItem(i).IsSelected&& !devLogWindow.currentEntry.metaData.Contains(items.GetItem(i).name)) { devLogWindow.currentEntry.metaData.Add(items.GetItem(i).name); } } List <string> mediaFilePaths = new List <string>(); for (int i = 0; i < ScreenCaptures.Count; i++) { DevLogScreenCapture capture = ScreenCaptures.captures[i]; if (!ScreenCaptures.captures[i].IsSelected) { devLogWindow.currentEntry.captures.Remove(capture); } else if (ScreenCaptures.captures[i].IsSelected && !devLogWindow.currentEntry.captures.Contains(capture)) { devLogWindow.currentEntry.captures.Add(capture); ScreenCaptures.captures[i].IsSelected = false; } } devLogWindow.currentEntry.longDescription = detailText; EditorUtility.SetDirty(entries); AssetDatabase.SaveAssets(); }
internal string CapturesFolderPath(DevLogScreenCapture capture) { string path = Settings.CaptureFileFolderPath; if (Settings.OrganizeCapturesByProject) { path += Path.DirectorySeparatorChar + Application.productName; } if (Settings.OrganizeCapturesByScene) { path += Path.DirectorySeparatorChar + SceneManager.GetActiveScene().name; } path += Path.DirectorySeparatorChar; Directory.CreateDirectory(path); return(path); }
internal ImageContent(string name, DevLogScreenCapture capture) { this.name = name; this.filepath = capture.ImagePath; this.filename = Path.GetFileName(capture.ImagePath); this.fileData = File.ReadAllBytes(this.filepath); if (this.filepath.EndsWith("jpg")) { this.contentType = "image/jpg"; } else if (this.filepath.EndsWith("png")) { this.contentType = "image/png"; } else if (this.filepath.EndsWith("gif")) { this.contentType = "image/gif"; } }
internal void CaptureGif() { currentScreenCapture = ScriptableObject.CreateInstance <DevLogScreenCapture>(); currentScreenCapture.productName = Application.productName; currentScreenCapture.version = Application.version; currentScreenCapture.timestamp = DateTime.Now; currentScreenCapture.sceneName = SceneManager.GetActiveScene().name; currentScreenCapture.encoding = DevLogScreenCapture.ImageEncoding.gif; currentScreenCapture.windowName = "In_Game_Footage"; currentScreenCapture.name = Application.productName + " v" + Application.version + currentScreenCapture.timestamp.ToLongDateString(); currentScreenCapture.AbsoluteSaveFolder = CapturesFolderPath(currentScreenCapture); Debug.Log("Created ScreenCapture object:\n" + currentScreenCapture.ToString()); Recorder.OnPreProcessingDone = OnPreProcessingDone; Recorder.OnFileSaved = OnFileSaved; Recorder.SavePath = currentScreenCapture.ImagePath; Recorder.Save(); }
internal Message(string username, DevLogEntry entry) { this.entry = entry; this.username = username; this.introText = entry.shortDescription; for (int i = 0; i < entry.metaData.Count; i++) { if (!entry.metaData[i].StartsWith("#")) { introText += " " + entry.metaData[i]; } } this.bodyText = entry.longDescription; for (int i = 0; i < entry.captures.Count; i++) { DevLogScreenCapture capture = entry.captures[i]; ImageContent image = new ImageContent("File" + i, capture); files.Add(image); } }
/// <summary> /// Append a devlog entry. /// </summary> /// <param name="withTweet">If true record that the entry was tweeted at the current time.</param> /// <param name="withDiscord">If true record that the entry was posted to discord at the current time.</param> /// <returns></returns> public DevLogEntry AppendDevlog(bool withTweet = false, bool withDiscord = false) { DevLogEntry entry = ScriptableObject.CreateInstance <DevLogEntry>(); entry.name = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); entry.status = status; entry.shortDescription = shortText; StringBuilder text = new StringBuilder(entry.shortDescription); entry.isSocial = isSocial; if (!string.IsNullOrEmpty(gitCommit)) { entry.commitHash = gitCommit; text.Append("\n\nGit Commit: " + gitCommit); gitCommit = ""; } MetaDataItems items = EntryPanelSettings.GetSuggestedMetaDataItems(); for (int i = 0; i < items.Count; i++) { if (items.GetItem(i).IsSelected) { entry.metaData.Add(items.GetItem(i).name); } } if (withTweet) { entry.tweeted = true; entry.lastTweetFileTime = DateTime.Now.ToFileTimeUtc(); text.Append("\n\n[This DevLog entry was last Tweeted at " + entry.lastTweetPrettyTime + ".]"); } if (withDiscord) { entry.discordPost = true; entry.lastDiscordPostFileTime = DateTime.Now.ToFileTimeUtc(); text.Append("\n\n[This DevLog entry was last posted to Discord at " + entry.lastTweetPrettyTime + ".]"); } List <string> mediaFilePaths = new List <string>(); for (int i = 0; i < ScreenCaptures.Count; i++) { if (ScreenCaptures.captures[i].IsSelected) { DevLogScreenCapture capture = ScreenCaptures.captures[i]; entry.captures.Add(capture); ScreenCaptures.captures[i].IsSelected = false; } } entry.longDescription = detailText; entries.AddEntry(entry); AssetDatabase.AddObjectToAsset(entry, entries); EditorUtility.SetDirty(entries); AssetDatabase.SaveAssets(); shortText = ""; detailText = ""; return(entry); }