Browse Source

Made logic tray be able to work in any level + efefcts character

Josh_Dev_branch
Joshua Reason 5 years ago
parent
commit
90a7ac5688
24 changed files with 1619 additions and 3170 deletions
  1. +2
    -2
      Assets/Data/Inventory/PlayerInventory.asset
  2. +8
    -0
      Assets/Data/Logic Blocks.meta
  3. +2
    -2
      Assets/Data/Logic Blocks/ForLoop.asset
  4. +2
    -2
      Assets/Data/Logic Blocks/Jump.asset
  5. +2
    -2
      Assets/Data/Logic Blocks/Move x2.asset
  6. +8
    -0
      Assets/Data/Logic Blocks/Move x2.asset.meta
  7. +2
    -2
      Assets/Data/Logic Blocks/Move.asset
  8. +8
    -0
      Assets/Data/Logic Blocks/Move.asset.meta
  9. +2
    -2
      Assets/Data/Logic Blocks/Rotate Left.asset
  10. +8
    -0
      Assets/Data/Logic Blocks/Rotate Left.asset.meta
  11. +2
    -2
      Assets/Data/Logic Blocks/Rotate Right.asset
  12. +8
    -0
      Assets/Data/Logic Blocks/Rotate Right.asset.meta
  13. +8
    -0
      Assets/Materials/block_notification 1.mat.meta
  14. +1123
    -0
      Assets/Prefabs/UI/Player Canvas.prefab
  15. +7
    -0
      Assets/Prefabs/UI/Player Canvas.prefab.meta
  16. +220
    -3139
      Assets/Scenes/UI_TestScene.unity
  17. +12
    -3
      Assets/Scripts/BlockInput.cs
  18. +48
    -1
      Assets/Scripts/Logic/BlockReader.cs
  19. +4
    -1
      Assets/Scripts/UI/BagItem.cs
  20. +10
    -3
      Assets/Scripts/UI/ILogicElementHolder.cs
  21. +4
    -0
      Assets/Scripts/UI/LogicElementUI.cs
  22. +33
    -9
      Assets/Scripts/UI/LogicTrayUI.cs
  23. +85
    -0
      Assets/Scripts/UI/PlayerUIManager.cs
  24. +11
    -0
      Assets/Scripts/UI/PlayerUIManager.cs.meta

+ 2
- 2
Assets/Data/Inventory/PlayerInventory.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0c95bbb6ed08b700412d51e115fe5989b61124432da37f0bf4b4d51dc54cd8f2
size 415
oid sha256:362b0120802255e93f8c0b15edc15dd357571757d07e6a9f75a9666050a1469a
size 962

+ 8
- 0
Assets/Data/Logic Blocks.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e082f07e6a38ded42945888080672510
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 2
Assets/Data/Logic Blocks/ForLoop.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:815e838d40fc858ba3fca1d9f6ac75c76fdd5b6e1859a7145c142a7f636d3a5f
size 616
oid sha256:34e0722afbe625d87d5ef748ee29a3ed763df335fd3bb1f189820962121e4411
size 675

+ 2
- 2
Assets/Data/Logic Blocks/Jump.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4b1a4c27ea4794695f72f8d3f5d345c28103a2b6cc53e67b8f24f0757617b5e7
size 449
oid sha256:49d74fee28f711c623d0d219f70aa6b3099be45bbb398fc9b46373c2f962a3c5
size 507

+ 2
- 2
Assets/Data/Logic Blocks/Move x2.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6cd2eb3de9510a6319b174a92b11d1966b6f1bf6258b95c60b88af35c2666499
size 437
oid sha256:32f839ca370d74c812af63fa2b54ea03337bbc29aa02e1c325a37869ea9e2f0f
size 511

+ 8
- 0
Assets/Data/Logic Blocks/Move x2.asset.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 48f0ea7af28c10846b5b76ce70d06b60
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 2
Assets/Data/Logic Blocks/Move.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8f30f384f120eeb69292d9ff04a9e267e536ef80a35c6a7820a032e88257d9e8
size 434
oid sha256:2c02ccd234c974be76b21bbc246437fb9b8bb724e596d77213d0023012cf1996
size 508

