Пример #1
0
        public void OnGUI()
        {
            TimeLineData data = TimeLineDataManager.Instance.GetCurSelectTimeLine();

            if (data == null)
            {
                return;
            }
            if (TimeLineDataManager.Instance.GetGUIMemInfoCount() == 0)
            {
                return;
            }

            StartTime = EditorGUILayout.FloatField("开始时间", startTime);
            EndTime   = EditorGUILayout.FloatField("结束时间", endTime);
            ActionItemData tempad = TimeLineDataManager.Instance.curOperationAction;

            if (tempad != null)
            {
                tempad.actionStartTime = StartTime;
                tempad.actionEndTime   = EndTime;
            }
            if (GUILayout.Button("Save"))
            {
                SaveLineData();
            }
        }
Пример #2
0
        public ActionItemData GetActionByKey(string key)
        {
            ActionItemData ad = null;

            if (actionDic.TryGetValue(key, out ad))
            {
                return(ad);
            }
            return(null);
        }
Пример #3
0
        public void DeleteAction(ActionItemData ac)
        {
            int    key    = Mathf.CeilToInt(ac.actionStartTime / TimeLineDataManager.Instance.TickDelta);
            string keyStr = string.Format("{0:D5}", key);

            if (actionDic.ContainsKey(keyStr))
            {
                actionDic.Remove(keyStr);
            }
        }
Пример #4
0
        public ActionItemData GetActionByKey(int key)
        {
            ActionItemData ad     = null;
            string         keystr = key.ToString();

            if (actionDic.TryGetValue(keystr, out ad))
            {
                return(ad);
            }
            return(null);
        }
Пример #5
0
        public ActionItemData SetActionValue(ActionItemData ad)
        {
            TimeLineData data = TimeLineDataManager.Instance.GetCurSelectTimeLine();

            if (data == null)
            {
                return(null);
            }
            SetAtctionParamList(data);
            ad.paramList = actionParamList.ToArray();
            return(ad);
        }
Пример #6
0
        void LeftClick()
        {
            //左键单击
            // CurMemInfo = null;
            TimeLineData data = TimeLineDataManager.Instance.GetCurSelectTimeLine();

            if (data == null)
            {
                return;
            }
            data.InitDefaultTime();
            Type t = data.GetType();

            data.SetFieldValue(data);
            var memInfo = t.GetMethods();

            TimeLineDataManager.Instance.memDic.Clear();
            int selectKey = -1;

            TimeLineDataManager.Instance.curOperationAction = null;
            foreach (MethodInfo info in memInfo)
            {
                foreach (var item in data.GetActionDic())
                {
                    ActionItemData ad = item.Value;
                    if (ad.IsSelect())
                    {
                        foreach (var name in ad.methodNameList)
                        {
                            if (name == info.Name)
                            {
                                TimeLineDataManager.Instance.AddGUIMemInfo(info);
                            }
                        }
                        //移除要操作的action 用临时变量保存
                        TimeLineDataManager.Instance.curOperationAction = ad.Clone();
                        selectKey = ad.index;
                    }
                    else
                    {
                        if (LastSelectGridY != CurSelectGridY)
                        {
                            //更换timeline
                            //  TimeLineDataManager.Instance.curOperationAction = null;
                        }
                    }
                }
            }

            data.DeleteAction(selectKey);
        }
Пример #7
0
 public ActionItemData GetCurActionItemData()
 {
     if (actionDic != null)
     {
         foreach (var itemdata in actionDic)
         {
             ActionItemData ad = itemdata.Value;
             if (ad.IsSelect())
             {
                 return(ad);
             }
         }
     }
     return(null);
 }
Пример #8
0
        public void AddAction(ActionItemData ac)
        {
            int key = Mathf.CeilToInt(ac.actionStartTime / TimeLineDataManager.Instance.TickDelta);

            ac.index = key;
            string keyStr = string.Format("{0:D5}", key);

            if (actionDic.ContainsKey(keyStr))
            {
                actionDic[keyStr] = ac;
            }
            else
            {
                actionDic.Add(keyStr, ac);
            }
        }
