/// <summary> /// Copies the root settings from this object to the next. /// </summary> private MemberAspect Internal_CreateClone() { MemberAspect clone = reflectedObject.CreateAspect(m_FieldInfo); clone.m_MemberName = m_MemberName; return(clone); }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { AnimationCurveAspect cruveAspect = clone as AnimationCurveAspect; cruveAspect.m_Value.keys = m_Value.keys; cruveAspect.m_Value.postWrapMode = m_Value.postWrapMode; cruveAspect.m_Value.preWrapMode = m_Value.preWrapMode; }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { ObjectAspect objectAspect = clone as ObjectAspect; for (int i = 0; i < m_Children.Count; i++) { MemberAspect childClone = m_Children[i].Copy(); objectAspect.m_Children.Add(childClone); } }
/// <summary> /// If a dictionary returns the value at that key otherwise throws an exception. /// </summary> public virtual MemberAspect this[MemberAspect key] { get { throw new System.NotImplementedException("String indexer has not been implemented for " + GetType().Name); } protected set { throw new System.NotImplementedException("String indexer has not been implemented for " + GetType().Name); } }
/// <summary> /// Loads all the children from our current value. /// </summary> private void LoadChildren() { if (hasValue) { FieldInfo[] fields = m_ValueType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < fields.Length; i++) { object value = fields[i].GetValue(m_Value); MemberAspect member = reflectedObject.CreateAspect(fields[i], value); m_Children.Add(member); } } }
/// <summary> /// /// </summary> /// <param name="targets"></param> public ReflectedObject(object[] targets) { m_Members = new List <MemberAspect>(); m_Aspects = new List <MemberAspect>(); m_Targets = targets; Type type = m_Targets[0].GetType(); FieldInfo[] fileds = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < fileds.Length; i++) { MemberAspect member = CreateAspect(fileds[i]); m_Members.Add(member); } LoadMemberValues(); }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected abstract void CloneMembers(MemberAspect clone);
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { Vector3Aspect vect3Aspect = clone as Vector3Aspect; vect3Aspect.m_Value = m_Value; }
/// <summary> /// Takes our current instance and converts it into a new type. This preserves all values /// that have the same name. If we don't currently value a value you should call /// <see cref="CreateNewInstanceOfType(Type)"/>. If our value is already that type this /// function has no effect. /// </summary> /// <param name="newType">The type you want to convert too.</param> protected virtual void ConvertType(Type newType) { // Our new type is null so we don't need to convert. if (newType == null) { DestroyInstance(); return; } // We are already this type no point running our logic. if (newType == m_ValueType) { return; } // If we are down casting we can lose data so we want inform the user. if (m_ValueType.IsSubclassOf(newType)) { if (!EditorUtility.DisplayDialog("Down casting Type", "Do you really want to downcast '" + m_ValueType.Name + "' to it's base class '" + newType + "'? All inherited values will be kept but new values will be discarded.", "Down Cast", "Cancel")) { return; } } // We have not type assigned so we can just create a new one. if (!hasValue) { Debug.LogWarning("Can't Convert Type if we have no current instance set"); CreateNewInstanceOfType(newType); } FieldInfo[] newFields = newType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); // First remove extra fields for (int i = m_Children.Count - 1; i >= 0; i--) { if (!newFields.Any(nf => { return(nf.Name == m_Children[i].fieldInfo.Name); })) { // This field does not exist on our new type. m_Children.RemoveAt(i); } } List <MemberAspect> sortedChildren = new List <MemberAspect>(); for (int i = 0; i < newFields.Length; i++) { // Find this asepct if we have one MemberAspect child = m_Children.Where(aspect => { return(aspect.fieldInfo.Name == newFields[i].Name); }).FirstOrDefault(); if (child != null) { sortedChildren.Add(child); } else { MemberAspect member = reflectedObject.CreateAspect(newFields[i], null); sortedChildren.Add(member); } } // Save our children m_Children = sortedChildren; // Save our new type. m_ValueType = newType; // Create a new value. m_Value = System.Activator.CreateInstance(m_ValueType, nonPublic: true); }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { ColorAspect colorAspect = clone as ColorAspect; colorAspect.m_Value = m_Value; }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { BoundsAspect boundsAspect = clone as BoundsAspect; boundsAspect.m_Value = m_Value; }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { StringAspect stringAspect = clone as StringAspect; stringAspect.m_Value = m_Value; }
/// <summary> /// Adds an aspect to the list of watched aspects. /// </summary> internal void RemoveAspect(MemberAspect aspect) { m_Aspects.Remove(aspect); }
/// <summary> /// Removes an aspect to the list of watched aspects. /// </summary> internal void AddAspect(MemberAspect aspect) { m_Aspects.Add(aspect); }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { RectAspect rectAspect = clone as RectAspect; rectAspect.m_Value = m_Value; }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { FloatAspect floatAspect = clone as FloatAspect; floatAspect.m_Value = m_Value; }
/// <summary> /// A function used to copy all members to a copy of this class. /// </summary> protected override void CloneMembers(MemberAspect clone) { IntAspect intAspect = clone as IntAspect; intAspect.m_Value = m_Value; }