private static HashSet <ResourceData> ScanObjectData(NodeObjectData parentNodeData)
        {
            PropertyAccessorHandler[] resourceProperties = parentNodeData.GetResourceProperties();
            HashSet <ResourceData>    hashSet            = new HashSet <ResourceData>();

            if (resourceProperties != null)
            {
                PropertyAccessorHandler[] array = resourceProperties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyAccessorHandler propertyAccessorHandler = array[i];
                    ResourceItemData        resourceItemData        = propertyAccessorHandler.GetValue(parentNodeData, null) as ResourceItemData;
                    if (resourceItemData != null)
                    {
                        hashSet.Add(resourceItemData);
                    }
                }
            }
            if (parentNodeData.Children != null)
            {
                foreach (NodeObjectData current in parentNodeData.Children)
                {
                    hashSet.UnionWith(GameProjectContent.ScanObjectData(current));
                }
            }
            return(hashSet);
        }
示例#2
0
 private static PropertyAccessorHandler[] CreateProperties(Type type)
 {
     PropertyInfo[]            properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
     PropertyAccessorHandler[] array      = new PropertyAccessorHandler[properties.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = new PropertyAccessorHandler(properties[i]);
     }
     return(array);
 }
示例#3
0
 private static PropertyAccessorHandler[] CreateProperties(Type type)
 {
     PropertyInfo[]            properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
     PropertyAccessorHandler[] propertyAccessorHandlerArray = new PropertyAccessorHandler[properties.Length];
     for (int index = 0; index < propertyAccessorHandlerArray.Length; ++index)
     {
         propertyAccessorHandlerArray[index] = new PropertyAccessorHandler(properties[index]);
     }
     return(propertyAccessorHandlerArray);
 }
        private static bool UpdateResourcesInObjectData(NodeObjectData parentNodeData, ChangedResourceCollection changedResourceCollection)
        {
            PropertyAccessorHandler[] resourceProperties = parentNodeData.GetResourceProperties();
            bool result;

            if (resourceProperties == null)
            {
                result = false;
            }
            else
            {
                bool flag = false;
                PropertyAccessorHandler[] array = resourceProperties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyAccessorHandler propertyAccessorHandler = array[i];
                    ResourceItemData        resourceItemData        = propertyAccessorHandler.GetValue(parentNodeData, null) as ResourceItemData;
                    if (!(resourceItemData == null))
                    {
                        ResourceFile resourceFile = null;
                        if (changedResourceCollection.TryGetValue(resourceItemData, out resourceFile))
                        {
                            if (resourceFile != null)
                            {
                                resourceItemData.Update(resourceFile.GetResourceData());
                            }
                            else
                            {
                                propertyAccessorHandler.SetValue(parentNodeData, null, null);
                            }
                            if (!flag)
                            {
                                flag = true;
                            }
                        }
                    }
                }
                if (parentNodeData.Children != null)
                {
                    foreach (NodeObjectData current in parentNodeData.Children)
                    {
                        bool flag2 = GameProjectContent.UpdateResourcesInObjectData(current, changedResourceCollection);
                        if (!flag && flag2)
                        {
                            flag = flag2;
                        }
                    }
                }
                result = flag;
            }
            return(result);
        }
示例#5
0
        private static NodeObject ConvertObject(NodeObjectData objectData, GameProjectLoadResult gResult, Dictionary <int, VisualObject> objectDictionary)
        {
            Type       viewModelType = Services.ProjectsService.DataModelManager.GetViewModelType(objectData.GetType());
            NodeObject nodeObject    = Activator.CreateInstance(viewModelType, true) as NodeObject;
            NodeObject result;

            if (nodeObject == null)
            {
                result = null;
            }
            else
            {
                nodeObject.IsAutoSize = objectData.IsAutoSize;
                PropertyAccessorHandler[] properties = objectData.GetProperties();
                PropertyAccessorHandler[] array      = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyAccessorHandler propertyAccessorHandler = array[i];
                    string propertyName = propertyAccessorHandler.PropertyName;
                    if (!(propertyName == "Children"))
                    {
                        PropertyInfo property = nodeObject.GetType().GetProperty(propertyName);
                        object       obj      = propertyAccessorHandler.GetValue(objectData, null);
                        if (property != null && obj != null)
                        {
                            object value = obj;
                            if (!property.PropertyType.Equals(propertyAccessorHandler.PropertyType))
                            {
                                if (!(obj is IDataConvert))
                                {
                                    string message = string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", nodeObject.GetType().Name, property.PropertyType.Name, propertyAccessorHandler.PropertyType.Name);
                                    throw new InvalidCastException(message);
                                }
                                value = ((IDataConvert)obj).CreateViewModel();
                            }
                            property.SetValue(nodeObject, value, null);
                        }
                    }
                }
                if (!objectDictionary.ContainsKey(nodeObject.ActionTag))
                {
                    objectDictionary.Add(nodeObject.ActionTag, nodeObject);
                }
                if (objectData != null)
                {
                    ((IDataInitialize)objectData).DataInitialize(nodeObject);
                }
                Type type = nodeObject.GetType();
                if (gResult.TypeIndex.ContainsKey(type))
                {
                    if (nodeObject.ObjectIndex > gResult.TypeIndex[type])
                    {
                        gResult.TypeIndex[type] = nodeObject.ObjectIndex;
                    }
                }
                else
                {
                    gResult.TypeIndex.Add(type, nodeObject.ObjectIndex);
                }
                if (objectData.Children != null)
                {
                    foreach (NodeObjectData current in objectData.Children)
                    {
                        NodeObject item = GameProjectLoader.ConvertObject(current, gResult, objectDictionary);
                        nodeObject.Children.Add(item);
                    }
                }
                nodeObject.IsAutoSize = false;
                result = nodeObject;
            }
            return(result);
        }