Esempio n. 1
0
        void sceneViewGameControl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (SceneManager.ActiveScene == null) return;

            if (e.Data.GetDataPresent(typeof(ExplorerTreeViewItem)))
            {
                FieldInfo info;
                object obj;
                info = e.Data.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
                obj = info.GetValue(e.Data);
                info = obj.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
                System.Windows.DataObject dataObj = info.GetValue(obj) as System.Windows.DataObject;
                ExplorerTreeViewItem item = dataObj.GetData(typeof(ExplorerTreeViewItem)) as ExplorerTreeViewItem;

                if (EditorUtils.isDirectory(item.FullPath)) return;

                string relativePath = item.FullPath.Replace(SceneManager.GameProject.ProjectPath + "\\", string.Empty);
                string name = System.IO.Path.GetFileNameWithoutExtension(relativePath);

                
                string[] extensions = item.Text.ToLower().Split('.');


                string secundaryExtension = string.Empty;
                if (extensions.Length > 2)
                    secundaryExtension = extensions[extensions.Length - 2];

                GameObject objToAdd = null;

                if (secundaryExtension.ToLower().Equals(Properties.Settings.Default.secundaryExtension))
                {
                    objToAdd = new AnimatedSprite() { ImageName = relativePath, Name = name.ToLower().Replace("." + Properties.Settings.Default.secundaryExtension, ""), TotalFramesPerRow = 1, TotalRows = 1 };
                }
                else
                {
                    string extension = extensions.Last();

                    switch (extension)
                    {
                        case "png":
                        case "jpeg":
                        case "jpg":
                        case "gif":
                        case "bmp":
                            objToAdd = new Sprite() { ImageName = relativePath, Name = name };
                            break;
                        case "mp3":
                        case "wav":
                            objToAdd = new AudioObject() { FilePath = relativePath, Name = name };
                            break;
                    }
                }

                if (objToAdd != null)
                {
                    EditorHandler.SceneTreeView.AddGameObject(objToAdd, "", true);
                    EditorHandler.ChangeSelectedObjects();
                }
                
                
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        private void AddGameObject(GameObject gameObject, string type)
        {
            if (gameObject == null)
            {
                switch (type.ToLower())
                {
                    case "empty":
                        gameObject = new GameObject();
                        gameObject.Name = "Empty Game Object";

                        break;

                    case "sprite":
                        gameObject = new Sprite();
                        gameObject.Name = "Sprite Game Object"; 

                        break;

                    case "animatedsprite":
                        gameObject = new AnimatedSprite();
                        gameObject.Name = "Animated Sprite Game Object";

                        break;

                    case "audio":
                        gameObject = new AudioObject();
                        gameObject.Name = "Audio Game Object";

                        break;

                    case "tileset":
                        gameObject = new Tileset();
                        gameObject.Name = "Tileset Game Object";

                        break;

                    case "bmfont":
                        gameObject = new BMFont();
                        gameObject.Name = "Bitmap Font Object";

                        break;
                } 
            }
            else
            {
                gameObject.Initialize();
            }

            if (SelectedNode.Tag is Layer)
            {
                Layer layer = (Layer)SelectedNode.Tag;
                layer.GameObjects.Add(gameObject);
            }
            else if (SelectedNode.Tag is GameObject)
            {
                GameObject _gameObject = (GameObject)SelectedNode.Tag;
                _gameObject.Children.Add(gameObject);
            }

            if (gameObject != null)
            {
                TreeNode node = AddNode(SelectedNode, gameObject, GameObjectImageIndex(gameObject));
                node.ContextMenuStrip = objectContextMenuStrip;

                EditorHandler.SelectedGameObjects = new List<GameObject>();
                EditorHandler.SelectedGameObjects.Add(gameObject);
            }
        }
        internal void AddGameObject(GameObject gameObject, string type, bool autoselect = true)
        {
            if (gameObject == null)
            {
                switch (type.ToLower())
                {
                    case "empty":
                        gameObject = new GameObject();
                        gameObject.Name = "Empty Game Object";

                        break;

                    case "sprite":
                        gameObject = new Sprite();
                        gameObject.Name = "Sprite Game Object";

                        break;

                    case "animatedsprite":
                        gameObject = new AnimatedSprite();
                        gameObject.Name = "Animated Sprite Game Object";

                        break;

                    case "audio":
                        gameObject = new AudioObject();
                        gameObject.Name = "Audio Game Object";

                        break;

                    case "tileset":
                        gameObject = new Tileset();
                        gameObject.Name = "Tileset Game Object";

                        break;

                    case "bmfont":
                        gameObject = new BMFont();
                        gameObject.Name = "Bitmap Font Object";

                        break;

                    case "particleemitter":
                        gameObject = new ParticleEmitter();
                        gameObject.Name = "Particle Emitter Object";

                        break;
                }
            }
            else
            {
                gameObject.Initialize();
            }

            if (SelectedItem == null)
            {
                SceneManager.ActiveScene.GameObjects.Add(gameObject);
            }
            else
            {
                GameObject _gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag;
                _gameObject.Children.Add(gameObject);
            }

            if (gameObject != null)
            {
                DragDropTreeViewItem node = AddNode(SelectedItem as DragDropTreeViewItem, gameObject, GameObjectImageSource(gameObject));
                node.ContextMenu = contextMenu;
                // AddNodes(gameObject);
                //node.IsSelected = true;

                AttachChildren(node);
                //foreach (GameObject _obj in gameObject.Children)
                //    AddGameObject(_obj, string.Empty);

                if (autoselect)
                {
                    EditorHandler.SelectedGameObjects = new List<GameObject>();
                    EditorHandler.SelectedGameObjects.Add(gameObject);
                }
            }
        }
        internal void AddGameObject(GameObject gameObject, string type, bool autoselect = true, bool addToSelectedParent = false, bool expand = false)
        {
            if (gameObject == null)
            {
                switch (type.ToLower())
                {
                    case "empty":
                        gameObject = new GameObject();
                        gameObject.Name = "Empty Game Object";

                        break;

                    case "sprite":
                        gameObject = new Sprite();
                        gameObject.Name = "Sprite Game Object";

                        break;

                    case "animatedsprite":
                        gameObject = new AnimatedSprite();
                        gameObject.Name = "Animated Sprite Game Object";

                        break;

                    case "audio":
                        gameObject = new AudioObject();
                        gameObject.Name = "Audio Game Object";

                        break;

                    case "tileset":
                        gameObject = new Tileset();
                        gameObject.Name = "Tileset Game Object";

                        break;

                    case "bmfont":
                        gameObject = new BMFont();
                        gameObject.Name = "Bitmap Font Object";

                        break;

                    case "particleemitter":
                        gameObject = new ParticleEmitter();
                        gameObject.Name = "Particle Emitter Object";

                        break;
                }
            }
            else
            {
                gameObject.Initialize();
            }

            if (SelectedItem == null)
            {
                SceneManager.ActiveScene.GameObjects.Add(gameObject);
            }
            else
            {
                if (addToSelectedParent)
                {
                    GameObject _gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag;
                    if (_gameObject.Transform.Parent == null)
                        SceneManager.ActiveScene.GameObjects.Add(gameObject);
                    else
                        _gameObject.Transform.Parent.GameObject.Children.Add(gameObject);
                }
                else
                {
                    GameObject _gameObject = (GameObject)(SelectedItem as DragDropTreeViewItem).Tag;
                    _gameObject.Children.Add(gameObject);
                }
            }

            if (gameObject != null)
            {
                DragDropTreeViewItem _parent = SelectedItem as DragDropTreeViewItem;
                if (addToSelectedParent)
                {
                    var tmp = EditorUtils.FindVisualParent<DragDropTreeViewItem>(_parent);

                    if (tmp != null)
                        _parent = tmp;
                    else
                        _parent = null;
                }

                DragDropTreeViewItem node = AddNode(_parent, gameObject, GameObjectImageSource(gameObject));

                if (_parent != null && expand)
                {
                    //_parent.ExpandSubtree();
                    _parent.IsExpanded = true;
                }

                node.ContextMenu = contextMenu;
                // AddNodes(gameObject);
                //node.IsSelected = true;

                AttachChildren(node);
                //foreach (GameObject _obj in gameObject.Children)
                //    AddGameObject(_obj, string.Empty);

                if (autoselect)
                {
                    node.IsSelected = true;
                    EditorHandler.SelectedGameObjects = new List<GameObject>();
                    EditorHandler.SelectedGameObjects.Add(gameObject);
                }
            }
        }
        private void TryAdd()
        {
            try
            {
                string name = (nameTextBox.Text.Trim().Equals(string.Empty) ? "New Game Object" : nameTextBox.Text);

                GameObject obj = new GameObject();
                switch (itemListBox.SelectedIndex)
                {
                    case 1:
                        obj = new Sprite();
                        break;
                    case 2:
                        obj = new AnimatedSprite();
                        break;
                    case 3:
                        obj = new Tileset();
                        break;
                    case 4:
                        obj = new AudioObject();
                        break;
                    case 5:
                        obj = new BMFont();
                        break;
                    case 6:
                        obj = new ParticleEmitter();
                        break;
                }

                obj.Name = name;
                DragDropTreeViewItem insertedItem;
                if (addToSelectedCheckBox.IsChecked == true)
                {
                    if (targetObject == null)
                        SceneManager.ActiveScene.GameObjects.Add(obj);
                    else
                        targetObject.Children.Add(obj);

                    insertedItem = EditorHandler.SceneTreeView.AddNode(target as DragDropTreeViewItem, obj, EditorHandler.SceneTreeView.GameObjectImageSource(obj));
                }
                else
                {
                    SceneManager.ActiveScene.GameObjects.Add(obj);
                    insertedItem = EditorHandler.SceneTreeView.AddNode(null, obj, EditorHandler.SceneTreeView.GameObjectImageSource(obj));

                }

                EditorHandler.SelectedGameObjects.Clear();
                EditorHandler.SelectedGameObjects.Add(obj);
                EditorHandler.ChangeSelectedObjects();

                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }