Пример #1
0
 private static void ConvertTimeLineActionData(NodeObject nObject, TimelineActionData nTimelineActionData)
 {
     foreach (NodeObject current in nObject.Children)
     {
         GameProjectLoader.ConvertTimeLineActionData(current, nTimelineActionData);
         foreach (Timeline current2 in current.Timelines)
         {
             if (current2.Frames.Count > 0)
             {
                 TimelineData timelineData = new TimelineData();
                 timelineData.ActionTag = current.ActionTag;
                 timelineData.FrameType = current2.FrameType;
                 timelineData.Frames    = new List <FrameData>();
                 foreach (Frame current3 in current2.OrderedFrames)
                 {
                     string name = current3.GetType().BaseType.Name;
                     if (name == "Frame")
                     {
                         name = current3.GetType().Name;
                     }
                     string    newValue  = name + "Data";
                     string    typeName  = current3.GetType().FullName.Replace("CocoStudio.Model.ViewModel", "CocoStudio.Model.DataModel").Replace(current3.GetType().Name, newValue);
                     FrameData frameData = Activator.CreateInstance(Type.GetType(typeName), true) as FrameData;
                     if (frameData != null)
                     {
                         PropertyInfo[] properties = current3.GetType().GetProperties();
                         PropertyInfo[] array      = properties;
                         for (int i = 0; i < array.Length; i++)
                         {
                             PropertyInfo propertyInfo = array[i];
                             string       name2        = propertyInfo.Name;
                             if (!(name2 == "Children"))
                             {
                                 PropertyInfo property = frameData.GetType().GetProperty(name2);
                                 object       value    = propertyInfo.GetValue(current3, 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(frameData, obj, null);
                                 }
                             }
                         }
                         timelineData.Frames.Add(frameData);
                     }
                 }
                 nTimelineActionData.Timelines.Add(timelineData);
             }
         }
     }
 }
Пример #2
0
 private static void ConvertTimeLineActionData(NodeObject nObject, TimelineActionData nTimelineActionData)
 {
     foreach (NodeObject child in (Collection <NodeObject>)nObject.Children)
     {
         GameProjectLoader.ConvertTimeLineActionData(child, nTimelineActionData);
         foreach (Timeline timeline in (Collection <Timeline>)child.Timelines)
         {
             if (timeline.Frames.Count > 0)
             {
                 TimelineData timelineData = new TimelineData();
                 timelineData.ActionTag = child.ActionTag;
                 timelineData.FrameType = timeline.FrameType;
                 timelineData.Frames    = new List <FrameData>();
                 foreach (Frame orderedFrame in timeline.OrderedFrames)
                 {
                     string name1 = orderedFrame.GetType().BaseType.Name;
                     if (name1 == "Frame")
                     {
                         name1 = orderedFrame.GetType().Name;
                     }
                     string    newValue = name1 + "Data";
                     FrameData instance = Activator.CreateInstance(Type.GetType(orderedFrame.GetType().FullName.Replace("CocoStudio.Model.ViewModel", "CocoStudio.Model.DataModel").Replace(orderedFrame.GetType().Name, newValue)), true) as FrameData;
                     if (instance != null)
                     {
                         foreach (PropertyInfo property1 in orderedFrame.GetType().GetProperties())
                         {
                             string name2 = property1.Name;
                             if (!(name2 == "Children"))
                             {
                                 PropertyInfo property2  = instance.GetType().GetProperty(name2);
                                 object       viewObject = property1.GetValue((object)orderedFrame, (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);
                                 }
                             }
                         }
                         timelineData.Frames.Add(instance);
                     }
                 }
                 nTimelineActionData.Timelines.Add(timelineData);
             }
         }
     }
 }
Пример #3
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
            });
        }
Пример #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);
        }