Skip to content
Yamastu edited this page Dec 1, 2017 · 9 revisions

Welcome to the UnitySysAPI wiki!

The UnitySysAPI is essentially an API layer for the UnityEngine. It adds an array of new methods as well as alternatives some older ones. Since the 'Sys' class lies within the 'UnityEngine' namespace, it will already be imported into your scripts. The API was created to provide Unity devs with faster and more efficient ways to code operations commonly used in Unity. Also it provides shorter, cleaner options for sometimes rather lengthy methods. The current purpose of the Sys API is not only to cater to this 'shorthand' variation of traditional Unity coding, but provide developers with the tools they need to create faster and more efficiently. Along side the scripting methods we are working on useful devtools that will be bundled with the UnitySysAPI. The most recent being SystemInformationLogger.cs standalone editor script.

Here's a good illustration of what it can do for System.IO.Directory methods:

fig 1

Whether you're a beginner or skilled Unity developer the Sys API can prove itself to be a valuable resource in your projects. We encourage developers to add their own methods to the Sys API so the project will continue to grow and gain more traction among the community. If you're interested in contributing you should check out this guide.

If this if your first time using the Sys API we recommend heading over to the Getting Started wiki page. Or jump on over to the Scripting Library.


Examples

In the Sys API we have provided examples in C# as well as javascript. Below displays two different translations of the same script. You will notice that calling Sys methods is the exact same regardless if you're coding in CSharp or javascript.

