UIScratchable.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class UIScratchable : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. private float Wide_X;
  9. private float Lenth_z;
  10. private float high_y;
  11. public Vector3 ScalPos=new Vector3(1f,1f,1f);
  12. private float Pos_X;
  13. private float Pos_z;
  14. float Multiple_X;
  15. float Multiple_Z;
  16. private float Scaleline = 0.1f;
  17. private float UDline = 0.1f;
  18. private void Awake()
  19. {
  20. ScalPos = new Vector3(this.transform.localScale.x*10, this.transform.localScale.y*10,this.transform.localScale.z*10);
  21. Wide_X = ScalPos.x / 10;
  22. Lenth_z = ScalPos.y / 10;
  23. high_y = ScalPos.z / 10;
  24. Pos_X = this.gameObject.transform.localScale.x;
  25. Pos_z = this.gameObject.transform.localScale.z;
  26. this.gameObject.transform.localScale = new Vector3(Wide_X, Lenth_z, this.gameObject.transform.localScale.y);
  27. AngleManaage();
  28. }
  29. void Update()
  30. {
  31. Wide_X = ScalPos.x / 10;
  32. Lenth_z = ScalPos.y / 10;
  33. high_y = ScalPos.z / 10;
  34. this.gameObject.transform.localScale = new Vector3(Wide_X, Lenth_z, high_y);
  35. if (Wide_X > 0 && Lenth_z > 0)
  36. {
  37. AngleManaage();
  38. }
  39. }
  40. public void AngleManaage()
  41. {
  42. //Debug.Log(Wide_X + "哈哈" + Pos_X);
  43. //Debug.Log(Lenth_z + "z轴" + Pos_z);
  44. Multiple_X = Wide_X / 0.1f;
  45. Multiple_Z = Lenth_z / 0.1f;
  46. float Angle_x = 1f / Multiple_X;
  47. float Angle_z = 1f / Multiple_Z;
  48. //Debug.Log(Angle_x + "XXXXXXXXXXXXXX" + Multiple_X);
  49. //Debug.Log(Angle_z + "@@@@@@@@@@@" + Multiple_Z);
  50. this.transform.GetChild(0).GetChild(4).transform.localScale = new Vector3(Angle_x, 1, Angle_z);
  51. this.transform.GetChild(0).GetChild(5).transform.localScale = new Vector3(Angle_x, 1, Angle_z);
  52. this.transform.GetChild(0).GetChild(6).transform.localScale = new Vector3(Angle_x, 1, Angle_z);
  53. this.transform.GetChild(0).GetChild(7).transform.localScale = new Vector3(Angle_x, 1, Angle_z);
  54. Scaleline = Angle_z;
  55. UDline = Angle_x;
  56. LeftRightManage(Angle_z);
  57. UPdownManage(UDline);
  58. }
  59. public void LeftRightManage(float bb)
  60. {
  61. float a = 1 - Scaleline;
  62. // Debug.Log("&&&&&&&&&&&&&&&&&&&&&&&&& " + a);
  63. this.transform.GetChild(0).GetChild(0).transform.localScale = new Vector3(1, 1, 7 + a);
  64. this.transform.GetChild(0).GetChild(1).transform.localScale = new Vector3(1, 1, 7 + a);
  65. }
  66. public void UPdownManage(float cc)
  67. {
  68. float a = 1 - UDline;
  69. // Debug.Log("&&&&&&&&&&&&&&&&&&&&&&&&& " + a);
  70. this.transform.GetChild(0).GetChild(2).transform.localScale = new Vector3(7 + a, 1, 1);
  71. this.transform.GetChild(0).GetChild(3).transform.localScale = new Vector3(7 + a, 1, 1);
  72. }
  73. }