void Pair(Pairable g, Actor a)
 {
     g.pairedActor = a;
     g.ApplyMotif(a != null?a.color:Color.gray);
     g.ClearTargets();
     g.lastPaired = Time.time;
     Debug.Log(a != null?
               "PairableManager: Pairable " + g.GetComponent <TrackedObject>().liveObjectTag + " paired with " + a.gameObject.name:
               "PairableManager: Pairable " + g.GetComponent <TrackedObject>().liveObjectTag + " unpaired"
               );
 }
        public override void OnInspectorGUI()
        {
            Pairable p = (Pairable)target;

            p.type   = EditorGUILayout.TextField("Pairable Type", p.type);
            p.offset = EditorGUILayout.Vector3Field("Offset", p.offset);
            EditorGUILayout.LabelField("Status:",
                                       (p.paired && !p.unpairing)?"Paired with " + p.pairedActor.gameObject.name:
                                       (!p.paired && !p.pairing)?"Unpaired":
                                       p.pairing?"Pairing...":"Unpairing..."
                                       );
        }
        void CheckPair(Pairable g, Actor a)
        {
            if (Time.time - g.lastPaired < cooldown)
            {
                return;
            }

            //Check within a sphere
            bool inRange = Vector3.Distance(
                g.center, a.transform.position + a.transform.forward * pairDistance
                ) <= 0.5f * pairRange;
            bool isTarget   = g.IsTarget(a);      //Is this actor currently attempting to pair?
            bool paired     = g.paired;           // || Paired(a); //Uncomment for pair limits
            bool thisPaired = g.pairedActor == a; //Is this pairable the actor's current pairable?

            //Render pairing sphere
            if (a == actorManager.buildActor && isTarget && inRange)
            {
                pairingSphere.localScale = pairRange * Vector3.one;
                pairingSphere.position   = a.transform.position + a.transform.forward * pairDistance;
                pairingSphere.GetComponent <Renderer>().enabled = true;
            }

            //Debug visualization
            float tick = 0.1f * (Time.time % 1);

            if (isTarget)
            {
                //Swap colors if unpairing
                Debug.DrawLine(g.center, a.transform.position, thisPaired?a.color:Color.white);
                //Draw animated axis
                Vector3 progress = Vector3.Lerp(g.center, a.transform.position, g.PairTime(a) / pairTime);
                Debug.DrawLine(progress + Vector3.up * tick, progress - Vector3.up * tick, thisPaired?Color.white:a.color);
                Debug.DrawLine(progress + Vector3.left * tick, progress - Vector3.left * tick, thisPaired?Color.white:a.color);
                Debug.DrawLine(progress + Vector3.forward * tick, progress - Vector3.forward * tick, thisPaired?Color.white:a.color);
            }
            else if (thisPaired)
            {
                Debug.DrawLine(g.center, a.transform.position, a.color);
            }
            else if (inRange)
            {
                Debug.DrawLine(g.center, a.transform.position, Color.gray);
            }

            if (isTarget && ((paired && !thisPaired) || !inRange))            //Remove if paired / remove if out of range
            {
                g.RemoveTarget(a);
            }
            else if (!isTarget && inRange && (!paired || thisPaired))            //Check for unpair / add if unpaired
            {
                g.AddTarget(a, Time.time);
            }

            //Pair
            isTarget = g.IsTarget(a);           //Recheck
            if (isTarget && g.PairTime(a) >= pairTime)
            {
                Pair(g, thisPaired?null:a);
            }
        }