Exemple #1
0
        public static GameProjectLoadResult LoadProject(GameProjectData objectData)
        {
            GameProjectLoadResult result;

            if (objectData == null || objectData.ObjectData == null)
            {
                result = null;
            }
            else
            {
                GameProjectLoadResult          gameProjectLoadResult = new GameProjectLoadResult();
                Dictionary <int, VisualObject> dictionary            = new Dictionary <int, VisualObject>();
                CSCocosHelp.RefreshLayoutSystemState(false);
                BaseRecorder.IsCreateDefaultRecorder     = false;
                gameProjectLoadResult.RootObject         = GameProjectLoader.ConvertObject(objectData.ObjectData, gameProjectLoadResult, dictionary);
                gameProjectLoadResult.RootObject.CanEdit = true;
                CSCocosHelp.RefreshLayoutSystemState(true);
                BaseRecorder.IsCreateDefaultRecorder = true;
                GameProjectLoader.RefreshObjectsRecorder(gameProjectLoadResult.RootObject);
                if (objectData.Animation != null)
                {
                    gameProjectLoadResult.TimelineAction = GameProjectLoader.ConvertTimeLineAction(objectData.Animation, gameProjectLoadResult.RootObject, dictionary);
                }
                result = gameProjectLoadResult;
            }
            return(result);
        }
 public override void Load(IProgressMonitor monitor)
 {
     if (!this.isLoaded)
     {
         GameProjectLoadResult gameProjectLoadResult = GameProjectLoader.LoadProject(this.Content);
         gameProjectLoadResult.RootObject.IconVisible = false;
         gameProjectLoadResult.RootObject.IsSelected  = false;
         gameProjectLoadResult.RootObject.Alpha       = 255;
         gameProjectLoadResult.RootObject.CColor      = Color.FromArgb(255, 255, 255, 255);
         this.RootVisualObject = gameProjectLoadResult.RootObject;
         this.TimelineAction   = gameProjectLoadResult.TimelineAction;
         this.TimelineAction.InitWithRootNode(this.RootVisualObject as NodeObject);
         this.TypeIndex = gameProjectLoadResult.TypeIndex;
         this.isLoaded  = true;
     }
 }
        public override void Load(IProgressMonitor monitor)
        {
            if (this.isLoaded)
            {
                return;
            }
            GameProjectLoadResult projectLoadResult = GameProjectLoader.LoadProject(this.Content);

            projectLoadResult.RootObject.IconVisible = false;
            projectLoadResult.RootObject.IsSelected  = false;
            projectLoadResult.RootObject.Alpha       = (int)byte.MaxValue;
            projectLoadResult.RootObject.CColor      = Color.FromArgb((int)byte.MaxValue, (int)byte.MaxValue, (int)byte.MaxValue, (int)byte.MaxValue);
            this.RootVisualObject = (VisualObject)projectLoadResult.RootObject;
            this.TimelineAction   = projectLoadResult.TimelineAction;
            this.TimelineAction.InitWithRootNode(this.RootVisualObject as NodeObject);
            this.TypeIndex = projectLoadResult.TypeIndex;
            this.isLoaded  = true;
        }
        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);
        }
Exemple #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);
        }