private void ReassignElements(TRVGameObjectElementViewModel element, TRVGameObjectElementViewModel newParent)
        {
            // remove the game object from its old parrent
            if (element.Parent != null)
            {
                element.Parent.RemoveChild(element);
            }
            else if (Root.Contains(element))
            {
                Root.Remove(element);
            }
            else
            {
                // element not found
                return;
            }

            // add the game object to its new parent
            if (newParent != null)
            {
                newParent.AddChild(element);
                OnElementReassigning(element.GameObject, newParent.GameObject);
            }
            else
            {
                Root.Add(element);
                OnElementReassigning(element.GameObject, null);
            }

        }
 public void AddChild(TRVGameObjectElementViewModel element) 
 {
     if (element.Parent != null)
     {
         if (element.Parent == this)
             Console.WriteLine("GOElemenetView::AddChild > Element to add is already attached to this parent");
         else
             Console.WriteLine("GOElemenetView::AddChild > Element to add is already attached to another GameObject. Detach it from it's current parent before attaching it to another one.");
         return;
     }
     Children.Add(element);
     element.Parent = this;
 }
        private void TryRemoveChild(TRVGameObjectElementViewModel element)
        {
            foreach (TRVGameObjectElementViewModel child in Children)
            {
                if (child.Children.Contains(element))
                {
                    RemoveChild(element,false);
                    return;
                }

                child.TryRemoveChild(element);
            }
            return;
        }
        public void RemoveChild(TRVGameObjectElementViewModel element, bool searchChildren = true)
        {
            if (Children.Contains(element) )
            {
                Children.Remove(element);
                element.Parent = null;
                return;
            }

            if (searchChildren)
            {
                TryRemoveChild(element);
            }

        }
        public void OnGameObectAdded(object sender,GameObjectEventArgs e) 
        {
            TRVGameObjectElementViewModel element = new TRVGameObjectElementViewModel(e.GameObject);
            element.ElementReassigning += OnElementReassigning;
            Root.Add(element);

            foreach (var child in e.GameObject.Children)
            {
                AddChildToParrent(child, element);
            }
        }
 private void RemoveInChildren(TRVGameObjectElementViewModel childElement,GameObject gameObject) 
 {
     childElement.Children.RemoveAll(element => (element.GameObject == gameObject));
     
     foreach (var child in childElement.Children)
     {
         RemoveInChildren(child, gameObject);
     }        
 }
        private void AddChildToParrent(GameObject gameObject,TRVGameObjectElementViewModel parent)
        {
            TRVGameObjectElementViewModel element = new TRVGameObjectElementViewModel(gameObject);
            element.ElementReassigning += OnElementReassigning;
            parent.AddChild(element);

            foreach (var child in gameObject.Children)
            {
                AddChildToParrent(child, element);
            }
        }
 //*******************************************************//
 //                      METHODS                          //
 //*******************************************************//
 public TRVGameObjectElementViewModel(GameObject obj,TRVGameObjectElementViewModel parent = null) 
 {
     _parent = parent;
     GameObject = obj;
 }
 protected virtual void OnElementReassigning(TRVGameObjectElementViewModel element, TRVGameObjectElementViewModel newParent)
 {
     if (ElementReassigning != null)
         ElementReassigning(this, new ElementReassigningEventArgs() { Element = element, NewParent = newParent });
 }