Пример #9
0
        public void InitDefaultTime()
        {
            ActionItemData ad = GetCurActionItemData();

            if (ad != null)
            {
                if (ad.IsSelect())
                {
                    endTime   = ad.actionEndTime;
                    startTime = ad.actionStartTime;
                    return;
                }
            }
            endTime   = (TimeLineDataManager.Instance.SelectColumn) * TimeLineDataManager.Instance.TickDelta;
            startTime = TimeLineDataManager.Instance.SelectColumn * TimeLineDataManager.Instance.TickDelta;
        }
Пример #10
0
        public void SetValueByAction(ActionItemData ad)
        {
            if (ad == null)
            {
                return;
            }
            var paramList = ad.paramList;

            if (paramList == null)
            {
                return;
            }
            endTime = ad.actionEndTime;

            startTime = ad.actionStartTime;
            SetObject(paramList);
        }
Пример #11
0
        IEnumerator PlayLine(TimeLineData data)
        {
            Type          t       = data.GetType();
            List <string> keyList = new List <string>();

            foreach (var actionPair in data.GetActionDic())
            {
                Debug.Log("key is " + actionPair.Key);
                keyList.Add(actionPair.Key);
            }
            for (int i = 0; i < keyList.Count; i++)
            {
                string key = keyList[i];
                if (i == 0)
                {
                    ActionItemData ad = data.GetActionByKey(key);
                    float          st = ad.actionStartTime;
                    yield return(new WaitForSeconds(st));

                    data.SetValueByAction(ad);
                    foreach (var name in ad.methodNameList)
                    {
                        string methodName = "Execute" + name;
                        t.InvokeMember(methodName, BindingFlags.InvokeMethod, null, data, null);
                    }
                }
                else
                {
                    string         lastkey = keyList[i - 1];
                    ActionItemData lastad  = data.GetActionByKey(lastkey);
                    float          lastst  = lastad.actionStartTime;
                    ActionItemData ad      = data.GetActionByKey(key);
                    float          st      = ad.actionStartTime;
                    float          time    = st - lastst;
                    Debug.Log(" time is " + time.ToString());
                    yield return(new WaitForSeconds(time));

                    data.SetValueByAction(ad);
                    foreach (var name in ad.methodNameList)
                    {
                        string methodName = "Execute" + name;
                        t.InvokeMember(methodName, BindingFlags.InvokeMethod, null, data, null);
                    }
                }
            }
        }
Пример #12
0
 public ActionItemData GetActionItemData(int index)
 {
     if (actionDic != null)
     {
         foreach (var itemdata in actionDic)
         {
             ActionItemData ad = itemdata.Value;
             int            st = (int)(ad.actionStartTime / TimeLineDataManager.Instance.TickDelta);
             int            et = (int)(ad.actionEndTime / TimeLineDataManager.Instance.TickDelta);
             if (st <= index && index < et)
             {
                 return(ad);
             }
         }
     }
     return(null);
 }
Пример #13
0
        void ShowMenu()
        {
            GenericMenu menu = new GenericMenu();

            if (CurSelectGridY < 0)
            {
                return;
            }
            if (CurSelectGridY < TimeLineDataManager.Instance.GetTimeLineCount())
            {
                var data = TimeLineDataManager.Instance.GetTimeLineByIndex(CurSelectGridY);
                foreach (var item in data.GetActionDic())
                {
                    ActionItemData ad = item.Value;
                    if (ad.IsSelect())
                    {
                        int index = Mathf.CeilToInt(ad.actionStartTime / TimeLineDataManager.Instance.TickDelta);
                        if (index != CurSelectGridX)
                        {
                            return;
                        }
                    }
                }

                Type   t        = data.GetType();
                string testName = GetTimeLineName(t);

                menu.AddDisabledItem(new GUIContent(testName));
                menu.AddSeparator("");
                var memInfo = t.GetMethods();

                foreach (MethodInfo info in memInfo)
                {
                    GridMenuItemAttribute[] attrArray = info.GetCustomAttributes(typeof(GridMenuItemAttribute), false) as GridMenuItemAttribute[];
                    for (int i = 0; i < attrArray.Length; i++)
                    {
                        GridMenuItemAttribute attrbute = attrArray[i];
                        // menu.AddItem(new GUIContent(attrbute.MenuDescription), false, (GenericMenu.MenuFunction2)DelegateCreate(info, typeof(GenericMenu.MenuFunction2), target), "adc");
                        menu.AddItem(new GUIContent(attrbute.MenuDescription), false, ClickMenuItem, info);
                    }
                }

                menu.ShowAsContext();
            }
        }
