﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Arugula
{
    public static class SymParentExtensions
    {
        public static void SymParent(this Transform t, Transform parent)
        {
            SymParent p = parent.GetComponent<SymParent>();
            if (!p)
                parent.gameObject.AddComponent<SymParent>();

            SymChild s = t.GetComponent<SymChild>();
            if (s)
            {
                s.parent.children.Remove(t);
                if (s.parent.transform != parent)
                    p.children.Add(t);

            }
            else
            {
                s = t.gameObject.AddComponent<SymChild>();
                s.parent = p;
            }
        }
    }

    public class SymParent : MonoBehaviour
    {
        public List<Transform> children = new List<Transform>();

        private void OnDestroy()
        {
            foreach (var c in children)
                Destroy(c.gameObject);
        }
    }
}
