Initial commit: Unity WordConnect project

This commit is contained in:
2025-08-01 19:12:05 +08:00
commit f14db75802
3503 changed files with 448337 additions and 0 deletions

View File

@ -0,0 +1,86 @@
// // ©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.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Android;
namespace WordsToolkit.Scripts.System.Haptic
{
public class HapticFeedback : MonoBehaviour
{
public enum HapticForce
{
Light,
Medium,
Heavy
}
private const string VibrationPrefKey = "VibrationLevel";
#if UNITY_IOS
[DllImport("__Internal")]
private static extern void _TriggerHapticFeedback(int force);
#endif
private static bool IsSystemSupported()
{
#if UNITY_IOS
return SystemInfo.supportsVibration;
#elif UNITY_ANDROID
return SystemInfo.supportsVibration && Permission.HasUserAuthorizedPermission("android.permission.VIBRATE");
#else
return false;
#endif
}
private static bool TryHapticFeedback(HapticForce force)
{
if (!IsSystemSupported())
return false;
try
{
#if UNITY_IOS
_TriggerHapticFeedback((int)force);
#elif UNITY_ANDROID
long[] pattern = force switch
{
HapticForce.Light => new long[] { 0, 50 },
HapticForce.Medium => new long[] { 0, 100 },
HapticForce.Heavy => new long[] { 0, 200 },
_ => new long[] { 0, 50 }
};
Vibration.Vibrate(pattern, -1);
#endif
return true;
}
catch (Exception e)
{
return false;
}
}
public static void TriggerHapticFeedback(HapticForce force)
{
if (!IsVibrationEnabled())
return;
}
private static bool IsVibrationEnabled()
{
return PlayerPrefs.GetFloat(VibrationPrefKey, 1) > 0;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ad53e4c45a1d42d4bcee63a96caafa5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,36 @@
// // ©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.System.Haptic
{
public static class Vibration
{
public static void Vibrate(long[] pattern, int repeat)
{
if (Application.platform == RuntimePlatform.Android)
{
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using (var vibrator = currentActivity.Call<AndroidJavaObject>("getSystemService", "vibrator"))
{
vibrator.Call("vibrate", pattern, repeat);
}
}
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 29ec5197bae34b0d9bd40553ecd33494
timeCreated: 1729849644