using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum CurrentLevel
{
///
/// 省会
///
ProvincialCapital,
///
/// 城市
///
City,
///
/// 区
///
Area
}
public class Bootstrap : MonoSingleton
{
public LandMarksAndInfoController landMarkAndInfoCotroller;
//public CurrentLevel currentLevel = CurrentLevel.ProvincialCapital;
///
/// 0 省会 1 城市 2 区县
///
public int currentLevel = 0;
public List landMarks;
///
/// 透明
///
public Material[] opacity;
///
/// 选中
///
public Material[] select;
///
/// 默认
///
public Material[] mat;
///
/// 当前选中板块
///
//[HideInInspector]
public GameObject currentLand;
public CameraRT cameraRt;
///
/// 省会
///
public GameObject provincialCapital;
///
/// 城市
///
public GameObject[] citys;
public List logicViewList = new List();
// Start is called before the first frame update
void Start()
{
landMarks = new List { "网络负荷: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);
}
///
/// 展示地标
///
///
public void ShowLandMark(GameObject land)
{
currentLand = land;
//currentLand.GetComponent().materials[1].SetColor("_BaseCol", select.GetColor("_BaseCol"));
currentLand.GetComponent().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().position = new Vector3(worldToScreenPoint.x, worldToScreenPoint.y, 0);
landMarkAndInfoCotroller.SetMarksInfo(currentLand.name, landMarks);
}
///
/// 关闭地标
///
public void CloseLandMark()
{
landMarkAndInfoCotroller.gameObject.SetActive(false);
if (currentLand != null)
{
//currentLand.GetComponent().materials[1].SetColor("_BaseCol", mat.GetColor("_BaseCol"));
currentLand.GetComponent().materials = mat;
currentLand = null;
}
}
///
/// 放大
///
public void Amplify()
{
if (currentLand == null) return;
currentLevel++;
if (currentLevel > 2)
{
currentLevel = 2;
}
SwitchLand();
}
///
/// 缩小
///
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();
if (!isCity)
{
mesh.GetComponent().OnFadeUnFade(false);
mesh.materials = mat;
mesh.GetComponent().enabled = true;
//provincialCapital.SetActive(false);
}
else
{
mesh.GetComponent().enabled = false;
mesh.materials = opacity;
mesh.GetComponent().OnFadeUnFade(true);
provincialCapital.SetActive(true);
}
}
}
}