ShanDongVirtualPowerPlant/u3d-ShanDongVirtualPowerPlant/Assets/Adam/Scripts/Bootstrap.cs

186 lines
5.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum CurrentLevel
{
/// <summary>
/// 省会
/// </summary>
ProvincialCapital,
/// <summary>
/// 城市
/// </summary>
City,
/// <summary>
/// 区
/// </summary>
Area
}
public class Bootstrap : MonoSingleton<Bootstrap>
{
public LandMarksAndInfoController landMarkAndInfoCotroller;
//public CurrentLevel currentLevel = CurrentLevel.ProvincialCapital;
/// <summary>
/// 0 省会 1 城市 2 区县
/// </summary>
public int currentLevel = 0;
public List<string> landMarks;
/// <summary>
/// 透明
/// </summary>
public Material[] opacity;
/// <summary>
/// 选中
/// </summary>
public Material[] select;
/// <summary>
/// 默认
/// </summary>
public Material[] mat;
/// <summary>
/// 当前选中板块
/// </summary>
//[HideInInspector]
public GameObject currentLand;
public CameraRT cameraRt;
/// <summary>
/// 省会
/// </summary>
public GameObject provincialCapital;
/// <summary>
/// 城市
/// </summary>
public GameObject[] citys;
public List<Transform> logicViewList = new List<Transform>();
// Start is called before the first frame update
void Start()
{
landMarks = new List<string> { "网络负荷49.84 kw", "上网负荷49.84 kw", "削峰负荷49.84 kw", "填谷负荷49.84 kw", "发电负荷49.84 kw" };
landMarkAndInfoCotroller.gameObject.SetActive(false);
cameraRt.onMax += Reduce;
cameraRt.onMin += Amplify;
SwitchLand();
}
public void GotoView(string viewName, float _distance)
{
Transform viewTarget = logicViewList.Find(x => x.name == viewName);
cameraRt.SetTarget(viewTarget, _distance);
}
/// <summary>
/// 展示地标
/// </summary>
/// <param name="land"></param>
public void ShowLandMark(GameObject land)
{
currentLand = land;
//currentLand.GetComponent<MeshRenderer>().materials[1].SetColor("_BaseCol", select.GetColor("_BaseCol"));
currentLand.GetComponent<MeshRenderer>().materials = select;
landMarkAndInfoCotroller.gameObject.SetActive(true);
Vector3 worldToScreenPoint = Camera.main.WorldToScreenPoint(new Vector3(currentLand.transform.position.x, currentLand.transform.position.y, currentLand.transform.position.z));
landMarkAndInfoCotroller.GetComponent<RectTransform>().position = new Vector3(worldToScreenPoint.x, worldToScreenPoint.y, 0);
landMarkAndInfoCotroller.SetMarksInfo(currentLand.name, landMarks);
}
/// <summary>
/// 关闭地标
/// </summary>
public void CloseLandMark()
{
landMarkAndInfoCotroller.gameObject.SetActive(false);
if (currentLand != null)
{
//currentLand.GetComponent<MeshRenderer>().materials[1].SetColor("_BaseCol", mat.GetColor("_BaseCol"));
currentLand.GetComponent<MeshRenderer>().materials = mat;
currentLand = null;
}
}
/// <summary>
/// 放大
/// </summary>
public void Amplify()
{
if (currentLand == null) return;
currentLevel++;
if (currentLevel > 2)
{
currentLevel = 2;
}
SwitchLand();
}
/// <summary>
/// 缩小
/// </summary>
public void Reduce()
{
//if (currentLand == null) return;
currentLevel--;
if (currentLevel < 0)
{
currentLevel = 0;
}
SwitchLand();
}
public void SwitchLand()
{
switch (currentLevel)
{
case 0:
Transform viewTarget = logicViewList.Find(x => x.name == "省会视角");
cameraRt.SetTarget(viewTarget, 50, 120, 65);
for (int i = 0; i < citys.Length; i++)
{
citys[i].SetActive(false);
}
FadeOrUnFade(false);
break;
case 1:
cameraRt.SetTarget(currentLand.transform, 20, 100, 90);
for (int i = 0; i < citys.Length; i++)
{
citys[i].SetActive(false);
if (citys[i].name.Equals(currentLand.name))
citys[i].SetActive(true);
}
FadeOrUnFade(true);
break;
case 2:
break;
}
CloseLandMark();
}
private void FadeOrUnFade(bool isCity)
{
for (int i = 0; i < provincialCapital.transform.childCount; i++)
{
MeshRenderer mesh = provincialCapital.transform.GetChild(i).GetComponent<MeshRenderer>();
if (!isCity)
{
mesh.GetComponent<FadeController>().OnFadeUnFade(false);
mesh.materials = mat;
mesh.GetComponent<Collider>().enabled = true;
//provincialCapital.SetActive(false);
}
else
{
mesh.GetComponent<Collider>().enabled = false;
mesh.materials = opacity;
mesh.GetComponent<FadeController>().OnFadeUnFade(true);
provincialCapital.SetActive(true);
}
}
}
}