show_select_child_scene.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { scene_item_data } from '../../../data/data';
  3. import { show_select_child_scene_item } from './show_select_child_scene_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('show_select_child_scene')
  6. export class show_select_child_scene extends Component {
  7. @property(Node) content:Node = null;
  8. @property(Node) btn_close:Node = null;
  9. @property(Prefab) item_prefab:Prefab = null;
  10. private call_back = null;
  11. public show(list:scene_item_data[],call){
  12. this.call_back = call;
  13. for (let index = 0; index < list.length; index++) {
  14. const element = list[index];
  15. let item = instantiate(this.item_prefab)
  16. item.parent = this.content;
  17. item.getComponent(show_select_child_scene_item).initView(element,this.onItemClick.bind(this))
  18. }
  19. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  20. this.close()
  21. })
  22. }
  23. onItemClick(data:scene_item_data){
  24. if(this.call_back!=null){
  25. this.call_back(data)
  26. this.close()
  27. }
  28. }
  29. close(){
  30. this.node.removeFromParent()
  31. }
  32. }