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();
[Tooltip("An Element with a higher priority will be used if two object overlap")]
public int Priority = 0;
#region Unity Functions
protected virtual void OnEnable()
{
EnabledHolders.Add(this);
}
protected virtual 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) { }
///
/// Called when an element in this holder is double clicked
///
/// element which was double clicked
public abstract void OnDoubleClick(LogicElementUI element);
///
/// Called to check if this holder can hold the provided element;
///
/// element to check if it can hold
/// returns true if this can hold the element
public virtual bool canHold(LogicBlock element) { return true; }
#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();
}
public static void DebugDrawAll(Color color, float duration = 0.0f, bool depthTest = false)
{
EnabledHolders.ForEach(p => DebugExtensions.DrawRect(p.transform as RectTransform, color,duration, depthTest));
}
#endregion
}