+ 8
- 0
Assets/Data/Logic Blocks/Move.asset.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0b1bcd75cb7dade4fb598ee3412594c2
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 2
Assets/Data/Logic Blocks/Rotate Left.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:323f3c70cf40755730cb81a31da6a58931177674b836d0b5bbc8b9f88af4b447
size 456
oid sha256:b8a99ebd1cdcc067be9e66d49377b3fea82bccb6ed878edf467bd9af4020451b
size 514

+ 8
- 0
Assets/Data/Logic Blocks/Rotate Left.asset.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa238796cf1886244951ec8c2fed1855
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 2
Assets/Data/Logic Blocks/Rotate Right.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a6886b6e048617b3ecd1de69b35f0e598467d7d2444a59a26f58fcb16a988960
size 457
oid sha256:03cc745c401648ff6ebd18a61cb036d5b11da4725fe81d5d8203de7d48e44684
size 516

+ 8
- 0
Assets/Data/Logic Blocks/Rotate Right.asset.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 41f4cb946475b2849a802a8297d81e25
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

+ 8
- 0
Assets/Materials/block_notification 1.mat.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9f894080ae602c6439d69dad1ff79bdd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

+ 1123
- 0
Assets/Prefabs/UI/Player Canvas.prefab
File diff suppressed because it is too large
View File


+ 7
- 0
Assets/Prefabs/UI/Player Canvas.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3fbc9b76d5c4f7348b60a029bc2ba63f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 220
- 3139
Assets/Scenes/UI_TestScene.unity
File diff suppressed because it is too large
View File


+ 12
- 3
Assets/Scripts/BlockInput.cs View File

@ -14,7 +14,7 @@ public class BlockInput : MonoBehaviour
if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Space))
ReadNext();
else if (Input.GetKeyDown(KeyCode.Space))
StartCoroutine(ReadRoutine(waitTime));
ReadAll();
}
[ContextMenu("Read Next")]
@ -23,6 +23,16 @@ public class BlockInput : MonoBehaviour
blockReader.Read(character);
}
public void ReadAll()
{
StartCoroutine(ReadRoutine(waitTime));
}
public void FinishedReading()
{
blockReader.Reset();
blockReader.Clear();
}
public IEnumerator ReadRoutine(float waitTime)
{
@ -31,8 +41,7 @@ public class BlockInput : MonoBehaviour
ReadNext();
yield return new WaitForSeconds(waitTime);
}
blockReader.Reset();
FinishedReading();
}
}

+ 48
- 1
Assets/Scripts/Logic/BlockReader.cs View File

@ -12,7 +12,7 @@ public class BlockReader
#region Inspector Variables
[SerializeField]
[Tooltip("List of LogicBlocks which will affected this character")]
protected List<LogicBlock> LogicChain;
public List<LogicBlock> LogicChain;
#endregion Inspector Variables
#region Read-only Variables
@ -20,6 +20,12 @@ public class BlockReader
/// returns true if all LogicBlocks in LogicChain have been completed
/// </summary>
public bool Finished { get { return currentBlockIndex >= LogicChain.Count; } }
/// <summary>
/// Fired whenever the logic chain is updated, useful for UI
/// </summary>
public event System.Action OnUpdate;
#endregion Read-only Variables
#region Private Variables
@ -63,6 +69,47 @@ public class BlockReader
//Should other readers wait for this one
return (currentBlock.isFinished() || !currentBlock.WaitUntilFinished);
}
/// <summary>
/// Clears all elements out of the Block Reader
/// </summary>
public void Clear()
{
LogicChain.Clear();
OnUpdate.Invoke();
}
/// <summary>
/// Removes the first instance found in the Block Reader
/// </summary>
/// <param name="item">LogicElement to remove</param>
public void Remove(LogicBlock item)
{
LogicChain.Remove(item);
OnUpdate.Invoke();
}
/// <summary>
/// Addes item to the end of the BlockReader
/// </summary>
/// <param name="item">item to add</param>
public void Add(LogicBlock item)
{
LogicChain.Add(item);
OnUpdate.Invoke();
}
/// <summary>
/// Inserts item at index of the Block Reader
/// </summary>
/// <param name="index">index to insert at</param>
/// <param name="item">item to insert</param>
public void Insert(int index, LogicBlock item)
{
LogicChain.Insert(index, item);
OnUpdate.Invoke();
}
#endregion
}

