using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
namespace DisComputer
{
///
/// 硬盘控制器
///
public class YingPanControl : SpareItemControl
{
//UI控制
public GameObject controlUIGo;
public override void OnRecLoadColliderMsg(Grid grid)
{
isBaseOnReced = true;
if (grid.spareInfo.fitId == GameDataConfig.Instance.pcId)
{
if (grid.chectSpareTag.Contains(type.ToString()))
{
//Debug.LogFormat("{0}与{1}当前目标匹配成功", grid.chectSpareTag, type);
if (spareAnimation.IsCompareTag(grid))
{
MouseControl.Instance.SpareLoading(() =>
{
StartCoroutine(ProgressLoad());
});
}
else
{
// Debug.LogFormat("{0}与{1}当前目标不匹配", grid.chectSpareTag, type);
}
}
}
else
{
//Debug.Log("型号不匹配,请选择别的零件!!!");
MessageContainer.SendMessage(unFitTipStr(grid), this, MsgName.TipViewShowPoint);
}
}
public override void OnRecUnloadColliderMsg(ToolItem item)
{
isBaseOnReced = true;
if (item.chectSpareTag.Contains(type.ToString()))
{
//Debug.LogFormat("{0}与{1}当前目标匹配成功", item.chectSpareTag, type);
if (spareAnimation.IsCompareTag(item))
{
MouseControl.Instance.ToolLoading(() =>
{
/*spareAnimation.OnUnLoadAct();
triggerGo.SetActive(false);
HideArrowTip();
type = SpareType.Null;*/
StartCoroutine(ProgressUnload());
});
}
}
else
{
//Debug.LogFormat("{0}与{1}当前目标不匹配", item.chectSpareTag, type);
}
}
int[] randomEugles = { 30,60,90,-30,-60,90};
int eulerX;
int eulerZ;
int eulerY;
GameObject uiGo;
///
/// 安装流程
///
///
IEnumerator ProgressLoad()
{
GuangQuAnimation guangQu = spareAnimation.GetComponent();
if(guangQu!=null)
StartCoroutine(guangQu.JiXiangGaiAni(0));
yield return StartCoroutine(spareAnimation.ProgressFocuse());
spareAnimation.mainGo.SetActive(true);
eulerX = (int)spareAnimation.mainGo.transform.localEulerAngles.x;
eulerY = (int)spareAnimation.mainGo.transform.localEulerAngles.y;
spareAnimation.mainGo.transform.localEulerAngles = new Vector3(eulerX, eulerY, randomEugles[Random.Range(0, randomEugles.Length)]);
uiGo = Instantiate(controlUIGo);
uiGo.SetActive(true);
SpareRotationCanvas rotationCanvas = uiGo.GetComponent();
rotationCanvas.RotEnterHandle += OnRotOk;
rotationCanvas.RotLeftHandle += OnRotLeft;
rotationCanvas.RotRightHandle += OnRotRight;
}
///
/// 拆解流程
///
///
IEnumerator ProgressUnload()
{
yield return StartCoroutine(spareAnimation.ProgressFocuse());
spareAnimation.OnUnLoadAct();
triggerGo.SetActive(false);
HideArrowTip();
type = SpareType.Null;
}
bool isCanRot;
void OnRotLeft()
{
//Debug.LogFormat("rotation left 30");
if(isCanRot)
return;
isCanRot = true;
eulerZ = (int)spareAnimation.mainGo.transform.localEulerAngles.z + 30;
spareAnimation.mainGo.transform.DOLocalRotate(new Vector3(eulerX, eulerY, eulerZ), 0.2f, RotateMode.FastBeyond360).OnComplete(()=>
{
isCanRot = false;
//Debug.LogFormat("Left >>> {0}", eulerZ);
if (eulerZ == 0.0f || eulerZ == 360.0f)
{
spareAnimation.mainGo.GetComponent().OutlineColor = loadOutLineColor;
}
else
{
spareAnimation.mainGo.GetComponent().OutlineColor = outLineColor;
}
});
}
void OnRotRight()
{
if (isCanRot)
return;
isCanRot = true;
eulerZ = (int)spareAnimation.mainGo.transform.localEulerAngles.z - 30;
spareAnimation.mainGo.transform.DOLocalRotate(new Vector3(eulerX, eulerY, eulerZ), 0.2f,RotateMode.FastBeyond360).OnComplete(()=>
{
isCanRot = false;
//Debug.LogFormat("Right >>> {0}",eulerZ);
if(eulerZ == 0.0f || eulerZ == 360.0f)
{
spareAnimation.mainGo.GetComponent().OutlineColor = loadOutLineColor;
}else
{
spareAnimation.mainGo.GetComponent().OutlineColor = outLineColor;
}
});
}
void OnRotOk()
{
Debug.LogFormat("rotation ok {0}", spareAnimation.mainGo.transform.localEulerAngles.z);
if(eulerZ == 0.0f || eulerZ == 360.0f)
{
Debug.LogFormat("Rotation is Complete!!!");
spareAnimation.OnLoadAct();
DisableLoadColor();
HideArrowTip();
triggerGo.SetActive(false);
type = SpareType.Null;
GameObject.DestroyImmediate(uiGo);
}
else
{
Debug.LogFormat("Rotation is miss!!!");
}
}
}
}