private void RecordProperties(RuntimeAnimationProperty[] properties) { m_timelineView.BeginSetKeyframeValues(true); for (int i = 0; i < properties.Length; ++i) { RuntimeAnimationProperty property = properties[i]; if (property.ComponentIsNull) { continue; } if (property.Children == null || property.Children.Count == 0) { int index = m_propertiesView.IndexOf(property); m_timelineView.SetKeyframeValue(index, property); } else { foreach (RuntimeAnimationProperty childProperty in property.Children) { int index = m_propertiesView.IndexOf(childProperty); m_timelineView.SetKeyframeValue(index, childProperty); } } } m_timelineView.EndSetKeyframeValues(true); }
public void OnComponentAdded(Component component) { if (component == null) { return; } Type type = component.GetType(); for (int i = 0; i < m_props.Count; ++i) { RuntimeAnimationProperty property = m_props[i]; if (property.ComponentType == type && property.ComponentIsNull) { ResolveComponent(property, Target); //property.Component = component; m_propertiesTreeView.DataBindItem(property); if (property.Children != null) { foreach (RuntimeAnimationProperty childProperty in property.Children) { childProperty.Component = property.Component; m_propertiesTreeView.DataBindItem(childProperty); } } } } }
/// <summary> /// Read property values and add keyframes /// </summary> /// <param name="time">keyframes time</param> public void AddKeyframes(float time) { for (int i = 0; i < m_properties.Count; ++i) { RuntimeAnimationProperty property = m_properties[i]; AddKeyframes(time, property); } }
/// <summary> /// Remove keyframes by index /// </summary> /// <param name="index"></param> public void RemoveKeyframes(int index) { for (int i = 0; i < m_properties.Count; ++i) { RuntimeAnimationProperty property = m_properties[i]; RemoveKeyframes(index, property); } }
private void SetCurve(RuntimeAnimationProperty property) { Type componentType = property.ComponentType; if (componentType != null && property.Children == null) { m_clip.SetCurve("", componentType, property.AnimationPropertyPath, property.Curve); } }
private void ClearCurve(RuntimeAnimationProperty property) { Type componentType = property.ComponentType; if (componentType != null && property.Parent == null) { m_clip.SetCurve("", componentType, property.AnimationPropertyPath, null); } }
public RuntimeAnimationProperty(RuntimeAnimationProperty item) : this() { ComponentTypeName = item.ComponentTypeName; ComponentDisplayName = item.ComponentDisplayName; PropertyName = item.PropertyName; AnimationPropertyName = item.AnimationPropertyName; PropertyDisplayName = item.PropertyDisplayName; Parent = item.Parent; Children = item.Children; Component = item.Component; }
private void OnPropertyCollapsed(object sender, VirtualizingItemCollapsedArgs e) { if (PropertyCollapsed != null) { RuntimeAnimationProperty item = (RuntimeAnimationProperty)e.Item; int index = IndexOf(item); PropertyCollapsed(new ItemArg { Item = (RuntimeAnimationProperty)e.Item, Row = index }); } }
private void OnItemDatabinding(object sender, VirtualizingTreeViewItemDataBindingArgs e) { AnimationComponentView ui = e.ItemPresenter.GetComponent <AnimationComponentView>(); RuntimeAnimationProperty item = (RuntimeAnimationProperty)e.Item; ui.Item = item; ui.View = View; ui.Dialog = this; e.HasChildren = item.Children != null && item.Children.Count > 0; }
private void OnPropertyValueChanged(RuntimeAnimationProperty property, object oldValue, object newValue) { if (PropertyValueChanged != null) { int rowIndex = m_props.IndexOf(property); m_itemArg.Row = rowIndex; m_itemArg.Item = property; PropertyValueChanged(m_itemArg); } }
private void OnPropertyEndEdit(RuntimeAnimationProperty property) { if (PropertyEndEdit != null) { int rowIndex = m_props.IndexOf(property); m_itemArg.Row = rowIndex; m_itemArg.Item = property; PropertyEndEdit(m_itemArg); } }
public virtual void RemoveProperty(RuntimeAnimationProperty propertyItem) { RuntimeAnimationProperty parent = propertyItem.Parent; m_propertiesTreeView.RemoveChild(propertyItem.Parent, propertyItem); if (parent != null && parent.Children != null && parent.Children.Count > 0) { parent.Children.Remove(propertyItem); if (parent.Children.Count == 0) { m_propertiesTreeView.RemoveChild(null, parent); } } }
private void AddKeyframes(float time, RuntimeAnimationProperty property) { if (property.HasChildren) { List <RuntimeAnimationProperty> children = property.Children; for (int j = 0; j < children.Count; ++j) { RuntimeAnimationProperty child = children[j]; AddKeyframes(time, child); } } else { property.AddKey(time, property.FloatValue); } }
public void Add(RuntimeAnimationProperty property) { m_properties.Add(property); if (property.Children != null) { for (int i = 0; i < property.Children.Count; ++i) { SetCurve(property.Children[i]); } } else { SetCurve(property); } }
private void RemoveKeyframes(int index, RuntimeAnimationProperty property) { if (property.HasChildren) { List <RuntimeAnimationProperty> children = property.Children; for (int j = 0; j < children.Count; ++j) { RuntimeAnimationProperty child = children[j]; RemoveKeyframes(index, child); } } else { property.RemoveKey(index); } }
private void DataBind() { if (!m_isStarted) { return; } m_props = new List <RuntimeAnimationProperty>(); if (Clip != null) { if (Clip.Properties.Count > 0) { m_props.Add(m_emptyTop); } foreach (RuntimeAnimationProperty property in Clip.Properties) { //Type componentType = property.ComponentType; //if(componentType != null) //{ // property.Component = Target.GetComponent(componentType); //} ResolveComponent(property); m_props.Add(property); if (property.Children != null) { for (int i = 0; i < property.Children.Count; i++) { RuntimeAnimationProperty childProperty = property.Children[i]; childProperty.Component = property.Component; m_props.Add(childProperty); Subscribe(childProperty); } } else { Subscribe(property); } } } m_props.Add(m_emptyBottom); m_propertiesTreeView.Items = m_props.Where(p => p.Parent == null || p == m_emptyTop || p == m_emptyBottom); }
private void OnPropertiesItemDataBinding(object sender, VirtualizingTreeViewItemDataBindingArgs e) { AnimationPropertyView ui = e.ItemPresenter.GetComponent <AnimationPropertyView>(); RuntimeAnimationProperty item = (RuntimeAnimationProperty)e.Item; ui.View = this; if (m_emptyBottom != item && m_emptyTop != item) { e.CanSelect = true; } else { e.CanSelect = false; } ui.Item = item; e.HasChildren = item.Children != null && item.Children.Count > 0; }
public void Refresh() { for (int i = 0; i < m_properties.Count; ++i) { RuntimeAnimationProperty property = m_properties[i]; ClearCurve(property); if (property.Children != null) { for (int j = 0; j < property.Children.Count; ++j) { SetCurve(property.Children[j]); } } else { SetCurve(property); } } }
public void Clear() { if (m_properties == null) { return; } if (m_clip != null) { for (int i = 0; i < m_properties.Count; ++i) { RuntimeAnimationProperty property = m_properties[i]; if (property != null) { ClearCurve(property); } } } m_properties.Clear(); }
private void ResolveComponent(RuntimeAnimationProperty property, RuntimeAnimation target) { Type componentType = property.ComponentType; if (componentType == null) { return; } m_voidComponentEditor.Components = new[] { target.GetComponent(componentType) }; PropertyDescriptor[] propertyDescriptors = m_editorsMap.GetPropertyDescriptors(componentType, m_voidComponentEditor); for (int i = 0; i < propertyDescriptors.Length; ++i) { PropertyDescriptor desc = propertyDescriptors[i]; if (property.PropertyName == desc.MemberInfo.Name) { property.Component = desc.Target; break; } } }
private void _ResolveComponents(RuntimeAnimationProperty property, RuntimeAnimation animation) { if (property.HasChildren) { if (property.ComponentIsNull) { ResolveComponent(property, animation); } foreach (RuntimeAnimationProperty child in property.Children) { _ResolveComponents(child, animation); } } else { if (property.ComponentIsNull) { ResolveComponent(property, animation); } } }
public void CollapseRow(int row, RuntimeAnimationProperty property) { Dopesheet.Collapse(row, property.Children.Count); }
private void OnPropertiesRemoved(object sender, ItemsRemovedArgs e) { m_propertiesTreeView.ItemsRemoved -= OnPropertiesRemoved; List <Tuple <int, RuntimeAnimationProperty> > removedProperties = new List <Tuple <int, RuntimeAnimationProperty> >(); HashSet <int> removedHs = new HashSet <int>(); foreach (RuntimeAnimationProperty item in e.Items) { if (item.Parent != null) { int row = IndexOf(item.Parent); if (!removedHs.Contains(row)) { removedHs.Add(row); removedProperties.Add(new Tuple <int, RuntimeAnimationProperty>(row, item.Parent)); m_propertiesTreeView.RemoveChild(null, item.Parent); for (int i = 0; i < item.Parent.Children.Count; ++i) { row = IndexOf(item.Parent.Children[i]); if (!removedHs.Contains(row)) { removedHs.Add(row); removedProperties.Add(new Tuple <int, RuntimeAnimationProperty>(row, item.Parent.Children[i])); } } } } else { int row = IndexOf(item); if (!removedHs.Contains(row)) { removedHs.Add(row); removedProperties.Add(new Tuple <int, RuntimeAnimationProperty>(row, item)); if (item.Children != null) { for (int i = 0; i < item.Children.Count; ++i) { row = IndexOf(item.Children[i]); if (!removedHs.Contains(row)) { removedHs.Add(row); removedProperties.Add(new Tuple <int, RuntimeAnimationProperty>(row, item.Children[i])); } } } } } } for (int i = 0; i < removedProperties.Count; ++i) { RuntimeAnimationProperty property = removedProperties[i].Item2; Unsubscribe(property); m_props.Remove(property); Clip.Remove(property); } if (m_propertiesTreeView.ItemsCount == 2) { m_props.Remove(m_emptyTop); m_propertiesTreeView.RemoveChild(null, m_emptyTop); removedProperties.Insert(0, new Tuple <int, RuntimeAnimationProperty>(0, m_emptyTop)); } IEnumerable <Tuple <int, RuntimeAnimationProperty> > orderedItems = removedProperties.OrderBy(t => t.Item1); if (PropertiesRemoved != null) { PropertiesRemoved(new ItemsArg { Items = orderedItems.Select(t => t.Item2).ToArray(), Rows = orderedItems.Select(t => t.Item1).ToArray() }); } m_propertiesTreeView.ItemsRemoved += OnPropertiesRemoved; }
public void Remove(RuntimeAnimationProperty property) { m_properties.Remove(property); ClearCurve(property); }
public void ExpandRow(int row, RuntimeAnimationProperty property) { Dopesheet.Expand(row, property.Children.Count); }
public bool TryToCreateChildren() { if (ComponentTypeName == k_SpecialEmptySpace || ComponentTypeName == k_SpecialAddButton) { return(false); } Type type = Value.GetType(); if (Reflection.IsPrimitive(type)) { return(false); } if (!Reflection.IsValueType(type)) { return(false); } List <RuntimeAnimationProperty> children = new List <RuntimeAnimationProperty>(); FieldInfo[] fields = type.GetSerializableFields(); for (int i = 0; i < fields.Length; ++i) { FieldInfo field = fields[i]; if (!Reflection.IsPrimitive(field.FieldType)) { continue; } RuntimeAnimationProperty child = new RuntimeAnimationProperty { PropertyName = field.Name, AnimationPropertyName = field.Name, PropertyDisplayName = field.Name, ComponentTypeName = ComponentTypeName, Parent = this, Component = Component, Curve = new AnimationCurve(), }; child.SetValue(GetMemberValue(Value, field.Name), false); children.Add(child); } PropertyInfo[] properties = type.GetSerializableProperties(); for (int i = 0; i < properties.Length; ++i) { PropertyInfo property = properties[i]; if (!Reflection.IsPrimitive(property.PropertyType)) { continue; } RuntimeAnimationProperty child = new RuntimeAnimationProperty { PropertyName = property.Name, AnimationPropertyName = property.Name, PropertyDisplayName = property.Name, ComponentTypeName = ComponentTypeName, Parent = this, Component = Component, Curve = new AnimationCurve(), }; child.SetValue(GetMemberValue(Value, property.Name), false); children.Add(child); } Children = children; return(true); }
private void OnItemExpanding(object sender, VirtualizingItemExpandingArgs e) { RuntimeAnimationProperty item = (RuntimeAnimationProperty)e.Item; e.Children = item.Children; }
public void AddRows(int[] rows, RuntimeAnimationProperty[] properties, bool isNew = true) { //if(isNew) //{ // OnClipBeginModify(); //} int parentIndex = 0; for (int i = 0; i < properties.Length; ++i) { RuntimeAnimationProperty property = properties[i]; if (property.ComponentTypeName == RuntimeAnimationProperty.k_SpecialEmptySpace) { Dopesheet.AddRow(true, isNew, -1, 0, null); } else { if (property.Parent == null) { if (property.Curve != null) { Dopesheet.AddRow(true, isNew, 0, property.FloatValue, property.Curve); } else { parentIndex = rows[i]; Dopesheet.AddRow(true, isNew, 0, 0, null); } } else { Dopesheet.AddRow(false, isNew, parentIndex, property.FloatValue, property.Curve); } } } if (isNew) { OnClipModified(); } else { float clipLength = Clip.Clip.length; Dopesheet.BeginSetKeyframeValues(false); for (int i = 0; i < properties.Length; ++i) { RuntimeAnimationProperty property = properties[i]; if (property.ComponentTypeName == RuntimeAnimationProperty.k_SpecialEmptySpace) { continue; } AnimationCurve curve = property.Curve; if (curve != null) { Keyframe[] keys = curve.keys; for (int k = 0; k < keys.Length; ++k) { Keyframe kf = keys[k]; int sample = Mathf.RoundToInt(kf.time * Dopesheet.SamplesCount / clipLength); Dopesheet.SetKeyframeValue(kf.value, rows[i], sample); } } } Dopesheet.EndSetKeyframeValues(false); } }
public void SetKeyframeValue(int row, RuntimeAnimationProperty property) { Dopesheet.SetKeyframeValue(Convert.ToSingle(property.Value), row); }
protected virtual void Start() { m_parentDialog = GetComponentInParent <Dialog>(); if (m_parentDialog != null) { m_parentDialog.IsOkVisible = true; } HashSet <string> alreadyAddedHs = new HashSet <string>(); RuntimeAnimationProperty[] alreadyAddedProperties = View.Props; for (int i = 0; i < alreadyAddedProperties.Length; ++i) { RuntimeAnimationProperty property = alreadyAddedProperties[i]; alreadyAddedHs.Add(property.ComponentTypeName + " " + property.PropertyName); } MemberInfo enabledProperty = Strong.MemberInfo((Behaviour x) => x.enabled); List <RuntimeAnimationProperty> components = new List <RuntimeAnimationProperty>(); IEditorsMap editorsMap = IOC.Resolve <IEditorsMap>(); Type[] editableTypes = editorsMap.GetEditableTypes(); for (int i = 0; i < editableTypes.Length; ++i) { Type editableType = editableTypes[i]; if (!(typeof(Component).IsAssignableFrom(editableType)) || typeof(Component) == editableType) { continue; } Component targetComponent = Target.GetComponent(editableType); if (targetComponent == null) { continue; } m_voidComponentEditor.Components = new[] { targetComponent }; RuntimeAnimationProperty component = new RuntimeAnimationProperty(); component.ComponentDisplayName = editableType.Name; component.ComponentTypeName = string.Format("{0},{1}", editableType.FullName, editableType.Assembly.FullName.Split(',')[0]); component.Children = new List <RuntimeAnimationProperty>(); component.Component = m_voidComponentEditor.Components[0]; PropertyDescriptor[] propertyDescriptors = editorsMap.GetPropertyDescriptors(editableType, m_voidComponentEditor); for (int j = 0; j < propertyDescriptors.Length; ++j) { PropertyDescriptor propertyDescriptor = propertyDescriptors[j]; Type memberType = propertyDescriptor.MemberType; if (memberType.IsClass || memberType.IsEnum || typeof(MonoBehaviour).IsAssignableFrom(editableType) && propertyDescriptor.MemberInfo is PropertyInfo) { continue; } if (alreadyAddedHs.Contains(component.ComponentTypeName + " " + propertyDescriptor.MemberInfo.Name)) { continue; } RuntimeAnimationProperty property = new RuntimeAnimationProperty(); property.Parent = component; property.ComponentTypeName = component.ComponentTypeName; property.ComponentDisplayName = component.ComponentDisplayName; property.PropertyName = propertyDescriptor.MemberInfo.Name; property.PropertyDisplayName = propertyDescriptor.Label; if (propertyDescriptor.MemberInfo.Name == enabledProperty.Name && propertyDescriptor.MemberInfo.DeclaringType == enabledProperty.DeclaringType) { property.AnimationPropertyName = "m_Enabled"; } else { if (string.IsNullOrEmpty(propertyDescriptor.AnimationPropertyName)) { Type componentType = property.ComponentType; if (typeof(Component).IsAssignableFrom(componentType) && !typeof(MonoBehaviour).IsAssignableFrom(componentType)) { //Trying to derive serialized property name string aPropName = propertyDescriptor.MemberInfo.Name; property.AnimationPropertyName = "m_" + Char.ToUpper(aPropName[0]) + aPropName.Substring(1); } else { property.AnimationPropertyName = propertyDescriptor.MemberInfo.Name; } } else { property.AnimationPropertyName = propertyDescriptor.AnimationPropertyName; } } property.Component = propertyDescriptor.Target; component.Children.Add(property); } if (component.Children.Count > 0) { components.Add(component); } m_voidComponentEditor.Components = null; } m_propertiesTreeView.Items = components; }