|
@ -7,8 +7,8 @@ using UnityEngine.UI; |
|
|
public class LogicTrayUI : LogicElementHolder |
|
|
public class LogicTrayUI : LogicElementHolder |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
protected List<LogicBlock> list; |
|
|
|
|
|
|
|
|
//[SerializeField]
|
|
|
|
|
|
//protected List<LogicBlock> list;
|
|
|
[SerializeField] |
|
|
[SerializeField] |
|
|
protected LogicElementUI Prefab; |
|
|
protected LogicElementUI Prefab; |
|
|
[SerializeField] |
|
|
[SerializeField] |
|
@ -16,13 +16,39 @@ public class LogicTrayUI : LogicElementHolder |
|
|
[SerializeField] |
|
|
[SerializeField] |
|
|
private Transform content; |
|
|
private Transform content; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
protected BlockReader reader; |
|
|
|
|
|
|
|
|
#region Unity Functions
|
|
|
#region Unity Functions
|
|
|
public void Start() |
|
|
public void Start() |
|
|
{ |
|
|
{ |
|
|
UpdateDisplay(); |
|
|
UpdateDisplay(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void OnEnable() |
|
|
|
|
|
{ |
|
|
|
|
|
base.OnEnable(); |
|
|
|
|
|
if (reader != null) |
|
|
|
|
|
reader.OnUpdate += UpdateDisplay; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDisable() |
|
|
|
|
|
{ |
|
|
|
|
|
base.OnDisable(); |
|
|
|
|
|
if (reader != null) |
|
|
|
|
|
reader.OnUpdate -= UpdateDisplay; |
|
|
|
|
|
} |
|
|
#endregion Unity Functions
|
|
|
#endregion Unity Functions
|
|
|
|
|
|
|
|
|
|
|
|
public void SetBlockReader(BlockReader newBlockReader) |
|
|
|
|
|
{ |
|
|
|
|
|
if (reader != null) |
|
|
|
|
|
reader.OnUpdate -= UpdateDisplay; |
|
|
|
|
|
|
|
|
|
|
|
reader = newBlockReader; |
|
|
|
|
|
reader.OnUpdate += UpdateDisplay; |
|
|
|
|
|
UpdateDisplay(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[ContextMenu("Update Display")] |
|
|
[ContextMenu("Update Display")] |
|
|
public void UpdateDisplay() |
|
|
public void UpdateDisplay() |
|
@ -33,7 +59,7 @@ public class LogicTrayUI : LogicElementHolder |
|
|
Destroy(child.gameObject); |
|
|
Destroy(child.gameObject); |
|
|
|
|
|
|
|
|
//Instatiate logicElement prefab
|
|
|
//Instatiate logicElement prefab
|
|
|
foreach (LogicBlock element in list) |
|
|
|
|
|
|
|
|
foreach (LogicBlock element in reader.LogicChain) |
|
|
{ |
|
|
{ |
|
|
LogicElementUI elementUI = Instantiate(Prefab.gameObject, content).GetComponent<LogicElementUI>(); |
|
|
LogicElementUI elementUI = Instantiate(Prefab.gameObject, content).GetComponent<LogicElementUI>(); |
|
|
elementUI.Initialise(element, this); |
|
|
elementUI.Initialise(element, this); |
|
@ -62,9 +88,7 @@ public class LogicTrayUI : LogicElementHolder |
|
|
/// <param name="element">Element which is being dragged</param>
|
|
|
/// <param name="element">Element which is being dragged</param>
|
|
|
public override void OnRemove(LogicElementUI element) |
|
|
public override void OnRemove(LogicElementUI element) |
|
|
{ |
|
|
{ |
|
|
list.Remove(element.logicElement); |
|
|
|
|
|
|
|
|
|
|
|
UpdateDisplay(); |
|
|
|
|
|
|
|
|
reader.Remove(element.logicElement); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -74,9 +98,8 @@ public class LogicTrayUI : LogicElementHolder |
|
|
public override void OnAdd(LogicElementUI element) |
|
|
public override void OnAdd(LogicElementUI element) |
|
|
{ |
|
|
{ |
|
|
int index = GetInsertIndex(element.rectTransform); |
|
|
int index = GetInsertIndex(element.rectTransform); |
|
|
list.Insert(index, element.logicElement); |
|
|
|
|
|
|
|
|
reader.Insert(index, element.logicElement); |
|
|
|
|
|
|
|
|
UpdateDisplay(); |
|
|
|
|
|
Destroy(element.gameObject); |
|
|
Destroy(element.gameObject); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -96,6 +119,7 @@ public class LogicTrayUI : LogicElementHolder |
|
|
/// <param name="element">Element which is hovering</param>
|
|
|
/// <param name="element">Element which is hovering</param>
|
|
|
public override void OnHoverStart(LogicElementUI element) |
|
|
public override void OnHoverStart(LogicElementUI element) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Debug.Log("OnHoverStart"); |
|
|
//Create insert prefab at End
|
|
|
//Create insert prefab at End
|
|
|
insertIndex = content.childCount; |
|
|
insertIndex = content.childCount; |
|
|
UpdateDisplay(); |
|
|
UpdateDisplay(); |
|
@ -126,7 +150,7 @@ public class LogicTrayUI : LogicElementHolder |
|
|
if (rect.Overlaps(childRect.GlobalRect())) |
|
|
if (rect.Overlaps(childRect.GlobalRect())) |
|
|
return child.GetSiblingIndex(); |
|
|
return child.GetSiblingIndex(); |
|
|
} |
|
|
} |
|
|
return list.Count; |
|
|
|
|
|
|
|
|
return reader.LogicChain.Count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion Helper Functions
|
|
|
#endregion Helper Functions
|
|
|