i18nSprite.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** @format */
  2. import {Mgr} from '../GameControl'
  3. const {ccclass, property, executeInEditMode, disallowMultiple, requireComponent, menu} = cc._decorator
  4. @ccclass
  5. @executeInEditMode
  6. @requireComponent(cc.Sprite)
  7. @disallowMultiple
  8. @menu('多语言/i18nSprite')
  9. export class i18nSprite extends cc.Component {
  10. @property({visible: false})
  11. private i18n_string: string = ''
  12. start() {
  13. Mgr.i18n.addOrDelSprite(this, true)
  14. this._resetValue()
  15. }
  16. @property({type: cc.String})
  17. get string() {
  18. return this.i18n_string
  19. }
  20. set string(value: string) {
  21. this.i18n_string = value
  22. let sprite = this.getComponent(cc.Sprite)
  23. if (cc.isValid(sprite)) {
  24. Mgr.i18n.getSprite(value, spriteFrame => {
  25. if (cc.isValid(sprite)) {
  26. sprite.spriteFrame = spriteFrame
  27. }
  28. })
  29. }
  30. }
  31. _resetValue() {
  32. this.string = this.i18n_string
  33. }
  34. onDestroy() {
  35. Mgr.i18n.addOrDelSprite(this, false)
  36. }
  37. }