Пример #1
0
        private void ItemDoubleClicked(FileModel file)
        {
            if (file.Extension.ToLower() == ".ovm")
            {
                var obj = new GameObject();
                obj.Name = NameManeger.GetNameFromPath(file.FilePath);

                var modelcomp = new ModelComponent(file.FilePath);
                modelcomp.Shader = new PosNormColEffect();
                obj.AddComponent(modelcomp);
                UndoRedoStack.ClearRedoStack();
                GameObjectManager.Instance().AddGameObject(obj);
            }
            if (file.Extension.ToLower() == ".xmlprefab")
            {
                LoadPrefab(file.FilePath);
            }
            if (file.Extension.ToLower() == ".xmlmap")
            {
                GoManager.Clear();

                XMLLoader xmlLoader = new XMLLoader();
                xmlLoader.AddingObject += GoManager.OnAddingObject;
                xmlLoader.LoadXMLMap(file.FilePath,_CurrentProjectPath);
                UndoRedoStack.Clear();
            }
        }
Пример #2
0
        private void LoadComponents(GameObject gameobject, XElement components, string currentProjectPath) 
        {
            if (components == null)
            {
                //Warn user that filename was not found
                MessageBox.Show(String.Format("{0}: No components found", gameobject.Name), "XMLLoader Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            XElement xTranformComponent = components.Element("TransformComponent");
            if (xTranformComponent != null)
            {
                XElement xPosition = xTranformComponent.Element("Position");
                if (xPosition != null)
                {
                    float parseOut;
                    XElement xX = xPosition.Element("X");
                    if (xX != null)
                    {
                        if (!float.TryParse((string)xX.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut)) 
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Position.X = parseOut;
                    }

                    XElement xY = xPosition.Element("Y");
                    if (xY != null)
                    {
                        if (!float.TryParse((string)xY.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Position.Y = parseOut;
                    }

                    XElement xZ = xPosition.Element("Z");
                    if (xZ != null)
                    {
                        if (!float.TryParse((string)xZ.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Position.Z = parseOut;
                    }
                }

                XElement xRotation = xTranformComponent.Element("Rotation");
                if (xRotation != null)
                {
                    float parseOut;
                    XElement xX = xRotation.Element("X");
                    if (xX != null)
                    {
                        if (!float.TryParse((string)xX.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.RotationEuler.X = parseOut;
                    }

                    XElement xY = xRotation.Element("Y");
                    if (xY != null)
                    {
                        if (!float.TryParse((string)xY.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.RotationEuler.Y = parseOut;
                    }

                    XElement xZ = xRotation.Element("Z");
                    if (xZ != null)
                    {
                        if (!float.TryParse((string)xZ.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.RotationEuler.Z = parseOut;
                    }
                }

                XElement xScale = xTranformComponent.Element("Scale");
                if (xScale != null)
                {
                    float parseOut;
                    XElement xX = xScale.Element("X");
                    if (xX != null)
                    {
                        if (!float.TryParse((string)xX.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Scale.X = parseOut;
                    }

                    XElement xY = xScale.Element("Y");
                    if (xY != null)
                    {
                        if (!float.TryParse((string)xY.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Scale.Y = parseOut;
                    }

                    XElement xZ = xScale.Element("Z");
                    if (xZ != null)
                    {
                        if (!float.TryParse((string)xZ.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out parseOut))
                        {
                            MessageBox.Show(String.Format("Parse error in Transform component: {0}", gameobject.Name), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            parseOut = 0;
                        }
                        gameobject.Transform.Scale.Z = parseOut;
                    }
                }
            }
            else
            {
                MessageBox.Show(String.Format("{0}: No TransformComponent found", gameobject.Name), "XMLLoader Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            XElement xModelComponent = components.Element("ModelComponent");
            if (xModelComponent != null)
            {
                XElement xFilePath = xModelComponent.Element("FilePath");
                if (xFilePath != null)
                {
                    string fullFilePath = currentProjectPath + "\\" + (string)xFilePath.Value;
                    if (!File.Exists(fullFilePath))
                    {
                        MessageBox.Show("ModelComponent: File does not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    ModelComponent modelComponent = new ModelComponent(fullFilePath);
                    modelComponent.Shader = new PosNormColEffect();
                    gameobject.AddComponent(modelComponent);
                }
                else 
                {
                    //Warn user that filename was not found
                    MessageBox.Show(String.Format("{0}: ModelComponent was found but no filename", gameobject.Name), "XMLLoader Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }    
        }