This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
UDBase.Utils
konh edited this page Sep 24, 2018
·
5 revisions
Common dictionary utils
public static class UDBase.Utils.DictUtils
Static Methods
Type | Name | Summary |
---|---|---|
TValue |
GetOrDefault(this Dictionary<TKey, TValue> dict, TKey key) |
Input/output helpers
public static class UDBase.Utils.IOTool
Static Methods
Type | Name | Summary |
---|---|---|
Boolean |
CopyFile(String originPath, String destinationPath, Boolean silent = False) |
Exception-safe helper for File.Copy (silent = 'no log output') |
Boolean |
CreateDirectory(String path, Boolean silent = False) |
Exception-safe helper for Directory.CreateDirectory (silent = 'no log output') |
Boolean |
CreateFile(String path, Boolean silent = False) |
Exception-safe helper for File.Create (silent = 'no log output') |
Boolean |
DeleteDirectory(String path, Boolean recursive, Boolean silent = False) |
Exception-safe helper for Directory.Delete (silent = 'no log output') |
Boolean |
DeleteFile(String path, Boolean silent = False) |
Exception-safe helper for File.Delete (silent = 'no log output') |
FileInfo[] |
GetDirFiles(String path, String searchPattern, Boolean silent = False) |
Exception-safe helper for new DirectoryInfo().GetFiles(); (silent = 'no log output') |
Boolean |
Open(String path, Boolean silent = False) |
Exception-safe helper for open file/directory (silent = 'no log output') |
String[] |
ReadAllLines(String path, Boolean silent = False) |
Exception-safe helper for File.ReadAllLines (silent = 'no log output') |
String |
ReadAllText(String path, Boolean silent = False) |
Exception-safe helper for File.ReadAllText (silent = 'no log output') |
void |
WriteAllLines(String path, IEnumerable<String> contents, Boolean silent = False) |
Exception-safe helper for File.WriteAllLines (silent = 'no log output') |
void |
WriteAllText(String path, String contents, Boolean silent = False) |
Exception-safe helper for File.WriteAllText (silent = 'no log output') |
Utility to perform web requests
public class UDBase.Utils.NetUtils
: MonoBehaviour, ILogContext
Methods
Type | Name | Summary |
---|---|---|
void |
AddHeader(UnityWebRequest request, String name, String value) |
Add given header to request |
void |
AddHeaders(UnityWebRequest request, Dictionary<String, String> headers) |
Add given headers to request |
String |
CreateBasicAuthorization(String userName, String userPassword) |
Creates the basic authorization header value by user name and password |
void |
Initialize(ILog log) |
Init with dependencies |
void |
SendDeleteRequest(String url, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the delete request |
void |
SendGetRequest(String url, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the get request |
void |
SendJsonPostRequest(String url, String data, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the post request with 'application/json' contentType |
void |
SendPostRequest(String url, String data, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the post request |
void |
SendRequest(UnityWebRequest request, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the request |
Static Fields
Type | Name | Summary |
---|---|---|
Single |
DefaultTimeout | Default request timeout value |
Helper methods for PlayerPrefs usage
public static class UDBase.Utils.PlayerPrefsUtils
Static Methods
Type | Name | Summary |
---|---|---|
Boolean |
GetBool(String key, Boolean defaultValue) |
Get boolean value in int representation (1 = true, 0 = false) |
void |
SetBool(String key, Boolean value, Boolean save = True) |
Set boolean value in int representation (1 = true, 0 = false) |
Set of random helper methods
public static class UDBase.Utils.RandomUtils
Static Methods
Type | Name | Summary |
---|---|---|
T |
GetEnumValue() | |
T |
GetItem(List<T> items) |
|
TValue |
GetItem(Dictionary<TKey, TValue> items) |
|
T |
GetItem(T[] items) |
|
T |
GetItem(List<T> items, List<Single> weights) |
|
T |
GetItem(T[] items, Single[] weights) |
|
Int32 |
RangeExcluded(Int32 min, Int32 max, Int32[] exclusions) |
Returns random value in [min, max] interval without exclusion items Throws InvalidOperationException when all items is excluded |
Utility class to hold string function, that called only when ToString() is called. Useful for allocation-safe log calls.
public class UDBase.Utils.StringFunctor
Methods
Type | Name | Summary |
---|---|---|
String |
ToString() |
Utils for text processing
public static class UDBase.Utils.TextUtils
Static Methods
Type | Name | Summary |
---|---|---|
String |
EnsureString(String value) |
Returns given value or non-null empty string if value is null |
Boolean |
EqualsIgnoreWhitespaces(String leftStr, String rightStr, StringComparison comparison = Ordinal) |
Check given strings is equals without all white-spaces and control chars inside |
String |
RemoveWhitespaces(String str) |
Remove all white-spaces and control chars from given string |
String |
TrimFileContent(String text) |
Trim all begin/end empty chars and possible byte order mark in file content start https://en.wikipedia.org/wiki/Byte_order_mark |
String |
TrimQuotes(String text) |
Trim all single and double quotes from given string |
Helper methods for DG.Tween/Sequence usage
public static class UDBase.Utils.TweenHelper
Static Methods
Type | Name | Summary |
---|---|---|
Sequence |
Replace(Sequence seq, Boolean complete = False) |
Reset given sequence and replace it with new |
Sequence |
Reset(Sequence seq, Boolean complete = False) |
Reset given sequence |
HetUtils wrapper to send web requests with authorization
public class UDBase.Utils.WebClient
Properties
Type | Name | Summary |
---|---|---|
Boolean |
HasAuthorization | Is client authorized? |
Boolean |
InProgress | Is any request in progress |
Methods
Type | Name | Summary |
---|---|---|
void |
AddUserData(String userName, String userPassword) |
Adds the user name and password to use with this client |
void |
ApplyAuthHeader(String value) |
Adds auth header value |
void |
SendDeleteRequest(String url, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the delete request |
void |
SendGetRequest(String url, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the get request |
void |
SendJsonPostRequest(String url, String data, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the json post request |
void |
SendPostRequest(String url, String data, Single timeout = 10, Dictionary<String, String> headers = null, Action<Response> onComplete = null) |
Sends the post request. |