112 lines
3.2 KiB
C#
112 lines
3.2 KiB
C#
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2007-2020 , Inc. All Rights Reserved.
|
|
//
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
using GCSeries.Core.Sdk;
|
|
using GCSeries.Core;
|
|
|
|
/// <summary>
|
|
/// 未来立体 笔震动脚本
|
|
/// </summary>
|
|
public class StylusVibration : MonoBehaviour,
|
|
IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
////////////////////////////////////////////////////////////////////////
|
|
// Inspector Fields
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
public VibrationTypeEnum VibrationType;
|
|
public float VibrationIntensity;
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// Enumerators
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
public enum VibrationTypeEnum
|
|
{
|
|
Constant,
|
|
FastPulse,
|
|
MediumPulse,
|
|
SlowPulse
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// MonoBehaviour Callbacks
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
private void Start()
|
|
{
|
|
if (ZProvider.IsInitialized)
|
|
{
|
|
this._stylusTarget = ZProvider.StylusTarget;
|
|
this._stylusTarget.IsVibrationEnabled = true;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("ZProvider can not initialize.\n Stylus" +
|
|
"vibration and LED light feedback will not be experienced.");
|
|
|
|
Destroy(this);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// Public Methods
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
this.Vibrate();
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
this._stylusTarget.StopVibration();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// Private Methods
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
private void Vibrate()
|
|
{
|
|
switch (this.VibrationType)
|
|
{
|
|
case VibrationTypeEnum.Constant:
|
|
this._stylusTarget.StartVibration(
|
|
1.0f, 0.0f, 100, this.VibrationIntensity);
|
|
break;
|
|
|
|
case VibrationTypeEnum.FastPulse:
|
|
this._stylusTarget.StartVibration(
|
|
0.1f, 0.1f, 100, this.VibrationIntensity);
|
|
break;
|
|
|
|
case VibrationTypeEnum.MediumPulse:
|
|
this._stylusTarget.StartVibration(
|
|
0.3f, 0.3f, 100, this.VibrationIntensity);
|
|
break;
|
|
|
|
case VibrationTypeEnum.SlowPulse:
|
|
this._stylusTarget.StartVibration(
|
|
0.6f, 0.6f, 100, this.VibrationIntensity);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// Private Members
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
private ZTarget _stylusTarget;
|
|
}
|
|
|