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);
        }
        private static HashSet <ResourceData> ScanObjectData(NodeObjectData parentNodeData)
        {
            PropertyAccessorHandler[] resourceProperties = parentNodeData.GetResourceProperties();
            HashSet <ResourceData>    resourceDataSet    = new HashSet <ResourceData>();

            if (resourceProperties != null)
            {
                foreach (PropertyAccessorHandler propertyAccessorHandler in resourceProperties)
                {
                    ResourceItemData resourceItemData = propertyAccessorHandler.GetValue((object)parentNodeData, (object[])null) as ResourceItemData;
                    if ((ResourceData)resourceItemData != (ResourceData)null)
                    {
                        resourceDataSet.Add((ResourceData)resourceItemData);
                    }
                }
            }
            if (parentNodeData.Children != null)
            {
                foreach (NodeObjectData child in parentNodeData.Children)
                {
                    resourceDataSet.UnionWith((IEnumerable <ResourceData>)GameProjectContent.ScanObjectData(child));
                }
            }
            return(resourceDataSet);
        }
示例#3
0
        private static NodeObjectData ConvertObjectData(NodeObject nObject)
        {
            Type           dataModelType  = Services.ProjectsService.DataModelManager.GetDataModelType(nObject.GetType());
            NodeObjectData nodeObjectData = Activator.CreateInstance(dataModelType, true) as NodeObjectData;
            NodeObjectData result;

            if (nodeObjectData == null)
            {
                result = null;
            }
            else
            {
                PropertyInfo[] properties = nObject.GetType().GetProperties();
                PropertyInfo[] array      = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyInfo propertyInfo = array[i];
                    string       name         = propertyInfo.Name;
                    if (!(name == "Children"))
                    {
                        PropertyInfo property = nodeObjectData.GetType().GetProperty(name);
                        object       value    = propertyInfo.GetValue(nObject, null);
                        if (property != null && value != null)
                        {
                            object obj = value;
                            if (!property.PropertyType.Equals(propertyInfo.PropertyType))
                            {
                                obj = Activator.CreateInstance(property.PropertyType, true);
                                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.", nObject.GetType().Name, propertyInfo.PropertyType.Name, property.PropertyType.Name);
                                    throw new InvalidCastException(message);
                                }
                                ((IDataConvert)obj).SetData(value);
                            }
                            property.SetValue(nodeObjectData, obj, null);
                        }
                    }
                }
                if (nObject.Children == null || nObject.Children.Count <= 0)
                {
                    result = nodeObjectData;
                }
                else
                {
                    nodeObjectData.Children = new List <NodeObjectData>();
                    foreach (NodeObject current in nObject.Children)
                    {
                        NodeObjectData item = GameProjectLoader.ConvertObjectData(current);
                        nodeObjectData.Children.Add(item);
                    }
                    result = nodeObjectData;
                }
            }
            return(result);
        }
        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);
        }
        private static bool CheckReferenceProjectInObjectData(NodeObjectData parentNode, Project project, ResourceData projectPath)
        {
            bool result;

            if (parentNode == null)
            {
                result = false;
            }
            else
            {
                ProjectNodeObjectData projectNodeObjectData = parentNode as ProjectNodeObjectData;
                if (projectNodeObjectData != null)
                {
                    ResourceItemData fileData = projectNodeObjectData.FileData;
                    if (projectPath.Equals(fileData))
                    {
                        result = true;
                        return(result);
                    }
                    if (fileData != null)
                    {
                        Project project2 = Services.ProjectsService.CurrentResourceGroup.FindResourceItem(fileData) as Project;
                        if (project2 != null)
                        {
                            bool flag = project2.HasReferencedProject(project);
                            if (flag)
                            {
                                result = true;
                                return(result);
                            }
                        }
                    }
                }
                if (parentNode.Children != null)
                {
                    foreach (NodeObjectData current in parentNode.Children)
                    {
                        bool flag2 = GameProjectContent.CheckReferenceProjectInObjectData(current, project, projectPath);
                        if (flag2)
                        {
                            result = true;
                            return(result);
                        }
                    }
                }
                result = false;
            }
            return(result);
        }
        private static bool UpdateResourcesInObjectData(NodeObjectData parentNodeData, ChangedResourceCollection changedResourceCollection)
        {
            PropertyAccessorHandler[] resourceProperties = parentNodeData.GetResourceProperties();
            if (resourceProperties == null)
            {
                return(false);
            }
            bool flag1 = false;

            foreach (PropertyAccessorHandler propertyAccessorHandler in resourceProperties)
            {
                ResourceItemData resourceItemData = propertyAccessorHandler.GetValue((object)parentNodeData, (object[])null) as ResourceItemData;
                if (!((ResourceData)resourceItemData == (ResourceData)null))
                {
                    ResourceFile resourceFile = (ResourceFile)null;
                    if (changedResourceCollection.TryGetValue((ResourceData)resourceItemData, out resourceFile))
                    {
                        if (resourceFile != null)
                        {
                            resourceItemData.Update(resourceFile.GetResourceData());
                        }
                        else
                        {
                            propertyAccessorHandler.SetValue((object)parentNodeData, (object)null, (object[])null);
                        }
                        if (!flag1)
                        {
                            flag1 = true;
                        }
                    }
                }
            }
            if (parentNodeData.Children != null)
            {
                foreach (NodeObjectData child in parentNodeData.Children)
                {
                    bool flag2 = GameProjectContent.UpdateResourcesInObjectData(child, changedResourceCollection);
                    if (!flag1 && flag2)
                    {
                        flag1 = flag2;
                    }
                }
            }
            return(flag1);
        }
        public static GameProjectData SaveProject(NodeObject vObject, TimelineAction action)
        {
            if (vObject == null)
            {
                return((GameProjectData)null);
            }
            NodeObjectData     nodeObjectData      = GameProjectLoader.ConvertObjectData(vObject);
            TimelineActionData nTimelineActionData = new TimelineActionData();

            nTimelineActionData.Duration = action.Duration;
            nTimelineActionData.Speed    = action.Speed;
            GameProjectLoader.ConvertTimeLineActionData(vObject, nTimelineActionData);
            return(new GameProjectData()
            {
                ObjectData = nodeObjectData,
                Animation = nTimelineActionData
            });
        }
        private static NodeObjectData ConvertObjectData(NodeObject nObject)
        {
            NodeObjectData instance = Activator.CreateInstance(Services.ProjectsService.DataModelManager.GetDataModelType(nObject.GetType()), true) as NodeObjectData;

            if (instance == null)
            {
                return((NodeObjectData)null);
            }
            foreach (PropertyInfo property1 in nObject.GetType().GetProperties())
            {
                string name = property1.Name;
                if (!(name == "Children"))
                {
                    PropertyInfo property2  = instance.GetType().GetProperty(name);
                    object       viewObject = property1.GetValue((object)nObject, (object[])null);
                    if (property2 != (PropertyInfo)null && viewObject != null)
                    {
                        object obj = viewObject;
                        if (!property2.PropertyType.Equals(property1.PropertyType))
                        {
                            obj = Activator.CreateInstance(property2.PropertyType, true);
                            if (!(obj is IDataConvert))
                            {
                                throw new InvalidCastException(string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", (object)nObject.GetType().Name, (object)property1.PropertyType.Name, (object)property2.PropertyType.Name));
                            }
                            ((IDataConvert)obj).SetData(viewObject);
                        }
                        property2.SetValue((object)instance, obj, (object[])null);
                    }
                }
            }
            if (nObject.Children == null || nObject.Children.Count <= 0)
            {
                return(instance);
            }
            instance.Children = new List <NodeObjectData>();
            foreach (NodeObject child in (Collection <NodeObject>)nObject.Children)
            {
                NodeObjectData nodeObjectData = GameProjectLoader.ConvertObjectData(child);
                instance.Children.Add(nodeObjectData);
            }
            return(instance);
        }
示例#9
0
        public static GameProjectData SaveProject(NodeObject vObject, TimelineAction action)
        {
            GameProjectData result;

            if (vObject == null)
            {
                result = null;
            }
            else
            {
                NodeObjectData     objectData         = GameProjectLoader.ConvertObjectData(vObject);
                TimelineActionData timelineActionData = new TimelineActionData();
                timelineActionData.Duration = action.Duration;
                timelineActionData.Speed    = action.Speed;
                GameProjectLoader.ConvertTimeLineActionData(vObject, timelineActionData);
                result = new GameProjectData
                {
                    ObjectData = objectData,
                    Animation  = timelineActionData
                };
            }
            return(result);
        }
        private static bool CheckReferenceProjectInObjectData(NodeObjectData parentNode, Project project, ResourceData projectPath)
        {
            if (parentNode == null)
            {
                return(false);
            }
            ProjectNodeObjectData projectNodeObjectData = parentNode as ProjectNodeObjectData;

            if (projectNodeObjectData != null)
            {
                ResourceItemData fileData = projectNodeObjectData.FileData;
                if (projectPath.Equals((ResourceData)fileData))
                {
                    return(true);
                }
                if ((ResourceData)fileData != (ResourceData)null)
                {
                    Project resourceItem = Services.ProjectsService.CurrentResourceGroup.FindResourceItem((ResourceData)fileData) as Project;
                    if (resourceItem != null && resourceItem.HasReferencedProject(project))
                    {
                        return(true);
                    }
                }
            }
            if (parentNode.Children != null)
            {
                foreach (NodeObjectData child in parentNode.Children)
                {
                    if (GameProjectContent.CheckReferenceProjectInObjectData(child, project, projectPath))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#11
0
        public GameProjectData(NodeType type)
        {
            this.Animation = new TimelineActionData();
            switch (type)
            {
            case NodeType.Scene:
                this.ObjectData = (NodeObjectData) new SingleNodeObjectData();
                break;

            case NodeType.Layer:
                this.ObjectData = (NodeObjectData) new LayerObjectData();
                break;

            case NodeType.Node:
                this.ObjectData = (NodeObjectData) new SingleNodeObjectData();
                break;

            default:
                this.ObjectData = (NodeObjectData) new SingleNodeObjectData();
                break;
            }
            this.ObjectData.Tag  = VisualObject.tag;
            this.ObjectData.Name = type.ToString();
        }
示例#12
0
 public GameProjectData()
 {
     this.ObjectData = (NodeObjectData) new SingleNodeObjectData();
     this.Animation  = new TimelineActionData();
 }
示例#13
0
        private static NodeObject ConvertObject(NodeObjectData objectData, GameProjectLoadResult gResult, Dictionary <int, VisualObject> objectDictionary)
        {
            NodeObject instance = Activator.CreateInstance(Services.ProjectsService.DataModelManager.GetViewModelType(objectData.GetType()), true) as NodeObject;

            if (instance == null)
            {
                return((NodeObject)null);
            }
            instance.IsAutoSize = objectData.IsAutoSize;
            foreach (PropertyAccessorHandler property1 in objectData.GetProperties())
            {
                string propertyName = property1.PropertyName;
                if (!(propertyName == "Children"))
                {
                    PropertyInfo property2 = instance.GetType().GetProperty(propertyName);
                    object       obj1      = property1.GetValue((object)objectData, (object[])null);
                    if (property2 != (PropertyInfo)null && obj1 != null)
                    {
                        object obj2 = obj1;
                        if (!property2.PropertyType.Equals(property1.PropertyType))
                        {
                            if (!(obj1 is IDataConvert))
                            {
                                throw new InvalidCastException(string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", (object)instance.GetType().Name, (object)property2.PropertyType.Name, (object)property1.PropertyType.Name));
                            }
                            obj2 = ((IDataConvert)obj1).CreateViewModel();
                        }
                        property2.SetValue((object)instance, obj2, (object[])null);
                    }
                }
            }
            if (!objectDictionary.ContainsKey(instance.ActionTag))
            {
                objectDictionary.Add(instance.ActionTag, (VisualObject)instance);
            }
            IDataInitialize dataInitialize = (IDataInitialize)objectData;

            if (dataInitialize != null)
            {
                dataInitialize.DataInitialize((VisualObject)instance);
            }
            Type type = instance.GetType();

            if (gResult.TypeIndex.ContainsKey(type))
            {
                if (instance.ObjectIndex > gResult.TypeIndex[type])
                {
                    gResult.TypeIndex[type] = instance.ObjectIndex;
                }
            }
            else
            {
                gResult.TypeIndex.Add(type, instance.ObjectIndex);
            }
            if (objectData.Children != null)
            {
                foreach (NodeObjectData child in objectData.Children)
                {
                    NodeObject nodeObject = GameProjectLoader.ConvertObject(child, gResult, objectDictionary);
                    instance.Children.Add(nodeObject);
                }
            }
            instance.IsAutoSize = false;
            return(instance);
        }
示例#14
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);
        }