+ 4
- 1
Assets/Scripts/UI/BagItem.cs View File

@ -39,7 +39,10 @@ public class BagItem : LogicElementHolder
public void UpdateUI()
{
CountText.text = Count.ToString();
if (!InventoryData.infinit)
CountText.text = Count.ToString();
else
CountText.text = "∞";
}
#endregion Class Functionality

+ 10
- 3
Assets/Scripts/UI/ILogicElementHolder.cs View File

@ -15,12 +15,12 @@ public abstract class LogicElementHolder : MonoBehaviour
private static List<LogicElementHolder> EnabledHolders = new List<LogicElementHolder>();
#region Unity Functions
private void OnEnable()
protected virtual void OnEnable()
{
EnabledHolders.Add(this);
}
private void OnDisable()
protected virtual void OnDisable()
{
EnabledHolders.Remove(this);
}
@ -79,6 +79,13 @@ public abstract class LogicElementHolder : MonoBehaviour
}
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
}

+ 4
- 0
Assets/Scripts/UI/LogicElementUI.cs View File

@ -93,6 +93,10 @@ public class LogicElementUI : Dragable
//Get all overlapping holders
List<LogicElementHolder> currentHover = LogicElementHolder.OverlappingElements(transform as RectTransform).ToList();
DebugExtensions.DrawRect(rectTransform, Color.blue);
LogicElementHolder.DebugDrawAll(Color.red);
//Call OnHoverStart() for each holder which wasn't in the last update
currentHover.Except(lastHover).ForEach(p => p.OnHoverStart(this));

+ 33
- 9
Assets/Scripts/UI/LogicTrayUI.cs View File

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

+ 85
- 0
Assets/Scripts/UI/PlayerUIManager.cs View File

@ -0,0 +1,85 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerUIManager : MonoBehaviour
{
[SerializeField]
private RectTransform Inventory;
[SerializeField]
private float AnimationSpeed = 0.5f;
[SerializeField]
private BlockInput characterInput;
[SerializeField]
private LogicTrayUI TrayUI;
private Vector3 ShowPosition;
private Vector3 HidePosition;
private void Awake()
{
ShowPosition = new Vector3(0, -Inventory.rect.height / 2, 0);
HidePosition = new Vector3(0, Inventory.rect.height/2, 0);
Debug.Log(Inventory.rect.height);
Inventory.anchoredPosition = HidePosition;
TrayUI.SetBlockReader(characterInput.blockReader);
}
[ContextMenu("Show")]
public void OnClick_Show()
{
StopAllCoroutines();
StartCoroutine( LerpPosition(Inventory, ShowPosition, AnimationSpeed));
}
[ContextMenu("Hide")]
public void OnClick_Hide()
{
StopAllCoroutines();
StartCoroutine( LerpPosition(Inventory, HidePosition, AnimationSpeed));
}
public void OnClick_Toggle()
{
if (Vector3.Distance(Inventory.anchoredPosition,ShowPosition) < Vector3.Distance(Inventory.anchoredPosition, HidePosition))
{
Debug.Log("Hiding Menu");
OnClick_Hide();
}
else
{
Debug.Log("Showing Menu");
OnClick_Show();
}
}
public void OnClick_Play() {
OnClick_Hide();
characterInput.ReadAll();
}
private IEnumerator LerpPosition(RectTransform rt, Vector3 endPosition, float time)
{
float elapsedTime = 0;
Vector3 startPos = rt.anchoredPosition;
while (elapsedTime < time)
{
rt.anchoredPosition = Vector3.Slerp(startPos, endPosition, (elapsedTime / time));
elapsedTime += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
rt.anchoredPosition = endPosition;
}
}

+ 11
- 0
Assets/Scripts/UI/PlayerUIManager.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0d56bc0314445a44cb43d566c4a87510
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save