C#:

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Sys_API_CSharp_Example : MonoBehaviour {
	
	[HeaderAttribute("Directory Info")]
	[Tooltip("This is the filename for exported Sys.Log data")]
		public string logFileName = "SysLog.txt";
	[Tooltip("This is the filename for exported System Information data")]
		public string sysFileName = "SystemInformation.txt";
	string dir;
	[Tooltip("This is the default path to save files. Read Only!")]
		public string dataPath;
	[Space(15)]
		//public Texture2D capture;
	[HeaderAttribute("Sys Method Switches")]
	[Tooltip("Click this to capture a screenshot!")]
		public bool CaptureScreenView;
	[Tooltip("Click this to save 'saveArray' to a text file")]
		public bool SaveArrayToFile;
	[Tooltip("Click this to load 'saveArray' data from a text file")]
		public bool GetArrayFromFile;
	[Tooltip("Click this save the current system's information to a text file")]
		public bool SaveSystemInfo;
	[Tooltip("Click this read the current system's information and cast to 'SystemInfo' list variable")]
		public bool GetSystemInfo;
	[Tooltip("Click this save the Sys.Log to a text file")]
		public bool SaveSystemLog;
	[Tooltip("Click this to clear the Sys.Log cache")]
		public bool ClearSystemLog;
	[Space(15)]
	
	[HeaderAttribute("Sys Logger Imported Data")]
	[Tooltip("This is the raw Sys.Log messages without time stamps")]
		public List<string> logRaw = new List<string>();
	[Tooltip("This is the Sys.Log messages WITH time stamps")]
		public List<string> logData = new List<string>();
	[Space(12)]
	
	[HeaderAttribute("File Save/Load Example Arrays")]
	[Tooltip("This is the example string array to save to a file using 'Sys.SaveFile()'")]
		public string[] saveArray = new string[]{"a","b","c","d","e","f","g","h","i","j"};
	[Tooltip("This array reads all the data saved from the 'saveArray' variable when activated by 'GetArrayFromFile' boolean")]
		public string[] loadArray;
	[Space(12)]
	
	[HeaderAttribute("Imported System Info")]
	[Tooltip("This is current system's information cast to a list of strings. Activated by 'GetSystemInfo' boolean")]
		public List<string> SystemInfo = new List<string>();
	[Space(12)]
	
	[HeaderAttribute("Hash Code Generation [Alpha]")]
	[Tooltip("Click this generate a random hash code")]
		public bool GenerateUniqueID;
	[Tooltip("This is current system's information cast to a list of strings. Activated by 'GetSystemInfo' boolean")]
	public int uIDLength;
	public string uniqueID;
	
	[Space(12)]
	
	[HeaderAttribute("Arithmetic Testing [Unstable]")]
	[Tooltip("The Cartesian Product of sets 'a' and 'b'.")]
	public int[] cProduct;
	public int[] a = new int[]{1,2,3,4};
	public int[] b = new int[]{1,1,2,3};
	
	public void Awake () {
		dir = Sys.DeviceExternalStorage();
		dataPath = dir + "/" + Application.productName + "/Logs2";
		if(Sys.DirectoryCheck(dataPath,true)){
			Sys.FileCheck(dataPath+"/", logFileName, true);
		}
	}
	void Start () {
		Sys.Log("This is a test..");
		Sys.Log("This is a test...",true);
		Sys.Log("This is a test....");
		Sys.Log("This is a test.....", true);
		Sys.Log("This is a test......");
		Sys.Log("This is a test.......",true);
		Sys.Log("This is a test........");
		Sys.Log("This is a test.........", true);
		Sys.Log("This is a test..........");
		Sys.Log("This is a test...........",true);
		Sys.Log("This is a test............");
		Sys.Log("This is a test.............", true);
		Sys.Log("This is a test..............");
		Sys.Log("This is a test...............", true);
		Sys.Log("This is a test................", false);
		logRaw = Sys.logRaw;
		logData = Sys.logData;
		//Sys.SaveLog(dataPath + "/" + logFileName, true);
		//Sys.SaveSystemInfo(dataPath + "/" + sysFileName);
		//uniqueID = Sys.GenerateUniqueID(21);
		cProduct = Sys.cProduct(a,b);
		
	}
	
	// Update is called once per frame
	void Update () {
		logRaw = Sys.logRaw;
		logData = Sys.logData;

		if(CaptureScreenView){
			string getDateTime = System.DateTime.Now.ToString("MMddyyyy_hhmmss");
			Sys.CaptureScreenshot(this, (dataPath + "/" + getDateTime + ".png"), true);
			//capture = Sys.ScreenToTexture2D();
			//capture = Sys.LoadImageAtPath(dataPath + "/" + getDateTime + ".png");
			CaptureScreenView = false;
		}
		
		if(SaveArrayToFile){
			//Sys.SaveDataToFile(dataPath + "/" + "abc.txt", saveArray);
			Sys.SaveFile(dataPath + "/" + "abc.txt", saveArray);
			SaveArrayToFile = false;
		}
		if(GetArrayFromFile){
			//loadArray = Sys.LoadDataFromFile(dataPath + "/" + "abc.txt");
			loadArray = Sys.ReadFile(dataPath + "/" + "abc.txt");
			GetArrayFromFile = false;
		}
		
		if(SaveSystemInfo){
			Sys.SaveSystemInfo(dataPath + "/" + sysFileName, true);
			SaveSystemInfo = false;
		}
		
		if(GetSystemInfo){
			SystemInfo = new List<string>(Sys.GetSystemInfo());
			GetSystemInfo = false;
		}
		
		if(SaveSystemLog){
			Sys.SaveLog(dataPath + "/" + logFileName, true);
			SaveSystemLog = false;
		}
		
		if(ClearSystemLog){
			Sys.ClearLog();
			ClearSystemLog = false;
		}
		
		if(GenerateUniqueID){
			uniqueID = Sys.GenerateUniqueID(uIDLength);
			GenerateUniqueID = false;
		}
	}
}

javascript:

import System.Collections.Generic;

