private void InitializeManager() { MegacoolManager manager = null; foreach (Camera cam in Camera.allCameras) { MegacoolManager foundManager = cam.GetComponent <MegacoolManager>(); if (foundManager) { manager = foundManager; break; } } if (!manager) { Camera mainCamera = Camera.main; if (!mainCamera) { UnityEngine.Debug.Log("No MegacoolManager already in the scene and no main camera to attach to, " + "either attach it manually to a camera or tag one of the cameras as MainCamera"); return; } mainCamera.gameObject.AddComponent <MegacoolManager>(); manager = mainCamera.GetComponent <MegacoolManager>(); } // Doing an explicit initialize ensures that if the capture method was customized the changes // are respected even if the manager was explicitly added to a camera and thus awoke before the // capture method was set. manager.Initialize(); }
private MegacoolManager GetManager() { MegacoolManager manager = null; foreach (Camera cam in Camera.allCameras) { MegacoolManager foundManager = cam.GetComponent <MegacoolManager>(); if (foundManager) { manager = foundManager; break; } } if (!manager) { Camera mainCamera = Camera.main; if (!mainCamera) { UnityEngine.Debug.Log("No MegacoolManager already in the scene and no main camera to attach to, " + "either attach it manually to a camera or tag one of the cameras as MainCamera"); return(null); } mainCamera.gameObject.AddComponent <MegacoolManager>(); manager = mainCamera.GetComponent <MegacoolManager>(); } return(manager); }
/// <summary> /// Capture a single frame. /// </summary> /// <description> /// If the recording doesn't already exist it'll be created with the settings specified in the /// config. /// </description> /// <param name="config">the configuration to use to create the recording, if it doesn't already /// exist.</param> /// <param name="forceAdd">Set to true to ensure the frame is included in the recording, even if /// the overflow strategy otherwise would skip it. Useful for timelapse to include the last /// frame with a score board or final state.</param> public void CaptureFrame(MegacoolRecordingConfig config, bool forceAdd) { captureManager = GetManager(); if (!captureManager) { return; } captureManager.StartWrites(0); _RenderThisFrame = true; _platformAgent.CaptureFrame(config, forceAdd); }
/// <summary> /// Start customized GIF recording. /// </summary> /// <remarks> /// This will keep a buffer of 50 frames (default). The frames are overwritten until <c>StopRecording</c> gets called. /// </remarks> /// <param name="config">Config to customize the recording.</param> public void StartRecording(MegacoolRecordingConfig config) { captureManager = GetManager(); if (!captureManager) { return; } captureManager.StartWrites(GetTimeBetweenCaptures(config)); _platformAgent.StartRecording(config); _IsRecording = true; SafeReleaseTextureReady(); }
/// <summary> /// Take a screenshot and share it immediately. /// </summary> /// <description> /// <para> /// This is a helper around {@link #captureFrame(View)} and {@link #share(Activity)} when you /// only need to share a screenshot and not all the other bells and whistles for recordings. /// </para> /// <para> /// This method is functionally equivalent to: /// <code> /// Megacool.Instance.PauseRecording(); /// string tempRecording = "random-unused-id"; /// Megacool.Instance.CaptureFrame(new MegacoolRecordingConfig { /// RecordingId = tempRecordingId, /// MaxFrames = 1, /// }); /// Megacool.Instance.Share(new MegacoolShareConfig { /// RecordingId = tempRecordingId, /// }); /// Megacool.Instance.DeleteRecording(tempRecordingId); /// </code> /// Note that if this method is called while a recording is underway the screenshot is likely to /// be missing from the share. To stay on the safe side, leave a couple hundred ms between /// stopping a recording and sharing a screenshot. /// </para> /// </description> /// <param name="recordingConfig">The recording config, or <c>null</c>. Most properties don't /// apply to screenshots, but the last frame overlay does.</param> /// <param name="shareConfig">The share config, or <c>null</c>.</param> public void ShareScreenshot(MegacoolRecordingConfig recordingConfig = null, MegacoolShareConfig shareConfig = null) { captureManager = GetManager(); if (captureManager) { // Only try to capture if we have a manager, but always call down to the SDK to make // sure the share happens anyway captureManager.StartWrites(0); _RenderThisFrame = true; } _platformAgent.ShareScreenshot(recordingConfig, shareConfig); }