赞
踩
-
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG.Tweening;
- using Tx3d.Framework;
- using DG.Tweening.Plugins.Options;
- using DG.Tweening.Core;
- using DG.Tweening.Plugins.Core.PathCore;
-
- namespace SimpleUIFrame
- {
- public class PlaybackRoamingControl : MonoBehaviour
- {
- #region 成员属性&变量
-
- //主摄像机
- private Camera mainCamera;
-
- //DOTweenPath组件
- private DOTweenPath doTweenPath;
-
- //暂停和播放按钮
- public Button playOrPauseBut;
-
- //复制的节点数组
- Vector3[] waypoints = new[] { new Vector3(-3.8f, 3f, 213.1f), new Vector3(-11f, 3f, 185.01f), new Vector3(-20f, 3f, 153.01f), new Vector3(-78f, 3f, 141.01f), new Vector3(-81f, 3f, 82.60999f), new Vector3(-64.8f, 3f, 49.71f), new Vector3(-66f, 3f, -116.99f), new Vector3(-47f, 3f, -161.99f), new Vector3(49f, 3f, -161.99f), new Vector3(67f, 3f, -117.99f), new Vector3(64f, 3f, 49.00999f), new Vector3(78.8f, 3f, 85.60999f), new Vector3(80f, 3f, 147.01f), new Vector3(79f, 3f, 199.01f), new Vector3(62f, 3f, 211.01f) };
-
- //进度条暂停播放判断
- private bool timeStop;
-
- //进度条
- public Slider slider;
-
- //速度
- private float speed = 1;
-
- //跳转阶段按钮
- public Button _TiaoZ0;
- public Button _TiaoZ1;
- public Button _TiaoZ2;
-
- //TweenerCore 插件中路径移动的变量
- TweenerCore<Vector3, Path, PathOptions> _TC_Path;
-
- //进行时间 总时间
- public Text proceed_Time, total_Ttime;
-
- //总的时间设置
- public float duration = 30;
-
- //执行播放的动画
- public Animator animationGo;
-
- //数组下标第几个执行方法
- private int subscript = 8;
-
- //移动中执行等待时间
- private float moveAwaitSpeed=2;
-
- #endregion
-
- #region MonoBehaviour方法
-
- void Start()
- {
-
- //获取到主摄像机
- mainCamera = CameraControllerManager.Instance.MainCamera;
-
- //跳转节点add方法
- _TiaoZ0.onClick.AddListener(delegate { TiaoZhuan(0); });
- _TiaoZ1.onClick.AddListener(delegate { TiaoZhuan(1); });
- _TiaoZ2.onClick.AddListener(delegate { TiaoZhuan(2); });
-
- //获取到主摄像机的DOTweenPath组件
- doTweenPath = mainCamera.GetComponent<DOTweenPath>();
-
- //按钮方法
- playOrPauseBut.onClick.AddListener(DoPlayOrPause_AutoMoveCamera);
-
- //变量赋值
- _TC_Path = transform.GetComponent<Rigidbody>().DOPath(waypoints, duration, PathType.CatmullRom, PathMode.Full3D, 10, null).SetAutoKill(true);
-
- //速度值
- _TC_Path.timeScale = 0.1f;
-
- //获取总执行的时间
- if (total_Ttime != null)
- total_Ttime.text = duration.ToString();
- }
-
- private void Update()
- {
- //进度条
- if (!timeStop)
- {
- //获取进度条0-1
- if (slider != null)
- slider.value = _TC_Path.ElapsedDirectionalPercentage();
-
- //获取已播放多长时间
- if (proceed_Time != null)
- proceed_Time.text = _TC_Path.Elapsed().ToString();
-
- //当数值大于0.96的时候直接等于
- if (_TC_Path.ElapsedDirectionalPercentage() >= 0.96)
- {
- slider.value = 1;
- //获取已播放多长时间
- proceed_Time.text = duration.ToString();
- timeStop = true;
- }
- }
-
- //根据节点下标执行
- _TC_Path.OnWaypointChange((index) =>
- {
- index++;
-
- //当下标到达之后执行方法
- if (index == subscript)
- StartCoroutine(IntervalTime(moveAwaitSpeed));
- });
- }
-
- #endregion
-
- #region 公有方法
-
- /// <summary>
- /// 跳转节点方法 0是前面 1是中间 2是后面
- /// </summary>
- /// <param name="nums"></param>
- public void TiaoZhuan(int nums)
- {
- if (!timeStop)
- {
- switch (nums)
- {
- case 0:
- _TC_Path.Goto(duration * 0.2f, true);
- Debug.Log(duration * 0.2f + ":" + duration);
- break;
- case 1:
- _TC_Path.Goto(duration * 0.5f, true);
- Debug.Log(duration * 0.5f + ":" + duration);
- break;
- case 2:
- _TC_Path.Goto(duration * 0.8f, true);
- Debug.Log(duration * 0.8f + ":" + duration);
- break;
- }
- }
- }
-
- /// <summary>
- /// 快进
- /// </summary>
- public void SpeedK()
- {
- _TC_Path.timeScale = 1f;
- speed = 10f;
- }
-
- /// <summary>
- /// 减速
- /// </summary>
- public void ExitK()
- {
- // speedkauijin--;
- _TC_Path.timeScale = 0.1f;
- speed = 1f;
- }
-
-
- /// <summary>
- /// 时间间隔停止等待
- /// </summary>
- /// <returns></returns>
- public IEnumerator IntervalTime(float moveAwait)
- {
- //停止等待几秒后执行
- if (animationGo != null)
- animationGo.SetBool("isOn", true);
- float ol = _TC_Path.timeScale;
- _TC_Path.timeScale = 0.0001f;
- yield return new WaitForSeconds(moveAwait);
- _TC_Path.timeScale = ol;
- if (animationGo != null)
- animationGo.SetBool("isOn", false);
- }
-
- /// <summary>
- /// 控制主摄像机的暂停
- /// </summary>
- public void DoPause_AutoMoveCamera()
- {
- if (doTweenPath != null)
- {
- doTweenPath.DOPause();
- }
- }
-
- /// <summary>
- /// 控制主摄像机的移动与暂停
- /// </summary>
- public void DoPlayOrPause_AutoMoveCamera()
- {
- if (!timeStop)
- {
- _TC_Path.Pause();
- timeStop = !timeStop;
- }
- else
- {
- _TC_Path.Play();
- timeStop = !timeStop;
- }
- }
-
- #endregion
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。