暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ConformingSpline.cs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.U2D;
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. #endif
  8. // Demo Script Usage:
  9. // When you want multiple SpriteShapes to share a common Spline,
  10. // attach this script to the secondary objects you would like to
  11. // copy the Spline and set the ParentObject to the original object
  12. // you are copying from.
  13. namespace SpriteShapeExtras
  14. {
  15. [ExecuteInEditMode]
  16. public class ConformingSpline : MonoBehaviour
  17. {
  18. public GameObject m_ParentObject;
  19. private int hashCode;
  20. // Use this for initialization
  21. void Start()
  22. {
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. if (m_ParentObject != null)
  28. {
  29. hashCode = CopySpline(m_ParentObject, gameObject, hashCode);
  30. }
  31. }
  32. private static int CopySpline(GameObject src, GameObject dst, int hashCode)
  33. {
  34. #if UNITY_EDITOR
  35. var parentSpriteShapeController = src.GetComponent<SpriteShapeController>();
  36. var mirrorSpriteShapeController = dst.GetComponent<SpriteShapeController>();
  37. if (parentSpriteShapeController != null && mirrorSpriteShapeController != null && parentSpriteShapeController.spline.GetHashCode() != hashCode)
  38. {
  39. SerializedObject srcController = new SerializedObject(parentSpriteShapeController);
  40. SerializedObject dstController = new SerializedObject(mirrorSpriteShapeController);
  41. SerializedProperty srcSpline = srcController.FindProperty("m_Spline");
  42. dstController.CopyFromSerializedProperty(srcSpline);
  43. dstController.ApplyModifiedProperties();
  44. EditorUtility.SetDirty(mirrorSpriteShapeController);
  45. return parentSpriteShapeController.spline.GetHashCode();
  46. }
  47. #endif
  48. return hashCode;
  49. }
  50. }
  51. }