@HeaderAttribute("Directory Info")
	@Tooltip("This is the filename for exported Sys.Log data")
		var logFileName : String = "SysLog.txt";
	@Tooltip("This is the filename for exported System Information data")
		var sysFileName : String = "SystemInformation.txt";
	var dir : String;
	@Tooltip("This is the default path to save files. Read Only!")
		var dataPath : String;
	@Space(15)
		//var Texture2D capture;
	@HeaderAttribute("Sys Method Switches")
	@Tooltip("Click this to capture a screenshot!")
		var CaptureScreenView : boolean;
	@Tooltip("Click this to save 'saveArray' to a text file")
		var SaveArrayToFile : boolean;
	@Tooltip("Click this to load 'saveArray' data from a text file")
		var GetArrayFromFile : boolean;
	@Tooltip("Click this save the current system's information to a text file")
		var SaveSystemInfo : boolean;
	@Tooltip("Click this read the current system's information and cast to 'SystemInfo' list variable")
		var GetSystemInfo : boolean;
	@Tooltip("Click this save the Sys.Log to a text file")
		var SaveSystemLog : boolean;
	@Tooltip("Click this to clear the Sys.Log cache")
		var ClearSystemLog : boolean;
	@Space(15)
	
	@HeaderAttribute("Sys Logger Imported Data")
	@Tooltip("This is the raw Sys.Log messages without time stamps")
		var logRaw : List.<String> = new List.<String>();
	@Tooltip("This is the Sys.Log messages WITH time stamps")
		var logData : List.<String> = new List.<String>();
	@Space(12)
	
	@HeaderAttribute("File Save/Load Example Arrays")
	@Tooltip("This is the example String array to save to a file using 'Sys.SaveFile()'")
		var saveArray : String[] = ["a","b","c","d","e","f","g","h","i","j"];
	@Tooltip("This array reads all the data saved from the 'saveArray' variable when activated by 'GetArrayFromFile' boolean")
		var loadArray : String[];
	@Space(12)
	
	@HeaderAttribute("Imported System Info")
	@Tooltip("This is current system's information cast to a list of strings. Activated by 'GetSystemInfo' boolean")
		var SystemInfo : List.<String> = new List.<String>();
	@Space(12)
	
	@HeaderAttribute("Hash Code Generation [Alpha]")
	@Tooltip("Click this generate a random hash code")
		var GenerateUniqueID : boolean;
	@Tooltip("This is current system's information cast to a list of strings. Activated by 'GetSystemInfo' boolean")
		var uIDLength : int;
		var uniqueID : String;
	
	public function Awake () {
		dir = Sys.DeviceExternalStorage();
		dataPath = dir + "/" + Application.productName + "/Logs2";
		if(Sys.DirectoryCheck(dataPath,true)){
			Sys.FileCheck(dataPath+"/", logFileName, true);
		}
	}
	function Start () {
		Sys.Log("This is a test..");
		Sys.Log("This is a test...",true);
		Sys.Log("This is a test....");
		Sys.Log("This is a test.....", true);
		Sys.Log("This is a test......");
		Sys.Log("This is a test.......",true);
		Sys.Log("This is a test........");
		Sys.Log("This is a test.........", true);
		Sys.Log("This is a test..........");
		Sys.Log("This is a test...........",true);
		Sys.Log("This is a test............");
		Sys.Log("This is a test.............", true);
		Sys.Log("This is a test..............");
		Sys.Log("This is a test...............", true);
		Sys.Log("This is a test................", false);
		logRaw = Sys.logRaw;
		logData = Sys.logData;
	}
	
	// Update is called once per frame
	function Update () {
		logRaw = Sys.logRaw;
		logData = Sys.logData;

		if(CaptureScreenView){
			var getDateTime : String = System.DateTime.Now.ToString("MMddyyyy_hhmmss");
			Sys.CaptureScreenshot(this, (dataPath + "/" + getDateTime + ".png"), true);
			//capture = Sys.ScreenToTexture2D();
			//capture = Sys.LoadImageAtPath(dataPath + "/" + getDateTime + ".png");
			CaptureScreenView = false;
		}
		
		if(SaveArrayToFile){
			//Sys.SaveDataToFile(dataPath + "/" + "abc.txt", saveArray);
			Sys.SaveFile(dataPath + "/" + "abc.txt", saveArray);
			SaveArrayToFile = false;
		}
		if(GetArrayFromFile){
			//loadArray = Sys.LoadDataFromFile(dataPath + "/" + "abc.txt");
			loadArray = Sys.ReadFile(dataPath + "/" + "abc.txt");
			GetArrayFromFile = false;
		}
		
		if(SaveSystemInfo){
			Sys.SaveSystemInfo(dataPath + "/" + sysFileName, true);
			SaveSystemInfo = false;
		}
		
		if(GetSystemInfo){
			SystemInfo = new List.<String>(Sys.GetSystemInfo());
			GetSystemInfo = false;
		}
		
		if(SaveSystemLog){
			Sys.SaveLog(dataPath + "/" + logFileName, true);
			SaveSystemLog = false;
		}
		
		if(ClearSystemLog){
			Sys.ClearLog();
			ClearSystemLog = false;
		}
		
		if(GenerateUniqueID){
			uniqueID = Sys.GenerateUniqueID(uIDLength);
			GenerateUniqueID = false;
		}
	}