Add the screenshot helper to the project, add assembly definitions and setup cross-references
This commit is contained in:
83
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.cs
vendored
Normal file
83
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.cs
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class MinimumDemo : MonoBehaviour
|
||||
{
|
||||
public Camera m_Camera;
|
||||
public MeshRenderer m_CubeMeshRenderer;
|
||||
|
||||
[Space]
|
||||
public SDev.FileSaveUtil.AppPath ApplicationPath = SDev.FileSaveUtil.AppPath.PersistentDataPath;
|
||||
public string SubFolderName;
|
||||
public string FileName;
|
||||
|
||||
private Texture2D _texture2D;
|
||||
|
||||
public void TakeScreenshot()
|
||||
{
|
||||
//ScreenshotHelper.iClear(); // Clear the old texture (if any)
|
||||
ScreenshotHelper.iCaptureScreen((texture2D) =>
|
||||
{
|
||||
if (_texture2D) Destroy(_texture2D); // Manually clear the old texture
|
||||
_texture2D = texture2D;
|
||||
|
||||
// Set the new (captured) screenshot texture to the cube renderer.
|
||||
m_CubeMeshRenderer.material.mainTexture = texture2D;
|
||||
|
||||
SaveTexture(texture2D);
|
||||
});
|
||||
}
|
||||
|
||||
public void CaptureWithCamera()
|
||||
{
|
||||
//ScreenshotHelper.iClear(); // Clear the old texture (if any)
|
||||
ScreenshotHelper.iCaptureWithCamera(m_Camera, (texture2D) =>
|
||||
{
|
||||
if (_texture2D) Destroy(_texture2D); // Manually clear the old texture
|
||||
_texture2D = texture2D;
|
||||
|
||||
// Set the new (captured) screenshot texture to the cube renderer.
|
||||
m_CubeMeshRenderer.material.mainTexture = texture2D;
|
||||
|
||||
SaveTexture(texture2D);
|
||||
});
|
||||
}
|
||||
|
||||
private void SaveTexture(Texture2D texture2D)
|
||||
{
|
||||
// Example: Save to Application data path
|
||||
string savePath = SDev.FileSaveUtil.Instance.SaveTextureAsJPG(texture2D, ApplicationPath, SubFolderName, FileName);
|
||||
//string savePath = SDev.FileSaveUtil.Instance.SaveTextureAsJPG(texture2D, System.Environment.SpecialFolder.MyPictures, SubFolderName, FileName);
|
||||
Debug.Log("Result - Texture resolution: " + texture2D.width + " x " + texture2D.height + "\nSaved at: " + savePath);
|
||||
|
||||
|
||||
// ----- Below are other save methods for different Unity player platforms (ScreenshotHelper Plus or related plugin required) -----
|
||||
|
||||
// Example: Save to mobile device gallery(iOS/Android). <- Requires Mobile Media Plugin (Included in Screenshot Helper Plus, and SwanDev GIF Assets)
|
||||
//MobileMedia.SaveImage(texture2D, SubFolderName, FileName, MobileMedia.ImageFormat.JPG);
|
||||
|
||||
// Example: Save to persistent data path on WebGL
|
||||
//savePath = SDev.EasyIO.SaveImage(texture2D, SDev.EasyIO.ImageEncodeFormat.JPG, FileName + ".jpg", SubFolderName);
|
||||
|
||||
// Example: Open the 'Save As' dialog box on WebGL
|
||||
//SDev.EasyIO.WebGL_SaveToLocal(texture2D.EncodeToJPG(), FileName + ".jpg");
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
ScreenshotHelper.iClear();
|
||||
}
|
||||
|
||||
public void OpenSaveFolder()
|
||||
{
|
||||
string dir = SDev.FileSaveUtil.Instance.GetAppPath(ApplicationPath);
|
||||
string path = System.IO.Path.Combine(dir, SubFolderName);
|
||||
if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path);
|
||||
|
||||
#if UNITY_EDITOR_OSX
|
||||
System.Diagnostics.Process.Start(path);
|
||||
#else
|
||||
Application.OpenURL(path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
20
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.cs.meta
vendored
Normal file
20
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.cs.meta
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d815b251b9ae2747be1c55d055b1586
|
||||
timeCreated: 1532478200
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 130885
|
||||
packageName: Screenshot Helper Free
|
||||
packageVersion: 1.3.8
|
||||
assetPath: Assets/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.cs
|
||||
uploadId: 673764
|
||||
1698
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.unity
vendored
Normal file
1698
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.unity
vendored
Normal file
File diff suppressed because it is too large
Load Diff
16
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.unity.meta
vendored
Normal file
16
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.unity.meta
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a490636f8f553fa4ca906067cf6c9fa7
|
||||
timeCreated: 1532478803
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 130885
|
||||
packageName: Screenshot Helper Free
|
||||
packageVersion: 1.3.8
|
||||
assetPath: Assets/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemo.unity
|
||||
uploadId: 673764
|
||||
63
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemoSettings.lighting
vendored
Normal file
63
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemoSettings.lighting
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!850595691 &4890085278179872738
|
||||
LightingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: MinimumDemoSettings
|
||||
serializedVersion: 3
|
||||
m_GIWorkflowMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_RealtimeEnvironmentLighting: 1
|
||||
m_BounceScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_UsingShadowmask: 0
|
||||
m_BakeBackend: 0
|
||||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 40
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 1
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAO: 0
|
||||
m_MixedBakeMode: 1
|
||||
m_LightmapsBakeMode: 1
|
||||
m_FilterMode: 1
|
||||
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_RealtimeResolution: 2
|
||||
m_ForceWhiteAlbedo: 0
|
||||
m_ForceUpdates: 0
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherRayCount: 256
|
||||
m_FinalGatherFiltering: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVREnvironmentSampleCount: 500
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_PVRBounces: 2
|
||||
m_PVRMinBounces: 2
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
15
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemoSettings.lighting.meta
vendored
Normal file
15
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemoSettings.lighting.meta
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5563661363824e8397f0744c8c5b77d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 4890085278179872738
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 130885
|
||||
packageName: Screenshot Helper Free
|
||||
packageVersion: 1.3.8
|
||||
assetPath: Assets/SWAN Dev/ScreenshotHelper/Scenes/MinimumDemoSettings.lighting
|
||||
uploadId: 673764
|
||||
223
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.cs
vendored
Normal file
223
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.cs
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
/// <summary>
|
||||
/// By SwanDEV 2017
|
||||
/// </summary>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// Screenshot Helper example.
|
||||
/// </summary>
|
||||
public class ScreenshotDemo : DImageDisplayHandler // Inherits the image handler script, we use this handler to set the captured texture/sprite for displaying on the UI Image in this demo.
|
||||
{
|
||||
[Header("[ Save Settings ]")]
|
||||
public FilePathName.SaveFormat saveFormat = FilePathName.SaveFormat.JPG;
|
||||
|
||||
[Header("[ Camera Capture (Camera Capture method example) ]")]
|
||||
[Tooltip("Request Texture2D or RenderTexture?")]
|
||||
public bool m_RequestTexture2D_CameraCapture = true;
|
||||
public float m_Scale = 1f;
|
||||
public int m_TaregtWidth, m_TargetHeight;
|
||||
|
||||
[Header("[ Capture Cutout (Capture screen with cutout area Example) ]")]
|
||||
public Vector2 iCaptureRegionSize = new Vector2(512, 512);
|
||||
|
||||
[Header("[ Object References ]")]
|
||||
public CanvasScaler canvasScaler;
|
||||
public UnityEngine.UI.Image displayImage;
|
||||
public Text debugText;
|
||||
public InputField widthInputField;
|
||||
public InputField heightInputField;
|
||||
public MeshRenderer cubeMesh;
|
||||
|
||||
public Camera camera1;
|
||||
public Camera camera2;
|
||||
public Camera camera3;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Check the max. texture size support by the current device GPU
|
||||
Debug.Log("Max. texture size support by the current device GPU: " + SystemInfo.maxTextureSize);
|
||||
|
||||
// Set the anti-aliasing level (1, 2, 4, 8), 1 = disable; 8 = best quality.
|
||||
ScreenshotHelper.AntiAliasingLevel = 8;
|
||||
|
||||
ScreenshotHelper.iSetMainOnCapturedCallback((Sprite sprite) =>
|
||||
{
|
||||
// Your Code to use the captured sprite..
|
||||
SetImage(sprite);
|
||||
cubeMesh.material.mainTexture = sprite.texture;
|
||||
|
||||
switch (saveFormat)
|
||||
{
|
||||
case FilePathName.SaveFormat.JPG:
|
||||
SaveAsJPG(sprite.texture);
|
||||
break;
|
||||
case FilePathName.SaveFormat.PNG:
|
||||
SaveAsPNG(sprite.texture);
|
||||
break;
|
||||
case FilePathName.SaveFormat.GIF:
|
||||
#if PRO_GIF
|
||||
// Require Pro GIF to save image(s) as GIF.
|
||||
SaveAsGIF(sprite.texture);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// Show screenshot helper debug message
|
||||
ScreenshotHelper.Instance.m_DebugText = debugText;
|
||||
|
||||
OnInputChanges();
|
||||
|
||||
// Check screen orientation for setting canvas resolution
|
||||
if(Screen.width > Screen.height)
|
||||
{
|
||||
canvasScaler.referenceResolution = new Vector2(1920, 1080);
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasScaler.referenceResolution = new Vector2(1080, 1920);
|
||||
}
|
||||
}
|
||||
|
||||
private PointerEventData uiPointerEventData = new PointerEventData(EventSystem.current);
|
||||
private List<RaycastResult> uiRaycastResuls = new List<RaycastResult>();
|
||||
private bool _isPointedOnUI = false;
|
||||
private void Update()
|
||||
{
|
||||
/*if(Input.GetMouseButtonDown(0))
|
||||
{
|
||||
uiPointerEventData.position = Input.mousePosition;
|
||||
EventSystem.current.RaycastAll(uiPointerEventData, uiRaycastResuls);
|
||||
_isPointedOnUI = (uiRaycastResuls.Count > 0)? true:false;
|
||||
}
|
||||
|
||||
if(Input.GetMouseButtonUp(0))
|
||||
{
|
||||
if(!_isPointedOnUI)
|
||||
{
|
||||
ScreenshotHelper.iCapture(Input.mousePosition, iCaptureRegionSize, (texture2D) => {
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("Touch to capture screen, result image size: " + texture2D.width + " x " + texture2D.height);
|
||||
});
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void OnInputChanges()
|
||||
{
|
||||
int captureWidth = 512;
|
||||
int.TryParse(widthInputField.text, out captureWidth);
|
||||
|
||||
int captureHeight = 512;
|
||||
int.TryParse(heightInputField.text, out captureHeight);
|
||||
|
||||
iCaptureRegionSize = new Vector2(captureWidth, captureHeight);
|
||||
}
|
||||
|
||||
public void CaptureScreen()
|
||||
{
|
||||
ScreenshotHelper.iCaptureScreen((texture2D)=>{
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("iCaptureScreen - result image size: " + texture2D.width + " x " + texture2D.height);
|
||||
});
|
||||
}
|
||||
|
||||
public void CaptureWithCamera(Camera camera)
|
||||
{
|
||||
if (m_RequestTexture2D_CameraCapture)
|
||||
{
|
||||
if (m_Scale > 0)
|
||||
{
|
||||
// Capture with camera, request Texture2D of the specific scale:
|
||||
ScreenshotHelper.iCaptureWithCamera(camera, m_Scale, (texture2D) =>
|
||||
{
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("1. iCaptureWithCamera - result image size: " + texture2D.width + " x " + texture2D.height);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Capture with camera, request Texture2D of the specific Width and Height:
|
||||
ScreenshotHelper.iCaptureWithCamera(camera, (texture2D) =>
|
||||
{
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("2. iCaptureWithCamera - result image size: " + texture2D.width + " x " + texture2D.height);
|
||||
}, m_TaregtWidth, m_TargetHeight);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Scale > 0)
|
||||
{
|
||||
// Capture with camera, request RenderTexture of the specific scale:
|
||||
ScreenshotHelper.iCaptureWithCamera_RenderTexture(camera, m_Scale, (renderTexture) =>
|
||||
{
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("3. iCaptureWithCamera - result image size: " + renderTexture.width + " x " + renderTexture.height);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Capture with camera, request RenderTexture of the specific Width and Height:
|
||||
ScreenshotHelper.iCaptureWithCamera_RenderTexture(camera, (renderTexture) =>
|
||||
{
|
||||
// Your Code to use the captured texture..
|
||||
Debug.Log("4. iCaptureWithCamera - result image size: " + renderTexture.width + " x " + renderTexture.height);
|
||||
}, m_TaregtWidth, m_TargetHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetImage(Sprite sprite)
|
||||
{
|
||||
base.Clear(displayImage); // Clear the previous texture (if any)
|
||||
base.SetImage(displayImage, sprite); // Set the sprite to the UI Image, using the DImageDisplayHandler that inherited by this demo script.
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
base.Clear(displayImage);
|
||||
displayImage.rectTransform.sizeDelta = Vector2.zero;
|
||||
ClearScreenshotHelper();
|
||||
}
|
||||
|
||||
public void ClearScreenshotHelper()
|
||||
{
|
||||
ScreenshotHelper.iClear(clearCallback: false, clearTextures: true);
|
||||
}
|
||||
|
||||
private void SaveAsJPG(Texture2D tex2D)
|
||||
{
|
||||
string debugMessage = "Saved_as_JPG_to:_" + new FilePathName().SaveTextureAs(tex2D, FilePathName.SaveFormat.JPG);
|
||||
ScreenshotHelper.Instance.UpdateDebugText(debugMessage);
|
||||
}
|
||||
|
||||
private void SaveAsPNG(Texture2D tex2D)
|
||||
{
|
||||
string debugMessage = "Saved_as_PNG_to:_" + new FilePathName().SaveTextureAs(tex2D, FilePathName.SaveFormat.PNG);
|
||||
ScreenshotHelper.Instance.UpdateDebugText(debugMessage);
|
||||
}
|
||||
|
||||
#if PRO_GIF
|
||||
private void SaveAsGIF(Texture2D tex2D)
|
||||
{
|
||||
string debugMessage = "Saved as GIF to: " + new FilePathName().SaveTextureAs(tex2D, FilePathName.SaveFormat.GIF);
|
||||
ScreenshotHelper.Instance.UpdateDebugText(debugMessage);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void UnRegRenderCameras()
|
||||
{
|
||||
ScreenshotHelper.iUnRegisterAllRenderCameras();
|
||||
}
|
||||
|
||||
public void MoreAssets()
|
||||
{
|
||||
Application.OpenURL("https://www.swanob2.com/assets");
|
||||
}
|
||||
}
|
||||
19
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.cs.meta
vendored
Normal file
19
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.cs.meta
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 614475b0fd1d54ad088aeff598138f0d
|
||||
timeCreated: 1507705456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 130885
|
||||
packageName: Screenshot Helper Free
|
||||
packageVersion: 1.3.8
|
||||
assetPath: Assets/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.cs
|
||||
uploadId: 673764
|
||||
5883
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.unity
vendored
Normal file
5883
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.unity
vendored
Normal file
File diff suppressed because it is too large
Load Diff
15
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.unity.meta
vendored
Normal file
15
Assets/External/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.unity.meta
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33689c9ca9ef3489da2cace4a1b94d00
|
||||
timeCreated: 1507723470
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 130885
|
||||
packageName: Screenshot Helper Free
|
||||
packageVersion: 1.3.8
|
||||
assetPath: Assets/SWAN Dev/ScreenshotHelper/Scenes/ScreenshotDemo.unity
|
||||
uploadId: 673764
|
||||
Reference in New Issue
Block a user