PlayerAnimTransformProxy.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEngine;
  3. namespace SceneStory
  4. {
  5. public class PlayerAnimTransformProxy : BaseBehaviour
  6. {
  7. private void OnEnable()
  8. {
  9. GameObject gameObject = R.Player.GameObject;
  10. if (gameObject == null)
  11. {
  12. return;
  13. }
  14. this.pac = gameObject.GetComponent<PlayerAction>();
  15. }
  16. public void PlayerHasGravity(BoolEnum open)
  17. {
  18. if (open == BoolEnum.True)
  19. {
  20. this.pac.GetComponent<Rigidbody2D>().gravityScale = 1f;
  21. }
  22. if (open == BoolEnum.False)
  23. {
  24. this.pac.GetComponent<Rigidbody2D>().gravityScale = 0f;
  25. }
  26. }
  27. private void Update()
  28. {
  29. if (this.pac == null)
  30. {
  31. return;
  32. }
  33. if (this.refreshPos)
  34. {
  35. Vector3 position = base.transform.position;
  36. position.z = this.pac.transform.position.z;
  37. this.pac.transform.position = position;
  38. }
  39. if (this.refreshOffset)
  40. {
  41. Vector3 position2 = this.pac.transform.position + (this.lastOffset - this.offset);
  42. position2.z = this.pac.transform.position.z;
  43. this.lastOffset = this.offset;
  44. this.pac.transform.position = position2;
  45. }
  46. }
  47. private PlayerAction pac;
  48. [Header("玩家设置只会更新2D属性")]
  49. public bool refreshPos;
  50. public Vector3 offset = Vector3.zero;
  51. public bool refreshOffset;
  52. private Vector3 lastOffset = Vector3.zero;
  53. }
  54. }