76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using Microsoft.MixedReality.Toolkit.Input;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
/// <summary>
|
|
/// 红色锁操作
|
|
/// </summary>
|
|
public class RedLockControl : PermanentTriggerBase
|
|
{
|
|
private int count = 0;
|
|
public Transform offState;
|
|
public Transform onState;
|
|
public FunctionSync_Active Switch;
|
|
private FunctionSync_PositionRoate myPosition;
|
|
|
|
//public override void Start()
|
|
//{
|
|
// base.Start();
|
|
// myPosition = GetComponent<FunctionSync_PositionRoate>();
|
|
//}
|
|
|
|
//public override void OnInputDown(InputEventData eventData)
|
|
//{
|
|
// count++; if (count == 2) count = 0;
|
|
// ChangeState();
|
|
//}
|
|
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
count++; if (count == 2) count = 0;
|
|
ChangeState();
|
|
|
|
StepManager.Instance.FinishStep(triggerName);
|
|
}
|
|
/// <summary>
|
|
/// 切换开关状态
|
|
/// </summary>
|
|
public void ChangeState()
|
|
{
|
|
if (count % 2 == 1)
|
|
{
|
|
if (transform.localPosition == offState.localPosition)
|
|
{
|
|
StartCoroutine(move(onState));
|
|
Switch.ShowObject();
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(move(offState));
|
|
Switch.DisShowObject();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
IEnumerator move(Transform tran)
|
|
{
|
|
//myPosition.GetControl();
|
|
while (transform.localPosition != tran.localPosition)
|
|
{
|
|
|
|
transform.localPosition = Vector3.MoveTowards(transform.localPosition, tran.localPosition, Time.deltaTime*0.1f);
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
//myPosition.ReleaseControl();
|
|
}
|
|
//public override void Init()
|
|
//{
|
|
// base.Init();
|
|
|
|
//}
|
|
}
|