fix:修改体感服管理脚本,解决调用体感服方法时 游戏闪退问题

This commit is contained in:
bzx
2025-10-17 18:06:28 +08:00
parent 05e60cff41
commit 0dbdfafb1a
12 changed files with 21875 additions and 15 deletions

View File

@@ -8,7 +8,7 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="picoapp" android:host="launch" android:path="/com.pineappletech.futuremen"/>
<data android:scheme="picoapp" android:host="launch" android:path="/com.pineappletech.futuremen.gongsi1lou"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

View File

@@ -35,7 +35,7 @@ public class MRInput : MonoBehaviour
#if !UNITY_EDITOR && UNITY_ANDROID && (PICO || VIVE)
PXR_Input.SendHapticImpulse(VibrateType.RightController, amplitude, duration, frequency);
TrueGearEffectManager.Ins.OnHit(true,4,true);
//TrueGearEffectManager.Ins.OnHit(true,4,true);
#endif
}

View File

@@ -111,17 +111,27 @@ public class TrueGearEffectManager : MonoBehaviour
if (!res)
return;
List<DeviceData> res1 = androidConnector.GetScanedDevices();
Debug.Log(res1.ToString());
foreach (var item in res1)
List<DeviceData> devices = androidConnector.GetScanedDevices();
if (devices == null || devices.Count == 0)
{
Debug.Log("未扫描到任何设备");
return;
}
foreach (var device in devices)
{
bool connected = androidConnector.ConnectToDevice(device.address);
if (connected)
{
androidConnector.ConnectToDevice(item.address);
Debug.Log(string.Format("Device Connect: {0}, {1}", item.name, item.address));
Debug.Log($"成功连接设备: {device.name} - {device.address}");
isGetConnect = true;
ChangeElectricalLevel();
return;
}
else
{
Debug.LogWarning($"设备被占用或连接失败: {device.name} - {device.address}");
}
}
Debug.Log("No device found");
}
@@ -197,7 +207,7 @@ public class TrueGearEffectManager : MonoBehaviour
}}
]
}}";
SendPlayEffectByContent(json);
}
@@ -208,8 +218,34 @@ public class TrueGearEffectManager : MonoBehaviour
Debug.Log("OnTestClick" + res);
if (!res)
return;
androidConnector.SendPlayEffectByContent(jsonStr);
try
{
androidConnector.SendPlayEffectByContent(jsonStr);
}
catch (Exception ex)
{
Debug.LogError("调用 TrueGear 崩溃保护: " + ex);
ReconnectTrueGear();
}
}
// 当检测蓝牙断开或异常时调用
void ReconnectTrueGear()
{
try
{
var conn = TruegearAndroidConnector.Instance;
conn.InitShellJavaObject();
conn.RequestPermission();
conn.StartScan();
}
catch (Exception e)
{
Debug.LogError("重新初始化 TrueGear 失败:" + e);
}
}
public List<string> hitParts=new List<string>();
public void AddHitPart()
@@ -222,7 +258,26 @@ public class TrueGearEffectManager : MonoBehaviour
}
public void OnHit(bool isUp, int index,bool isArm)
{
//ChangeElectricalLevel();
TruegearAndroidConnector androidConnector = TruegearAndroidConnector.Instance;
if (androidConnector == null)
{
Debug.LogWarning("TrueGear connector 为空,跳过调用");
isGetConnect = false;
return;
}
if (!androidConnector.IsAvailable())
{
Debug.LogWarning("TrueGear 蓝牙不可用或断开,跳过调用");
isGetConnect = false;
return;
}
if (!isGetConnect)
{
StartCoroutine(TrueGearAndroidConnector());
return;
}
List<int> motorIDs = new List<int>();
string hitPart= hitParts[index];
switch (hitPart)
@@ -241,6 +296,7 @@ public class TrueGearEffectManager : MonoBehaviour
default:
motorIDs.Add(0); break;
}
PlayVibrationEffect(
effectName: $"Hit_{hitPart}",
motorIndex: motorIDs,

View File

@@ -1 +1 @@
Build from CHINAMI-UKDLSK3 at 2025/10/11 14:52:39
Build from CHINAMI-UKDLSK3 at 2025/10/17 17:58:18

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,5 @@
<linker>
<assembly fullname="Unity.VisualScripting.Core" preserve="all" />
<assembly fullname="Unity.VisualScripting.Flow" preserve="all" />
<assembly fullname="Unity.VisualScripting.State" preserve="all" />
</linker>

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8877eee7fdd9bdc40a1eee419cdea92b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -115,7 +115,7 @@ Material:
- _BaseColor: {r: 0.9921568, g: 0.93333334, b: 0.24705878, a: 0.47058824}
- _BaseColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 0.9921568, g: 0.93333334, b: 0.24705875, a: 0.47058824}
- _Color: {r: 0.9921568, g: 0.93333334, b: 0.24705878, a: 0.47058824}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _GlowColor: {r: 1, g: 1, b: 0, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}

View File

@@ -114,7 +114,7 @@ Material:
- _BaseColor: {r: 0.99215686, g: 0.93333334, b: 0.24705882, a: 0.47058824}
- _BaseColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 0.9921568, g: 0.93333334, b: 0.24705878, a: 0.47058824}
- _Color: {r: 0.99215686, g: 0.93333334, b: 0.24705882, a: 0.47058824}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
- _TintColor: {r: 1, g: 0.7922921, b: 0.5294118, a: 0.5}

View File

@@ -114,7 +114,7 @@ Material:
- _BaseColor: {r: 0.99215686, g: 0.93333334, b: 0.24705882, a: 0.47058824}
- _BaseColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 0.9921568, g: 0.93333334, b: 0.24705878, a: 0.47058824}
- _Color: {r: 0.99215686, g: 0.93333334, b: 0.24705882, a: 0.47058824}
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
- _TintColor: {r: 1, g: 0.7922921, b: 0.5294118, a: 0.5}

View File

@@ -108,7 +108,7 @@ GraphicsSettings:
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 1
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 1
m_DefaultRenderingLayerMask: 1
m_LogWhenShaderIsCompiled: 0