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.

57 lines
1.6 KiB

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