Add the screenshot helper to the project, add assembly definitions and setup cross-references

This commit is contained in:
Michal Pikulski
2025-11-25 10:46:01 +01:00
parent 86c1df55f2
commit 83fcf24f52
89 changed files with 14031 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CanvasScaler))]
public class DCanvasScalerHandler : MonoBehaviour
{
public Vector2 m_ReferenceResolution = new Vector2(1080, 1920);
void Start ()
{
CanvasScaler cs = GetComponent<CanvasScaler>();
if(cs)
{
if(Screen.width > Screen.height)
{
if(m_ReferenceResolution.x > m_ReferenceResolution.y) cs.referenceResolution = m_ReferenceResolution;
else cs.referenceResolution = new Vector2(m_ReferenceResolution.y, m_ReferenceResolution.x);
}
else
{
if (m_ReferenceResolution.x > m_ReferenceResolution.y) cs.referenceResolution = new Vector2(m_ReferenceResolution.y, m_ReferenceResolution.x);
else cs.referenceResolution = m_ReferenceResolution;
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 4d97ce3077157c54db6c6ae23cd38048
timeCreated: 1548426802
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/Common/DCanvasScalerHandler.cs
uploadId: 673764

View File

@@ -0,0 +1,276 @@
// Created by SwanDEV 2018
using UnityEngine;
/// <summary>
/// DynamicUI - Image Display Handler for UGUI Image & RawImage.
/// How to use: (1) add as a base class (Inherits), (2) Drop this script in a GameObject and reference it.
/// Call the SetImage/SetRawImage method.
/// </summary>
public class DImageDisplayHandler : MonoBehaviour
{
public enum BoundingTarget
{
/// <summary> Constraints the target image with the Vector2 size(m_Size). </summary>
Size,
/// <summary> Constraints the target image with the sizeDelta of the RectTranform(m_RectTransform). </summary>
RectTransform,
/// <summary> Constraints the target image with the device screen size. </summary>
Screen,
}
public enum BoundingType
{
SetNativeSize = 0,
/// <summary> Sets the entire image RectTransform to be constrained within a specified area size (width and height). </summary>
WidthAndHeight,
/// <summary> Sets the image RectTransform's width equal to the width of specified area size, the image height is not constrained. </summary>
Width,
/// <summary> Sets the image RectTransform's height equal to the height of specified area size, the image width is not constrained. </summary>
Height,
/// <summary> Sets the image RectTransform to cover the entire specified area size, either the image width or height will exceed that size if the aspect ratio is different. </summary>
FillAll,
}
[Header("[ Image Display Handler ]")]
public BoundingTarget m_BoundingTarget = BoundingTarget.Size;
public RectTransform m_RectTransform;
public Vector2 m_Size = new Vector2(512, 512);
[Space()]
public BoundingType m_BoundingType = BoundingType.SetNativeSize;
[Space()]
public float m_ScaleFactor = 1f;
/// <summary>Auto clear the texture of the last set Image/RawImage before setting a new one.</summary>
[Space()]
[Tooltip("Auto clear the texture of the last set Image/RawImage before setting a new one.")]
public bool m_AutoClearTexture = true;
/// <summary>
/// Is the target display(Image/RawImage) RectTranform (eulerAngles.z) rotated by 90/-90.
/// </summary>
[HideInInspector] public bool m_Rotated_90 = false;
public void SetImage(UnityEngine.UI.Image displayImage, Sprite sprite)
{
if (m_AutoClearTexture) Clear(displayImage);
displayImage.sprite = sprite;
_SetSize(displayImage);
}
public void SetImage(UnityEngine.UI.Image displayImage, Texture2D texture2D)
{
if (m_AutoClearTexture) Clear(displayImage);
displayImage.sprite = _TextureToSprite(texture2D);
_SetSize(displayImage);
}
public void SetRawImage(UnityEngine.UI.RawImage displayImage, Sprite sprite)
{
if (m_AutoClearTexture) Clear(displayImage);
displayImage.texture = (Texture)sprite.texture;
_SetSize(displayImage);
}
public void SetRawImage(UnityEngine.UI.RawImage displayImage, Texture2D texture2D)
{
if (m_AutoClearTexture) Clear(displayImage);
displayImage.texture = (Texture)texture2D;
_SetSize(displayImage);
}
public void SetRawImage(UnityEngine.UI.RawImage displayImage, Texture texture)
{
if (m_AutoClearTexture) Clear(displayImage);
displayImage.texture = texture;
_SetSize(displayImage);
}
public void SetImage(UnityEngine.UI.Image displayImage, float width, float height)
{
displayImage.rectTransform.sizeDelta = _CalculateSize(new Vector2(width, height));
_ApplyScaleFactor(displayImage.transform);
}
public void SetRawImage(UnityEngine.UI.RawImage displayImage, float width, float height)
{
displayImage.rectTransform.sizeDelta = _CalculateSize(new Vector2(width, height));
_ApplyScaleFactor(displayImage.transform);
}
private void _SetSize(UnityEngine.UI.Image displayImage)
{
if (m_BoundingType == BoundingType.SetNativeSize)
{
displayImage.SetNativeSize();
}
else
{
displayImage.rectTransform.sizeDelta = _CalculateSize(new Vector2(displayImage.sprite.texture.width, displayImage.sprite.texture.height));
}
_ApplyScaleFactor(displayImage.transform);
}
private void _SetSize(UnityEngine.UI.RawImage displayImage)
{
if (m_BoundingType == BoundingType.SetNativeSize)
{
displayImage.SetNativeSize();
}
else
{
displayImage.rectTransform.sizeDelta = _CalculateSize(new Vector2(displayImage.texture.width, displayImage.texture.height));
}
_ApplyScaleFactor(displayImage.transform);
}
private void _ApplyScaleFactor(Transform displayImageT)
{
displayImageT.localScale = new Vector3(m_ScaleFactor, m_ScaleFactor, 1f);
}
private Vector2 _CalculateSize(Vector2 textureSize)
{
Vector2 boundarySize = Vector2.zero;
switch (m_BoundingTarget)
{
case BoundingTarget.Size:
boundarySize = m_Size;
break;
case BoundingTarget.RectTransform:
boundarySize = m_RectTransform.GetComponent<RectTransform>().rect.size;
break;
case BoundingTarget.Screen:
boundarySize = new Vector2(Screen.width, Screen.height);
break;
}
float newWidth = textureSize.x;
float newHeight = textureSize.y;
float imageRatio = newWidth / newHeight;
switch (m_BoundingType)
{
case BoundingType.FillAll:
if (m_Rotated_90)
{
newHeight = boundarySize.x;
newWidth = newHeight * imageRatio;
if (newWidth < boundarySize.y)
{
newWidth = boundarySize.y;
newHeight = newWidth / imageRatio;
}
}
else
{
newWidth = boundarySize.x;
newHeight = newWidth / imageRatio;
if (newHeight < boundarySize.y)
{
newHeight = boundarySize.y;
newWidth = newHeight * imageRatio;
}
}
break;
case BoundingType.WidthAndHeight:
if (m_Rotated_90)
{
newHeight = boundarySize.x;
newWidth = newHeight * imageRatio;
if (newWidth > boundarySize.y)
{
newWidth = boundarySize.y;
newHeight = newWidth / imageRatio;
}
}
else
{
newWidth = boundarySize.x;
newHeight = newWidth / imageRatio;
if (newHeight > boundarySize.y)
{
newHeight = boundarySize.y;
newWidth = newHeight * imageRatio;
}
}
break;
case BoundingType.Width:
if (m_Rotated_90)
{
newHeight = boundarySize.x;
newWidth = newHeight * imageRatio;
}
else
{
newWidth = boundarySize.x;
newHeight = newWidth / imageRatio;
}
break;
case BoundingType.Height:
if (m_Rotated_90)
{
newWidth = boundarySize.y;
newHeight = newWidth / imageRatio;
}
else
{
newHeight = boundarySize.y;
newWidth = newHeight * imageRatio;
}
break;
default:
newWidth = textureSize.x;
newHeight = textureSize.y;
break;
}
return new Vector2(newWidth, newHeight);
}
private Sprite _TextureToSprite(Texture2D texture)
{
if (texture == null) return null;
Vector2 pivot = new Vector2(0.5f, 0.5f);
float pixelPerUnit = 100;
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), pivot, pixelPerUnit);
}
public void Clear(UnityEngine.UI.Image displayImage)
{
if (displayImage != null && displayImage.sprite != null && displayImage.sprite.texture != null)
{
Destroy(displayImage.sprite.texture);
displayImage.sprite = null;
}
}
public void Clear(UnityEngine.UI.RawImage displayImage)
{
if (displayImage != null && displayImage.texture != null)
{
Destroy(displayImage.texture);
displayImage.texture = null;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: a44aec65d5a8844b1b91534d0499c7bb
timeCreated: 1523165703
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/Common/DImageDisplayHandler.cs
uploadId: 673764

View File

@@ -0,0 +1,781 @@
// Created by SwanDEV 2017
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
using System.Text;
#if UNITY_2017_3_OR_NEWER
using UnityEngine.Networking;
#endif
/// <summary> Files, Paths, Names and IO common methods. (Last update: 2024-06-25) </summary>
public class FilePathName
{
private static string _lastGeneratedFileNameWithoutExt_fff = "";
private static int _lastSameFileNameCounter_fff = 1;
private static string _lastGeneratedFileNameWithoutExt = "";
private static int _lastSameFileNameCounter = 1;
public enum SaveFormat
{
NONE = -1,
GIF = 0,
JPG = 1,
PNG = 2,
}
#region ----- Instance -----
private static FilePathName fpn = null;
public static FilePathName Instance
{
get
{
if (fpn == null) fpn = new FilePathName();
return fpn;
}
}
#endregion
#region ----- Path & FileName -----
public enum AppPath
{
/// <summary> The directory path where you can store data that you want to be kept between runs. </summary>
PersistentDataPath = 0,
/// <summary> The directory path where temporary data can be stored. </summary>
TemporaryCachePath,
/// <summary> The folder located at /Assets/StreamingAssets in the project. Files in this directory will be included in the build. (Not work with System.IO methods when running on Android/WebGL, use Unity WWW or WebRequest instead) </summary>
StreamingAssetsPath,
/// <summary> The path at /Assets in the project. (Works in Unity editor only) </summary>
DataPath
}
public string GetAppPath(AppPath appPath)
{
string directory = "";
switch (appPath)
{
case AppPath.PersistentDataPath:
directory = Application.persistentDataPath;
break;
case AppPath.TemporaryCachePath:
directory = Application.temporaryCachePath;
break;
case AppPath.StreamingAssetsPath:
directory = Application.streamingAssetsPath;
break;
case AppPath.DataPath:
directory = Application.dataPath;
break;
}
return directory;
}
public string GetSaveDirectory(bool isTemporaryPath = false, string subFolder = "", bool createDirectoryIfNotExist = false)
{
string result = "";
if (isTemporaryPath)
{
result = Application.temporaryCachePath;
}
else
{
#if UNITY_EDITOR
result = Application.dataPath;
//result = Application.persistentDataPath;
#else
result = Application.persistentDataPath;
#endif
}
result = string.IsNullOrEmpty(subFolder) ? result : Path.Combine(result, subFolder);
if (createDirectoryIfNotExist && !Directory.Exists(result))
{
Directory.CreateDirectory(result);
}
return result;
}
public string GetFileNameWithoutExt(bool millisecond = false)
{
if (millisecond)
{
return _GetComparedFileName(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"),
_lastGeneratedFileNameWithoutExt_fff, _lastSameFileNameCounter_fff,
out _lastGeneratedFileNameWithoutExt_fff, out _lastSameFileNameCounter_fff);
}
return _GetComparedFileName(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"),
_lastGeneratedFileNameWithoutExt, _lastSameFileNameCounter,
out _lastGeneratedFileNameWithoutExt, out _lastSameFileNameCounter);
}
private string _GetComparedFileName(string newFileName, string lastGeneratedFileName, int sameFileNameCounter,
out string outLastGeneratedFileName, out int outSameFileNameCounter)
{
if (lastGeneratedFileName == newFileName)
{
sameFileNameCounter++;
}
else
{
sameFileNameCounter = 1;
}
outLastGeneratedFileName = newFileName;
outSameFileNameCounter = sameFileNameCounter;
if (sameFileNameCounter > 1)
{
newFileName += " " + sameFileNameCounter;
}
return newFileName;
}
public string GenerateFileNameWithDateTimeParameters(int YYYY, int MM, int DD, int hh = 0, int mm = 0, int ss = 0, int fff = -1)
{
DateTime dateTime = new DateTime(Mathf.Clamp(YYYY, 1, 9999), Mathf.Clamp(MM, 1, 12), Mathf.Clamp(DD, 1, 31), Mathf.Clamp(hh, 0, 23), Mathf.Clamp(mm, 0, 59), Mathf.Clamp(ss, 0, 59), Mathf.Clamp(fff, 0, 999));
return dateTime.ToString("yyyy-MM-dd-HH-mm-ss" + (fff < 0 ? "" : "-fff"));
}
/// <summary>
/// Parse the time string (generated by FilePathName class) to DateTime.
/// </summary>
/// <param name="timeString_FPN"> Time string generated by FilePathName class (e.g: 2019-08-31-00-00-00-000, or without millisecond: 2019-08-31-00-00-00) </param>
public DateTime TimeStringToTime(string timeString_FPN)
{
string[] texts = timeString_FPN.Split('-');
int.TryParse(texts[0], out int YYYY);
int.TryParse(texts[1], out int MM);
int.TryParse(texts[2], out int DD);
int.TryParse(texts[3], out int hh);
int.TryParse(texts[4], out int mm);
int.TryParse(texts[5], out int ss);
int fff = -1;
if (texts.Length > 6) int.TryParse(texts[6].Substring(0, 3), out fff);
DateTime dt = fff == -1 ? new DateTime(YYYY, MM, DD, hh, mm, ss) : new DateTime(YYYY, MM, DD, hh, mm, ss, fff);
return dt;
}
/// <summary>
/// Parse the filename (generated by FilePathName class) to DateTime.
/// </summary>
/// <param name="timeStringFileName_FPN"> FileName generated by FilePathName class (e.g: Photo_2019-08-31-00-00-00-000.jpg/.png, or without millisecond: Photo_2019-08-31-00-00-00.jpg/.png) </param>
public DateTime FileNameToTime(string timeStringFileName_FPN)
{
if (timeStringFileName_FPN.Contains(".")) timeStringFileName_FPN = timeStringFileName_FPN.Substring(0, timeStringFileName_FPN.IndexOf('.'));
string[] texts1 = timeStringFileName_FPN.Split('_');
return TimeStringToTime(texts1[0]);
}
/// <summary>
/// Compare the filename (generated by FilePathName class) with the provided DateTime. Return -1, 0, 1. (-1: fileName time is earlier; 0: equals; 1: fileName time is later)
/// </summary>
/// <param name="timeStringFileName_FPN"> FileName generated by FilePathName class (e.g: Photo_2019-08-31-00-00-00-000.jpg/.png, or without millisecond: Photo_2019-08-31-00-00-00.jpg/.png) </param>
/// <param name="dateTime"> The DateTime to be compared with the time formated file name string. </param>
public int CompareFileNameWithTime(string timeStringFileName_FPN, DateTime dateTime)
{
DateTime dt = FileNameToTime(timeStringFileName_FPN);
if (dt == dateTime) return 0;
else if (dt > dateTime) return 1;
else return -1;
}
/// <summary>
/// Check if the filename (generated by FilePathName class) within the Start and End DateTime interval.
/// </summary>
/// <param name="fileName_FPN"> FileName generated by FilePathName class (e.g: Photo_2019-08-31-00-00-00-000.jpg/.png) </param>
/// <param name="startDateTime">Start date time.</param>
/// <param name="endDateTime">End date time.</param>
public bool CheckFileNameWithinDateTimeInterval(string fileName_FPN, DateTime startDateTime, DateTime endDateTime)
{
return CompareFileNameWithTime(fileName_FPN, startDateTime) >= 0 && CompareFileNameWithTime(fileName_FPN, endDateTime) <= 0;
}
public string EnsureValidPath(string pathOrUrl)
{
string path = pathOrUrl;
if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{
// WEB
}
else if (path.StartsWith("/idbfs/", StringComparison.OrdinalIgnoreCase))
{
// WebGL index DB
}
else
{
// Local path
path = EnsureLocalPath(path);
}
return path;
}
/// <summary>
/// Ensure the given path is a local path supported by the WWW/UWR class.
/// </summary>
public string EnsureLocalPath(string path)
{
if (path.StartsWith("jar:", StringComparison.OrdinalIgnoreCase)) // Android streamingAssetsPath
{ }
else if (!path.StartsWith("file:///", StringComparison.OrdinalIgnoreCase))
{
while (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
{
path = path.Remove(0, 1);
}
path = "file:///" + path;
}
return path;
}
public string EnsureValidFileName(string fileName)
{
string replaceChars = "[:\\\\/*\"?|<>']";
for (int i = 0; i < replaceChars.Length; i++)
{
if (fileName.Contains(replaceChars[i].ToString()))
{
fileName = fileName.Replace(replaceChars[i], '_');
}
}
return fileName;
}
public string GetGifFileName()
{
string timestamp = GetFileNameWithoutExt();
return "GIF_" + timestamp;
}
public string GetGifFullPath(string subFolder = "", bool createDirectoryIfNotExist = false)
{
return GetSaveDirectory(false, subFolder, createDirectoryIfNotExist) + "/" + GetGifFileName() + ".gif";
}
public string GetDownloadedGifSaveFullPath(string subFolder = "", bool createDirectoryIfNotExist = false)
{
return GetSaveDirectory(false, subFolder, createDirectoryIfNotExist) + "/" + GetGifFileName() + ".gif";
}
public string GetJpgFileName()
{
string timestamp = GetFileNameWithoutExt(true);
return "Photo_" + timestamp;
}
public string GetJpgFullPath(string subFolder = "", bool createDirectoryIfNotExist = false)
{
return GetSaveDirectory(false, subFolder, createDirectoryIfNotExist) + "/" + GetJpgFileName() + ".jpg";
}
public string GetPngFileName()
{
string timestamp = GetFileNameWithoutExt(true);
return "Photo_" + timestamp;
}
public string GetPngFullPath(string subFolder = "", bool createDirectoryIfNotExist = false)
{
return GetSaveDirectory(false, subFolder, createDirectoryIfNotExist) + "/" + GetPngFileName() + ".png";
}
#endregion
#region ----- IO -----
public byte[] ReadFileToBytes(string fromFullPath)
{
if (!File.Exists(fromFullPath))
{
#if UNITY_EDITOR
Debug.LogWarning("File Not Found: " + fromFullPath);
#endif
return null;
}
return File.ReadAllBytes(fromFullPath);
}
public void WriteBytesToFile(string toFullPath, byte[] byteArray)
{
CheckToCreateDirectory(Path.GetDirectoryName(toFullPath));
File.WriteAllBytes(toFullPath, byteArray);
}
public void CopyFile(string fromFullPath, string toFullPath, bool overwrite = false)
{
if (!File.Exists(fromFullPath))
{
#if UNITY_EDITOR
Debug.LogWarning("File Not Found: " + fromFullPath);
#endif
return;
}
CheckToCreateDirectory(Path.GetDirectoryName(toFullPath));
File.Copy(fromFullPath, toFullPath, overwrite);
}
public void MoveFile(string fromFullPath, string toFullPath, bool replaceIfExist = false)
{
if (!File.Exists(fromFullPath))
{
#if UNITY_EDITOR
Debug.LogWarning("File Not Found: " + fromFullPath);
#endif
return;
}
if (replaceIfExist && File.Exists(toFullPath)) File.Delete(toFullPath);
CheckToCreateDirectory(Path.GetDirectoryName(toFullPath));
File.Move(fromFullPath, toFullPath);
}
public void DeleteFile(string fileFullPath)
{
if (!File.Exists(fileFullPath))
{
#if UNITY_EDITOR
Debug.LogWarning("File Not Found: " + fileFullPath);
#endif
return;
}
File.Delete(fileFullPath);
}
public void CheckToCreateDirectory(string directory)
{
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
}
/// <summary> Determine whether a given path is a directory. </summary>
public bool PathIsDirectory(string path)
{
FileAttributes attr = File.GetAttributes(path);
if ((attr & FileAttributes.Directory) == FileAttributes.Directory) return true; else return false;
}
public void RenameFile(string originFilePath, string newFileName)
{
string directory = Path.GetDirectoryName(originFilePath);
string newFilePath = Path.Combine(directory, newFileName);
CopyFile(originFilePath, newFilePath, true);
}
public bool FileStreamTo(string fileFullpath, byte[] byteArray)
{
try
{
CheckToCreateDirectory(Path.GetDirectoryName(fileFullpath));
using (FileStream fs = new FileStream(fileFullpath, FileMode.Create, FileAccess.Write))
{
fs.Write(byteArray, 0, byteArray.Length);
return true; // success
}
}
catch (Exception e)
{
Console.WriteLine("Exception caught in process: {0}", e);
return false; // fail
}
}
public void WriteBytesToText(byte[] bytes, string toFileFullPath, string separator = "", bool toChar = true)
{
// int bkCount = 0;
StringBuilder sb = new StringBuilder();
if (string.IsNullOrEmpty(separator))
{
if (toChar)
{
for (int i = 0; i < bytes.Length; i++)
{
sb.Append((char)bytes[i]);
}
}
else
{
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(bytes[i]);
//Test
// bkCount++;
// if(bkCount == 3)
// {
// bkCount = 0;
// sb.Append(" (" + (i+1)/3 + ")\n");
// }
}
}
}
else
{
if (toChar)
{
for (int i = 0; i < bytes.Length; i++)
{
sb.Append((char)bytes[i]);
sb.Append(separator);
}
}
else
{
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(bytes[i]);
sb.Append(separator);
//Test
// bkCount++;
// if(bkCount == 3)
// {
// bkCount = 0;
// sb.Append(" (" + ((i+1)/3-1) + ")\n");
// }
}
}
}
CheckToCreateDirectory(Path.GetDirectoryName(toFileFullPath));
File.WriteAllText(toFileFullPath, sb.ToString());
}
/// <summary>
/// Saves texture as JPG/PNG on Windows/Mac.
/// </summary>
public string SaveImage(Texture2D texture, string subFolder, string fileName, SaveFormat imageFormat, Environment.SpecialFolder specialFolder = Environment.SpecialFolder.MyPictures, int jpgQuality = 90)
{
string extensionName = "." + imageFormat.ToString().ToLower();
byte[] bytes = null;
string gifPath = "";
switch (imageFormat)
{
case SaveFormat.JPG:
bytes = texture.EncodeToJPG(jpgQuality);
break;
case SaveFormat.PNG:
bytes = texture.EncodeToPNG();
break;
case SaveFormat.GIF:
#if PRO_GIF
gifPath = SaveBytes(new byte[] { 0 }, subFolder, fileName + extensionName, specialFolder);
ProGifTexturesToGIF tex2Gif = ProGifTexturesToGIF.Instance;
tex2Gif.Save(new List<Texture2D> { texture }, texture.width, texture.height, 1, -1, 10, (id, path) =>
{
Debug.Log("Save GIF.." + path + "\n" + gifPath);
CopyFile(path, gifPath, true);
DeleteFile(path);
}, null, ProGifTexturesToGIF.ResizeMode.ResizeKeepRatio, false);
#endif
break;
}
if (!string.IsNullOrEmpty(gifPath))
{
return gifPath;
}
return SaveBytes(bytes, subFolder, fileName + extensionName, specialFolder);
}
/// <summary>
/// Saves file byte array on Windows/Mac.
/// </summary>
public string SaveBytes(byte[] bytes, string subFolder, string fileNameWithExtension, Environment.SpecialFolder specialFolder = Environment.SpecialFolder.MyPictures)
{
string directory = Path.Combine(Environment.GetFolderPath(specialFolder), subFolder);
string savePath = Path.Combine(directory, fileNameWithExtension);
WriteBytesToFile(savePath, bytes);
return savePath;
}
public string SaveTextureAs(Texture2D texture2D, SaveFormat format = SaveFormat.JPG)
{
string savePath = string.Empty;
switch (format)
{
case SaveFormat.JPG:
savePath = GetJpgFullPath();
WriteBytesToFile(savePath, texture2D.EncodeToJPG(90));
break;
case SaveFormat.PNG:
savePath = GetPngFullPath();
WriteBytesToFile(savePath, texture2D.EncodeToPNG());
break;
case SaveFormat.GIF:
#if PRO_GIF
savePath = ProGifTexturesToGIF.Instance.Save(new List<Texture2D> { texture2D }, texture2D.width, texture2D.height, 1, -1, 10, null, null, ProGifTexturesToGIF.ResizeMode.ResizeKeepRatio, false);
#endif
break;
}
return savePath;
}
public string SaveTextureAs(Texture2D texture2D, AppPath appPath, string subFolder, bool isJPG, string optionalFileName_WithoutExtension = "")
{
string savePath = GetAppPath(appPath);
if (!string.IsNullOrEmpty(subFolder)) savePath = Path.Combine(savePath, subFolder);
if (!Directory.Exists(savePath)) Directory.CreateDirectory(savePath);
savePath = Path.Combine(savePath, (string.IsNullOrEmpty(optionalFileName_WithoutExtension) ? GetFileNameWithoutExt(true) : optionalFileName_WithoutExtension) + (isJPG ? ".jpg" : ".png"));
WriteBytesToFile(savePath, (isJPG ? texture2D.EncodeToJPG(90) : texture2D.EncodeToPNG()));
return savePath;
}
#if PRO_GIF
public string SaveTexturesAsGIF(List<Texture2D> textureList, int width, int height, int fps, int loop, int quality,
Action<int, string> onFileSaved = null, Action<int, float> onFileSaveProgress = null,
ProGifTexturesToGIF.ResizeMode resizeMode = ProGifTexturesToGIF.ResizeMode.ResizeKeepRatio)
{
return ProGifTexturesToGIF.Instance.Save(textureList, width, height, fps, loop, quality, onFileSaved, onFileSaveProgress, resizeMode, false);
}
#endif
public Texture2D LoadImage(string fullFilePath)
{
if (!File.Exists(fullFilePath))
{
#if UNITY_EDITOR
Debug.LogWarning("File not exist! " + fullFilePath);
#endif
return null;
}
else
{
Texture2D tex2D = new Texture2D(1, 1); //, TextureFormat.ARGB32, false);
tex2D.LoadImage(ReadFileToBytes(fullFilePath));
return tex2D;
}
}
/// <summary>
/// Load images in the target directory, to a texture2D list.
/// Warning! Loading a folder of images without setting a reasonable limit may crash your app due to running out of memory.
/// </summary>
/// <returns>A list of Texture2D.</returns>
/// <param name="directory">Directory.</param>
/// <param name="fileExtensions">A list of file extension names, indicating the type of files to be loaded. Load jpg, png if Null or Empty.</param>
/// <param name="startIndex">An offset index to load the image files from the target folder.</param>
/// <param name="maxImageToLoad">The maximum number of images to load.</param>
/// <param name="sortingMode">0: no sorting; 1: sort by filename ascending; 2: sort by filename descending</param>
/// <param name="onImageLoaded">A callback to be called on an image loaded, returns: fileIndex, filePath, and the Texture2D</param>
public List<Texture2D> LoadImages(string directory, List<string> fileExtensions = null, int startIndex = 0, int maxImageToLoad = 12, int sortingMode = 0, Action<int, string, Texture2D> onImageLoaded = null)
{
if (fileExtensions == null || fileExtensions.Count == 0)
{
fileExtensions = new List<string> { ".jpg", ".png" };
}
List<Texture2D> textureList = new List<Texture2D>();
List<string> filePaths = GetFilePathsRange(directory, fileExtensions, startIndex, maxImageToLoad, sortingMode);
for (int i = 0; i < filePaths.Count; i++)
{
Texture2D texture = LoadImage(filePaths[i]);
textureList.Add(texture);
onImageLoaded?.Invoke(startIndex + i, filePaths[i], texture);
}
return textureList;
}
/// <summary>
/// Load files in the target directory, to a byte[] list.
/// Warning! Loading a folder of files without setting a reasonable limit may crash your app due to running out of memory.
/// </summary>
/// <returns>A list of files' byte array data.</returns>
/// <param name="directory">Directory.</param>
/// <param name="fileExtensions">A list of file extension names, indicating the type of files to be loaded. Load all files if Null or Empty.</param>
/// <param name="startIndex">An offset index to load the image files from the target folder.</param>
/// <param name="maxImageToLoad">The maximum number of images to load.</param>
/// <param name="sortingMode">0: no sorting; 1: sort by filename ascending; 2: sort by filename descending</param>
/// <param name="onFileLoaded">A callback to be called on an file loaded, returns: fileIndex, filePath, and the file data</param>
public List<byte[]> LoadFiles(string directory, List<string> fileExtensions = null, int startIndex = 0, int maxFileToLoad = 12, int sortingMode = 0, Action<int, string, byte[]> onFileLoaded = null)
{
List<byte[]> fileByteList = new List<byte[]>();
List<string> filePaths = GetFilePathsRange(directory, fileExtensions, startIndex, maxFileToLoad, sortingMode);
for (int i = 0; i < filePaths.Count; i++)
{
byte[] data = ReadFileToBytes(filePaths[i]);
fileByteList.Add(data);
onFileLoaded?.Invoke(startIndex + i, filePaths[i], data);
}
return fileByteList;
}
public List<string> GetFilePathsRange(string directory, List<string> fileExtensions = null, int startIndex = 0, int maxFileToLoad = 12, int sortingMode = 0)
{
List<string> results = new List<string>();
List<string> filePaths = GetFilePaths(directory, fileExtensions, sortingMode);
int total = filePaths.Count;
if (startIndex < total)
{
int loadNum = Mathf.Min(total, startIndex + maxFileToLoad);
for (int i = startIndex; i < loadNum; i++)
{
results.Add(filePaths[i]);
}
}
return results;
}
/// <summary>
/// Get file paths in the target directory.
/// </summary>
/// <returns>File paths list.</returns>
/// <param name="directory">Directory.</param>
/// <param name="fileExtensions">A list of file extension names, indicating the type of file paths to get. Get all file paths if Null or Empty.</param>
/// <param name="sortingMode">0: no sorting; 1: sort by filename ascending; 2: sort by filename descending</param>
public List<string> GetFilePaths(string directory, List<string> fileExtensions = null, int sortingMode = 0)
{
if (!Directory.Exists(directory))
{
#if UNITY_EDITOR
Debug.Log("Directory Not Found: " + directory);
#endif
return new List<string>();
}
string[] allFiles_src = Directory.GetFiles(directory);
bool loadAllFile = (fileExtensions == null) ? true : (fileExtensions.Count == 0 ? true : false);
if (loadAllFile)
{
#if UNITY_EDITOR
Debug.Log("Load ALL");
#endif
List<string> fileList = new List<string>();
int len = allFiles_src.Length;
for (int i = 0; i < len; i++)
{
fileList.Add(allFiles_src[i]);
}
return fileList;
}
#if UNITY_EDITOR
Debug.Log("Load Filtered");
#endif
for (int i = 0; i < fileExtensions.Count; i++)
{
fileExtensions[i] = fileExtensions[i].ToLower();
}
List<string> filteredFilePathList = new List<string>();
foreach (string f in allFiles_src)
{
if (fileExtensions.Contains(Path.GetExtension(f).ToLower()))
{
filteredFilePathList.Add(f);
}
}
if (sortingMode == 1) filteredFilePathList.Sort();
if (sortingMode == 2) filteredFilePathList.Reverse();
return filteredFilePathList;
}
#if UNITY_2017_3_OR_NEWER
/// <summary>
/// Loads texture using UnityWebRequest. Return the texture in the onComplete callback.
/// ( IEnumerator: Remember to call this method in StartCoroutine )
/// </summary>
public IEnumerator LoadTextureUWR(string url, Action<Texture2D> onComplete)
{
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
{
yield return uwr.SendWebRequest();
#if UNITY_2020_1_OR_NEWER
if (uwr.result == UnityWebRequest.Result.ConnectionError || uwr.result == UnityWebRequest.Result.ProtocolError || uwr.result == UnityWebRequest.Result.DataProcessingError)
#else
if (uwr.isNetworkError || uwr.isHttpError)
#endif
{
#if UNITY_EDITOR
Debug.LogWarning("Failed to load texture: " + url);
#endif
}
else
{
if (onComplete != null) onComplete(DownloadHandlerTexture.GetContent(uwr));
}
}
}
#endif
#if UNITY_2017_3_OR_NEWER
/// <summary>
/// Loads file using UnityWebRequest. Return the byte array of the file in the onComplete callback.
/// ( IEnumerator: Remember to call this method in StartCoroutine )
/// </summary>
/// <returns>The file byte array.</returns>
/// <param name="url">Local file path or http/https link.</param>
/// <param name="onComplete">On load completed callback. Return the byte array of the downloaded file.</param>
/// <param name="onCompleteUWR">On load completed callback. Return the UnityWebRequest object.</param>
public IEnumerator LoadFileUWR(string url, Action<byte[]> onComplete = null, Action<UnityWebRequest> onCompleteUWR = null)
{
string path = EnsureValidPath(url);
using (UnityWebRequest uwr = UnityWebRequest.Get(path))
{
uwr.SendWebRequest();
while (!uwr.isDone)
{
yield return null;
}
#if UNITY_2020_1_OR_NEWER
if (uwr.result == UnityWebRequest.Result.ConnectionError || uwr.result == UnityWebRequest.Result.ProtocolError || uwr.result == UnityWebRequest.Result.DataProcessingError)
#else
if (uwr.isNetworkError || uwr.isHttpError)
#endif
{
if (onComplete != null) onComplete(null);
if (onCompleteUWR != null) onCompleteUWR(null);
Debug.LogError("File load error.\n" + uwr.error);
}
else
{
if (onComplete != null) onComplete(uwr.downloadHandler.data);
if (onCompleteUWR != null) onCompleteUWR(uwr);
}
}
}
#else
/// <summary>
/// Loads file using WWW. Return the byte array of the file in onLoadCompleted callback.
/// ( IEnumerator: Remember to call this method in StartCoroutine )
/// </summary>
/// <returns>The file byte array.</returns>
/// <param name="url">Local file path or http/https link.</param>
/// <param name="onLoadCompleted">On load completed callback. Return the byte array of the downloaded file.</param>
/// <param name="onLoadCompletedWWW">On load completed callback. Return the WWW object.</param>
public IEnumerator LoadFileWWW(string url, Action<byte[]> onLoadCompleted = null, Action<WWW> onLoadCompletedWWW = null)
{
string path = EnsureValidPath(url);
using (WWW www = new WWW(path))
{
yield return www;
if (string.IsNullOrEmpty(www.error) == false)
{
if (onLoadCompleted != null) onLoadCompleted(null);
if (onLoadCompletedWWW != null) onLoadCompletedWWW(null);
Debug.LogError("File load error.\n" + www.error);
yield break;
}
if (onLoadCompleted != null) onLoadCompleted(www.bytes);
if (onLoadCompletedWWW != null) onLoadCompletedWWW(www);
}
}
#endif
#endregion
public Sprite Texture2DToSprite(Texture2D texture2D)
{
if (texture2D == null) return null;
Vector2 pivot = new Vector2(0.5f, 0.5f);
float pixelPerUnit = 100;
return Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), pivot, pixelPerUnit);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 4b06fb57cc187478aa017ccb83b15002
timeCreated: 1498492533
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/Common/FilePathName.cs
uploadId: 673764

View File

@@ -0,0 +1,196 @@

using System;
using System.IO;
using UnityEngine;
namespace SDev
{
/// <summary>
/// Save byte array, Texture2D to file on current platform's Application data path or Windows/Mac special folder.
/// </summary>
public class FileSaveUtil
{
public enum AppPath
{
/// <summary> The directory path where you can store data that you want to be kept between runs. </summary>
PersistentDataPath = 0,
/// <summary> The directory path where temporary data can be stored. </summary>
TemporaryCachePath,
/// <summary> The folder located at /Assets/StreamingAssets in the project. (Not work with System.IO methods when running on Android/WebGL) </summary>
StreamingAssetsPath,
/// <summary> The folder located at /Assets in the project. (Work on the Unity editor only) </summary>
DataPath
}
public string GetAppPath(AppPath appPath)
{
string directory = "";
switch (appPath)
{
case AppPath.PersistentDataPath:
directory = Application.persistentDataPath;
break;
case AppPath.TemporaryCachePath:
directory = Application.temporaryCachePath;
break;
case AppPath.StreamingAssetsPath:
directory = Application.streamingAssetsPath;
break;
case AppPath.DataPath:
directory = Application.dataPath;
break;
}
return directory;
}
#region ----- Instance -----
private static FileSaveUtil _instance = null;
public static FileSaveUtil Instance
{
get
{
if (_instance == null) _instance = new FileSaveUtil();
return _instance;
}
}
#endregion
#region ----- Save Texture2D as EXR -----
/// <summary>
/// Saves Texture2D as EXR to accessible path (e.g. Application data path).
/// </summary>
public string SaveTextureAsEXR(Texture2D texture2D, string directory, string fileNameWithoutExtension, Texture2D.EXRFlags exrFlags = Texture2D.EXRFlags.None)
{
return SaveBytes(texture2D.EncodeToEXR(exrFlags), directory, fileNameWithoutExtension + ".exr");
}
/// <summary>
/// Saves Texture2D as JPG to Application data path.
/// </summary>
public string SaveTextureAsEXR(Texture2D texture2D, AppPath appPath, string subFolderName, string fileNameWithoutExtension, Texture2D.EXRFlags exrFlags = Texture2D.EXRFlags.None)
{
string directory = GetAppPath(appPath);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsEXR(texture2D, directory, fileNameWithoutExtension, exrFlags);
}
/// <summary>
/// Saves Texture2D as JPG to Windows/Mac special folder.
/// </summary>
public string SaveTextureAsEXR(Texture2D texture2D, Environment.SpecialFolder specialFolder, string subFolderName, string fileNameWithoutExtension, Texture2D.EXRFlags exrFlags = Texture2D.EXRFlags.None)
{
string directory = Environment.GetFolderPath(specialFolder);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsEXR(texture2D, directory, fileNameWithoutExtension, exrFlags);
}
#endregion
#region ----- Save Texture2D as JPG -----
/// <summary>
/// Saves Texture2D as JPG to accessible path (e.g. Application data path).
/// </summary>
public string SaveTextureAsJPG(Texture2D texture2D, string directory, string fileNameWithoutExtension, int quality = 90)
{
return SaveBytes(texture2D.EncodeToJPG(quality), directory, fileNameWithoutExtension + ".jpg");
}
/// <summary>
/// Saves Texture2D as JPG to Application data path.
/// </summary>
public string SaveTextureAsJPG(Texture2D texture2D, AppPath appPath, string subFolderName, string fileNameWithoutExtension, int quality = 90)
{
string directory = GetAppPath(appPath);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsJPG(texture2D, directory, fileNameWithoutExtension, quality);
}
/// <summary>
/// Saves Texture2D as JPG to Windows/Mac special folder.
/// </summary>
public string SaveTextureAsJPG(Texture2D texture2D, Environment.SpecialFolder specialFolder, string subFolderName, string fileNameWithoutExtension, int quality = 90)
{
string directory = Environment.GetFolderPath(specialFolder);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsJPG(texture2D, directory, fileNameWithoutExtension, quality);
}
#endregion
#region ----- Save Texture2D as PNG -----
/// <summary>
/// Saves Texture2D as PNG to accessible path (e.g. Application data path).
/// </summary>
public string SaveTextureAsPNG(Texture2D texture2D, string directory, string fileNameWithoutExtension)
{
return SaveBytes(texture2D.EncodeToPNG(), directory, fileNameWithoutExtension + ".png");
}
/// <summary>
/// Saves Texture2D as PNG to Application data path.
/// </summary>
public string SaveTextureAsPNG(Texture2D texture2D, AppPath appPath, string subFolderName, string fileNameWithoutExtension)
{
string directory = GetAppPath(appPath);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsPNG(texture2D, directory, fileNameWithoutExtension);
}
/// <summary>
/// Saves Texture2D as PNG to Windows/Mac special folder.
/// </summary>
public string SaveTextureAsPNG(Texture2D texture2D, Environment.SpecialFolder specialFolder, string subFolderName, string fileNameWithoutExtension)
{
string directory = Environment.GetFolderPath(specialFolder);
if (!string.IsNullOrEmpty(subFolderName)) directory = Path.Combine(directory, subFolderName);
return SaveTextureAsPNG(texture2D, directory, fileNameWithoutExtension);
}
#endregion
#region ----- Save byte array to File -----
/// <summary>
/// Saves file byte array to accessible path (e.g. Application data path).
/// </summary>
public string SaveBytes(byte[] bytes, string directory, string fileNameWithExtension)
{
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
string savePath = Path.Combine(directory, fileNameWithExtension);
File.WriteAllBytes(savePath, bytes);
return savePath;
}
/// <summary>
/// Saves file byte array to Application data path.
/// </summary>
public string SaveBytes(byte[] bytes, AppPath appPath, string subFolderName, string fileNameWithExtension)
{
string directory = GetAppPath(appPath);
return SaveBytes(bytes, directory, fileNameWithExtension);
}
/// <summary>
/// Saves file byte array to Windows/Mac special folder.
/// </summary>
public string SaveBytes(byte[] bytes, Environment.SpecialFolder specialFolder, string subFolderName, string fileNameWithExtension)
{
string directory = Path.Combine(Environment.GetFolderPath(specialFolder), subFolderName);
return SaveBytes(bytes, directory, fileNameWithExtension);
}
/// <summary>
/// Saves file byte array to Windows/Mac special folder.
/// </summary>
public string SaveBytes(byte[] bytes, Environment.SpecialFolder specialFolder, string fileNameWithExtension)
{
string directory = Environment.GetFolderPath(specialFolder);
return SaveBytes(bytes, directory, fileNameWithExtension);
}
#endregion
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: f2594c43cd6ca45a79ae97dcb56e29c3
timeCreated: 1581483126
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/Common/FileSaveUtil.cs
uploadId: 673764

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 93f9be3b4312e42d5b97f1d39c9de8df
folderAsset: yes
timeCreated: 1507540924
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: c6c5f3596ba1e425bbdaf3d737b6a2f1
timeCreated: 1509871138
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Fonts/Archived.zip
uploadId: 673764

Binary file not shown.

View File

@@ -0,0 +1,28 @@
fileFormatVersion: 2
guid: d8497cc02ae19440db5712114c197511
timeCreated: 1432116480
licenseType: Store
TrueTypeFontImporter:
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontName: Bowlby One
fontNames:
- Bowlby One
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Fonts/BowlbyOne-Regular.ttf
uploadId: 673764

Binary file not shown.

View File

@@ -0,0 +1,23 @@
fileFormatVersion: 2
guid: 928f503de488e44408a8625d75d54c61
TrueTypeFontImporter:
serializedVersion: 2
fontSize: 16
forceTextureCase: -2
characterSpacing: 1
characterPadding: 0
includeFontData: 1
use2xBehaviour: 0
fontNames: []
customCharacters:
fontRenderingMode: 0
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Fonts/DroidSansMono.ttf
uploadId: 673764

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7fca35315925040ffa31514d1737fdb6
folderAsset: yes
timeCreated: 1509189743
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: SpriteDefault
m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _ALPHATEST_ON _EMISSION
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 1
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Shininess: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Emission: {r: 0.49803922, g: 0.49803922, b: 0.49803922, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 06815d34bb8fc42cc87fb36fd544e895
timeCreated: 1509189371
licenseType: Store
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Materials/SpriteDefault.mat
uploadId: 673764

View File

@@ -0,0 +1,98 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: SpriteDiffuse
m_Shader: {fileID: 10800, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _ALPHATEST_ON _EMISSION
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 1
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Shininess: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _UseUIAlphaClip: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Emission: {r: 0.49803922, g: 0.49803922, b: 0.49803922, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 2a24339e859244551bed51e4e9a5981d
timeCreated: 1509189371
licenseType: Store
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Materials/SpriteDiffuse.mat
uploadId: 673764

View File

@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: TransparentCutout
m_Shader: {fileID: 10751, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 4fef5a2006fff80409f004e4296bf8e5, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 8c3a517ff6bfbb34c8726553ee00b5d9
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Materials/TransparentCutout.mat
uploadId: 673764

View File

@@ -0,0 +1,84 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: UnlitTexture
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _EMISSION
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- <noninit>:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 720d0e265574a4eff864e3a06d08081e, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- <noninit>: 0
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- <noninit>: {r: 0, g: 9.289661e-35, b: 0, a: 9.289624e-35}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: b9168857582884d4291ec78efde6ecf6
timeCreated: 1509189371
licenseType: Store
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Materials/UnlitTexture.mat
uploadId: 673764

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -0,0 +1,176 @@
fileFormatVersion: 2
guid: 4fef5a2006fff80409f004e4296bf8e5
AssetOrigin:
serializedVersion: 1
productId: 130885
packageName: Screenshot Helper Free
packageVersion: 1.3.8
assetPath: Assets/SWAN Dev/Common/Materials/sprite_demo.png
uploadId: 673764
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 1
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 0
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
swizzle: 50462976
cookieLightType: 1
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 1
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Android
maxTextureSize: 512
resizeAlgorithm: 1
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 1
ignorePlatformSupport: 0
androidETC2FallbackOverride: 1
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: WindowsStoreApps
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 1
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 1
- serializedVersion: 4
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 1
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: iOS
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 4
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
customData:
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class OnEnableTrigger : MonoBehaviour
{
/// The condition/permission for triggering events in this script.
public EventTriggerPermission m_EventTriggerPermission = EventTriggerPermission.NotReady;
/// Do not trigger any event(in this script) earlier than this game time, game time is the time since the begin of the app started.
/// (Why? Sometimes you need to wait for other scripts to completely initiated before calling their methods.)
public float m_TiggerNotEarlyThanGameTime = 1f;
public enum EventTriggerPermission
{
/// Do not trigger any event(in this script)
NotReady = 0,
/// Wait after the provided game time(m_TiggerNotEarlyThanGameTime)
AfterGameTime,
/// Allow trigger events(in this script)
Ready,
}
public UnityEvent m_OnEnableEvent;
public UnityEvent m_OnDisableEvent;
void OnEnable()
{
if(m_EventTriggerPermission == EventTriggerPermission.Ready ||
(m_EventTriggerPermission == EventTriggerPermission.AfterGameTime && Time.time > m_TiggerNotEarlyThanGameTime))
{
m_OnEnableEvent.Invoke();
}
}
void OnDisable()
{
if(m_EventTriggerPermission == EventTriggerPermission.Ready ||
(m_EventTriggerPermission == EventTriggerPermission.AfterGameTime && Time.time > m_TiggerNotEarlyThanGameTime))
{
m_OnDisableEvent.Invoke();
}
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: c7864ff6ac004004d8315dd54408d46c
timeCreated: 1532858381
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/Common/OnEnableTrigger.cs
uploadId: 673764

View File

@@ -0,0 +1,436 @@
// Created by SwanDEV 2017
using UnityEngine;
using System.Collections;
using System;
using SDev.Component;
/// <summary>
/// SDev simple Animation (Tweening).
/// </summary>
public class SDemoAnimation : MonoBehaviour
{
private static SDemoAnimation _instance = null;
public static SDemoAnimation Instance
{
get{
if(_instance == null)
{
_instance = FindObjectOfType<SDemoAnimation>();
if(_instance == null) _instance = new GameObject("[SDev Animation]").AddComponent<SDemoAnimation>();
}
return _instance;
}
}
public enum LoopType
{
None = 0,
Loop,
PingPong,
}
public SDemoControl Move(GameObject targetGO, Vector3 fromPosition, Vector3 toPosition, float time, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Move(targetGO, fromPosition, toPosition, time, 0f, loop, onComplete, control));
return control;
}
public SDemoControl Move(GameObject targetGO, Vector3 fromPosition, Vector3 toPosition, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Move(targetGO, fromPosition, toPosition, time, delay, loop, onComplete, control));
return control;
}
private IEnumerator _Move(GameObject targetGO, Vector3 fromPosition, Vector3 toPosition, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localPosition = fromPosition;
float elapsedTime = 0;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
targetGO.transform.localPosition = Vector3.Lerp(fromPosition, toPosition, (elapsedTime / time));
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localPosition = toPosition;
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Move(targetGO, fromPosition, toPosition, time, delay, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Move(targetGO, toPosition, fromPosition, time, delay, loop, onComplete, control));
}
public SDemoControl Scale(GameObject targetGO, Vector3 fromScale, Vector3 toScale, float time, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Scale(targetGO, fromScale, toScale, time, 0f, loop, onComplete, control));
return control;
}
public SDemoControl Scale(GameObject targetGO, Vector3 fromScale, Vector3 toScale, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Scale(targetGO, fromScale, toScale, time, delay, loop, onComplete, control));
return control;
}
private IEnumerator _Scale(GameObject targetGO, Vector3 fromScale, Vector3 toScale, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localScale = fromScale;
float elapsedTime = 0;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
targetGO.transform.localScale = Vector3.Lerp(fromScale, toScale, (elapsedTime / time));
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localScale = toScale;
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Scale(targetGO, fromScale, toScale, time, delay, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Scale(targetGO, toScale, fromScale, time, delay, loop, onComplete, control));
}
public SDemoControl Rotate(GameObject targetGO, Vector3 fromEulerAngle, Vector3 toEulerScale, float time, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Rotate(targetGO, fromEulerAngle, toEulerScale, time, 0f, loop, onComplete, control));
return control;
}
public SDemoControl Rotate(GameObject targetGO, Vector3 fromEulerAngle, Vector3 toEulerScale, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Rotate(targetGO, fromEulerAngle, toEulerScale, time, delay, loop, onComplete, control));
return control;
}
private IEnumerator _Rotate(GameObject targetGO, Vector3 fromEulerAngle, Vector3 toEulerAngle, float time, float delay, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localEulerAngles = fromEulerAngle;
float elapsedTime = 0;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
targetGO.transform.localEulerAngles = Vector3.Lerp(fromEulerAngle, toEulerAngle, (elapsedTime / time));
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
targetGO.transform.localEulerAngles = toEulerAngle;
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Rotate(targetGO, fromEulerAngle, toEulerAngle, time, delay, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Rotate(targetGO, toEulerAngle, fromEulerAngle, time, delay, loop, onComplete, control));
}
public SDemoControl FloatTo(float fromValue, float toValue, float time, Action<float> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_FloatTo(fromValue, toValue, time, 0f, onUpdate, loop, onComplete, control));
return control;
}
public SDemoControl FloatTo(float fromValue, float toValue, float time, float delay, Action<float> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_FloatTo(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
return control;
}
private IEnumerator _FloatTo(float fromValue, float toValue, float time, float delay, Action<float> onUpdate, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
float elapsedTime = 0;
float val = 0f;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
val = Mathf.Lerp(fromValue, toValue, (elapsedTime / time));
onUpdate(val);
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
onUpdate(toValue);
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_FloatTo(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_FloatTo(toValue, fromValue, time, delay, onUpdate, loop, onComplete, control));
}
public SDemoControl Vector2To(Vector2 fromValue, Vector2 toValue, float time, Action<Vector2> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector2To(fromValue, toValue, time, 0f, onUpdate, loop, onComplete, control));
return control;
}
public SDemoControl Vector2To(Vector2 fromValue, Vector2 toValue, float time, float delay, Action<Vector2> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector2To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
return control;
}
private IEnumerator _Vector2To(Vector2 fromValue, Vector2 toValue, float time, float delay, Action<Vector2> onUpdate, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
float elapsedTime = 0;
Vector2 val = Vector2.zero;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
val = Vector2.Lerp(fromValue, toValue, (elapsedTime / time));
onUpdate(val);
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
onUpdate(toValue);
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Vector2To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Vector2To(toValue, fromValue, time, delay, onUpdate, loop, onComplete, control));
}
public SDemoControl Vector3To(Vector3 fromValue, Vector3 toValue, float time, Action<Vector3> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector3To(fromValue, toValue, time, 0f, onUpdate, loop, onComplete, control));
return control;
}
public SDemoControl Vector3To(Vector3 fromValue, Vector3 toValue, float time, float delay, Action<Vector3> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector3To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
return control;
}
private IEnumerator _Vector3To(Vector3 fromValue, Vector3 toValue, float time, float delay, Action<Vector3> onUpdate, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
float elapsedTime = 0;
Vector3 val = Vector3.zero;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
val = Vector3.Lerp(fromValue, toValue, (elapsedTime / time));
onUpdate(val);
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
onUpdate(toValue);
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Vector3To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Vector3To(toValue, fromValue, time, delay, onUpdate, loop, onComplete, control));
}
public SDemoControl Vector4To(Vector4 fromValue, Vector4 toValue, float time, Action<Vector4> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector4To(fromValue, toValue, time, 0f, onUpdate, loop, onComplete, control));
return control;
}
public SDemoControl Vector4To(Vector4 fromValue, Vector4 toValue, float time, float delay, Action<Vector4> onUpdate, LoopType loop = LoopType.None, Action onComplete = null)
{
SDemoControl control = new SDemoControl();
StartCoroutine(_Vector4To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
return control;
}
private IEnumerator _Vector4To(Vector4 fromValue, Vector4 toValue, float time, float delay, Action<Vector4> onUpdate, LoopType loop = LoopType.None, Action onComplete = null, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
float elapsedTime = 0;
Vector4 val = Vector4.zero;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
val = Vector4.Lerp(fromValue, toValue, (elapsedTime / time));
onUpdate(val);
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
onUpdate(toValue);
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Vector4To(fromValue, toValue, time, delay, onUpdate, loop, onComplete, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Vector4To(toValue, fromValue, time, delay, onUpdate, loop, onComplete, control));
}
public SDemoControl Wait(float time, Action onComplete)
{
if(time < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_Wait(time, 0f, onComplete, LoopType.None, control));
return control;
}
public SDemoControl Wait(float time, Action onComplete, LoopType loop = LoopType.None)
{
if(time < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_Wait(time, 0f, onComplete, loop, control));
return control;
}
public SDemoControl Wait(float time, float delay, Action onComplete, LoopType loop = LoopType.None)
{
if(time < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_Wait(time, delay, onComplete, loop, control));
return control;
}
private IEnumerator _Wait(float time, float delay, Action onComplete, LoopType loop = LoopType.None, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
float elapsedTime = 0;
while (elapsedTime < time)
{
if(control.m_State == SDemoControl.State.Playing)
{
elapsedTime += Time.deltaTime;
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_Wait(time, delay, onComplete, loop, control));
else if(loop == LoopType.PingPong) StartCoroutine(_Wait(time, delay, onComplete, loop, control));
}
public SDemoControl WaitFrames(int frameNum, Action onComplete)
{
if(frameNum < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_WaitFrames(frameNum, 0f, onComplete, LoopType.None, control));
return control;
}
public SDemoControl WaitFrames(int frameNum, Action onComplete, LoopType loop = LoopType.None)
{
if(frameNum < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_WaitFrames(frameNum, 0f, onComplete, loop, control));
return control;
}
public SDemoControl WaitFrames(int frameNum, float delay, Action onComplete, LoopType loop = LoopType.None)
{
if(frameNum < 0) return null;
SDemoControl control = new SDemoControl();
StartCoroutine(_WaitFrames(frameNum, delay, onComplete, loop, control));
return control;
}
private IEnumerator _WaitFrames(int frameNum, float delay, Action onComplete, LoopType loop = LoopType.None, SDemoControl control = null)
{
if(delay > 0) yield return new WaitForSeconds(delay);
if(control.m_State == SDemoControl.State.Kill) yield break;
int currFrame = 0;
while (currFrame < frameNum)
{
if(control.m_State == SDemoControl.State.Playing)
{
currFrame++;
}
else if(control.m_State == SDemoControl.State.Kill)
{
loop = LoopType.None;
break;
}
yield return new WaitForEndOfFrame();
}
if(control.m_State == SDemoControl.State.Kill) yield break;
if(onComplete != null) onComplete();
if(loop == LoopType.Loop) StartCoroutine(_WaitFrames(frameNum, delay, onComplete, loop, control));
else if(loop == LoopType.PingPong) StartCoroutine(_WaitFrames(frameNum, delay, onComplete, loop, control));
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 34fdda83a19d24a06be41f2a39a61b42
timeCreated: 1506672609
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/Common/SDemoAnimation.cs
uploadId: 673764

View File

@@ -0,0 +1,38 @@
// Created by SwanDEV 2017
using UnityEngine;
namespace SDev.Component
{
public class SDemoControl
{
public State m_State = State.Playing;
public enum State
{
/// <summary>
/// The tweening will be destroyed in the next update.
/// </summary>
Kill = 0,
Playing,
Paused,
}
public SelfAnimation.SelfAnimType m_SelfAnimType = SelfAnimation.SelfAnimType.None;
// public Vector3 initValue;
// public Vector3 fromValue;
// public Vector3 toValue;
// public float time = 0.5f;
// public float delay = 0f;
// public SDemoAnimation.LoopType loop = SDemoAnimation.LoopType.None;
// public bool destroyOnComplete = false;
// public bool executeAtStart = true;
// public bool enableInitValue = false;
//
// public UnityEvent onComplete;
}
}

View File

@@ -0,0 +1,20 @@
fileFormatVersion: 2
guid: 07bb6d9dbb9c55c47b0dfac2078b58fc
timeCreated: 1532858381
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/Common/SDemoControl.cs
uploadId: 673764

View File

@@ -0,0 +1,201 @@
//Created by SwanDEV 2017
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace SDev.Component
{
public class SelfAnimation : MonoBehaviour
{
public SDemoControl m_Control = null;
public enum SelfAnimType
{
None = 0,
Move,
Rotate,
Scale,
Move_RelativePosition,
}
public SelfAnimType m_SelfAnimType = SelfAnimType.None;
public SDemoAnimation.LoopType loop = SDemoAnimation.LoopType.None;
//public Vector3 initValue;
public Vector3 fromValue;
public Vector3 toValue;
public float time = 0.5f;
public float delay = 0f;
public float delay_Revert = 0f;
public bool executeAtStart = true;
public bool enableInitValue = false;
public bool destroyOnComplete = false;
public UnityEvent onComplete;
//private Vector3 _originRotation;
public Vector3 OriginPosition { get; private set; }
void Awake()
{
OriginPosition = transform.localPosition;
//_originRotation = transform.localEulerAngles;
if (executeAtStart) StartAnimation();
}
void OnEnable()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Playing;
}
void OnDisable()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Paused;
}
void OnComplete()
{
if (onComplete != null) onComplete.Invoke();
if (destroyOnComplete) Destroy(gameObject);
}
void OnDestroy()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Kill;
}
private bool _isOdd = false;
public void SwitchAnimation()
{
_isOdd = !_isOdd;
if (_isOdd)
{
StartAnimation(delay);
}
else
{
StartAnimationRevert(delay_Revert);
}
}
public void SwitchAnimationRevert()
{
_isOdd = !_isOdd;
if (!_isOdd)
{
StartAnimation(delay);
}
else
{
StartAnimationRevert(delay_Revert);
}
}
public void StartAnimation(float inDelay = 0f)
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Kill; // Kill the current tweening if existed
switch (m_SelfAnimType)
{
case SelfAnimType.Move:
if (enableInitValue) gameObject.transform.localPosition = fromValue;
m_Control = SDemoAnimation.Instance.Move(gameObject, fromValue, toValue, time, delay, loop, OnComplete);
break;
case SelfAnimType.Rotate:
if (enableInitValue) gameObject.transform.localEulerAngles = fromValue;
m_Control = SDemoAnimation.Instance.Rotate(gameObject, fromValue, toValue, time, delay, loop, OnComplete);
break;
case SelfAnimType.Scale:
if (enableInitValue) gameObject.transform.localScale = fromValue;
m_Control = SDemoAnimation.Instance.Scale(gameObject, fromValue, toValue, time, delay, loop, OnComplete);
break;
case SelfAnimType.Move_RelativePosition:
if (enableInitValue) gameObject.transform.localPosition = OriginPosition + fromValue;
m_Control = SDemoAnimation.Instance.Move(gameObject, OriginPosition + fromValue, OriginPosition + toValue, time, delay, loop, OnComplete);
break;
}
}
public void StartAnimationRevert(float inDelay = 0f)
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Kill; // Kill the current tweening if existed
switch (m_SelfAnimType)
{
case SelfAnimType.Move:
if (enableInitValue) gameObject.transform.localPosition = toValue;
m_Control = SDemoAnimation.Instance.Move(gameObject, toValue, fromValue, time, inDelay, loop, OnComplete);
break;
case SelfAnimType.Rotate:
if (enableInitValue) gameObject.transform.localEulerAngles = toValue;
m_Control = SDemoAnimation.Instance.Rotate(gameObject, toValue, fromValue, time, inDelay, loop, OnComplete);
break;
case SelfAnimType.Scale:
if (enableInitValue) gameObject.transform.localScale = toValue;
m_Control = SDemoAnimation.Instance.Scale(gameObject, toValue, fromValue, time, inDelay, loop, OnComplete);
break;
case SelfAnimType.Move_RelativePosition:
if (enableInitValue) gameObject.transform.localPosition = OriginPosition + toValue;
m_Control = SDemoAnimation.Instance.Move(gameObject, OriginPosition + toValue, OriginPosition + fromValue, time, inDelay, loop, OnComplete);
break;
}
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(SelfAnimation))]
public class SelfAnimationCustomEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
SelfAnimation anim = (SelfAnimation)target;
GUILayout.Space(10);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Play"))
{
if (IsApplicationPlaying) anim.StartAnimation();
}
if (GUILayout.Button("Reverse"))
{
if (IsApplicationPlaying) anim.StartAnimationRevert();
}
if (GUILayout.Button("Pause"))
{
if (IsApplicationPlaying) anim.m_Control.m_State = SDemoControl.State.Paused;
}
EditorGUILayout.EndHorizontal();
}
private bool IsApplicationPlaying
{
get
{
bool isPlaying = Application.isPlaying;
if (!isPlaying)
{
Debug.Log("This function intended for use in the Editor play mode.");
}
return isPlaying;
}
}
}
#endif
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: dce419e36a78641928c771d2cd8b5b89
timeCreated: 1506672609
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/Common/SelfAnimation.cs
uploadId: 673764

