You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. using System.Collections;
  2. using UnityEngine;
  3. [CreateAssetMenu(menuName = "Major Project/Pick Ups/Replace Block")]
  4. [System.Serializable]
  5. public class Replace : LogicBlock
  6. {
  7. public GameObject blockPrefab;
  8. public override Block GetEndBlock(Block startBlock, Transform transform, LayerMask layerMask)
  9. {
  10. return startBlock;
  11. }
  12. protected override IEnumerator BlockLogic(Character player, float animationTime, bool useBlockDirection = false)
  13. {
  14. Block oldBlock = player.CurrentBlock;
  15. Transform parent = oldBlock.transform.parent;
  16. Vector3 position = oldBlock.position;
  17. Block newBlock = Instantiate(blockPrefab, parent).GetComponent<Block>();
  18. newBlock.transform.position = position;
  19. yield return player.StartCoroutine(player.MoveToBlock(newBlock, Character.Animation.None, 0.0f));
  20. Destroy(oldBlock);
  21. }
  22. public override void CopyToken(BlockToken token)
  23. {
  24. base.CopyToken(token);
  25. blockPrefab= Resources.Load<GameObject>(((ReplaceToken)token).prefabName);
  26. }
  27. public override BlockToken ToToken(BlockToken token = null)
  28. {
  29. if (token == null)
  30. token = new ReplaceToken(this);
  31. Debug.Log(base.ToToken(token).GetType().Name);
  32. ReplaceToken retVal = (ReplaceToken)base.ToToken(token);
  33. retVal.prefabName = blockPrefab.name;
  34. return retVal;
  35. }
  36. }
  37. [System.Serializable]
  38. public class ReplaceToken : BlockToken
  39. {
  40. public string prefabName;
  41. public ReplaceToken(LogicBlock block) : base(block) { }
  42. }