using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
///
/// 红色锁操作
///
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();
//}
//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);
}
///
/// 切换开关状态
///
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();
//}
}