177 lines
4.7 KiB
C#
177 lines
4.7 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class concentrator : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 集中器
|
|
/// </summary>
|
|
public GameObject concentratorObj;
|
|
|
|
/// <summary>
|
|
/// 集中器端子螺丝
|
|
/// </summary>
|
|
public GameObject[] ScrewObj;
|
|
|
|
/// <summary>
|
|
/// 集线盒电线动画
|
|
/// </summary>
|
|
public SkinnedMeshRenderer ElectricWireSMR;
|
|
|
|
/// <summary>
|
|
/// 电线碰撞
|
|
/// </summary>
|
|
public BoxCollider TapeMarCol;
|
|
|
|
/// <summary>
|
|
/// 电线前段胶带
|
|
/// </summary>
|
|
public Material TapeMar;
|
|
/// <summary>
|
|
/// 螺丝是否全部显示
|
|
/// </summary>
|
|
int allls;
|
|
/// <summary>
|
|
/// 是否播放集线器螺丝拆完后电线动画
|
|
/// </summary>
|
|
public static bool isPlayAni = true;
|
|
|
|
/// <summary>
|
|
/// 集中器盖子
|
|
/// </summary>
|
|
public GameObject Cover;
|
|
|
|
/// <summary>
|
|
/// 新盖子上左右两颗螺丝
|
|
/// </summary>
|
|
public GameObject[] screw;
|
|
bool isplaying = true;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// 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 == "新的集中器碰撞")
|
|
{
|
|
StartCoroutine(Newconcentrator());
|
|
Debug.Log(hit.collider.gameObject.name);
|
|
}
|
|
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].GetComponent<MeshRenderer>().enabled = true;
|
|
}
|
|
}
|
|
if (hit.collider.gameObject.name == "pCylinder170")
|
|
{
|
|
if (isplaying)
|
|
{
|
|
StartCoroutine(IEElectricWire());
|
|
isplaying = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (AreAllObjectsHidden())
|
|
{
|
|
isPlayAni = false;
|
|
StartCoroutine(TapeBack());
|
|
Debug.Log("所有螺丝都显示");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新集中器螺丝
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool AreAllObjectsHidden()
|
|
{
|
|
allls = 0;
|
|
for (int i = 0; i < ScrewObj.Length; i++)
|
|
{
|
|
if (ScrewObj[i].gameObject.GetComponent<MeshRenderer>().enabled)
|
|
{
|
|
allls++;
|
|
}
|
|
}
|
|
if (allls >= ScrewObj.Length - 1)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 集线器复位动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator Newconcentrator()
|
|
{
|
|
concentratorObj.gameObject.transform.DOLocalMove(new Vector3(3.0778f, 2.2149f, -1.4581f), 1f);
|
|
yield return new WaitForSeconds(1.0f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 集线器上线动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator IEElectricWire()
|
|
{
|
|
TapeMarCol.enabled = false;
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
for (int a = 100; a >= 0; a--)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
ElectricWireSMR.SetBlendShapeWeight(i, a);
|
|
}
|
|
}
|
|
yield return new WaitForSeconds(6f);
|
|
Cover.gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(1.0f);
|
|
screw[0].gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(1.0f);
|
|
screw[1].gameObject.SetActive(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 胶带还原动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator TapeBack()
|
|
{
|
|
TapeMarCol.enabled = true;
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p6", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p5", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p4", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p3", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p2", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
TapeMar.SetFloat("_step_p1", 0);
|
|
yield return new WaitForSeconds(1f);
|
|
}
|
|
}
|