/// <summary> /// Invoked by Unity.Properties for each list container type (i.e. Array or IList type) /// </summary> /// <remarks> /// This will be called for built in array types. /// </remarks> /// <param name="properties">The property bag being visited.</param> /// <param name="srcContainer">The source list being visited.</param> /// <typeparam name="TList">The list type.</typeparam> /// <typeparam name="TElement">The element type.</typeparam> void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList srcContainer) { // Unbox the current destination container being written to. var dstContainer = (TList)m_Stack; if (typeof(TList).IsArray) { // We assume the list has been initialized correctly by a previous call to CloneValue. var index = 0; foreach (var element in srcContainer) { var value = default(TElement); CloneValue(ref value, element); dstContainer[index++] = value; } } else { dstContainer.Clear(); foreach (var element in srcContainer) { var value = default(TElement); CloneValue(ref value, element); dstContainer.Add(value); } } // Re-box the container. m_Stack = dstContainer; }
/// <inheritdoc/> void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList container) { foreach (var property in properties.GetProperties(ref container)) { ((IPropertyAccept <TList>)property).Accept(this, ref container); } }
void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList container) { var elements = m_Metadata.HasElements ? m_View.AsObjectView()[k_SerializedElementsKey] : m_View; if (elements.Type != TokenType.Array) { throw new ArgumentException(); } var arr = elements.AsArrayView(); if (typeof(TList).IsArray) { var index = 0; // @FIXME boxing foreach (var element in arr) { var value = default(TElement); ReadValue(ref value, element); container[index++] = value; } } else { container.Clear(); foreach (var element in arr) { var value = default(TElement); ReadValue(ref value, element); container.Add(value); } } }
void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList container) { m_Stream->Add(container.Count); for (var i = 0; i < container.Count; i++) { WriteValue(container[i]); } }
/// <summary> /// Invoked by Unity.Properties for each list container type (i.e. Array or IList type) /// </summary> /// <remarks> /// This will be called for built in array types. /// </remarks> /// <param name="properties">The property bag being visited.</param> /// <param name="srcContainer">The source list being visited.</param> /// <typeparam name="TList">The list type.</typeparam> /// <typeparam name="TElement">The element type.</typeparam> void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList srcContainer) { var dstContainer = (TList)m_Stack; if (srcContainer.Count != dstContainer.Count) { m_Equals = false; return; } for (var i = 0; i < srcContainer.Count; i++) { if (CompareEquality(srcContainer[i], dstContainer[i])) { continue; } m_Equals = false; return; } }
void IListPropertyBagVisitor.Visit <TList, TElement>(IListPropertyBag <TList, TElement> properties, ref TList container) { m_SerializedReferences?.AddDeserializedReference(container); var count = m_Stream->ReadNext <int>(); if (typeof(TList).IsArray) { for (var i = 0; i < count; i++) { container[i] = ReadValue <TElement>(); } } else { container.Clear(); for (var i = 0; i < count; i++) { container.Add(ReadValue <TElement>()); } } }