一、框架视图
二、主要代码
MainBuilding
using FrameWork.Event;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class MainBuilding : MonoBehaviour
{
public PlanShow planShow;
public GameObject[] MainBuilings;
void Start()
{
planShow.OnModelSelected.AddListener(MainBuildingCtrl); //注册事件
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnBtnTriggered);
}
private void MainBuildingCtrl(GameObject menu)
{
if (GameManager.Instance.currentStateScene== StateScene.PlanShow)
{
// Debug.Log("选中物体的名字-----" + menu.name);
if (menu.name == "MainBuilding")
{
GrowUp();
}
}
}
/// <summary>
/// 动画
/// </summary>
private void GrowUp()
{
foreach (var item in MainBuilings)
{
if (item.name == "CBD")
{
SubModel_CBD.Instance.PlayForeward();
Debug.Log("item.name"+ item.name);
}
}
}
/// <summary>
/// 反向动画
/// </summary>
public void ReverseMainBuilding()
{
foreach (var item in MainBuilings)
{
if (item.name == "CBD")
{
SubModel_CBD.Instance.PlayBack();
}
}
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_MainReturn") //点击返回按钮
{
//复位
if (GameManager.Instance.currentStateScene== StateScene.PlanShow)
{
GameManager.Instance.ResetScene();
}
}
}
}
PlanMap
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using DG.Tweening;
using System;
public class PlanMap : MonoBehaviour {
public PlanShow planShow;
private MainBuilding mainBuilding;
public GameObject[] planMapChild;
void Start () {
planShow.OnModelSelected.AddListener(PlamMapCtrl); //注册事件
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
mainBuilding = FindObjectOfType<MainBuilding>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_MainReturn")
{
if (GameManager.Instance.currentStateScene== StateScene.PlanShow)
{
ResetPlanMap();
}
}
}
/// <summary>
/// 回复默认状态
/// </summary>
/// <param name="menu"></param>
private void PlamMapCtrl(GameObject menu)
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
if (menu.name == "PlanMap")
{
GameManager.Instance.HideScene();
}
}
FindObjectOfType<IndependentCtrlAni>().menuName = menu.name;
}
/// <summary>
/// 播放地面动画
/// </summary>
public void PlayAni() {
foreach (var item in planMapChild)
{
if (item.GetComponent<Animator>()!=null)
{
item.GetComponent<Animator>().enabled = true;
}
item.SetActive(true);
}
}
/// <summary>
/// 重置显示
/// </summary>
public void ResetPlanMap() {
foreach (var item in planMapChild)
{
if (item.GetComponent<Animator>() != null)
{
item.GetComponent<Animator>().enabled = false;
}
item.SetActive(true);
}
}
}
SurroundBuilding
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
using DG.Tweening;
public class SurroundBuilding : MonoBehaviour
{
public PlanShow planShow;
// public GameObject[] SurroundBuildings;
public GameObject surroundBuildingChild;
public Animator mAnimator;
void Start()
{
planShow.OnModelSelected.AddListener(SurroundBuildingCtrl); //注册事件
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnBtnTriggered);
ResetSurroundBuildings();
mAnimator = surroundBuildingChild.transform.GetComponent<Animator>();
}
private void SurroundBuildingCtrl(GameObject menu)
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
if (menu.name == "SurroundBuilding")
{
SurroundGrowUp();
}
}
}
/// <summary>
/// 点击返回按钮
/// </summary>
/// <param name="obj"></param>
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_MainReturn")
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
//重置
ResetSurroundBuildings();
// Debug.Log("执行了SurroundBuilding");
}
}
}
///生长动画
public void SurroundGrowUp()
{
surroundBuildingChild.SetActive(true);
mAnimator.enabled = true;
mAnimator.SetFloat("BackSpeed", 1);
mAnimator.Play("building",0,0);
}
/// <summary>
/// 反向动画
/// </summary>
public void ReverseSurroundBuilding()
{
surroundBuildingChild.SetActive(true);
mAnimator.enabled = true;
mAnimator.SetFloat("BackSpeed", -1);
mAnimator.Play("building",0,1f);
//mAnimator.Play("building", 0, GetLengthName());
Debug.Log("倒播周边建筑动画");
}
public float GetLengthName() {
float length = 0;
AnimationClip[] clips = mAnimator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
if (clip.name.Equals(name))
{
length = clip.length;
break;
}
}
return length;
}
/// <summary>
/// 隐藏
/// </summary>
public void HideSurroundBuildings()
{
surroundBuildingChild.SetActive(false);
}
/// <summary>
/// 重置
/// </summary>
public void ResetSurroundBuildings()
{
surroundBuildingChild.transform.localPosition = new Vector3(0, 0f, 0);
surroundBuildingChild.SetActive(true);
if (mAnimator != null)
{
mAnimator.enabled = false;
}
}
}
Traffic
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using DG.Tweening;
using System;
public class Traffic : MonoBehaviour {
public PlanShow planShow;
public GameObject[] traffics;
DOTweenPath[] tweenPath;
void Start () {
planShow.OnModelSelected.AddListener(TrafficCtrl); //注册事件
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
TrafficReset();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name=="CubeUIBtn_MainReturn")
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
TrafficReset();
}
}
}
private void TrafficCtrl(GameObject menu)
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
if (menu.name == "Traffic")
{
TrafficForeward();
}
}
}
/// <summary>
/// 正向
/// </summary>
public void TrafficForeward()
{
foreach (var item in traffics)
{
item.SetActive(true);
tweenPath=item.GetComponentsInChildren<DOTweenPath>();
foreach (var path in tweenPath)
{
//path.DORestart();
path.DOPlayForward();
}
}
}
/// <summary>
/// 反向
/// </summary>
public void TrafficBack() {
foreach (var item in traffics)
{
item.SetActive(true);
tweenPath = item.GetComponentsInChildren<DOTweenPath>();
foreach (var path in tweenPath)
{
// path.DOPause();
path.DOPlayBackwards();
}
}
}
/// <summary>
/// 重置
/// </summary>
public void TrafficReset() {
foreach (var item in traffics)
{
item.SetActive(true);
item.transform.position = new Vector3(-12,0,20);
tweenPath = item.GetComponentsInChildren<DOTweenPath>();
foreach (var path in tweenPath)
{
if (GameManager.Instance.currentStateScene== StateScene.SceneRoam)
{
path.DORestart();
}
else
{
path.DORestart();
path.DOPause();
}
}
}
}
CameraManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System;
/// <summary>
/// 控制寻路起始点
/// </summary>
public class CameraManager : MonoBehaviour
{
public Transform refPoint; //参考点
private Transform orignPoint;
private Transform startPoint;
DOTweenPath tweenPath;
private void Awake()
{
tweenPath = GetComponent<DOTweenPath>();
// tweenPath.enabled = false;
tweenPath.isClosedPath = true;
tweenPath.DOPause();
startPoint = refPoint.Find("StartPoint");
orignPoint = refPoint.Find("OrignPoint");
transform.position = orignPoint.transform.position;
transform.rotation = orignPoint.transform.rotation;
}
void Start()
{
}
public void Return()
{
tweenPath.DOPause();
//transform.rotation = orignPoint.transform.rotation;
//transform.position = orignPoint.transform.position;
//transform.localScale = Vector3.one;
//transform.SetParent(cameraParent,true);
}
public void StartTween(Action beforetween)
{
//tweenPath.enabled = true;
if (null != beforetween)
{
beforetween();
}
transform.DORotate(startPoint.localEulerAngles, 2);
transform.DOMove(startPoint.position, 2).SetEase(Ease.Linear).OnComplete(() =>
{
tweenPath.DORestart();
});
}
}
Follow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Utility;
public class Follow : MonoBehaviour {
// 路径脚本
[SerializeField]
private WaypointCircuit circuit;
//移动距离
public float dis;
//移动速度
public float speed=100;
// Use this for initialization
void Start()
{
transform.localScale = new Vector3(0.1f,0.1f,0.1f);
// dis = 0;
//speed = 10;
}
// Update is called once per frame
void Update()
{
//计算距离
dis += Time.deltaTime * speed;
//获取相应距离在路径上的位置坐标
transform.position = circuit.GetRoutePoint(dis).position;
//获取相应距离在路径上的方向
transform.rotation = Quaternion.LookRotation(circuit.GetRoutePoint(dis).direction);
}
}
GodView
using FrameWork.Event;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GodView : MonoBehaviour {
public GameObject godViewTips; //提示面板
public GameObject mainReturnBtn;
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnBtnTriggered);
//Debug.Log(godViewTips.name);
godViewTips.SetActive(false);
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_GodView") //上帝视觉按钮
{
//TODO 显示隐藏按钮和提示
//godViewTips.SetActive(true);
//pinchScale.CanAction = false;
//pinchRotate.canAction = false;
//pinchTranslate.CanAction = false;
//HandActionManager.Instance.CanStroke = false;
//GameManager.Instance.ResetScene();
//----------------显示返回按钮---------------
mainReturnBtn.SetActive(true);
pinchScale.CanAction = true;
pinchRotate.CanAction = true;
pinchTranslate.CanAction = true;
HandActionManager.Instance.CanStroke = false;
}
if (args.sender.name == "CubeUIBtn_MainReturn") //返回键
{
if (GameManager.Instance.currentStateScene== StateScene.GodView)
{
ResetScene();//重置场景
}
}
}
public void ResetScene() {
pinchScale.gameObject.transform.localScale = new Vector3(1, 1, 1);
pinchTranslate.gameObject.transform.localPosition = Vector3.zero;
pinchRotate.gameObject.transform.localEulerAngles = Vector3.zero;
//trans.localPosition = orginPos;
//trans.localEulerAngles = orginRot;
//trans.localScale = orginScale;
pinchScale.CanAction = false;
pinchRotate.canAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
GameManager.Instance.ResetScene();
GameManager.Instance.ResetPlayer();
}
}
PlanShow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using FrameWork.Event;
using System;
using UnityEngine.Events;
public class MenuEvent : UnityEvent<GameObject> { }//Inspector面板可见
public class PlanShow : MonoBehaviour
{
public GameObject Menu3D;
// public GameObject subMenu3DPrefab;
public Transform[] SubMenu3DChilds;
public int curIndex = 0;
public float Disx;
public float MoveSpeed;
public MenuEvent OnModelSelected = new MenuEvent(); //模型被选中
public bool isForward; //是否向前
public bool isCanStroke_PlanShow; //是否可以滑动
private float canStrokeTime;
private bool playing; //正在划
public GameObject fastTips; //提示过快
Coroutine fastCoroutine = null;
private bool isFirstShowUI = true;
public bool IsCanStroke_PlanShow
{
get { return isCanStroke_PlanShow; }
set { isCanStroke_PlanShow = value; }
}
public bool IsForward
{
get { return isForward; }
set { isForward = value; }
}
public bool Playing
{
get { return playing; }
set { playing = value; }
}
void Start()
{
HandActionManager.Instance.StrokeInBegin.AddListener(StrokeIn);
// HandActionManager.Instance.StrokeOutBegin.AddListener(StrokeOut);
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnBtnTriggered);
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
// Show();
isFirstShowUI = false;
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_PlanShow")
{
transform.GetChild(0).gameObject.SetActive(true); //显示3D菜单
ResetSubMenu3D();
IsForward = true;
pinchScale.CanAction = false;//设置LM相关属性
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = true;
IsCanStroke_PlanShow = true;
GameManager.Instance.HideScene();
//播放地面动画
// FindObjectOfType<PlanMap>().PlayAni();
}
if (args.sender.name == "CubeUIBtn_MainReturn")
{
if (GameManager.Instance.currentStateScene == StateScene.PlanShow)
{
transform.GetChild(0).gameObject.SetActive(false);//隐藏3D菜单
// Destroy(go); //销毁
IsForward = false;
pinchScale.CanAction = false;//设置LM相关属性
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
IsCanStroke_PlanShow = false;
GameManager.Instance.ResetScene();
}
}
//---------手势控制
if (args.sender.name == "UI Panel")
{
if (args.hand == HandActionManager.Instance.RightHand.gameObject)
{
//btn_MainReturn.SetActive(true);
//uIButtonBase.SetActive(false);
//StrokeIn();
}
if (args.hand == HandActionManager.Instance.LeftHand.gameObject)
{
//btn_MainReturn.SetActive(false);
//uIButtonBase.SetActive(true);
//StrokeOut();
}
}
}
void Update()
{
if (Input.GetMouseButtonDown(2))
{
transform.GetChild(0).gameObject.SetActive(true); //显示3D菜单
ResetSubMenu3D();
IsForward = true;
pinchScale.CanAction = false;//设置LM相关属性
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = true;
IsCanStroke_PlanShow = true;
GameManager.Instance.HideScene();
GameManager.Instance.currentStateScene = StateScene.PlanShow;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
curIndex = ++curIndex % SubMenu3DChilds.Length;
Show();
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
curIndex--;
if (curIndex < 0)
{
curIndex = SubMenu3DChilds.Length - 1;
}
Show();
}
}
void Show()
{
foreach (var item in SubMenu3DChilds)
{
item.gameObject.SetActive(false);
}
// string str = SubMenu3DChilds[curIndex].ToString();
if (curIndex == 0)
{
// str = string.Format("{0},{1}", SubMenu3DChilds[SubMenu3DChilds.Length - 1], SubMenu3DChilds[curIndex]);
SubMenu3DChilds[SubMenu3DChilds.Length - 1].gameObject.SetActive(true);
SubMenu3DChilds[curIndex].gameObject.SetActive(true);
if (!isFirstShowUI)
{
SubMenu3DChilds[SubMenu3DChilds.Length - 1].localPosition = new Vector3(-8, 0, 0);
SubMenu3DChilds[SubMenu3DChilds.Length - 1].DOLocalMoveX(0, 2f).From();
SubMenu3DChilds[SubMenu3DChilds.Length - 1].DOScale(1f, 2f);
SubMenu3DChilds[curIndex].localPosition = new Vector3(0, 0, 0);
SubMenu3DChilds[curIndex].DOLocalMoveX(8, 2f).From();
SubMenu3DChilds[curIndex].DOScale(2f, 2f).OnComplete(() =>
{
OnModelSelected.Invoke(SubMenu3DChilds[curIndex].gameObject); //发送最大的物体 表示选中
// Debug.Log("最大物体------"+SubMenu3DChilds[curIndex].gameObject.name);
StartCoroutine(DelayStroke());
}); ;
}
}
else
{
//str = string.Format("{0},{1}", SubMenu3DChilds[curIndex - 1], SubMenu3DChilds[curIndex]);
SubMenu3DChilds[curIndex - 1].gameObject.SetActive(true);
SubMenu3DChilds[curIndex - 1].localPosition = new Vector3(-8, 0, 0);
SubMenu3DChilds[curIndex - 1].DOLocalMoveX(0, 2f).From();
SubMenu3DChilds[curIndex - 1].DOScale(1f, 2f);
SubMenu3DChilds[curIndex].gameObject.SetActive(true);
SubMenu3DChilds[curIndex].localPosition = new Vector3(0, 0, 0);
SubMenu3DChilds[curIndex].DOLocalMoveX(8, 2f).From();
SubMenu3DChilds[curIndex].DOScale(2f, 2f).OnComplete(() =>
{
OnModelSelected.Invoke(SubMenu3DChilds[curIndex].gameObject); //发送最大的物体 表示选中
// Debug.Log("最大物体111------" + SubMenu3DChilds[curIndex].gameObject.name);
StartCoroutine(DelayStroke());
});
}
if (curIndex == SubMenu3DChilds.Length - 1)
{
// str = string.Format("{0},{1}", str, SubMenu3DChilds[0]);
SubMenu3DChilds[0].gameObject.SetActive(true);
SubMenu3DChilds[0].localScale = new Vector3(0.5f, 0.5f, 0.5f);
SubMenu3DChilds[0].localPosition = new Vector3(8, 0, 0);
SubMenu3DChilds[0].DOLocalMoveX(16, 2f).From();
SubMenu3DChilds[0].DOScale(1f, 2f);
}
else
{
// str = string.Format("{0},{1}", str, SubMenu3DChilds[curIndex + 1]);
SubMenu3DChilds[curIndex + 1].gameObject.SetActive(true);
if (!isFirstShowUI)
{
SubMenu3DChilds[curIndex + 1].localScale = new Vector3(0.5f, 0.5f, 0.5f);
SubMenu3DChilds[curIndex + 1].localPosition = new Vector3(8, 0, 0);
SubMenu3DChilds[curIndex + 1].DOLocalMoveX(16, 2f).From();
SubMenu3DChilds[curIndex + 1].DOScale(1f, 2f);
}
}
//控制主建筑的播放速度
if (curIndex == 0|| curIndex == 1) {
GameManager.Instance.subModel_CBD.speed = 1;
}
else
{
GameManager.Instance.subModel_CBD.speed = 20;
}
}
/// <summary>
/// 划进来
/// </summary>
public void StrokeIn()
{
curIndex = ++curIndex % SubMenu3DChilds.Length;
Show();
HandActionManager.Instance.CanStroke = false; //划进来时候等待
}
/// <summary>
/// 划出去
/// </summary>
public void StrokeOut()
{
if (IsCanStroke_PlanShow)
{
if (!Playing)
{
IsForward = false;
HandActionManager.Instance.CanStroke = false;
if (Menu3D.transform.localPosition.x < 0 && Menu3D.transform.localPosition.x >= -32)
{
tweener = Menu3D.transform.DOLocalMoveX(Disx += 8, MoveSpeed);
}
else
{
tweener = Menu3D.transform.DOLocalMoveX(0, MoveSpeed);
}
// tweener.SetEase(Ease.InOutBack);
if (Disx == -24)
{
ChangeState(SubMenu3DChilds[6], SubMenu3DChilds[5], SubMenu3DChilds[4], SubMenu3DChilds[3]);
}
else if (Disx == -16)
{
ChangeState(SubMenu3DChilds[5], SubMenu3DChilds[4], SubMenu3DChilds[3], SubMenu3DChilds[2]);
}
else if (Disx == -8)
{
ChangeState(SubMenu3DChilds[4], SubMenu3DChilds[3], SubMenu3DChilds[2], SubMenu3DChilds[1]);
}
else if (Disx == 0)
{
ChangeState(SubMenu3DChilds[3], SubMenu3DChilds[2], SubMenu3DChilds[1], SubMenu3DChilds[0]);
}
}
else
{
if (fastCoroutine != null)
{
fastTips.SetActive(true);
fastTips.GetComponent<Renderer>().sharedMaterial.DOFade(0, 2);
Debug.Log("点击过快~");
}
else
{
fastCoroutine = StartCoroutine(DelayStroke());
}
}
IsCanStroke_PlanShow = false;
}
//Debug.Log("StrokeOut----");
}
public void ChangeState(Transform fadehider, Transform smaller, Transform bigger, Transform shower)
{
//滑动失效canStroke false 完成才设置可以继续划 true
fade = fadehider.transform;
fade.DOScale(0.1f, 1f).OnComplete(() => { fadehider.gameObject.SetActive(false); });
small = smaller.transform;
small.DOScale(1.0f, 2f);
big = bigger.transform;
big.transform.DOScale(2f, 2f).OnComplete(() =>
{
OnModelSelected.Invoke(bigger.gameObject); //发送最大的物体 表示选中
// HandActionManager.Instance.CanStroke = true; //手滑的频率
StartCoroutine(DelayStroke()); //20180928 推迟延时
});
show = shower.transform;
show.DOScale(1f, 1f);
HideSub3DMenu();
}
IEnumerator DelayStroke()
{
if (IsForward)
{
// Debug.Log("big.name" + big.name);
}
else
{
//Debug.Log("big.name" + big.name);
}
canStrokeTime = 0.5f; //等待时间过度到最大物体之后才能划
yield return new WaitForSeconds(canStrokeTime);
Debug.Log("延迟完成");
HandActionManager.Instance.CanStroke = true; //手滑的频率
IsCanStroke_PlanShow = true;
Playing = false; //现在可以不在滑动
fastCoroutine = null;
fastTips.SetActive(false);
}
/// <summary>
/// 隐藏相关子物体
/// </summary>
public void HideSub3DMenu()
{
foreach (Transform item in SubMenu3DChilds)
{
if (item.name == fade.name && fade.gameObject.activeSelf)
{
item.gameObject.SetActive(true);
}
else if (item.name == small.name)
{
item.gameObject.SetActive(true);
}
else if (item.name == big.name)
{
item.gameObject.SetActive(true);
}
else if (item.name == show.name)
{
item.gameObject.SetActive(true);
}
else
{
item.gameObject.SetActive(false);
item.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
}
}
}
/// <summary>
/// 重置3d菜单
/// </summary>
public void ResetSubMenu3D()
{
curIndex = 0;//重置下标
Menu3D.transform.localPosition = new Vector3(0, 0, 0);
Disx = 0;
for (int i = 0; i < SubMenu3DChilds.Length; i++)
{
SubMenu3DChilds[i].localScale = new Vector3(1, 1, 1);
if (i < 2)
{
SubMenu3DChilds[i].gameObject.SetActive(true);
if (i == 0)
{
SubMenu3DChilds[i].localScale = new Vector3(2, 2, 2);
SubMenu3DChilds[i].localPosition = new Vector3(0, 0, 0);
}
else
{
SubMenu3DChilds[i].localPosition = new Vector3(8, 0, 0);
}
}
else if (i== SubMenu3DChilds.Length-1)
{
SubMenu3DChilds[i].gameObject.SetActive(true);
SubMenu3DChilds[i].localPosition = new Vector3(-8, 0, 0);
}
else
{
SubMenu3DChilds[i].gameObject.SetActive(false);
}
}
}
GameObject go; //贮存3D菜单
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
Tweener tweener;
Transform fade;
Transform small;
Transform big;
Transform show;
}
PlayManager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using System;
/// <summary>
/// 控制寻路起始点
/// </summary>
public class PlayManager : MonoBehaviour
{
public Transform refPoint; //参考点
private Transform orignPoint;
private Transform startPoint;
DOTweenPath tweenPath;
private void Awake()
{
tweenPath = GetComponent<DOTweenPath>();
// tweenPath.enabled = false;
tweenPath.isClosedPath = true;
tweenPath.DOPause();
startPoint = refPoint.Find("StartPoint");
orignPoint = refPoint.Find("OrignPoint");
transform.position = orignPoint.transform.position;
transform.rotation = orignPoint.transform.rotation;
}
void Start()
{
}
public void ReturnTween()
{
tweenPath.DOPause();
}
public void StartTween()
{
transform.DOLocalRotate(startPoint.localEulerAngles, 2);
transform.DOLocalMove(startPoint.localPosition, 2).SetEase(Ease.Linear).OnComplete(() =>
{
tweenPath.DORestart();
});
}
VisualInteraction
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class VisualInteraction : MonoBehaviour {
public GameObject visualMenu;//可视化交互
public GameObject mainReturnBtn;
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
void Start () {
//订阅发送 监听
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
visualMenu.SetActive(false); //一开始隐藏
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs; //里式转换 父类强转成子类
if (args.sender.name== "CubeUIBtn_Interaction") //互动交互
{
//显示子菜单 和返回键
visualMenu.SetActive(true);
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
GameManager.Instance.ResetScene();
}
if (args.sender.name=="CubeUIBtn_MainReturn")
{
if (GameManager.Instance.currentStateScene== StateScene.VisualInteraction)
{
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
GameManager.Instance.ResetScene();
}
}
}
}
SubMain
SubBuildingTeather
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubBuildingTeather : MonoBehaviour {
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_BuildingTeather")
{
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
if (args.sender.name== "CubeUIBtn_SubReturn")
{
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
}
}
SubButtonPanel
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap.Unity.Interaction;
using System;
public class SubButtonPanel : MonoBehaviour {
private List<UILink> PanelBtns;
public GameObject mainUIButtonBase;
public GameObject subUIButtonBase;
public GameObject subModelUIButtonBase;
public GameObject btn_SubReturn;
private void Awake()
{
PanelBtns =new List<UILink>(transform.GetComponentsInChildren<UILink>(true));
foreach (UILink item in PanelBtns)
{
item.OnTriggerEvent.AddListener(()=>OnBtnTriggered(item));
}
foreach (UILink item in PanelBtns)
{
item.GetComponent<InteractionButton>().OnPress += () => OnPressed(item);
item.GetComponent<InteractionButton>().OnUnpress += () => OnUnPressed(item);
}
}
private void OnBtnTriggered(UILink item)
{
Debug.Log(item.name);
switch (item.name)
{
case "CubeUIBtn_ReturnMainMenu": //点击返回主场景按钮
mainUIButtonBase.SetActive(true);
FindObjectOfType<ButtonPanel>().Show(); //显示主按钮UI动画
subUIButtonBase.SetActive(false);
break;
case "CubeUIBtn_SubReturn": //点击子菜单的返回按钮
subUIButtonBase.SetActive(true);
item.gameObject.SetActive(false);
// Debug.Log(item.name + "点击子菜单返回按钮");
break;
case "CubeUIBtn_BuildingTeather":
subUIButtonBase.SetActive(false);
subModelUIButtonBase.SetActive(true);
break;
default:
btn_SubReturn.SetActive(true);
subUIButtonBase.SetActive(false);
break;
}
}
void Start()
{
HandActionManager.Instance.ShowUI.AddListener(Show);
HandActionManager.Instance.HildeUI.AddListener(Hide);
}
}
SubExplainPlan
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubExplainPlan : MonoBehaviour {
public GameObject[] effs; //特效显示
public GameObject[] txts; //文字说明
[HideInInspector]
public AudioSource audioSource; //声效介绍
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
audioSource = transform.GetComponent<AudioSource>();
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_ExplainPlan") //点击规划按钮
{
audioSource.Play(); //播放语音
ShowEff();//显示特效
ShowTxt();//显示文字说明
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
if (args.sender.name== "CubeUIBtn_SubReturn") //点击返回按钮
{
audioSource.Stop(); //暂停语音
HideEff();
HideTxt();
pinchScale.CanAction = false;
pinchRotate.canAction = false;
pinchTranslate.canAction = false;
HandActionManager.Instance.CanStroke = false;
}
//Debug.Log("子菜单触发建:::"+args.sender.name);
}
/// <summary>
/// 显示特效
/// </summary>
public void ShowEff() {
foreach (var item in effs)
{
item.SetActive(true);
}
}
/// <summary>
/// 隐藏特效
/// </summary>
public void HideEff() {
foreach (var item in effs)
{
item.SetActive(false);
}
}
/// <summary>
/// 显示文字说明
/// </summary>
public void ShowTxt()
{
foreach (var item in txts)
{
item.SetActive(true);
}
}
/// <summary>
/// 隐藏文字说明
/// </summary>
public void HideTxt()
{
foreach (var item in txts)
{
item.SetActive(false);
}
}
}
SubReturnMainMenu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubReturnMainMenu : MonoBehaviour {
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnTriggered);
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
}
private void OnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_ReturnMainMenu") //点击返回主场景的按钮
{
// GameManager.Instance.HideScene(); //隐藏场景
GameManager.Instance.ResetScene();
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
if (args.sender.name== "CubeUIBtn_SubReturn") //点击子菜单的返回按钮
{
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
}
void Update () {
}
}
SubWeather
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
using DG.Tweening;
public class SubWeather : MonoBehaviour {
public int weatherState; //天气状态
public bool canChangeWeather; //是否可以改变天气
public GameObject directLight;//方向光
public Vector3 posDayLight;//方向光旋转白天位置
public Vector3 posNightLight; //方向光黑色位置
private Vector3 posLight; //方向光位置
public GameObject bigRain; //下雨预制体
PinchScale pinchScale;
PinchRotate pinchRotate;
PinchTranslate pinchTranslate;
DayAndNight[] dayAndNight;
DayAndNightStreet01[] dayAndNightStreet01;
DayAndNightStreet02[] dayAndNightStreet02;
DayAndNightStreet03[] dayAndNightStreet03;
public bool isNight;
public GameObject nightLights;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered); //注册事件
HandActionManager.Instance.StrokeInBegin.AddListener(ChangeWeather); //注册事件 改变天气
posDayLight = directLight.transform.localPosition;
posNightLight = new Vector3(-85,-145,-30);
posLight = posDayLight;
pinchScale = FindObjectOfType<PinchScale>();
pinchRotate = FindObjectOfType<PinchRotate>();
pinchTranslate = FindObjectOfType<PinchTranslate>();
dayAndNight = FindObjectsOfType<DayAndNight>();
dayAndNightStreet01 = FindObjectsOfType<DayAndNightStreet01>();
dayAndNightStreet02 = FindObjectsOfType<DayAndNightStreet02>();
dayAndNightStreet03 = FindObjectsOfType<DayAndNightStreet03>();
}
private void OnBtnTriggered(BaseEventArgs obj)
{
//里氏转换
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_Weather") //点击天气按钮
{
canChangeWeather = true;
weatherState = 0;
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = true;
}
if (args.sender.name== "CubeUIBtn_SubReturn") //返回按钮
{
ResetWeather();//重置天气
pinchScale.CanAction = false;
pinchRotate.CanAction = false;
pinchTranslate.CanAction = false;
HandActionManager.Instance.CanStroke = false;
}
}
/// <summary>
/// 天气气象
/// </summary>
public void ChangeWeather() {
if (canChangeWeather)
{
switch (weatherState)
{
case 0:
// posDayLight = new Vector3(48, -388, 108);
// DOTween.To(() => posDayLight, x => posDayLight = x, new Vector3(9.8f, -418f, 57f), 5);
//GameManager.Instance.DayAndNight();
DOTween.To(() => posLight, x => posLight = x,posNightLight, 5);
DayAndNightShow();
break;
case 1:
//posDayLight = new Vector3(9.8f, -418f, 57f);
//DOTween.To(() => posDayLight, x => posDayLight = x, new Vector3(48, -388, 108), 5);
//GameManager.Instance.DayAndNight();
DOTween.To(() => posLight, x => posLight = x, posDayLight, 5);
DayAndNightShow();
break;
case 2:
bigRain.SetActive(true);
break;
default:
bigRain.SetActive(false);
weatherState = -1;
break;
}
weatherState++;
}
}
/// <summary>
/// 重置天气
/// </summary>
public void ResetWeather() {
canChangeWeather = false; //不可以改变天气
posLight = posDayLight;
bigRain.SetActive(false);
isNight = true;
DayAndNightShow();
}
/// <summary>
/// 切换白天黑夜
/// </summary>
public void DayAndNightShow() {
isNight = !isNight;
foreach (var item in dayAndNight)
{
if (isNight)
{
item.Night();
}
else
{
item.Day();
}
}
foreach (var item in dayAndNightStreet01)
{
if (isNight)
{
item.Night();
}
else
{
item.Day();
}
}
foreach (var item in dayAndNightStreet02)
{
if (isNight)
{
item.Night();
}
else
{
item.Day();
}
}
foreach (var item in dayAndNightStreet03)
{
if (isNight)
{
item.Night();
}
else
{
item.Day();
}
}
//控制夜晚灯光显示
if (isNight)
{
nightLights.SetActive(true);
}
else
{
nightLights.SetActive(false);
}
}
void Update () {
directLight.transform.localEulerAngles = posLight; //灯光
}
}
SubModelMenu
DayAndNight
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class DayAndNight : MonoBehaviour {
public Material dayMaterial;
public Material nightMaterial;
public Color dayColor;
public Color nightColor;
void Start () {
dayMaterial = gameObject.GetComponent<MeshRenderer>().materials[0];
nightMaterial = gameObject.GetComponent<MeshRenderer>().materials[1];
dayColor = dayMaterial.color;
nightColor = nightMaterial.color;
}
void Update () {
if (Input.GetMouseButtonDown(0))
{
Night();
}
if (Input.GetMouseButtonDown(1))
{
Day();
}
}
/// <summary>
/// 白天
/// </summary>
public void Day() {
Color tdayColor = dayColor;
tdayColor.a = 1;
dayMaterial.DOColor(tdayColor,6f);
Color tNightColor = nightColor;
tNightColor.a = 0;
nightMaterial.DOColor(tNightColor,3f);
}
/// <summary>
/// 晚上
/// </summary>
public void Night() {
Color tNightColor = nightColor;
tNightColor.a = 1f;
nightMaterial.DOColor(tNightColor, 6f);
Color tdayColor = dayColor;
tdayColor.a = 0;
dayMaterial.DOColor(tdayColor, 3f);
}
public void OnApplicationQuit()
{
gameObject.GetComponent<MeshRenderer>().materials[0] = dayMaterial;
gameObject.GetComponent<MeshRenderer>().materials[1] = nightMaterial;
dayMaterial.color = dayColor;
nightMaterial.color = nightColor;
}
}
SubModel_Air
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubModel_Air : MonoBehaviour {
public GameObject air_Eff;
public Vector3 orginPos;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnTriggered);
}
private void OnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_Air")
{
air_Eff.SetActive(true);
orginPos = transform.position;
transform.position = Vector3.zero;
GameManager.Instance.SetGesturesAction(gameObject);
}
if (args.sender.name== "CubeUIBtn_Yes")
{
if (GameManager.Instance.currentStateModel== StateModel.Air)
{
air_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<SurroundBuilding>().gameObject.transform;
}
}
if (args.sender.name== "CubeUIBtn_No")
{
if (GameManager.Instance.currentStateModel == StateModel.Air)
{
transform.position = orginPos;
air_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<SurroundBuilding>().gameObject.transform;
}
}
}
void Update () {
}
}
SubModel_Boat
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubModel_Boat : MonoBehaviour {
public Vector3 orginPos;
public GameObject boat_Eff;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnTriggered);
}
private void OnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_Boat")
{
orginPos = transform.position;
transform.position = Vector3.zero;
boat_Eff.SetActive(true);
GameManager.Instance.SetGesturesAction(gameObject);
}
if (args.sender.name== "CubeUIBtn_Yes")
{
if (GameManager.Instance.currentStateModel== StateModel.Boat)
{
boat_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<Traffic>().gameObject.transform;
}
}
if (args.sender.name== "CubeUIBtn_No")
{
if (GameManager.Instance.currentStateModel == StateModel.Boat)
{
orginPos = transform.position;
boat_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<Traffic>().gameObject.transform;
}
}
}
}
SubModel_Bridge
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
/// <summary>
/// 脚本挂在建筑物上
/// </summary>
public class SubModel_Bridge : MonoBehaviour {
public Vector3 orginPos;
public GameObject bridge_Eff;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBriggered);
}
private void OnBriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name== "CubeUIBtn_Bridge")
{
orginPos = transform.position;
transform.position = Vector3.zero;
bridge_Eff.SetActive(true);
GameManager.Instance.SetGesturesAction(gameObject);
}
if (args.sender.name== "CubeUIBtn_Yes")
{
if (GameManager.Instance.currentStateModel== StateModel.Bridge)
{
bridge_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<Environment>().gameObject.transform;
}
}
if (args.sender.name== "CubeUIBtn_No")
{
if (GameManager.Instance.currentStateModel == StateModel.Bridge)
{
transform.position = orginPos;
bridge_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<Environment>().gameObject.transform;
}
}
}
}
SubModel_CBD
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubModel_CBD : MonoBehaviour
{
public static SubModel_CBD Instance { get; set; }
public GameObject CBD_Eff; //特效
public Vector3 orginPos; //原始位置
public GameObject[] CBDChilds;
// private Animator ani;
Animation[] anis;
float[] aniLengths;
float playTime;
int index = 0;
public float speed = 1;
Animation mAnimation;
public void Awake()
{
Instance = this;
}
void Start()
{
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnBtnTriggered); //添加按钮触发事件
ShowMainBuilding(); //显示主建筑
anis = GetComponentsInChildren<Animation>();
aniLengths = new float[anis.Length];
//for (int i = 0; i < anis.Length; i++)
//{
// anis[i].enabled = false;
// anis[i].gameObject.SetActive(false);
// aniLengths[i] = anis[i].clip.length;
//}
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_CBD")
{
CBD_Eff.SetActive(true);
orginPos = transform.position;//记录下原始位置
transform.position = Vector3.zero;//旋转作准备
GameManager.Instance.SetGesturesAction(gameObject);
}
if (args.sender.name == "CubeUIBtn_Yes")
{
if (GameManager.Instance.currentStateModel == StateModel.CBD)
{
CBD_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<MainBuilding>().gameObject.transform;
}
}
if (args.sender.name == "CubeUIBtn_No")
{
if (GameManager.Instance.currentStateModel == StateModel.CBD)
{
CBD_Eff.SetActive(false);
transform.position = orginPos; //恢复原始位置
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<MainBuilding>().gameObject.transform;
}
}
}
/// <summary>
/// 正向播放动画
/// </summary>
/// <returns></returns>
public void PlayForeward()
{
for (int i = 0; i < anis.Length; i++)
{
anis[i].enabled = false;
anis[i].gameObject.SetActive(false);
aniLengths[i] = anis[i].clip.length;
}
if (mAnimation != null)
{
mAnimation.Stop();
}
StopCoroutine("Play");
//StopCoroutine(Play(true));
StartCoroutine("Play", true);
}
/// <summary>
/// 反向动画
/// </summary>
/// <returns></returns>
public void PlayBack()
{
if (mAnimation != null)
{
mAnimation.Stop();
}
// CBDChilds[CBDChilds.Length - 1].transform.GetComponent<AnimationCotroller>().BackPlay();
StopCoroutine("Play");
//StopCoroutine(Play(true));
StartCoroutine("Play", false);
}
/// <summary>
/// 显示主建筑 去掉动画
/// </summary>
public void ShowMainBuilding()
{
if (mAnimation!=null)
{
mAnimation.Stop();
}
StopCoroutine("Play"); //停止动画播放
for (int i = 0; i < CBDChilds.Length; i++)
{
CBDChilds[i].SetActive(true);
}
}
/// <summary>
/// 隐藏主建筑 动画为true
/// </summary>
public void HideMainBuilding()
{
if (mAnimation != null)
{
mAnimation.Stop();
}
StopCoroutine("Play"); //停止动画播放
for (int i = 0; i < CBDChilds.Length; i++)
{
CBDChilds[i].SetActive(false);
}
}
/// <summary>
/// 重置主建筑 动画为flase
/// </summary>
public void ResetMainBuilding()
{
if (mAnimation != null)
{
mAnimation.Stop();
}
StopCoroutine("Play"); //停止动画播放
//StopCoroutine(Play(true));
for (int i = 0; i < CBDChilds.Length; i++)
{
CBDChilds[i].SetActive(true);
}
}
/// <summary>
/// 播放动画
/// </summary>
/// <param name="forward"></param>
/// <returns></returns>
IEnumerator Play(bool forward)
{
bool first = true;
if (forward)
{
index = 0; //向前重置为0
Debug.Log("forward:" + forward);
//float speed = 10; //播放动画的速度
for (int i = index; i < anis.Length; i++)
{
mAnimation = anis[i];
mAnimation.enabled = true;
mAnimation[mAnimation.gameObject.name].speed = speed;
mAnimation.gameObject.SetActive(true);
if (first)
{
first = !first;
}
else
{
//a[a.gameObject.name].time = a[a.gameObject.name].length;
}
mAnimation.Play();
yield return new WaitForSeconds(mAnimation.clip.length / speed);
index++;
}
}
else
{
float speed = -1;
index = index >= anis.Length ? anis.Length - 1 : index;
first = false;
for (int j = index; j >= 0; j--)
{
// Animation a = anis[j];
mAnimation = anis[j];
mAnimation.enabled = true;
mAnimation[mAnimation.gameObject.name].speed = speed;
mAnimation.gameObject.SetActive(true);
if (first)
{
first = !first;
}
else
{
mAnimation[mAnimation.gameObject.name].time = mAnimation[mAnimation.gameObject.name].length;
}
mAnimation.Play();
yield return new WaitForSeconds(mAnimation.clip.length);
index--;
}
}
}
float GetTime()
{
float t = Time.time - playTime;
return t;
}
}
SubModel_Market
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class SubModel_Market : MonoBehaviour
{
public GameObject market_Eff;
public Vector3 orginPos;
void Start()
{
EventEntity.AddListener(UIEvent.OnBtnTrigger, OnTriggered);
}
private void OnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (args.sender.name == "CubeUIBtn_Market")
{
market_Eff.SetActive(true);
orginPos = transform.position;
transform.position = Vector3.zero;
GameManager.Instance.SetGesturesAction(gameObject);
}
if (args.sender.name == "CubeUIBtn_Yes")
{
if (GameManager.Instance.currentStateModel == StateModel.Market)
{
market_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<SurroundBuilding>().gameObject.transform;
}
}
if (args.sender.name == "CubeUIBtn_No")
{
if (GameManager.Instance.currentStateModel == StateModel.Market)
{
transform.position = orginPos;
market_Eff.SetActive(false);
GameManager.Instance.ResetGesturesAction();
gameObject.transform.parent = FindObjectOfType<SurroundBuilding>().gameObject.transform;
}
}
}
}
SubModelButtonPanel
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap.Unity.Interaction;
using System;
public class SubModelButtonPanel : MonoBehaviour {
private List<UILink> PanelBtns;
public GameObject subMenuUIButtonBase;
public GameObject subModelUIButtonBase;
public GameObject btn_SubModelConfirm;
private void Awake()
{
// animator =transform.Find("UI Button Base").GetComponent<Animator>();
PanelBtns =new List<UILink>(transform.GetComponentsInChildren<UILink>(true));
foreach (UILink item in PanelBtns)
{
item.OnTriggerEvent.AddListener(()=>OnBtnTriggered(item));
}
foreach (UILink item in PanelBtns)
{
item.GetComponent<InteractionButton>().OnPress += () => OnPressed(item);
item.GetComponent<InteractionButton>().OnUnpress += () => OnUnPressed(item);
}
}
private void OnBtnTriggered(UILink item)
{
Debug.Log(item.name);
switch (item.name)
{
case "CubeUIBtn_Yes": //点击确定键
btn_SubModelConfirm.SetActive(false);
subModelUIButtonBase.SetActive(true);
break;
case "CubeUIBtn_No": //点击取消键
btn_SubModelConfirm.SetActive(false);
subMenuUIButtonBase.SetActive(true);
break;
case "CubeUIBtn_ReturnSubMenu": //点击返回子菜单按钮
subModelUIButtonBase.SetActive(false);
subMenuUIButtonBase.SetActive(true);
break;
default:
btn_SubModelConfirm.SetActive(true);
subModelUIButtonBase.SetActive(false);
break;
}
}
}
private void Show()
{
//if (animator&&animator.gameObject.activeSelf)
//{
// animator.SetBool("Show",true);
//}
// Debug.Log("播放动画");
}
void Start()
{
HandActionManager.Instance.ShowUI.AddListener(Show);
HandActionManager.Instance.HildeUI.AddListener(Hide);
}
void Update () {
}
}
UI
IndependentCtrlAni
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWork.Event;
using System;
public class IndependentCtrlAni : MonoBehaviour {
public string menuName;
void Start () {
EventEntity.AddListener(UIEvent.OnBtnTrigger,OnBtnTriggered);
}
private void OnBtnTriggered(BaseEventArgs obj)
{
UIEventArgs args = obj as UIEventArgs;
if (GameManager.Instance.currentStateScene== StateScene.PlanShow)
{
if (args.sender.name== "CubeUIBtn_PlayForeward")
{
switch (menuName)
{
case "MainBuilding":
FindObjectOfType<SubModel_CBD>().PlayForeward();
break;
case "SurroundBuilding":
FindObjectOfType<SurroundBuilding>().SurroundGrowUp();
break;
case "Environment":
FindObjectOfType<Environment>().ShowEnviron();
break;
case "Traffic":
FindObjectOfType<Traffic>().TrafficForeward();
break;
default:
break;
}
}
else if (args.sender.name == "CubeUIBtn_PlayBack")
{
switch (menuName)
{
case "MainBuilding":
FindObjectOfType<SubModel_CBD>().PlayBack();
break;
case "SurroundBuilding":
FindObjectOfType<SurroundBuilding>().ReverseSurroundBuilding();
break;
case "Environment":
FindObjectOfType<Environment>().ReverseEnviron();
break;
case "Traffic":
FindObjectOfType<Traffic>().TrafficBack();
break;
default:
break;
}
}
}
}
}