Пример #14
0
        public void OnDrawDeleteButton(MemberInfo info)
        {
            if (GUILayout.Button("X"))
            {
                TimeLineDataManager.Instance.DeleteMemInfo(info);
                if (TimeLineDataManager.Instance.memDic.Count == 0)
                {
                    ActionItemData ad   = TimeLineDataManager.Instance.curOperationAction;
                    TimeLineData   data = TimeLineDataManager.Instance.GetCurSelectTimeLine();
                    if (data != null)
                    {
                        DeleteAction(ad.index);

                        TimeLineDataManager.Instance.curOperationAction = null;
                    }
                }
            }
        }
Пример #15
0
        void ClickMenuItem(object memInfo)
        {
            if (memInfo != null)
            {
                TimeLineDataManager.Instance.AddGUIMemInfo((MemberInfo)memInfo);
            }
            var            data = TimeLineDataManager.Instance.GetCurSelectTimeLine();
            ActionItemData ad   = data.GetActionItemData(TimeLineDataManager.Instance.SelectColumn);

            if (ad == null)
            {
                List <string> list = new List <string>();
                MemberInfo    info = memInfo as MemberInfo;
                list.Add(info.Name);
                ad = new ActionItemData(data.GetType(), list);
                TimeLineDataManager.Instance.curOperationAction = ad;
                data.AddAction(ad);
            }
        }
Пример #16
0
        public void ReadFromBinary(BinaryReader br)
        {
            TimeLineName  = br.ReadString();
            TimeLineIndex = br.ReadInt32();
            GridCount     = br.ReadInt32();
            StartTime     = br.ReadSingle();
            EndTime       = br.ReadSingle();

            int len = br.ReadInt32();

            actionDic.Clear();
            for (int i = 0; i < len; i++)
            {
                // int key = br.ReadInt32();
                ActionItemData data = new ActionItemData();
                data.ReadFromeBinary(br);

                AddAction(data);
            }
        }
Пример #17
0
        public void SetFieldValue(TimeLineData target)
        {
            InitDefaultTime();
            ActionItemData ad = GetCurActionItemData();

            if (ad == null)
            {
                return;
            }
            var paramList = ad.paramList;

            if (paramList == null)
            {
                return;
            }
            endTime = ad.actionEndTime;

            startTime = ad.actionStartTime;
            SetObject(paramList);
        }
Пример #18
0
        public void SaveData(Type t, List <string> nameList, List <object> list, bool isJson = true)
        {
            ActionItemData data = new ActionItemData(t, nameList);

            data.paramList = list.ToArray();
            TimeLineData lineData = GetCurSelectTimeLine();

            lineData.AddAction(data);
            if (isJson)
            {
                string newfilepath = filePath;
                if (newfilepath.EndsWith(".json"))
                {
                    SaveToJson(newfilepath, lineData);
                }
                else
                {
                    if (EditorUtility.DisplayDialog("error", "此文件不存在,请先创建", "ok"))
                    {
                        TimeLine.ShowFileUI();
                    }
                }
            }
            else
            {
                string newfilepath = filePath;
                if (newfilepath.EndsWith(".bytes"))
                {
                    SaveEditData(newfilepath, lineData);
                }
                else
                {
                    if (EditorUtility.DisplayDialog("error", "此文件不存在,请先创建", "ok"))
                    {
                        TimeLine.ShowFileUI();
                    }
                }
            }
        }
Пример #19
0
        public ActionItemData Clone()
        {
            ActionItemData ad = new ActionItemData();

            ad.name  = name;
            ad.index = index;
            foreach (var info in methodNameList)
            {
                ad.methodNameList.Add(info);
            }
            if (paramList != null && paramList.Length > 0)
            {
                ad.paramList = new object[paramList.Length];
                paramList.CopyTo(ad.paramList, 0);
            }
            else
            {
                ad.paramList = null;
            }

            ad.actionEndTime   = actionEndTime;
            ad.actionStartTime = actionStartTime;
            return(ad);
        }
Пример #20
0
        void OnTimeLineGUI()
        {
            curTimeLineRect = new Rect(0, TITLE_HEIGHT, totalGridCount * GRID_WIDTH, 600);
            GUILayout.BeginArea(curTimeLineRect);

            int len = TimeLineDataManager.Instance.GetTimeLineCount();

            for (int i = 0; i < len; i++)
            {
                TimeLineData data = TimeLineDataManager.Instance.GetTimeLineByIndex(i);
                DrawBox(data.TimeLineName, 0, LABEL_HEIGHT * i, LABLE_WIDTH, LABEL_HEIGHT, Color.white);
                for (int j = 0; j < totalGridCount; j++)
                {
                    Color c = Color.white;
                    SortedDictionary <string, ActionItemData> acDic = data.GetActionDic();

                    foreach (var acpair in acDic)
                    {
                        //当期操作的action 不画
                        ActionItemData ad = acpair.Value;
                        int            st = (int)(ad.actionStartTime / TimeLineDataManager.Instance.TickDelta);
                        int            et = (int)(ad.actionEndTime / TimeLineDataManager.Instance.TickDelta);
                        if (j == st)
                        {
                            c = Color.green;
                        }
                        if (j > st && j <= et)
                        {
                            c = Color.red;
                        }
                    }
                    if (CurSelectGridY == i)
                    {
                        //画当前操作的action
                        ActionItemData tempad = TimeLineDataManager.Instance.curOperationAction;
                        if (tempad != null)
                        {
                            int st = (int)(tempad.actionStartTime / TimeLineDataManager.Instance.TickDelta);
                            int et = (int)(tempad.actionEndTime / TimeLineDataManager.Instance.TickDelta);

                            if (j == st)
                            {
                                c = selectColor;
                            }
                            if (j > st && j <= et)
                            {
                                c = Color.red;
                            }
                        }
                        else
                        {
                            if (j == CurSelectGridX)
                            {
                                c = selectColor;
                            }
                        }
                    }

                    //if ( CurSelectGridX == j && CurSelectGridY == i )
                    //{
                    //    c = selectColor;
                    //}
                    DrawBox("", LABLE_WIDTH + j * GRID_WIDTH, LABEL_HEIGHT * i, GRID_WIDTH, GRID_HEIGHT, c);
                }
            }
            GUILayout.EndArea();
        }
Пример #21
0
        bool IsCanChange()
        {
            var data = TimeLineDataManager.Instance.GetCurSelectTimeLine();

            if (data == null)
            {
                return(true);
            }
            ActionItemData ad = TimeLineDataManager.Instance.curOperationAction;

            if (ad == null)
            {
                return(true);
            }
            List <int> keyList = new List <int>();

            foreach (var pari in data.actionDic)
            {
                if (ad.index != pari.Value.index)
                {
                    keyList.Add(pari.Value.index);
                }
            }
            int lastKey = -1, afterKey = -1;

            for (int i = 0; i < keyList.Count; i++)
            {
                if (keyList[i] > ad.index)
                {
                    int curKey = Mathf.CeilToInt(ad.actionEndTime / TimeLineDataManager.Instance.TickDelta);
                    if (keyList[i] != curKey)
                    {//过滤当前操作的action的key
                        afterKey = keyList[i];
                    }
                }
                if (keyList[i] < ad.index)
                {
                    lastKey = keyList[i];
                }
            }

            ActionItemData lastAd = GetActionByKey(lastKey);

            if (lastAd != null)
            {
                // Debug.Log( "starttime is " + startTime.ToString() + " lastad endtime is " + lastAd.actionEndTime.ToString() );
                if (startTime <= lastAd.actionEndTime)
                {
                    startTime = lastAd.actionEndTime + TimeLineDataManager.Instance.TickDelta;
                    //  Debug.LogWarning("lastKey is " + lastKey.ToString());
                    Debug.LogError("前方已有事件");
                    return(false);
                }
            }
            ActionItemData afterad = GetActionByKey(afterKey);

            if (afterad != null)
            {
                // Debug.Log( "endtime is " + startTime.ToString() + " afterad actionStartTime is " + afterad.actionStartTime.ToString() );
                if (endTime >= afterad.actionStartTime)
                {
                    endTime = afterad.actionStartTime - TimeLineDataManager.Instance.TickDelta;
                    Debug.LogError("后方已有事件");
                    return(false);
                }
            }

            return(true);
        }