128 lines
3.9 KiB
C#
128 lines
3.9 KiB
C#
using HighlightPlus;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SingleBubbleCtrl : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public bool isSelected = false;
|
|
|
|
public GameObject targetDevice;
|
|
public GameObject deviceObstacle;
|
|
private Coroutine flashLightsCoroutine;
|
|
[HideInInspector]
|
|
public Vector3 positionKey;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (targetDevice != null)
|
|
positionKey = targetDevice.transform.localPosition;
|
|
if (deviceObstacle == null)
|
|
{
|
|
Collider col = GetComponentInChildren<Collider>(true);
|
|
if (col != null)deviceObstacle = col.gameObject;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
//void Update()
|
|
//{
|
|
|
|
//}
|
|
public void RecoverGameObject()
|
|
{
|
|
if (targetDevice == null)
|
|
{
|
|
Tool_SelectComponent[] tscS = FindObjectsOfType<Tool_SelectComponent>();
|
|
foreach (var item in tscS)
|
|
{
|
|
if (item.transform.localPosition == positionKey)
|
|
{
|
|
targetDevice = item.gameObject;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void BubbleInit(bool _isSelected)
|
|
{
|
|
isSelected = _isSelected;
|
|
if (isSelected)
|
|
{
|
|
if (targetDevice == null)
|
|
RecoverGameObject();
|
|
if (targetDevice != null)
|
|
{
|
|
Tool_SelectComponent tsc = targetDevice.GetComponent<Tool_SelectComponent>();
|
|
HighlightEffect he = targetDevice.GetComponent<HighlightEffect>();
|
|
if (tsc != null) tsc.enabled = true;
|
|
if (he != null) he.enabled = true;
|
|
}
|
|
if (flashLightsCoroutine != null)
|
|
{
|
|
StopCoroutine(flashLightsCoroutine);
|
|
flashLightsCoroutine = null;
|
|
}
|
|
flashLightsCoroutine = StartCoroutine(FlashLights());
|
|
}
|
|
else
|
|
{
|
|
if (targetDevice != null)
|
|
{
|
|
Tool_SelectComponent tsc = targetDevice.GetComponent<Tool_SelectComponent>();
|
|
HighlightEffect he = targetDevice.GetComponent<HighlightEffect>();
|
|
if (tsc != null)tsc.enabled = false;
|
|
if (he != null) he.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void BubbleReset( )
|
|
{
|
|
isSelected = false;
|
|
if (flashLightsCoroutine != null)
|
|
{
|
|
StopCoroutine(flashLightsCoroutine);
|
|
flashLightsCoroutine = null;
|
|
}
|
|
Renderer renderer = this.GetComponent<Renderer>();
|
|
renderer.material.SetColor("_EmissionColor", Color.green);
|
|
if (targetDevice != null)
|
|
{
|
|
Tool_SelectComponent tsc = targetDevice.GetComponent<Tool_SelectComponent>();
|
|
HighlightEffect he = targetDevice.GetComponent<HighlightEffect>();
|
|
if (tsc != null)
|
|
tsc.enabled = true;
|
|
if (he != null)
|
|
he.enabled = true;
|
|
}
|
|
}
|
|
|
|
|
|
IEnumerator FlashLights()
|
|
{
|
|
|
|
while (isSelected)
|
|
{
|
|
if (deviceObstacle != null)
|
|
deviceObstacle.SetActive(!isSelected);
|
|
if (targetDevice != null && targetDevice.activeSelf)
|
|
{
|
|
Renderer renderer = this.GetComponent<Renderer>();
|
|
renderer.material.SetColor("_EmissionColor", Color.black);
|
|
yield return new WaitForSeconds(0.5f);
|
|
renderer.material.SetColor("_EmissionColor", Color.green);
|
|
}
|
|
else
|
|
{
|
|
Renderer renderer = this.GetComponent<Renderer>();
|
|
renderer.material.SetColor("_EmissionColor", Color.red);
|
|
}
|
|
yield return new WaitForSeconds(0.3f);
|
|
}
|
|
}
|
|
}
|