//返回值1,找到,0未设置过,1,已经设置过。 public int TryGetKeyFrameRunTime(float curFrame, float lastTime, out ObjDictionary value, out float time) { curFrame = curFrame * 100f; lastTime = lastTime * 100f; int ct0 = times.Count; int returnType = 0; for (int i = 0, c = ct0; i < c; i++) { int t = times[i]; if (t >= lastTime && t <= curFrame) { time = (curFrame - t) * 0.01f; value = values[i]; return(1); } else if (curFrame > t) { returnType = 2; } } time = 0f; value = null; return(returnType); }
public ObjDictionary Copy() { ObjDictionary d = new ObjDictionary(); foreach (var p in this) { d[p.Key] = p.Value; } return(d); }
public void DeleteKeyFrame(ObjDictionary ObjDictionary) { for (int i = 0, c = times.Count; i < c; i++) { if (values[i] == ObjDictionary) { times.RemoveAt(i); values.RemoveAt(i); return; } } }
public void AddKey(int index, int frame, ObjDictionary defaultVal = null) { times.Insert(index, frame); if (null == defaultVal) { values.Insert(index, new ObjDictionary()); } else { values.Insert(index, defaultVal); } }
public bool TryGetKeyFrame(float curFrame, out ObjDictionary value, out float time) { curFrame = curFrame * 100f; int ct0 = times.Count; for (int i = 0, c = ct0; i < c; i++) { int t = times[i]; if (curFrame == t) { time = 0f; value = values[i]; return(true); } else if (t > curFrame) { if (i == 0) { time = 0f; value = null; return(false); } else { time = (curFrame - times[i - 1]) * 0.01f; value = values[i - 1]; return(true); } } } if (ct0 > 0 && times[ct0 - 1] < curFrame) { value = values[ct0 - 1]; time = (curFrame - times[ct0 - 1]) * 0.01f; return(true); } ; time = 0f; value = null; return(false); }
public bool AddKeyFrame(int frame, ObjDictionary value) { int l = times.Count; for (int i = 0; i < l; i++) { var f = times[i]; if (f > frame) { times.Insert(i, frame); values.Insert(i, value); return(true); } else if (f == frame) { return(false); } } times.Add(frame); values.Add(value); return(true); }
private void AddEventKeyFrame(int index, string skillId, int curSelectChannel, int curSelectFrame, ObjDictionary defaultVal = null) { var skill = GetSkill(skillId); if (curSelectChannel < 0 || curSelectChannel >= skill.subSkills[index].events.Count) { return; } var events = skill.subSkills[index].events[curSelectChannel]; int count = events.times.Count; for (int i = 0; i < count; i++) { var f = events.times[i]; if (f > curSelectFrame) { events.AddKey(i, curSelectFrame, defaultVal); SaveSkill(skillId); return; } else if (f == curSelectFrame) { return; } } events.AddKey(count, curSelectFrame, defaultVal); SaveSkill(skillId); }
void OnGUI() { var width100 = GUILayout.Width(100f); var width150 = GUILayout.Width(150f); var width50 = GUILayout.Width(50f); var width80 = GUILayout.Width(80f); var width30 = GUILayout.Width(30f); EditorGUI.BeginDisabledGroup(SkillEditorMainWindow.golbalWindow == null || SkillEditorData.Instance.CurSkillId.Length == 0 || SkillEditorData.Instance.skillsData == null); LCHSkillData skill = null; if (null == SkillEditorMainWindow.golbalWindow || SkillEditorData.Instance.skillsData == null) { viewHeight = 600f; } else { skill = SkillEditorData.Instance.skillsData.GetSkill(SkillEditorData.Instance.CurSkillId); if (null != skill) { viewHeight = Mathf.Max(600f, ChannelHeight * skill.channels.Count + 100f); int c = skill.channels.Count + skill.events.Count; curSelectChannel = Mathf.Min(curSelectChannel, c - 1); int c1 = skill.channels.Count; int c2 = skill.events.Count; if (SkillEditorWindow.curSelectChannel >= 0) { if (SkillEditorWindow.curSelectChannel < c1) { selectNormalChannel = skill.channels[SkillEditorWindow.curSelectChannel]; selectEvent = null; selectEventChannel = null; selNormalKeyFrameIndex = selectNormalChannel.GetKeyframeIndex(SkillEditorWindow.curSelectFrame); } else if (SkillEditorWindow.curSelectChannel < c2 + c1) { selectNormalChannel = null; int index = SkillEditorWindow.curSelectChannel - c1; selectEventChannel = skill.events[index]; selectEvent = selectEventChannel.GetKeyFrame(SkillEditorWindow.curSelectFrame); } } } else { selectNormalChannel = null; selectEvent = null; selectEventChannel = null; selNormalKeyFrameIndex = -1; } } GUILayout.BeginArea(new Rect(0, 0, position.width, offset.y)); GUILayout.BeginHorizontal(); //GUI.SetNextControlName("FocusControl01"); if (GUILayout.Button("添加", width50)) { Rect buttonRect = new Rect(0f, 0f, 1f, 1f); PopupWindow.Show(buttonRect, new MenuDialog()); } ; if (GUILayout.Button("删除", width50)) { SkillEditorData.Instance.skillsData.RemoveChannel(skill.id, curSelectChannel); } GUILayout.Space(20f); if (SkillEditorData.Instance.playing) { if (GUILayout.Button("▍▍", width50)) { SkillEditorData.Instance.playing = false; } } else { if (GUILayout.Button("▶", width50)) { if (SkillEditorData.Instance.curTime == maxLength) { SkillEditorData.Instance.curTime = 0f; } SkillEditorData.Instance.playing = true; } } if (GUILayout.Button("■", width50)) { SkillEditorData.Instance.curTime = 0f; SkillEditorData.Instance.playing = false; } GUILayout.Space(50f); showCollider = EditorGUILayout.ToggleLeft("显示碰撞体", showCollider); GUILayout.Label("AI自动攻击范围", width100); if (null != skill) { skillRange = skill.skillRange = EditorGUILayout.Slider(skill.skillRange, 0f, 20f, width150); } else { EditorGUILayout.Slider(1f, 0f, 20f, width150); } GUILayout.Label("技能宽度", width100); if (null != skill) { skillWidth = skill.skillWidth = EditorGUILayout.Slider(skill.skillWidth, 0f, 20f, width150); } else { EditorGUILayout.Slider(1f, 0f, 20f, width150); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("技能长度", width100); if (null != skill) { maxLength = skill.maxLength = EditorGUILayout.Slider(skill.maxLength, 0f, 10f); } else { maxLength = EditorGUILayout.Slider(maxLength, 0f, 5f, width150); } GUILayout.Label("工具条缩放", width50); scale = EditorGUILayout.Slider(scale, 0.2f, 2f, width150); GUILayout.Space(30f); EditorGUI.BeginDisabledGroup(null == skill); GUI.SetNextControlName("FocusControl01"); if (GUILayout.Button("+", width30)) { if (null != skill) { SkillEditorData.Instance.skillsData.AddKeyFrame(skill.id, curSelectChannel, curSelectFrame); } } if (GUILayout.Button("-", width30)) { if (null != skill) { SkillEditorData.Instance.skillsData.RemoveKeyFrame(skill.id, curSelectChannel, curSelectFrame); } } if (GUILayout.Button("c", width30)) { if (null != skill) { SkillEditorData.Instance.skillsData.CopyKeyFrame(skill.id, curSelectChannel, curSelectFrame); } } EditorGUI.EndDisabledGroup(); GUILayout.Label("关键帧值:", width80); if (selectNormalChannel != null && selNormalKeyFrameIndex >= selectNormalChannel.values.Count) { selNormalKeyFrameIndex = selectNormalChannel.values.Count - 1; } if (selectNormalChannel == null || selNormalKeyFrameIndex == -1) { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.FloatField(0f, width80); EditorGUI.EndDisabledGroup(); } else { selectNormalChannel.values[selNormalKeyFrameIndex] = EditorGUILayout.FloatField(selectNormalChannel.values[selNormalKeyFrameIndex], width80); } GUILayout.Label("自动更新:", width80); autoUpdateKeyFrame = EditorGUILayout.Toggle(autoUpdateKeyFrame); GUILayout.Label(""); GUILayout.EndHorizontal(); SpeceLine(); GUILayout.EndArea(); float delta = 20f * scale; float width = maxLength * 10f * delta + 2f; scrollViewRect = new Rect(0, offset.y, position.width, position.height - offset.y); Rect scrollAreaRect = new Rect(0, 0, offset.x + width, viewHeight); scrollPosition = GUI.BeginScrollView(scrollViewRect, scrollPosition, scrollAreaRect); GUILayout.BeginArea(new Rect(offset.x + scrollPosition.x, 0, width - scrollPosition.x, viewHeight)); int channelCount = 0; int normalChanelCount = 0; int eventCount = 0; List <int> [] times; if (skill == null) { times = new List <int> [0]; } else { normalChanelCount = skill.channels.Count; eventCount = skill.events.Count; channelCount = normalChanelCount + eventCount; times = new List <int> [channelCount]; for (int i = 0; i < normalChanelCount; i++) { times[i] = skill.channels[i].times; } for (int i = 0; i < eventCount; i++) { times[i + normalChanelCount] = skill.events[i].times; } } TimeBarHelper.DrawChannels(maxLength, delta, fps, ChannelHeight, new Vector2(-scrollPosition.x, scrollPosition.y), SkillEditorData.Instance.curTime, channelCount, curSelectChannel, normalChanelCount); TimeBarHelper.DrawKeyFrames(maxLength, delta, fps, ChannelHeight, new Vector2(-scrollPosition.x, scrollPosition.y), curSelectChannel, curSelectFrame, times, normalChanelCount); TimeBarHelper.DrawTimeBar(maxLength, delta, fps, ChannelHeight, viewHeight, new Vector2(-scrollPosition.x, scrollPosition.y), SkillEditorData.Instance.curTime); GUILayout.EndArea(); GUILayout.BeginArea(new Rect(scrollPosition.x, 0, offset.x, viewHeight)); if (skill == null) { ArrayHelper.ResizeArray <string>(ref channelNames, 0); } else { int c0 = skill.channels.Count; int c1 = skill.events.Count; ArrayHelper.ResizeArray <string>(ref channelNames, c0 + c1); for (int i = 0; i < c0; i++) { var c = skill.channels[i]; channelNames[i] = skill.GetObjectName(c.objId) + c.GetTypeName(); } for (int i = 0; i < c1; i++) { var c = skill.events[i]; channelNames[i + c0] = skill.GetObjectName(c.objId) + c.GetTypeName(); } } TimeBarHelper.DrawHeater(offset.x, ChannelHeight, new Vector2(-scrollPosition.x, scrollPosition.y), SkillEditorData.Instance.curTime, curSelectChannel, channelNames, normalChanelCount); Handles.color = Color.gray; Handles.DrawLine(new Vector2(offset.x - 1, 0), new Vector2(offset.x - 1, viewHeight)); GUILayout.EndArea(); GUI.EndScrollView(); if (scrollViewRect.Contains(Event.current.mousePosition)) { Vector2 pos = Event.current.mousePosition + scrollPosition - offset; if (Event.current.mousePosition.x >= offset.x) { OnKeyFrameAreaEvent(pos); } if (Event.current.type == EventType.MouseUp) { dragging = false; } } EditorGUI.EndDisabledGroup(); }
void OnBindNameCallBack(string name, object[] args) { ObjDictionary propertys = (ObjDictionary)args[0]; propertys["bind_name"] = name; }