View File

@@ -0,0 +1,50 @@
// Created by SwanDEV 2017
using UnityEngine;
using UnityEngine.Events;
namespace SDev.Component
{
public class SelfCountdown : MonoBehaviour
{
public SDemoControl m_Control = null;
public float time = 0.5f;
public SDemoAnimation.LoopType loop = SDemoAnimation.LoopType.Loop;
public bool destroyOnComplete = false;
public bool executeAtStart = true;
public UnityEvent onComplete;
void Start()
{
if (!executeAtStart) return;
StartAnimation();
}
void OnComplete()
{
if (onComplete != null) onComplete.Invoke();
if (destroyOnComplete) GameObject.Destroy(gameObject);
}
void OnEnable()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Playing;
}
void OnDisable()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Paused;
}
void OnDestroy()
{
if (m_Control != null) m_Control.m_State = SDemoControl.State.Kill;
}
public void StartAnimation()
{
m_Control = SDemoAnimation.Instance.Wait(time, OnComplete, loop);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: bf6b408d30a1843cba586a34fd447012
timeCreated: 1511534849
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/Common/SelfCountdown.cs
uploadId: 673764

View File

@@ -0,0 +1,3 @@
{
"name": "SwanDevCommon"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6e5481446c8674f4ba82a809f7e78e9c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: