375 lines
12 KiB
C#
375 lines
12 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 螺丝刀
|
|
/// </summary>
|
|
public class Screwdriver : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 螺丝刀坐标
|
|
/// </summary>
|
|
public Transform ScrewdriverTrans;
|
|
|
|
/// <summary>
|
|
/// 右边螺丝
|
|
/// </summary>
|
|
public GameObject ScrewR;
|
|
|
|
/// <summary>
|
|
/// 左边螺丝
|
|
/// </summary>
|
|
public GameObject ScrewL;
|
|
|
|
/// <summary>
|
|
/// 集中器左侧螺丝
|
|
/// </summary>
|
|
public GameObject LconcentratorScrew;
|
|
|
|
/// <summary>
|
|
/// 集中器右侧螺丝
|
|
/// </summary>
|
|
public GameObject RconcentratorScrew;
|
|
|
|
/// <summary>
|
|
/// 集线器外壳螺丝和封印
|
|
/// </summary>
|
|
public GameObject[] concentratorScrew;
|
|
|
|
/// <summary>
|
|
/// 螺丝
|
|
/// </summary>
|
|
public GameObject[] ScrewObj;
|
|
|
|
/// <summary>
|
|
/// 集线盒电线动画
|
|
/// </summary>
|
|
public SkinnedMeshRenderer ElectricWireSMR;
|
|
|
|
/// <summary>
|
|
/// 电线碰撞
|
|
/// </summary>
|
|
public BoxCollider ElectricWireBcr;
|
|
|
|
/// <summary>
|
|
/// 集中器盖子
|
|
/// </summary>
|
|
public GameObject HubCoverObj;
|
|
|
|
/// <summary>
|
|
/// 集中器后边螺丝
|
|
/// </summary>
|
|
public GameObject[] ConcentratorScrewObj;
|
|
|
|
/// <summary>
|
|
/// 集线器物体
|
|
/// </summary>
|
|
public Transform ConcentratorObj;
|
|
|
|
/// <summary>
|
|
/// 电线前段胶带
|
|
/// </summary>
|
|
public Material TapeMar;
|
|
|
|
public InteractiveObjects[] interactiveObjects;
|
|
|
|
/// <summary>
|
|
/// 拆完封印
|
|
/// </summary>
|
|
bool issplit;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
void Init()
|
|
{
|
|
ElectricWireBcr.enabled = false;
|
|
ElectricWireSMR.SetBlendShapeWeight(0, 0);
|
|
ElectricWireSMR.SetBlendShapeWeight(1, 0);
|
|
ElectricWireSMR.SetBlendShapeWeight(2, 0);
|
|
ElectricWireSMR.SetBlendShapeWeight(3, 0);
|
|
ElectricWireSMR.SetBlendShapeWeight(4, 0);
|
|
ElectricWireSMR.SetBlendShapeWeight(5, 0);
|
|
TapeMar.SetFloat("_step_p1", 0);
|
|
TapeMar.SetFloat("_step_p2", 0);
|
|
TapeMar.SetFloat("_step_p3", 0);
|
|
TapeMar.SetFloat("_step_p4", 0);
|
|
TapeMar.SetFloat("_step_p5", 0);
|
|
TapeMar.SetFloat("_step_p6", 0);
|
|
//TapeMar.SetFloat("_step_p1", 1);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{//Camera.transform.forward
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
bool raycast = Physics.Raycast(ray, out hit);
|
|
if (raycast)
|
|
{
|
|
if (hit.collider.gameObject.name == "盖_固定螺丝_Rup")
|
|
{
|
|
StartCoroutine(Rscrew());
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
}
|
|
if (hit.collider.gameObject.name == "固定螺丝_Ldown")
|
|
{
|
|
StartCoroutine(Lscrew());
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
}
|
|
if (hit.collider.gameObject.name == "壳固定螺丝_R")
|
|
{
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
StartCoroutine(IERconcentratorScrew());
|
|
}
|
|
if (hit.collider.gameObject.name == "壳固定螺丝_L")
|
|
{
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
StartCoroutine(IELconcentratorScrew());
|
|
}
|
|
for (int i = 0; i < ScrewObj.Length; i++)
|
|
{
|
|
if (hit.collider.gameObject.name == ScrewObj[i].name)
|
|
{
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
StartCoroutine(IEHubSegmentRowScrews());
|
|
ScrewObj[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
if (hit.collider.gameObject.name == "固定螺丝_Rdown")
|
|
{
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
StartCoroutine(IEHubSegmentRowScrews());
|
|
ConcentratorScrewObj[0].SetActive(false);
|
|
ConcentratorScrewObj[1].SetActive(false);
|
|
}
|
|
if (hit.collider.gameObject.name == "集电器固定螺丝_Ldown")
|
|
{
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
StartCoroutine(IEHubSegmentRowScrews());
|
|
ConcentratorScrewObj[2].SetActive(false);
|
|
ConcentratorScrewObj[3].SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
//集中器螺丝全隐藏后播放电线动画
|
|
if (AreAllObjectsHidden()&& concentrator.isPlayAni)
|
|
{
|
|
StartCoroutine(ScrewdriverBack());
|
|
ElectricWireBcr.enabled = true;
|
|
StartCoroutine(IEElectricWire());
|
|
Debug.Log("所有螺丝都已隐藏");
|
|
}
|
|
//集中器外壳上的封印和螺丝
|
|
if (AllHubOfHubs())
|
|
{
|
|
HubCoverObj.gameObject.transform.DOLocalMove(new Vector3(0, 0.0167f, -0.2387f),1);
|
|
Debug.Log("所有集线器盖子螺丝都已隐藏");
|
|
}
|
|
if (ConcentratorScrew())
|
|
{
|
|
StartCoroutine(IEConcentratorScrew());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AreAllObjectsHidden()
|
|
{
|
|
foreach (GameObject obj in ScrewObj)
|
|
{
|
|
if (obj.activeInHierarchy)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器外壳上的封印和螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AllHubOfHubs()
|
|
{
|
|
foreach (GameObject obj in concentratorScrew)
|
|
{
|
|
if (obj.activeInHierarchy)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器后部四颗螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ConcentratorScrew()
|
|
{
|
|
foreach (GameObject obj in ConcentratorScrewObj)
|
|
{
|
|
if (obj.activeInHierarchy)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 螺丝刀返回动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator ScrewdriverBack()
|
|
{
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.274139f, 1.803738f, -1.191f), 0.5f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-90f, 0, 0), 0.5f);
|
|
yield return new WaitForSeconds(2f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接线盒右边螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator Rscrew()
|
|
{
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 0.5f);
|
|
yield return new WaitForSeconds(0.6f);
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2373f, 1.8549f, -1.244f), 1f);
|
|
yield return new WaitForSeconds(1);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f);
|
|
yield return new WaitForSeconds(1.2f);
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.191f, 1.831f, -1.158f), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewR.transform.DOLocalMove(new Vector3(0.1316f, 0.036f, 0.0034f), 1.6f);
|
|
yield return new WaitForSeconds(1.2f);
|
|
StartCoroutine(ScrewdriverBack());
|
|
ScrewR.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接线盒左边螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator Lscrew()
|
|
{
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2373f, 1.8284f, -1.3885f), 0.5f);
|
|
yield return new WaitForSeconds(0.6f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f);
|
|
yield return new WaitForSeconds(1f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewL.transform.DOLocalMove(new Vector3(-0.07357633f, -0.01137948f, -0.0366f), 1f);
|
|
yield return new WaitForSeconds(1.2f);
|
|
StartCoroutine(ScrewdriverBack());
|
|
ScrewL.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器右侧螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IERconcentratorScrew()
|
|
{
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2669f, 2.0962f, -1.3294f), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
RconcentratorScrew.transform.DOLocalMove(new Vector3(0.1143f, 0.0216f, -0.1031f), 1f);
|
|
yield return new WaitForSeconds(0.5f);
|
|
StartCoroutine(ScrewdriverBack());
|
|
RconcentratorScrew.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器左侧螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IELconcentratorScrew()
|
|
{
|
|
ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2669f, 2.0962f, -1.4616f), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f);
|
|
yield return new WaitForSeconds(1.5f);
|
|
LconcentratorScrew.transform.DOLocalMove(new Vector3(-0.1188f, 0.0216f, -0.1031f), 1f);
|
|
yield return new WaitForSeconds(2f);
|
|
StartCoroutine(ScrewdriverBack());
|
|
LconcentratorScrew.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集线器螺丝拆完后电线动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IEElectricWire()
|
|
{
|
|
//yield return new WaitForSeconds(1f);
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.001f);
|
|
ElectricWireSMR.SetBlendShapeWeight(0, i);
|
|
}
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.002f);
|
|
ElectricWireSMR.SetBlendShapeWeight(1, i);
|
|
}
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.002f);
|
|
ElectricWireSMR.SetBlendShapeWeight(2, i);
|
|
}
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.002f);
|
|
ElectricWireSMR.SetBlendShapeWeight(3, i);
|
|
}
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.002f);
|
|
ElectricWireSMR.SetBlendShapeWeight(4, i);
|
|
}
|
|
for (int i = 0; i <= 100; i++)
|
|
{
|
|
yield return new WaitForSeconds(0.002f);
|
|
ElectricWireSMR.SetBlendShapeWeight(5, i);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集中器背后螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IEConcentratorScrew()
|
|
{
|
|
ConcentratorObj.gameObject.transform.DOLocalMove(new Vector3(-0.2719f, 2.24768f, -0.0772f), 0.5f);
|
|
yield return new WaitForSeconds(1);
|
|
ConcentratorObj.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 螺丝刀移动到集中器旁动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IEHubSegmentRowScrews()
|
|
{
|
|
ScrewdriverTrans.gameObject.transform.DOLocalMove(new Vector3(3.1215f, 2.1383f, -1.3484f),0.5f);
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
}
|