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

namespace Tap.Tilt
{
    public class SelectionController : ObjectController
    {

        // The game object to show selection
        public GameObject selectionObject;

        private ObjectController[] ocs;

        // When an object is selected, see if it has a controller of any of these types
        // to run the Selector script on

        public void TriggerEnter(GameObject other)
        {
            Indicate();
        }
        public void TriggerLeave()
        {
            Dimmer();
        }

        public void OnEnable()
        {
            ocs = GetComponents<ObjectController>();
            Dimmer();
        }

        // Turn on the indicator for this object
        public override void Indicate()
        {
            if (selectionObject == null)
                return;

            selectionObject.SetActive(true);

            foreach (ObjectController oc in ocs)
                if (!oc.gameObject.Equals(gameObject))
                    oc.Indicate();
        }

        // Turn off indicator for this object
        public override void Dimmer()
        {
            if (selectionObject == null)
                return;

            if (selectionObject.activeSelf)
                selectionObject.SetActive(false);

            foreach (ObjectController oc in ocs)
                if (!oc.gameObject.Equals(gameObject))
                    oc.Dimmer();
        }
    }
}
