ShowDate.ts 783 B

12345678910111213141516171819202122232425
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. const { ccclass, executeInEditMode } = cc._decorator;
  8. @ccclass
  9. @executeInEditMode
  10. export default class ShowDate extends cc.Component {
  11. start() {
  12. if (CC_EDITOR) {
  13. let label = this.node.getComponent(cc.Label);
  14. if (label) {
  15. let d = new Date();
  16. label.string = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate();
  17. }
  18. }
  19. this.node.zIndex = cc.macro.MAX_ZINDEX;
  20. }
  21. }