Initial commit: Unity WordConnect project
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class Collider2DExtensions
|
||||
{
|
||||
public static void TryUpdateShapeToAttachedSprite(this PolygonCollider2D collider)
|
||||
{
|
||||
collider.UpdateShapeToSprite(collider.GetComponent<SpriteRenderer>().sprite);
|
||||
}
|
||||
|
||||
public static void UpdateShapeToSprite(this PolygonCollider2D collider, Sprite sprite)
|
||||
{
|
||||
if (collider != null && sprite != null)
|
||||
{
|
||||
collider.pathCount = sprite.GetPhysicsShapeCount();
|
||||
var path = new List<Vector2>();
|
||||
for (var i = 0; i < collider.pathCount; i++)
|
||||
{
|
||||
path.Clear();
|
||||
sprite.GetPhysicsShape(i, path);
|
||||
collider.SetPath(i, path.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4f7bfe15d845364780d90bf1f7bedf6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,90 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public class DefineSymbolsUtils
|
||||
{
|
||||
public static void SwichSymbol(string symbol)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var _buildTargets = GetBuildTargets();
|
||||
foreach (var _target in _buildTargets)
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(_target);
|
||||
if (!defines.Contains(symbol))
|
||||
{
|
||||
defines = defines + "; " + symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
defines.Replace(symbol, "");
|
||||
}
|
||||
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(_target, defines);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void AddSymbol(string symbol)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var _buildTargets = GetBuildTargets();
|
||||
foreach (var _target in _buildTargets)
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(_target);
|
||||
AddDefine(symbol, _target, ref defines);
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(_target, defines);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static void DeleteSymbol(string symbol)
|
||||
{
|
||||
var _buildTargets = GetBuildTargets();
|
||||
foreach (var _target in _buildTargets)
|
||||
{
|
||||
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(_target);
|
||||
DeleteDefine(symbol, _target, ref defines);
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(_target, defines);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeleteDefine(string symbol, BuildTargetGroup buildTargetGroup, ref string defines)
|
||||
{
|
||||
defines = defines.Replace(symbol, "");
|
||||
}
|
||||
|
||||
private static BuildTargetGroup[] GetBuildTargets()
|
||||
{
|
||||
var _targetGroupList = new ArrayList();
|
||||
_targetGroupList.Add(BuildTargetGroup.Standalone);
|
||||
_targetGroupList.Add(BuildTargetGroup.Android);
|
||||
_targetGroupList.Add(BuildTargetGroup.iOS);
|
||||
_targetGroupList.Add(BuildTargetGroup.WSA);
|
||||
return (BuildTargetGroup[])_targetGroupList.ToArray(typeof(BuildTargetGroup));
|
||||
}
|
||||
|
||||
private static void AddDefine(string symbols, BuildTargetGroup _target, ref string defines)
|
||||
{
|
||||
if (!defines.Contains(symbols))
|
||||
{
|
||||
defines = defines + "; " + symbols;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76db1a71ef284c028407b4bbe80445d0
|
||||
timeCreated: 1709623652
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 351aef08d7d1460aa574336d536d951b
|
||||
timeCreated: 1725685346
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e60c6201bf08740a7a2993c8a13bc8e6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,64 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils.ImageCreator.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class ImageCreator : UnityEditor.Editor
|
||||
{
|
||||
static ImageCreator()
|
||||
{
|
||||
EditorApplication.hierarchyChanged += OnChanged;
|
||||
}
|
||||
|
||||
private static void OnChanged()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = Selection.activeGameObject;
|
||||
if (obj == null || obj.transform.parent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((obj.transform.parent.GetComponent<CanvasRenderer>() != null || obj.transform.parent.GetComponent<Canvas>() != null || obj.transform.parent.GetComponent<RectTransform>() != null) &&
|
||||
obj.GetComponent<SpriteRenderer>() != null)
|
||||
{
|
||||
Undo.RegisterCompleteObjectUndo(obj, "Convert SpriteRenderer to Image");
|
||||
|
||||
var spriteRenderer = obj.GetComponent<SpriteRenderer>();
|
||||
var sprite = spriteRenderer.sprite;
|
||||
var color = spriteRenderer.color;
|
||||
|
||||
// Use Undo.AddComponent instead of obj.AddComponent
|
||||
var rectTransform = Undo.AddComponent<RectTransform>(obj);
|
||||
rectTransform.anchoredPosition3D = Vector3.zero;
|
||||
rectTransform.localScale = Vector3.one;
|
||||
|
||||
var image = Undo.AddComponent<Image>(obj);
|
||||
image.sprite = sprite;
|
||||
image.color = color;
|
||||
image.SetNativeSize();
|
||||
|
||||
// Use Undo.DestroyObjectImmediate instead of Object.DestroyImmediate
|
||||
Undo.DestroyObjectImmediate(spriteRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5defa41b2702e4797977c99288c048da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "ImageCreatorEditor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:343deaaf83e0cee4ca978e7df0b80d21"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80203850072e04e989fc8dcb13d2243e
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,215 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
[Serializable]
|
||||
public class SerializableDictionary<TKey, TValue> : IEnumerable
|
||||
{
|
||||
[SerializeField]
|
||||
private List<TKey> keys = new();
|
||||
|
||||
[SerializeField]
|
||||
private List<TValue> values = new();
|
||||
|
||||
private Dictionary<TKey, TValue> thisDictionary = new();
|
||||
|
||||
public TValue this[TKey key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
return thisDictionary[key];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
thisDictionary[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// New indexer that returns an object
|
||||
public object this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
return new KeyValuePair<TKey, TValue>(keys[index], values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
// save the dictionary to lists
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
keys.Clear();
|
||||
values.Clear();
|
||||
foreach (var pair in thisDictionary)
|
||||
{
|
||||
keys.Add(pair.Key);
|
||||
values.Add(pair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// load dictionary from lists
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
thisDictionary.Clear();
|
||||
|
||||
if (keys.Count != values.Count)
|
||||
{
|
||||
throw new Exception(string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable."));
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.Count; i++)
|
||||
{
|
||||
if (thisDictionary.ContainsKey(keys[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
thisDictionary.Add(keys[i], values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.Count; i++)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
public int Count => keys.Count;
|
||||
|
||||
public bool TryToGetPair(Func<KeyValuePair<TKey, TValue>, bool> predicate, out KeyValuePair<TKey, TValue> result)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.Count; i++)
|
||||
{
|
||||
var kvp = new KeyValuePair<TKey, TValue>(keys[i], values[i]);
|
||||
if (predicate(kvp))
|
||||
{
|
||||
result = kvp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public KeyValuePair<TKey, TValue> First(Func<KeyValuePair<TKey, TValue>, bool> predicate)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.Count; i++)
|
||||
{
|
||||
var kvp = new KeyValuePair<TKey, TValue>(keys[i], values[i]);
|
||||
if (predicate(kvp))
|
||||
{
|
||||
return kvp;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("No element satisfying the predicate was found.");
|
||||
}
|
||||
|
||||
public bool Any(Func<KeyValuePair<TKey, TValue>, bool> predicate)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.Count; i++)
|
||||
{
|
||||
var kvp = new KeyValuePair<TKey, TValue>(keys[i], values[i]);
|
||||
if (predicate(kvp))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey key, out TValue value)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
return thisDictionary.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<TKey> GetKeys()
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
return keys.AsReadOnly();
|
||||
}
|
||||
|
||||
public bool ContainsKey(TKey key)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
return thisDictionary.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void Remove(TKey key)
|
||||
{
|
||||
if (thisDictionary.Count == 0)
|
||||
{
|
||||
OnAfterDeserialize();
|
||||
}
|
||||
|
||||
thisDictionary.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90b414b9ad6f4ed8b2fedc4f7ccefc90
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/WordConnectGameToolkit/Scripts/Utils/StringUtlis.cs
Normal file
29
Assets/WordConnectGameToolkit/Scripts/Utils/StringUtlis.cs
Normal file
@ -0,0 +1,29 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class StringUtlis
|
||||
{
|
||||
public static string CamelCaseSplit(this string text)
|
||||
{
|
||||
return Regex.Replace(text, "((?<!^)([A-Z][a-z]|(?<=[a-z])[A-Z]))", " $1").Trim();
|
||||
}
|
||||
|
||||
public static int ToInt(this string text)
|
||||
{
|
||||
return int.Parse(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5042b383359b41b692173dc289a35756
|
||||
timeCreated: 1711701296
|
||||
71
Assets/WordConnectGameToolkit/Scripts/Utils/TimeUtils.cs
Normal file
71
Assets/WordConnectGameToolkit/Scripts/Utils/TimeUtils.cs
Normal file
@ -0,0 +1,71 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class TimeUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Formats time in seconds to a string representation (MM:SS)
|
||||
/// </summary>
|
||||
/// <param name="timeInSeconds">Time in seconds</param>
|
||||
/// <returns>Formatted time string</returns>
|
||||
public static string GetTimeString(float timeInSeconds)
|
||||
{
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(timeInSeconds);
|
||||
return string.Format("{0:00}:{1:00}",
|
||||
(int)timeSpan.TotalMinutes,
|
||||
timeSpan.Seconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats time in seconds to a string representation with hours (HH:MM:SS)
|
||||
/// </summary>
|
||||
/// <param name="timeInSeconds">Time in seconds</param>
|
||||
/// <returns>Formatted time string with hours</returns>
|
||||
public static string GetTimeStringWithHours(float timeInSeconds)
|
||||
{
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(timeInSeconds);
|
||||
return string.Format("{0:00}:{1:00}:{2:00}",
|
||||
(int)timeSpan.TotalHours,
|
||||
timeSpan.Minutes,
|
||||
timeSpan.Seconds);
|
||||
}
|
||||
|
||||
public static string GetTimeString(float time, float activeTimeLimit, bool descendant = true)
|
||||
{
|
||||
var adjustedTime = descendant ? activeTimeLimit - time % activeTimeLimit : time % activeTimeLimit;
|
||||
return GetTimeString(adjustedTime);
|
||||
}
|
||||
|
||||
public static float GetTimeInSeconds(string timeString)
|
||||
{
|
||||
var time = timeString.Split(':');
|
||||
if (time.Length == 3)
|
||||
{
|
||||
return GetTimeInSeconds(int.Parse(time[0]), int.Parse(time[1]), int.Parse(time[2]));
|
||||
}
|
||||
else if (time.Length == 2)
|
||||
{
|
||||
return GetTimeInSeconds(0, int.Parse(time[0]), int.Parse(time[1]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static float GetTimeInSeconds(int hours, int minutes, int seconds)
|
||||
{
|
||||
return hours * 3600 + minutes * 60 + seconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d8399464dcb46c3b5a1726fdd027e21
|
||||
timeCreated: 1711795062
|
||||
@ -0,0 +1,39 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class TransformUtils
|
||||
{
|
||||
public static void SetParentPosition(this Transform mainTR, Vector3 v)
|
||||
{
|
||||
var list = new List<Transform>();
|
||||
var parent = mainTR.parent;
|
||||
for (var i = parent.childCount - 1; i >= 0; --i)
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
child.SetParent(parent.parent);
|
||||
list.Add(child);
|
||||
}
|
||||
|
||||
parent.transform.position = v;
|
||||
|
||||
foreach (var child in list)
|
||||
{
|
||||
child.SetParent(parent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8663d9fc96504018ae29695268de3f47
|
||||
timeCreated: 1710917988
|
||||
@ -0,0 +1,34 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class TryAddComponent
|
||||
{
|
||||
public static T AddComponentIfNotExists<T>(this GameObject gameObject) where T : Component
|
||||
{
|
||||
return AddComponentIfNotExists<T>(gameObject.transform);
|
||||
}
|
||||
|
||||
public static T AddComponentIfNotExists<T>(this Transform transform) where T : Component
|
||||
{
|
||||
if (!transform.TryGetComponent<T>(out var component))
|
||||
{
|
||||
component = transform.gameObject.AddComponent<T>();
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eeb61e4db9d404ea02bf6c447d8c35f
|
||||
timeCreated: 1711722782
|
||||
76
Assets/WordConnectGameToolkit/Scripts/Utils/VectorUtils.cs
Normal file
76
Assets/WordConnectGameToolkit/Scripts/Utils/VectorUtils.cs
Normal file
@ -0,0 +1,76 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Utils
|
||||
{
|
||||
public static class VectorUtils
|
||||
{
|
||||
// Snaps the Z-coordinate of a Vector3 to 0
|
||||
public static Vector3 SnapZ(this Vector3 v)
|
||||
{
|
||||
return new Vector3(v.x, v.y, 0);
|
||||
}
|
||||
|
||||
// Snaps the Z-coordinate of a Vector3 to -10 (suitable for cameras)
|
||||
public static Vector3 SnapZCamera(this Vector3 v)
|
||||
{
|
||||
return new Vector3(v.x, v.y, -10);
|
||||
}
|
||||
|
||||
// Adjusts the x-coordinate of a Vector2Int if its y-coordinate is even
|
||||
public static Vector2Int SnapRow(this Vector2Int v)
|
||||
{
|
||||
if (v.y % 2 == 0)
|
||||
{
|
||||
v.x -= 1;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
// Returns the next Vector2Int in a specified direction from the current Vector2Int
|
||||
private static Vector2Int GetNext(this Vector2Int v, Vector2Int dir)
|
||||
{
|
||||
if (dir.y != 0)
|
||||
{
|
||||
if (v.y % 2 == 0 && dir.x < 0)
|
||||
{
|
||||
dir.x = 0;
|
||||
}
|
||||
else if (v.y % 2 == 1 && dir.x > 0)
|
||||
{
|
||||
dir.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return v + dir;
|
||||
}
|
||||
|
||||
// Overload of GetNext that accepts two integers as direction
|
||||
public static Vector2Int GetNext(this Vector2Int v, int x, int y)
|
||||
{
|
||||
return v.GetNext(new Vector2Int(x, y));
|
||||
}
|
||||
|
||||
public static Vector2Int ToV2Int(this Vector2 v)
|
||||
{
|
||||
return new Vector2Int((int)v.x, (int)v.y);
|
||||
}
|
||||
|
||||
public static Vector2Int ToV2Int(this Vector3 v)
|
||||
{
|
||||
return new Vector2Int((int)v.x, (int)v.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df60ddff9f8c4a3aaf38fff3d7c20b38
|
||||
timeCreated: 1712991176
|
||||
Reference in New Issue
Block a user