use_v2.0.x_cc.Toggle_event.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * This script is automatically generated by Cocos Creator and is only compatible with projects prior to v2.1.0.
  3. * You do not need to manually add this script in any other project.
  4. * If you don't use cc.Toggle in your project, you can delete this script directly.
  5. * If your project is hosted in VCS such as git, submit this script together.
  6. *
  7. * 此脚本由 Cocos Creator 自动生成,仅用于兼容 v2.1.0 之前版本的工程,
  8. * 你无需在任何其它项目中手动添加此脚本。
  9. * 如果你的项目中没用到 Toggle,可直接删除该脚本。
  10. * 如果你的项目有托管于 git 等版本库,请将此脚本一并上传。
  11. */
  12. if (cc.Toggle) {
  13. // Whether the 'toggle' and 'checkEvents' events are fired when 'toggle.check() / toggle.uncheck()' is called in the code
  14. // 在代码中调用 'toggle.check() / toggle.uncheck()' 时是否触发 'toggle' 与 'checkEvents' 事件
  15. cc.Toggle._triggerEventInScript_check = true;
  16. }
  17. (function () {
  18. let map = {
  19. Node: {
  20. "active": "Active",
  21. "opacity": "Opacity"
  22. }, Sprite: {
  23. "spriteFrame": "SpriteFrame"
  24. }, Label: {
  25. "string": "String"
  26. }, Button: {
  27. "interactable": "Interactable"
  28. }
  29. };
  30. let keys1 = Object.keys(map);
  31. for (let i = 0; i < keys1.length; i += 1) {
  32. let compName = keys1[i];
  33. let compMap = map[compName];
  34. let keys2 = Object.keys(compMap);
  35. for (let j = 0; j < keys2.length; j += 1) {
  36. let type = keys2[j];
  37. let funcName = compMap[type];
  38. cc.Node.prototype["getChild" + funcName] = function (childName) {
  39. let comp = nodeTools_getComp(this, compName, childName);
  40. if (comp) {
  41. let _type = comp[type];
  42. return _type;
  43. }
  44. }
  45. cc.Node.prototype["setChild" + funcName] = function (childName, comp_prototype) {
  46. let comp = nodeTools_getComp(this, compName, childName);
  47. if (comp) {
  48. comp[type] = comp_prototype;
  49. }
  50. }
  51. }
  52. }
  53. })()
  54. var nodeTools_getComp = function (targetThis, compName, childName) {
  55. let cacheName = "_cacheChild_" + compName + "_" + childName;
  56. let cacheComp = targetThis[cacheName];
  57. if (cacheComp) {
  58. return cacheComp;
  59. } else {
  60. let targetNode = nodeTools_checkChildName(targetThis, childName);
  61. let getComp = compName == "Node" ? this : targetNode.getComponent(cc[compName]);
  62. if (getComp) {
  63. targetNode[cacheName] = getComp;
  64. return getComp;
  65. } else {
  66. cc.error("未找到节点上有组件");
  67. debugger;
  68. }
  69. return null;
  70. }
  71. }
  72. var nodeTools_checkChildName = function (targetThis, childName) {
  73. let foundArr = childName.split("/");
  74. let foundNode = targetThis;
  75. for (let i = 0; i < foundArr.length; i += 1) {
  76. let foundName = foundArr[i];
  77. foundNode = foundNode.getChildByName(foundName);
  78. if (foundNode == null) {
  79. cc.error("未找到对应的子节点");
  80. debugger;
  81. }
  82. }
  83. return foundNode;
  84. }
  85. cc.Button.prototype._onTouchEnded = function (event) {
  86. if (!this.interactable || !this.enabledInHierarchy) return;
  87. if (this._pressed) {
  88. cc.Component.EventHandler.emitEvents(this.clickEvents, event);
  89. this.node.emit('click', this);
  90. }
  91. this._pressed = false;
  92. this._audiocb && this._audiocb();
  93. this._updateState();
  94. event.stopPropagation();
  95. }
  96. Array.prototype.remove = function (val) {
  97. var index = this.indexOf(val);
  98. if (index > -1) {
  99. this.splice(index, 1);
  100. }
  101. };
  102. Array.prototype.sum = function () {
  103. let sumNum = 0;
  104. for (let i = 0; i < this.length; i += 1) {
  105. sumNum += this[i];
  106. }
  107. return sumNum;
  108. }