private void TakeSnapshotFromSceneCamera(SerializedProperty thumbnailProperty)
        {
            var sceneTemplateAsset = serializedObject.targetObject as SceneTemplateAsset;

            if (!sceneTemplateAsset)
            {
                return;
            }

            var sceneView = EditorWindow.GetWindow <SceneView>();

            if (sceneView == null)
            {
                Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "Unable to retrieve the Scene view.");
                return;
            }

            SnapshotUtils.TakeSceneViewSnapshot(sceneView, snapshotTexture =>
            {
                snapshotTexture.name = sceneTemplateAsset.name;

                // Put the snapshot into the scene template asset
                // This needs to be done before we set it into the property
                // and apply modifications.
                sceneTemplateAsset.AddThumbnailToAsset(snapshotTexture);

                thumbnailProperty.objectReferenceValue = snapshotTexture;
                serializedObject.ApplyModifiedProperties();
            });
        }
        private void TakeSnapshotFromGameView(Action onFinishedCallback)
        {
            var sceneTemplateAsset = serializedObject.targetObject as SceneTemplateAsset;

            if (!sceneTemplateAsset)
            {
                return;
            }

            var gameViewType = Type.GetType("UnityEditor.GameView,UnityEditor");
            var gameView     = EditorWindow.GetWindow(gameViewType);

            if (gameView == null)
            {
                Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "Unable to retrieve the Game view.");
                return;
            }

            SnapshotUtils.TakeGameViewSnapshot(gameView, textureCopy =>
            {
                textureCopy.name = sceneTemplateAsset.name;

                // Put the snapshot into the scene template asset
                // This needs to be done before we set it into the property
                // and apply modifications.
                sceneTemplateAsset.AddThumbnailToAsset(textureCopy);

                var templateThumbnailProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateThumbnailPropertyName);
                templateThumbnailProperty.objectReferenceValue = textureCopy;
                serializedObject.ApplyModifiedProperties();

                onFinishedCallback?.Invoke();
            });
        }
        private void TakeSnapshotFromCamera(SnapshotTargetInfo targetInfo, Action onFinishedCallback)
        {
            var sceneTemplateAsset = serializedObject.targetObject as SceneTemplateAsset;

            if (!sceneTemplateAsset)
            {
                return;
            }

            var camera = Camera.allCameras.FirstOrDefault(c => c.name == targetInfo.Name);

            if (!camera)
            {
                Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, $"There is no camera named {targetInfo.Name} in the current scene.");
                return;
            }

            var snapshotTexture = SnapshotUtils.TakeCameraSnapshot(camera);

            snapshotTexture.name = sceneTemplateAsset.name;

            // Put the snapshot into the scene template asset
            // This needs to be done before we set it into the property
            // and apply modifications.
            sceneTemplateAsset.AddThumbnailToAsset(snapshotTexture);

            // Thumbnail property gets disposed after AssetDatabase.SaveAssets
            var templateThumbnailProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateThumbnailPropertyName);

            templateThumbnailProperty.objectReferenceValue = snapshotTexture;
            serializedObject.ApplyModifiedProperties();

            onFinishedCallback?.Invoke();
        }