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);
                }
            }
        }
Exemplo n.º 3
0
        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);
            }
        }