forked from cocos/cocos-test-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
12,105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"ver": "0.0.1", | ||
"importer": "*", | ||
"imported": true, | ||
"uuid": "be87f4d1-271e-4ec3-90c4-281ad158a359", | ||
"displayName": "", | ||
"files": [], | ||
"subMetas": {}, | ||
"userData": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { _decorator, Component, Prefab, LabelComponent, PageViewComponent, Color, Node, Vec3, SpriteComponent } from "cc"; | ||
const { ccclass, property, menu } = _decorator; | ||
|
||
@ccclass("PageViewCtrl") | ||
@menu('UI/PageViewCtrl') | ||
export class PageViewCtrl extends Component { | ||
@property | ||
public curNum = 3; | ||
@property | ||
public curTotal = 10; | ||
@property(Prefab) | ||
public pageTeample:Prefab | null = null; | ||
@property(PageViewComponent) | ||
target: PageViewComponent | null = null; | ||
@property(LabelComponent) | ||
label: LabelComponent | null = null; | ||
|
||
_createPage() { | ||
const page = cc.instantiate(this.pageTeample) as Node; | ||
page.name = `page_${this.curNum}`; | ||
page.setPosition(new Vec3()); | ||
const color = new Color(); | ||
color.r = Math.floor(Math.random() * 255); | ||
color.g = Math.floor(Math.random() * 255); | ||
color.b = Math.floor(Math.random() * 255); | ||
const comp = page.getComponent(SpriteComponent); | ||
comp.color = color; | ||
return page; | ||
} | ||
|
||
onLoad() { | ||
// 设置的当前页面为 1 | ||
this.target.setCurrentPageIndex(0); | ||
} | ||
|
||
update() { | ||
// 当前页面索引 | ||
this.label.string = "第" + (this.target.getCurrentPageIndex() + 1) + "页"; | ||
} | ||
|
||
// 返回首页 | ||
onJumpHome() { | ||
// 第二个参数为滚动所需时间,默认值为 0.3 秒 | ||
this.target.scrollToPage(0); | ||
} | ||
|
||
// 添加页面 | ||
plusPage(callback: Function) { | ||
if (this.curNum > this.curTotal) { | ||
return; | ||
} | ||
this.curNum++; | ||
if (callback) { | ||
callback(); | ||
} | ||
} | ||
|
||
// 减少页面 | ||
lessPageNum(callback: Function) { | ||
if (this.curNum <= 0) { | ||
return; | ||
} | ||
this.curNum--; | ||
if (callback) { | ||
callback(); | ||
} | ||
} | ||
|
||
// 添加页面 | ||
onAddPage() { | ||
this.plusPage(() => { | ||
this.target.addPage(this._createPage()); | ||
}); | ||
} | ||
|
||
// 插入当前页面 | ||
onInsertPage() { | ||
this.plusPage(() => { | ||
this.target.insertPage(this._createPage(), this.target.getCurrentPageIndex()); | ||
}); | ||
} | ||
|
||
// 移除最后一个页面 | ||
onRemovePage() { | ||
this.lessPageNum(() => { | ||
var pages = this.target.getPages(); | ||
this.target.removePage(pages[pages.length - 1]); | ||
}); | ||
} | ||
|
||
// 移除当前页面 | ||
onRemovePageAtIndex() { | ||
this.lessPageNum(() => { | ||
this.target.removePageAtIndex(this.target.getCurrentPageIndex()); | ||
}); | ||
} | ||
|
||
// 移除所有页面 | ||
onRemoveAllPage() { | ||
this.target.removeAllPages(); | ||
this.curNum = 0; | ||
} | ||
|
||
// 监听事件 | ||
onPageEvent(sender, eventType) { | ||
// 翻页事件 | ||
if (eventType !== PageViewComponent.EventType.PAGE_TURNING) { | ||
return; | ||
} | ||
console.log("当前所在的页面索引:" + sender.getCurrentPageIndex()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"ver": "1.0.812", | ||
"importer": "typescript", | ||
"imported": true, | ||
"uuid": "18f1c063-f897-497e-bf59-e6e877c22df8", | ||
"displayName": "", | ||
"files": [ | ||
".js" | ||
], | ||
"subMetas": {}, | ||
"userData": { | ||
"moduleId": "project:///assets/cases/ui/15.pageview/page-view-ctrl.ts", | ||
"importAsPlugin": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
[ | ||
{ | ||
"__type__": "cc.Prefab", | ||
"_name": "", | ||
"_objFlags": 0, | ||
"_native": "", | ||
"data": { | ||
"__id__": 1 | ||
}, | ||
"optimizationPolicy": 0, | ||
"asyncLoadAssets": false | ||
}, | ||
{ | ||
"__type__": "cc.Node", | ||
"_name": "page1", | ||
"_objFlags": 0, | ||
"_parent": null, | ||
"_children": [], | ||
"_active": true, | ||
"_level": 5, | ||
"_components": [ | ||
{ | ||
"__id__": 2 | ||
}, | ||
{ | ||
"__id__": 3 | ||
} | ||
], | ||
"_prefab": { | ||
"__id__": 4 | ||
}, | ||
"_lpos": { | ||
"__type__": "cc.Vec3", | ||
"x": 250, | ||
"y": 0, | ||
"z": 0 | ||
}, | ||
"_lrot": { | ||
"__type__": "cc.Quat", | ||
"x": 0, | ||
"y": 0, | ||
"z": 0, | ||
"w": 1 | ||
}, | ||
"_lscale": { | ||
"__type__": "cc.Vec3", | ||
"x": 1, | ||
"y": 1, | ||
"z": 1 | ||
}, | ||
"_layer": 16, | ||
"_euler": { | ||
"__type__": "cc.Vec3", | ||
"x": 0, | ||
"y": 0, | ||
"z": 0 | ||
}, | ||
"_id": "" | ||
}, | ||
{ | ||
"__type__": "cc.UITransformComponent", | ||
"_name": "", | ||
"_objFlags": 0, | ||
"node": { | ||
"__id__": 1 | ||
}, | ||
"_enabled": true, | ||
"_contentSize": { | ||
"__type__": "cc.Size", | ||
"width": 500, | ||
"height": 300 | ||
}, | ||
"_anchorPoint": { | ||
"__type__": "cc.Vec2", | ||
"x": 0.5, | ||
"y": 0.5 | ||
}, | ||
"_id": "" | ||
}, | ||
{ | ||
"__type__": "cc.SpriteComponent", | ||
"_name": "", | ||
"_objFlags": 0, | ||
"node": { | ||
"__id__": 1 | ||
}, | ||
"_enabled": true, | ||
"_priority": 0, | ||
"_srcBlendFactor": 2, | ||
"_dstBlendFactor": 4, | ||
"_color": { | ||
"__type__": "cc.Color", | ||
"r": 199, | ||
"g": 115, | ||
"b": 115, | ||
"a": 255 | ||
}, | ||
"_sharedMaterial": null, | ||
"_spriteFrame": { | ||
"__uuid__": "093b45c8-80d9-49a8-ac5c-bcdbaed2c6bf@spriteFrame" | ||
}, | ||
"_type": 0, | ||
"_fillType": 0, | ||
"_sizeMode": 0, | ||
"_fillCenter": { | ||
"__type__": "cc.Vec2", | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"_fillStart": 0, | ||
"_fillRange": 0, | ||
"_isTrimmedMode": true, | ||
"_atlas": null, | ||
"_id": "" | ||
}, | ||
{ | ||
"__type__": "cc.PrefabInfo", | ||
"root": { | ||
"__id__": 1 | ||
}, | ||
"asset": { | ||
"__id__": 0 | ||
}, | ||
"fileId": "420fEzKrZE7oOsyr/lpDSv", | ||
"sync": false, | ||
"_synced": { | ||
"default": false, | ||
"serializable": false | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"ver": "1.0.6", | ||
"importer": "prefab", | ||
"imported": true, | ||
"uuid": "806b3f9b-72f6-47c4-bacf-3f8527a13617", | ||
"displayName": "", | ||
"files": [ | ||
".json" | ||
], | ||
"subMetas": {}, | ||
"userData": {} | ||
} |
Oops, something went wrong.