Unity回放系统

作者: 游戏开发小Y | 来源:发表于2017-01-19 10:32 被阅读29次

    前言

    用了一些视屏录制插件,不过文件读比较大,后来改成记录事件状态,文件就比较小了,在使用Probuff来传输数据,回放的时候就不会有卡顿。

    ReTenderPlay.cs

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.Serialization.Formatters.Binary;
    using GGTPlugin;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.EventSystems;
    using Google.Protobuf;
    using Tenders.Protobuf;
    
    /// <summary>
    /// 回放
    /// </summary>
    public class ReTenderPlay : MonoBehaviour
    {
    
        public List<GameObject> ReparenetGameObjects;
        public List<GameObject> RePlayGameObjects;
    
        public List<GameObject> putlab;
    
        //    public Hashtable ht;
        //    public Hashtable ht1;
        //    public Hashtable reht;
        //    public Hashtable reht1;
        //    public int maxFrame;
        //    public int reMaxFrame;
        public DateTime date;
        public DateTime reDate;
        public string SGYQ;
        public string filepath;
        public static ReTenderPlay instance;
        public float time;
        public int step;
        public bool flag = false;
        public bool putflag;
        public ShowTianqi st;
        public ReTenderplayWnd rw;
        public Image zhezhao;
        public ReTenderplayData Hd = new ReTenderplayData();                      //记录回放数据
        public ReTenderplayData rd = new ReTenderplayData();                      //加载回放数据
    
        public bool flag_cun = false;
        public int zengliang;                           //每一个回放的郑亮
        public int ZhenSum;                             //每一个回放的总帧数
        public int CurrentmaxZhen;                      //播放开始帧数
        public static ReTenderPlay _instance;
        void Awake()
        {
            _instance = this;
        }
        public void Start()
        {
            instance = this;
    
            // ht = new Hashtable();
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<Scrollbar>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
            }
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<Dropdown>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
            }
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<Button>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
                VARIABLE1.gameObject.AddComponent<TenderClickTrigger>();
            }
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<InputField>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
            }
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<Slider>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
                VARIABLE1.gameObject.AddComponent<TenderClickTrigger>();
            }
            foreach (var VARIABLE1 in ReparenetGameObjects.SelectMany(VARIABLE => VARIABLE.GetComponentsInChildren<Toggle>(true)))
            {
                RePlayGameObjects.Add(VARIABLE1.gameObject);
                VARIABLE1.gameObject.AddComponent<TenderClickTrigger>();
            }
            //RePlayGameObjects.Add(st.gameObject);
    
        }
    
        //  void FixedUpdate()
        //  {
        ////        ZhenSum++;
        ////        if(flag)
        ////        {
        ////            Play();
        ////        }
        //  }
        void Update()
        {
            ZhenSum++;
            if (flag)
            {
    
                Play();
            }
        }
        //执行回放
        public void Play()
        {
            rw.Play();
            foreach (var VARIABLE in rd.Ht.Keys)
            {
    
                if (Time.frameCount == CurrentmaxZhen + Int32.Parse(VARIABLE.ToString().Substring(0, VARIABLE.ToString().IndexOf("_"))))
                {
                    //根据Id找到物体
                    string o = (string)rd.Ht[VARIABLE];
                    string buttonid = null;
                    string sliderid = null;
                    string sliderNum = null;
                    string inputId = null;
                    string inputValue = null;
                    string toggleID = null;
                    bool togglevalue = false;
                    string Scrollbarid = null;
                    float ScrollbarValue = 0;
                    string DropDownid = null;
                    int DropDownValue = 0;
    
                    for (int j = 0; j < DoSplit(o).Length; j++)
                    {
                        if (DoSplit(o)[j].Contains("[s]"))
                        {
                            sliderid = DoSplit(o)[j].Replace("[s]", "");
                        }
                        if (DoSplit(o)[j].Contains("[b]"))
                        {
                            buttonid = DoSplit(o)[j].Replace("[b]", "");
                        }
                        if (DoSplit(o)[j].Contains("[t]"))
                        {
                            toggleID = DoSplit(o)[j].Replace("[t]", "");
                        }
                        if (DoSplit(o)[j].Contains("[tv]"))
                        {
                            togglevalue = bool.Parse(DoSplit(o)[j].Replace("[tv]", ""));
                        }
                        if (DoSplit(o)[j].Contains("[v]"))
                        {
                            sliderNum = DoSplit(o)[j].Replace("[v]", "");
                        }
                        if (DoSplit(o)[j].Contains("[i]"))
                        {
                            inputId = DoSplit(o)[j].Replace("[i]", "");
                        }
                        if (DoSplit(o)[j].Contains("[n]"))
                        {
                            inputValue = DoSplit(o)[j].Replace("[n]", "");
                        }
                        if (DoSplit(o)[j].Contains("[SV]"))
                        {
                            ScrollbarValue = float.Parse(DoSplit(o)[j].Replace("[SV]", ""));
                        }
                        if (DoSplit(o)[j].Contains("[SC]"))
                        {
                            Scrollbarid = DoSplit(o)[j].Replace("[SC]", "");
                        }
                        if (DoSplit(o)[j].Contains("[DV]"))
                        {
                            DropDownValue = int.Parse(DoSplit(o)[j].Replace("[DV]", ""));
                        }
                        if (DoSplit(o)[j].Contains("[DC]"))
                        {
                            DropDownid = DoSplit(o)[j].Replace("[DC]", "");
                        }
                        //记录鼠标
                        foreach (var VARIABLE1 in RePlayGameObjects)
                        {
                            //按钮
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == (Convert.ToInt32(buttonid)))
                            {
                                if (VARIABLE1.GetComponent<Button>() != null)
                                {
                                    VARIABLE1.GetComponent<Button>().onClick.Invoke();
                                }
                            }
                            //toggle
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == Convert.ToInt32(toggleID))
                            {
                                if (VARIABLE1.GetComponent<Toggle>() != null)
                                {
                                    VARIABLE1.GetComponent<Toggle>().isOn = togglevalue;
                                    try
                                    {
                                        RYDownShow._instance.updateData();
                                    }
                                    catch (Exception ex)
                                    {
    
                                    }
    
    
                                }
                            }
                            //滑动
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == Convert.ToInt32(sliderid))
                            {
                                if (VARIABLE1.GetComponent<Slider>() != null)
                                {
                                    VARIABLE1.GetComponent<Slider>().value = Convert.ToInt32(sliderNum);
                                }
                            }
                            //滚动条
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == Convert.ToInt32(Scrollbarid))
                            {
                                if (VARIABLE1.GetComponent<Scrollbar>() != null)
                                {
                                    VARIABLE1.GetComponent<Scrollbar>().value = ScrollbarValue;
                                    VARIABLE1.GetComponent<Scrollbar>().onValueChanged.Invoke(-1);
                                }
                            }
                            //下拉列表
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == Convert.ToInt32(DropDownid))
                            {
                                if (VARIABLE1.GetComponent<Dropdown>() != null)
                                {
                                    VARIABLE1.GetComponent<Dropdown>().value = DropDownValue;
                                }
                            }
                            //输入
                            if (VARIABLE1.GetComponent<Tender_GUID>().ID == Convert.ToInt32(inputId))
                            {
                                if (VARIABLE1.GetComponent<InputField>() != null)
                                {
                                    VARIABLE1.GetComponent<InputField>().text = Convert.ToString(inputValue);
                                    VARIABLE1.GetComponent<InputField>().onEndEdit.Invoke("CheckZZS");
                                    VARIABLE1.GetComponent<InputField>().onEndEdit.Invoke("WeightComper");
                                    VARIABLE1.GetComponent<InputField>().onEndEdit.Invoke("updateData");
                                }
                            }
    
                        }
                        //                  if (o.Contains("[w]"))
                        //                  {
                        //                      var str = o.Replace("[w]", "");
                        //                      st.a = Convert.ToInt32(DoSplit1(str)[0]);
                        //                      st.b = Convert.ToInt32(DoSplit1(str)[1]);
                        //                      st.i = Convert.ToInt32(DoSplit1(str)[2]);
                        //                      st.j = Convert.ToInt32(DoSplit1(str)[3]);
                        //                      st.m = Convert.ToInt32(DoSplit1(str)[4]);
                        //                      st.n = Convert.ToInt32(DoSplit1(str)[5]);
                        //                  }
                    }
                    //记录摄像机的移动
                    if (o.Contains("[p]"))
                    {
                        int li_index = 0;
                        int last_index = o.LastIndexOf("|");
                        string str = o.Substring(0, last_index);
                        str = str.Replace("[p]", "").Replace("(", "").Replace(")", "");
                        Camera.main.transform.localPosition = new Vector3(Convert.ToSingle(DoSplit1(str)[0]), Convert.ToSingle(DoSplit1(str)[1]), Convert.ToSingle(DoSplit1(str)[2]));
    
                        string str1 = o.Substring(last_index + 1);
                        str1 = str1.Replace("[r]", "").Replace("(", "").Replace(")", "");
                        Camera.main.transform.localRotation = Quaternion.Euler(Convert.ToSingle(DoSplit1(str1)[0]), Convert.ToSingle(DoSplit1(str1)[1]), Convert.ToSingle(DoSplit1(str1)[2]));
                        //putflag = true;
                    }
                    //记录点击单塔
                    if (o.Contains("[ST]"))
                    {
                        int li_index = 0;
                        int last_index = o.LastIndexOf("|");
                        string str = o.Substring(0, last_index);
                        str = str.Replace("[ST]", "").Replace("(", "").Replace(")", "");
                        RunScript._instance.taPrefab.transform.localPosition = new Vector3(Convert.ToSingle(DoSplit1(str)[0]), Convert.ToSingle(DoSplit1(str)[1]), Convert.ToSingle(DoSplit1(str)[2]));
    
                        string str1 = o.Substring(last_index + 1);
                        str1 = str1.Replace("[Sr]", "").Replace("(", "").Replace(")", "");
                        RunScript._instance.taPrefab.transform.transform.localRotation = Quaternion.Euler(Convert.ToSingle(DoSplit1(str1)[0]), Convert.ToSingle(DoSplit1(str1)[1]), Convert.ToSingle(DoSplit1(str1)[2]));
                        UIControl._instance.ShowTowerMiddle();
                    }
                    //记录批量设置塔型
                    if (o.Contains("[PT]"))
                    {
                        int li_index = 0;
                        int last_index = o.LastIndexOf("|");
                        string str = o.Substring(0, last_index);
                        str = str.Replace("[PT]", "").Replace("(", "").Replace(")", "");
                        string str1 = o.Substring(last_index + 1);
                        str1 = str1.Replace("[S]", "").Replace("(", "").Replace(")", "");
                        if (str1 == "1")
                        {
                            RunScript._instance.PlTiShi.transform.FindChild("Text").GetComponent<Text>().text = "请点击选择截止点";
                            RunScript._instance.PLFirstTaPrefab = new Vector3(Convert.ToSingle(DoSplit1(str)[0]), Convert.ToSingle(DoSplit1(str)[1]), Convert.ToSingle(DoSplit1(str)[2]));
                        }
                        else if (str1 == "2")
                        {
                            RunScript._instance.PlTiShi.SetActive(false);
                            RunScript._instance.PlTiShi.transform.FindChild("Text").GetComponent<Text>().text = "请点击选择起始点";
                            RunScript._instance.PLSencondPrefab = new Vector3(Convert.ToSingle(DoSplit1(str)[0]), Convert.ToSingle(DoSplit1(str)[1]), Convert.ToSingle(DoSplit1(str)[2]));
                            UIControl._instance.PLShowTowerMiddle();
                        }
    
                    }
                    //点击塔型出现杆塔配置
                    if (o.Contains("[D]"))
                    {
    
                        int li_index = 0;
                        int last_index = o.LastIndexOf("|");
                        string str = o.Substring(0, last_index);
                        str = str.Replace("[D]", "").Replace("(", "").Replace(")", "");
                        UIControl._instance.TowerClickCheck(int.Parse(str));
                    }
                }
            }
        }
    
        public string[] DoSplit(string str)
        {
            string[] sarray = str.Split(Convert.ToChar("|"));
            return sarray;
        }
    
        public string[] DoSplit1(string str)
        {
            string[] sarray = str.Split(Convert.ToChar(","));
            return sarray;
        }
    
        public void isRepalay()
        {
            //flag = true;
        }
    
    
        //    #region 保存到文件
        //
        //    public void SerializeObject(string filename)
        //    {
        //        FileStream fs = new FileStream(filename, FileMode.Create);
        //        BinaryFormatter serialize = new BinaryFormatter();
        //        serialize.Serialize(fs, ht);
        //        serialize.Serialize(fs, maxFrame);
        //        serialize.Serialize(fs, date);
        //        fs.Close();
        //    }
        //
        //    #endregion
        //    public void reDeSerialize(string filename)
        //    {
        //        BinaryFormatter serialize = new BinaryFormatter();
        //        FileStream fs = new FileStream(filename, FileMode.Open);
        //        reht = (Hashtable)serialize.Deserialize(fs);
        //        reMaxFrame = (int)serialize.Deserialize(fs);
        //        Debug.Log(reMaxFrame.ToString());
        //        //时间
        //        reDate = (DateTime)serialize.Deserialize(fs);
        //        Debug.Log(reDate.ToString());
        //        fs.Close();
        //    }
        //  private void OnGUI()
        //  {
        //          if (GUI.Button(new Rect(100, 100, 30, 30), "保存"))
        //          {
        //              maxFrame = Time.frameCount;
        //              Debug.Log("CUN");
        //              SerializeObject(Application.dataPath+"//Savedata.dat");
        //              //SaveToNet();
        //          }
        //      if (GUI.Button(new Rect(150, 100, 30,30 ), "回放"))
        //      {
        //          reDeSerialize(Application.dataPath+"//Savedata.dat");
        //          flag=true;
        //      }
        //
        //  }
    
    }
    

    TenderClickTrigger.cs

    using System;
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using UnityEngine.EventSystems;
    using UnityEngine.UI;
    
    public class TenderClickTrigger : MonoBehaviour, IPointerClickHandler, IPointerUpHandler
    {
    
        void Update()
        {
    
        }
    
        public void OnPointerClick(PointerEventData eventData)
        {
            if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false)
            {
                //某些button不需要触发点击事件
                if (gameObject.GetComponent<Button>())
                {
                    
                    switch (gameObject.name)
                    {
                    case "MoNi_DW":
                        break;
                    case "MoNi_Reset":
                        break;
                    case "YL_Reset":
                        break;
                    case "YL_SubmitData":
                        break;
                    case "YL_Cancel":
                        break;
                    default:
                        ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum+"_" + ReTenderPlay.instance.zengliang++, "[b]" + gameObject.GetComponent<Tender_GUID>().ID);
                    
                        break;
                    }
                }
                if (gameObject.GetComponent<Slider>())
                {
    
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[s]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[v]" + (int)gameObject.GetComponent<Slider>().value);
    
    
    
                }
                if (gameObject.GetComponent<Scrollbar>())
                {
    
                    //Debug.Log("@#@#"+gameObject.GetComponent<Scrollbar>().value+"#@#$#$"+(float)gameObject.GetComponent<Scrollbar>().value);
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[S]" + gameObject.GetComponent<Tender_GUID>().ID+ "|" + "[V]" + (float)gameObject.GetComponent<Scrollbar>().value);
    
    
    
                }
                if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false&&UIControl._instance.isToogleType)
                {
                    if (gameObject.GetComponent<Toggle>())
                    {
                        ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[t]" + gameObject.GetComponent<Tender_GUID>().ID+ "|" + "[tv]" + (bool)gameObject.GetComponent<Toggle>().isOn);
    
    
    
                    }
                }
            
            }
    
    
        }
    
        public void OnPointerUp(PointerEventData eventData)
        {
            if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false)
            {
            if (gameObject.GetComponent<Slider>())
            {
    
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[s]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[v]" + (int)gameObject.GetComponent<Slider>().value);
    
    
    
            }
            if (gameObject.GetComponent<Scrollbar>())
            {
    
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay.instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[S]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[V]" + (float)gameObject.GetComponent<Scrollbar>().value);
    
    
    
            }
            }
        }
    }
    
    

    cameraFlyYJJ.cs

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.EventSystems;
    
    public class cameraFlyYJJ : MonoBehaviour
    {
    
        enum Axes { MouseXandY, MouseX, MouseY }
        Axes Axis = Axes.MouseXandY;
        [Tooltip("摄像机旋转速度")]
        public float sensitivityX = 15.0f;               //旋转速度
        public float sensitivityY = 15.0f;
    
        float minimumX = -360.0f;
        float maximumX = 360.0f;
    
        float minimumY = -150.0f;
        float maximumY = 60.0f;
        public float rotationX = 0.0f;
        public float rotationY = 0.0f;
    
        float traY = 0.0f;
        float traX = 0.0f;
    
        [Tooltip("中键移动速度")]
        public float speed = 200.0f;
        //public float traXSpeed = 250.0f;               //按中建之后摄像机的移动速度
        //public float traYSpeed = 100.0f;               //按中建之后摄像机的移动速度
    
        [Tooltip("方向键速度")]
        public float tXSpeed = 1.0f;                   //方向键速度
        public float tZSpeed = 1.0f;
    
        public GameObject cameraReference;
        [HideInInspector]
        public TerrainData td;
        [HideInInspector]
        public Terrain ter;
        Vector3 Pos;
        public static cameraFlyYJJ _insance;
        void Awake()
        {
            _insance = this;
        }
        void Update()
        {
            if (UIControl._instance.IsPlayBack && ReTenderPlay._instance.flag == false)
            {
                //当摄像机的坐标和旋转发生改变时记录
                if (cameraReference.transform.localPosition != Pos)
                {
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[p]" + cameraReference.transform.localPosition.ToString()
                        + "|" + "[r]" + cameraReference.transform.localEulerAngles);
                    Pos = cameraReference.transform.localPosition;
                }
            }
    
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
    
            traY = 0.0f;
            traX = 0.0f;
            if (Input.GetAxis("Mouse ScrollWheel") != 0)
            {
                float distance;
                distance = Input.GetAxis("Mouse ScrollWheel") * speed;
                float height = TerrainControl._instance.TaVector3(cameraReference.transform.localPosition);
                Pos = cameraReference.transform.localPosition;
                if (Pos.y <= height + 40)
                {
                    if (distance < 0)
                    {
                        cameraReference.transform.localPosition += cameraReference.transform.localRotation * new Vector3(0, 0, distance * 0.5f);
                    }
                }
                else
                {
                    cameraReference.transform.localPosition += cameraReference.transform.localRotation * new Vector3(0, 0, distance * 0.5f);
                }
            }
            if (Input.GetMouseButton(1))
            {
                if (UIControl._instance.CameraRig != null)
                {
                    UIControl._instance.CameraRig.isKinematic = false;
                }
                float translationZ = Input.GetAxis("Vertical");
                cameraReference.transform.localPosition += cameraReference.transform.localRotation * new Vector3(0, 0, translationZ * 0.5f * tZSpeed);
                float translationX = Input.GetAxis("Horizontal");
                cameraReference.transform.localPosition += cameraReference.transform.localRotation * new Vector3(translationX * 0.5f * tXSpeed, 0, 0);
                if (UIControl._instance.IsPlayBack && ReTenderPlay._instance.flag == false)
                {
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[p]" + cameraReference.transform.localPosition.ToString()
                    + "|" + "[r]" + cameraReference.transform.localEulerAngles);
                }
            }
            if (Input.GetMouseButton(1))
            {
                if (Axis == Axes.MouseXandY)
                {
    
                    rotationX += Input.GetAxis("Mouse X") * sensitivityX;
                    rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    
                    Adjust360andClamp();
    
                    KeyLookAround();
    
                    KeyLookUp();
                }
                else if (Axis == Axes.MouseX)
                {
                    rotationX += Input.GetAxis("Mouse X") * sensitivityX;
    
                    Adjust360andClamp();
    
                    KeyLookAround();
    
                    KeyLookUp();
                }
                else
                {
                    rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    
                    Adjust360andClamp();
    
                    KeyLookAround();
    
                    KeyLookUp();
                }
                if (UIControl._instance.IsPlayBack && ReTenderPlay._instance.flag == false)
                {
                    ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[p]" + cameraReference.transform.localPosition.ToString()
                    + "|" + "[r]" + cameraReference.transform.localEulerAngles);
                }
            }
            if (td != null)
            {
    
                float h = ter.SampleHeight(transform.position) + 1.8f;
                if (transform.position.y < h)
                {
                    transform.position = new Vector3(transform.position.x, h, transform.position.z);
                }
            }
        }
    
        void KeyLookAround()
        {
            Adjust360andClamp();
    
            transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
        }
    
        void KeyLookUp()
        {
            Adjust360andClamp();
    
            transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
        }
    
        void Adjust360andClamp()
        {
    
            if (rotationX < -360)
            {
                rotationX += 360;
            }
            else if (rotationX > 360)
            {
                rotationX -= 360;
            }
    
            if (rotationY < -360)
            {
                rotationY += 360;
            }
            else if (rotationY > 360)
            {
                rotationY -= 360;
            }
    
            rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
            rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
        }
    
        void Start()
        {
            Time.timeScale = 1.0f;
    
            if (GetComponent<Rigidbody>())
            {
                GetComponent<Rigidbody>().freezeRotation = true;
            }
            if (ter != null)
            {
                td = ter.terrainData;
            }
        }
    }
    

    TenderInputAdlistener.cd

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    public class TenderInputAdlistener : MonoBehaviour {
    
        void Start()
        {
            if(gameObject.GetComponent<InputField>()!=null)
            {
                gameObject.GetComponent<InputField>().onEndEdit.AddListener(delegate
                    {
                        if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false)
                        {
                            ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[i]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[n]" + gameObject.GetComponent<InputField>().text);
                        //Debug.Log("InputField="+ gameObject.GetInstanceID().ToString());
    
                        }
                    });
            }
        
            if(gameObject.GetComponent<Scrollbar>()!=null)
            {
                gameObject.GetComponent<Scrollbar>().onValueChanged.AddListener(delegate
                    {
                        if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false)
                        {
                            ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[SC]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[SV]" + (float) gameObject.GetComponent<Scrollbar>().value);
    
                        //Debug.Log("Scrollbar="+ gameObject.GetComponent<Scrollbar>().value.ToString());
    
                        }
                    });
            }
            if(gameObject.GetComponent<Dropdown>()!=null)
            {
                gameObject.GetComponent<Dropdown>().onValueChanged.AddListener(delegate
                    {
                        if(UIControl._instance.IsPlayBack&&ReTenderPlay._instance.flag==false)
                        {
                            ReTenderPlay.instance.Hd.Ht.Add(ReTenderPlay._instance.ZhenSum + "_" + ReTenderPlay.instance.zengliang++, "[DC]" + gameObject.GetComponent<Tender_GUID>().ID + "|" + "[DV]" + (int) gameObject.GetComponent<Dropdown>().value);
                            Debug.Log("Dropdown  =  "+gameObject.GetComponent<Dropdown>().value.ToString());
                            //Debug.Log("Scrollbar="+ gameObject.GetComponent<Scrollbar>().value.ToString());
    
                        }
                    });
            }
        }
    }
    
    

    proto生成:链接:http://pan.baidu.com/s/1slnP5Pr 密码:a56f

    相关文章

      网友评论

        本文标题:Unity回放系统

        本文链接:https://www.haomeiwen.com/subject/ksgvbttx.html