/// <summary> /// 设置当前帧数据至目标属性值 /// </summary> private void SetPropertyValue(int index) { for (int i = 0; i < _LA.Targets.Count; i++) { LinkageAnimationTarget lat = _LA.Targets[i]; if (lat.Target) { LAFrame laf = lat.Frames[index]; for (int j = 0; j < lat.Propertys.Count; j++) { Component cp = lat.Target.GetComponent(lat.Propertys[j].ComponentName); if (cp != null) { PropertyInfo pi = cp.GetType().GetProperty(lat.Propertys[j].PropertyName); if (pi != null) { pi.SetValue(cp, laf.GetFrameValue(j), null); } else { Debug.LogWarning("目标物体 " + lat.Target.name + " 的组件 " + lat.Propertys[j].ComponentName + " 不存在属性 " + lat.Propertys[j].PropertyName + "!"); } } else { Debug.LogWarning("目标物体 " + lat.Target.name + " 不存在组件 " + lat.Propertys[j].ComponentName + "!"); } } } } }
/// <summary> /// 设置关键帧属性值 /// </summary> public static void SetFrameValue(this LAFrame frame, int index, object value) { LAValueIndex lvi = frame.ValueIndex[index]; int i = lvi.Index; switch (lvi.Type) { case "Bool": frame.ValueBool[i] = (bool)value; break; case "Color": frame.ValueColor[i] = (Color)value; break; case "Float": frame.ValueFloat[i] = (float)value; break; case "Int": frame.ValueInt[i] = (int)value; break; case "Quaternion": frame.ValueQuaternion[i] = (Quaternion)value; break; case "String": frame.ValueString[i] = (string)value; break; case "Vector2": frame.ValueVector2[i] = (Vector2)value; break; case "Vector3": frame.ValueVector3[i] = (Vector3)value; break; case "Vector4": frame.ValueVector4[i] = (Vector4)value; break; case "Sprite": frame.ValueSprite[i] = (Sprite)value; break; default: break; } }
/// <summary> /// 克隆关键帧 /// </summary> private void CloneFrame(int index) { if (_LA.Targets.Count <= 0) { return; } for (int i = 0; i < _LA.Targets.Count; i++) { LAFrame laf = new LAFrame(); laf = _LA.Targets[i].Frames[index].Clone(); _LA.Targets[i].Frames.Add(laf); } _LA.FrameLength += 1; }
/// <summary> /// 克隆关键帧属性值 /// </summary> public static LAFrame Clone(this LAFrame frame) { LAFrame laf = new LAFrame(); laf.ValueIndex = new List <LAValueIndex>(frame.ValueIndex); laf.ValueBool = new List <bool>(frame.ValueBool); laf.ValueColor = new List <Color>(frame.ValueColor); laf.ValueFloat = new List <float>(frame.ValueFloat); laf.ValueInt = new List <int>(frame.ValueInt); laf.ValueQuaternion = new List <Quaternion>(frame.ValueQuaternion); laf.ValueString = new List <string>(frame.ValueString); laf.ValueVector2 = new List <Vector2>(frame.ValueVector2); laf.ValueVector3 = new List <Vector3>(frame.ValueVector3); laf.ValueVector4 = new List <Vector4>(frame.ValueVector4); laf.ValueSprite = new List <Sprite>(frame.ValueSprite); return(laf); }
/// <summary> /// 更新动画帧(一个固定值) /// </summary> private void UpdateFrame(LinkageAnimationTarget lat, int currentIndex) { if (lat.Target) { LAFrame currentLAF = lat.Frames[currentIndex]; for (int i = 0; i < lat.PropertysRunTime.Count; i++) { LAProperty lap = lat.Propertys[i]; LAPropertyRunTime laprt = lat.PropertysRunTime[i]; if (laprt.IsValid) { object value = currentLAF.GetFrameValue(i); laprt.PropertyValue.SetValue(laprt.PropertyComponent, value, null); } } } }
/// <summary> /// 获取关键帧属性值 /// </summary> public static object GetFrameValue(this LAFrame frame, int index) { LAValueIndex lvi = frame.ValueIndex[index]; int i = lvi.Index; switch (lvi.Type) { case "Bool": return(frame.ValueBool[i]); case "Color": return(frame.ValueColor[i]); case "Float": return(frame.ValueFloat[i]); case "Int": return(frame.ValueInt[i]); case "Quaternion": return(frame.ValueQuaternion[i]); case "String": return(frame.ValueString[i]); case "Vector2": return(frame.ValueVector2[i]); case "Vector3": return(frame.ValueVector3[i]); case "Vector4": return(frame.ValueVector4[i]); case "Sprite": return(frame.ValueSprite[i]); default: return(null); } }
/// <summary> /// 添加关键帧 /// </summary> private void AddFrame() { if (_LA.Targets.Count <= 0) { return; } for (int i = 0; i < _LA.Targets.Count; i++) { LinkageAnimationTarget lat = _LA.Targets[i]; LAFrame laf = new LAFrame(); for (int j = 0; j < lat.Propertys.Count; j++) { LAProperty lap = lat.Propertys[j]; object value = LinkageAnimationTool.GenerateOriginalValue(lap.PropertyType); laf.AddFrameValue(lap.PropertyType, value); } lat.Frames.Add(laf); } _LA.FrameLength += 1; }
/// <summary> /// 移除关键帧属性值 /// </summary> public static void RemoveFrameValue(this LAFrame frame, int index) { LAValueIndex lvi = frame.ValueIndex[index]; frame.ValueIndex.RemoveAt(index); int i = lvi.Index; switch (lvi.Type) { case "Bool": frame.ValueBool.RemoveAt(i); break; case "Color": frame.ValueColor.RemoveAt(i); break; case "Float": frame.ValueFloat.RemoveAt(i); break; case "Int": frame.ValueInt.RemoveAt(i); break; case "Quaternion": frame.ValueQuaternion.RemoveAt(i); break; case "String": frame.ValueString.RemoveAt(i); break; case "Vector2": frame.ValueVector2.RemoveAt(i); break; case "Vector3": frame.ValueVector3.RemoveAt(i); break; case "Vector4": frame.ValueVector4.RemoveAt(i); break; case "Sprite": frame.ValueSprite.RemoveAt(i); break; default: break; } for (int j = 0; j < frame.ValueIndex.Count; j++) { if (frame.ValueIndex[j].Type == lvi.Type && frame.ValueIndex[j].Index > i) { LAValueIndex lav = new LAValueIndex(); lav.Type = lvi.Type; lav.Index = frame.ValueIndex[j].Index - 1; frame.ValueIndex[j] = lav; } } }
/// <summary> /// 新增关键帧属性值 /// </summary> public static void AddFrameValue(this LAFrame frame, string type, object value) { int i = 0; switch (type) { case "Bool": frame.ValueBool.Add((bool)value); i = frame.ValueBool.Count - 1; break; case "Color": frame.ValueColor.Add((Color)value); i = frame.ValueColor.Count - 1; break; case "Float": frame.ValueFloat.Add((float)value); i = frame.ValueFloat.Count - 1; break; case "Int": frame.ValueInt.Add((int)value); i = frame.ValueInt.Count - 1; break; case "Quaternion": frame.ValueQuaternion.Add((Quaternion)value); i = frame.ValueQuaternion.Count - 1; break; case "String": frame.ValueString.Add((string)value); i = frame.ValueString.Count - 1; break; case "Vector2": frame.ValueVector2.Add((Vector2)value); i = frame.ValueVector2.Count - 1; break; case "Vector3": frame.ValueVector3.Add((Vector3)value); i = frame.ValueVector3.Count - 1; break; case "Vector4": frame.ValueVector4.Add((Vector4)value); i = frame.ValueVector4.Count - 1; break; case "Sprite": frame.ValueSprite.Add((Sprite)value); i = frame.ValueSprite.Count - 1; break; default: return; } LAValueIndex lvi = new LAValueIndex(); lvi.Type = type; lvi.Index = i; frame.ValueIndex.Add(lvi); }