using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// Class which component which an LogicElementUI can be dragged into should derive from
///
public abstract class LogicElementHolder : MonoBehaviour
{
///
/// List of all Holders in scene
///
private static List EnabledHolders = new List();
#region Unity Functions
private void OnEnable()
{
EnabledHolders.Add(this);
}
private void OnDisable()
{
EnabledHolders.Remove(this);
}
#endregion
#region Class Funtions
///
/// When a LogicElement has started being dragged from this holder
///
/// Element which is being dragged
public abstract void OnRemove(LogicElementUI element);
///
/// When a logicElement needs to be added back to this holder
///
/// Element which is being Added
public abstract void OnAdd(LogicElementUI element);
///
/// When a logic Element is hovering over this holder
///
/// Element which is hovering
public virtual void OnHover(LogicElementUI element) { }
///
/// First frame a logic Element is hovering over this holder
///
/// Element which is hovering
public virtual void OnHoverStart(LogicElementUI element) { }
///
/// first frame a logic Element is no longer hovering over this holder
///
/// Element which is hovering
public virtual void OnHoverEnd(LogicElementUI element) { }
#endregion Class Funtions
#region Static Functions
///
/// Gets an array of Any element holders a RectTransform is overlapping with
///
/// recttransform to check overlapping
/// array of Any element holders a rt is overlapping with
public static LogicElementHolder[] OverlappingElements(RectTransform rt)
{
List retVal = new List();
Rect rect = rt.GlobalRect();
Rect holderRect;
foreach (LogicElementHolder holder in EnabledHolders)
{
holderRect = (holder.transform as RectTransform).GlobalRect();
if (rect.Overlaps(holderRect))
retVal.Add(holder);
}
return retVal.ToArray();
}
#endregion
}