Пример #1
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);
        }
Пример #2
0
        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
            });
        }
Пример #3
0
        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);
        }
Пример #4
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);
        }