初始化项目

This commit is contained in:
ws.s
2019-04-28 15:41:36 +08:00
parent c1d4a96d00
commit c790c0d4ce
77 changed files with 41694 additions and 0 deletions

67
.gitignore vendored Normal file
View File

@@ -0,0 +1,67 @@
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
library/
temp/
local/
build/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.csproj
*.pidb
*.unityproj
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# exvim files
#/////////////////////////////////////////////////////////////////////////////
*UnityVS.meta
*.err
*.err.meta
*.exvim
*.exvim.meta
*.vimentry
*.vimentry.meta
*.vimproject
*.vimproject.meta
.vimfiles.*/
.exvim.*/
quick_gen_project_*_autogen.bat
quick_gen_project_*_autogen.bat.meta
quick_gen_project_*_autogen.sh
quick_gen_project_*_autogen.sh.meta
.exvim.app
#/////////////////////////////////////////////////////////////////////////////
# webstorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code
#//////////////////////////
.vscode/

7
assets/Behavior.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "c1566763-f92d-4654-98eb-929a26f10c2e",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

7
assets/Behavior/ui.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "db5db990-a4e8-45f0-9d71-86130657dc43",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,74 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property, executeInEditMode, requireComponent, menu} = cc._decorator;
@ccclass
@executeInEditMode
@requireComponent(cc.Sprite)
@menu("添加特殊行为/UI/Frame Index(帧图改变)")
export default class BhvFrameIndex extends cc.Component {
@property({
type:[cc.SpriteFrame],
tooltip:'sprite将会用到帧图片'
})
spriteFrames:Array<cc.SpriteFrame> = [null];
@property({
tooltip:'当前显示的帧图',
type:cc.Integer
})
get index(){
return this._index;
}
set index(value:number){
if (value < 0) return;
this._index = value % this.spriteFrames.length;
let sprite = this.node.getComponent(cc.Sprite);
//设置 Sprite 组件的spriteFrame属性变换图片
sprite.spriteFrame = this.spriteFrames[this._index];
}
@property
private _index:number = 0;
// LIFE-CYCLE CALLBACKS:
/**通过设置帧名字来设置对象 */
setName(name:string){
let index = this.spriteFrames.findIndex(v=>{return v.name == name});
if(index<0){cc.error('frameIndex 设置了不存在的name:',name)}
this.index = index||0;
}
/**随机范围设置帧图片 */
random(min?:number,max?:number){
if(!this.spriteFrames)return;
let frameMax = this.spriteFrames.length;
if(min ==null || min<0)min = 0;
if(max == null || max >frameMax)max = frameMax;
this.index = Math.floor( Math.random()* (max - min) + min );
}
next(){
this.index++;
}
previous(){
this.index--;
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "c238ec1f-2765-499d-9f06-6fc610b394ec",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,242 @@
/*
* @Author: wss
* @Date: 2019-04-17 16:33:34
* @Last Modified by: wss
* @Last Modified time: 2019-04-23 00:24:50
*/
const {ccclass, property, menu} = cc._decorator;
enum VALUE_TYPE {
/**整数模式,只会以整数处理 */
INTEGER,
/**两位小数模式,最终结果保留两位小数 0.00 */
FIXED_2,
/**计时器模式,以计时器格式变动 00:00 */
TIMER,
/**百分比模式 (百分比结果 基于小数,因此初始值必须为小数)*/
PERCENTAGE,
/*缩写单位模式KMBT */
KMBT_FIXED2,
/**自定义模式 (通过传入的函数,进行自定义) */
CUSTOMER
}
/**
* [滚动数字] ver 0.5.0
* 将会使用 lerp 自动滚动数字到目标数值
*/
@ccclass
@menu("添加特殊行为/UI/Roll Number (滚动数字)")
export default class BhvRollNumber extends cc.Component {
@property({
type:cc.Label,
tooltip:'需要滚动的 Label 组件,如果不进行设置,就会从自己的节点自动查找'
})
label:cc.Label = null;
@property({
tooltip:'当前的滚动值(开始的滚动值)'
})
value:number = 0;
@property({
tooltip:'是否显示正负符号'
})
showPlusSymbol:boolean = false;
@property({
tooltip:'滚动的目标值'
})
public get targetValue() : number {
return this._targetValue;
}
public set targetValue(v : number) {
this._targetValue = v;
this.scroll();//数据变动了就开始滚动
}
@property
private _targetValue : number = 100;
/** 滚动的线性差值 0 ~ 1 */
@property({
tooltip:'滚动的线性差值',
step:0.01,
max:1,
min:0
})
lerp = 0.1;
@property({
tooltip:'是否在开始时就播放'
})
private playAtStart:boolean = true;
@property({
tooltip:'在滚动之前会等待几秒',
step:0.1,
max:1,
min:0
})
private runWaitTimer:number = 0;
@property({
type:cc.Enum(VALUE_TYPE),
tooltip:'是否在开始时就播放'
})
private valueType:VALUE_TYPE = VALUE_TYPE.INTEGER;
/**自定义string 处理函数 */
private _custom_callback:(curValue:number,targetValue:number) => string = null;
private isScrolling:boolean = false;
private _lastLabelText:string = '';
//BhvRollNumber
// LIFE-CYCLE CALLBACKS:
onLoad () {
if(this.label == undefined){
this.label = this.node.getComponent(cc.Label);
}
if(this.playAtStart){
this.updateLabel();
this.scroll();
}
}
/**开始滚动数字 */
scroll(){
if(this.isScrolling)return;//已经在滚动了就返回
if(this.runWaitTimer>0){
this.scheduleOnce(()=>{
this.isScrolling = true;
},this.runWaitTimer);
}else{
this.isScrolling = true;
}
}
/**停止滚动数字 */
stop(){
this.value = this.targetValue;
this.isScrolling = false;
this.updateLabel();
}
/**初始化数值,不填写则全部按默认值处理 */
init(value?:number,target?:number,lerp?:number){
this.targetValue = target||0;
this.value = value||0;
this.lerp = lerp||0.1;
}
/**滚动到指定数字 */
scrollTo(target?:number){
if(target === null || target === undefined)return;
this.targetValue = target;
}
/** 更新文本 */
updateLabel(){
let value = this.value;
let string = '';
switch (this.valueType) {
case VALUE_TYPE.INTEGER://最终显示整数类型
string = Math.round(value) + '';
break;
case VALUE_TYPE.FIXED_2://最终显示两位小数类型
string = value.toFixed(2);
break;
case VALUE_TYPE.TIMER: //最终显示 计时器类型
string = parseTimer(value);
break;
case VALUE_TYPE.PERCENTAGE: //最终显示 百分比
string = Math.round(value*100) +'%';
break;
case VALUE_TYPE.KMBT_FIXED2: //长单位缩放,只计算到 KMBT
if(value>=Number.MAX_VALUE){
string = 'MAX';
}else if(value > 1000000000000){
string = (value/1000000000000).toFixed(2)+'T';
}else if(value >1000000000){
string = (value/1000000000).toFixed(2)+'B';
}else if(value >1000000){
string = (value/1000000).toFixed(2)+'M';
}else if(value >1000){
string = (value/1000).toFixed(2)+"K";
}else{
string = Math.round(value).toString();
}
break;
case VALUE_TYPE.CUSTOMER: //自定义设置模式 (通过给定的自定义函数..处理)
if(this._custom_callback){
string = this._custom_callback(this.value,this.targetValue)
}
break;
default:
break;
}
//显示正负符号
if(this.showPlusSymbol){
if(value>0){
string ='+'+string;
}else if(value<0){
string ='-'+string;
}
}
if(this.label){
if(string === this.label.string)return; //保证效率,如果上次赋值过,就不重复赋值
this.label.string = string;
}
}
update (dt) {
if(this.isScrolling == false)return;
this.value = cc.misc.lerp(this.value,this.targetValue,this.lerp);
this.updateLabel();
if(Math.abs(this.value - this.targetValue)<=0.0001){
this.value = this.targetValue;
this.isScrolling = false;
//this.node.emit('roll-hit-target');//滚动数字击中了目标
return;
}
}
}
/** 时间格式转换 */
function parseTimer(timer:number =0,isFullTimer:boolean = true){
let t:number = Math.floor(timer);
let hours:number = Math.floor( t/3600);
let mins:number = Math.floor( (t%3600)/60);
let secs:number = t%60;
let m = ''+mins;
let s = ''+secs;
if(secs<10)s = '0'+secs;
//full timer 按小时算,无论有没有小时
if(isFullTimer){
if(mins<10) m = '0' + mins;
return hours+':'+m+':'+s;
}else{
m = ''+ (mins +hours*60);
if(mins<10) m = '0' + mins;
return m+':'+s;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "72d13770-986f-4b4b-8824-2614ae029dc5",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

7
assets/Scene.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "adf169a1-5da0-42d7-bf15-d292cbe96bf6",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

239
assets/Scene/MvvmShop.fire Normal file
View File

@@ -0,0 +1,239 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "",
"_objFlags": 0,
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_level": 0,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 0.4196484565734863,
"y": 0.4196484565734863,
"z": 1
},
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_zIndex": 0,
"groupIndex": 0,
"autoReleaseAssets": false,
"_id": "eba9afb3-9138-49ef-b07e-832b1fb9974e"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
}
],
"_active": true,
"_level": 0,
"_components": [
{
"__id__": 5
},
{
"__id__": 6
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 480,
"y": 320,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": "5bwAdNMfNOoJav9tvZg41Q"
},
{
"__type__": "cc.Node",
"_name": "Main Camera",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_level": 1,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": "dbAmDZtPNGxKGfdZHl9Lzr"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"_cullingMask": 4294967295,
"_clearFlags": 7,
"_backgroundColor": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": -1,
"_zoomRatio": 1,
"_targetTexture": null,
"_id": "b1mFc5MxFJeKvIwM7s90hu"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_fitWidth": false,
"_fitHeight": true,
"_id": "c6j7SwKTdICo29meU0JDvM"
},
{
"__type__": "5592fzb9yRJaLYviShBDEq5",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"prefab": null,
"_id": "cdPDUwAjJNKqBS4q521yxj"
}
]

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "eba9afb3-9138-49ef-b07e-832b1fb9974e",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "b066bd1e-8c28-4621-afc1-035d48c99243",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "07e2466c-eded-47be-83de-7a2d33aa9dcd",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

4131
assets/Scene/demo.fire Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "b9137d0b-2f6b-41f9-bfa0-96d52ab1afe5",
"asyncLoadAssets": false,
"autoReleaseAssets": false,
"subMetas": {}
}

7
assets/Script.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "aa5d495c-3f0e-4c0a-854e-0648f18d84eb",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,34 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Prefab)
prefab: cc.Prefab = null;
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
onCreateWindow(){
let node = cc.instantiate(this.prefab);
this.node.addChild(node);
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "5592fcdb-f724-4968-b62f-8928410c4ab9",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "427b51aa-09df-4cee-843b-26de5f4421bf",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,980 @@
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false
},
{
"__type__": "cc.Node",
"_name": "CellTest",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 5
},
{
"__id__": 8
},
{
"__id__": 17
}
],
"_active": true,
"_level": 1,
"_components": [],
"_prefab": {
"__id__": 26
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 128,
"height": 128
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_level": 3,
"_components": [
{
"__id__": 3
}
],
"_prefab": {
"__id__": 4
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 97.87,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"_srcBlendFactor": 1,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "Label",
"_N$string": "Label",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "a0H5ydT1BC3LWYMxvJmZdG",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_level": 2,
"_components": [
{
"__id__": 6
}
],
"_prefab": {
"__id__": 7
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 97.87,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": -54.1,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
},
"_enabled": true,
"_srcBlendFactor": 1,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "Label",
"_N$string": "Label",
"_fontSize": 40,
"_lineHeight": 40,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 1,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "46Rez8IaxHUbF/a27BGVXf",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "toggle",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 9
},
{
"__id__": 12
}
],
"_active": true,
"_level": 2,
"_components": [
{
"__id__": 15
}
],
"_prefab": {
"__id__": 16
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -85.4,
"y": 1.8,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Background",
"_objFlags": 0,
"_parent": {
"__id__": 8
},
"_children": [],
"_active": true,
"_level": 0,
"_components": [
{
"__id__": 10
}
],
"_prefab": {
"__id__": 11
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 9
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "6827ca32-0107-4552-bab2-dfb31799bb44"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "775oeMSQpBtomh3G6EISVh",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "checkmark",
"_objFlags": 0,
"_parent": {
"__id__": 8
},
"_children": [],
"_active": true,
"_level": 0,
"_components": [
{
"__id__": 13
}
],
"_prefab": {
"__id__": 14
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 12
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "90004ad6-2f6d-40e1-93ef-b714375c6f06"
},
"_type": 0,
"_sizeMode": 2,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": false,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "ef6oe+xR1CHarmanBuIFtK",
"sync": false
},
{
"__type__": "cc.Toggle",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 8
},
"_enabled": true,
"transition": 3,
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 214,
"g": 214,
"b": 214,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 9
},
"toggleGroup": null,
"checkMark": {
"__id__": 13
},
"checkEvents": [],
"_N$isChecked": true,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "feepDPQMVMp4wOeOh8JkRa",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "toggle",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 18
},
{
"__id__": 21
}
],
"_active": true,
"_level": 2,
"_components": [
{
"__id__": 24
}
],
"_prefab": {
"__id__": 25
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": -85.4,
"y": -56.3,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Background",
"_objFlags": 0,
"_parent": {
"__id__": 17
},
"_children": [],
"_active": true,
"_level": 0,
"_components": [
{
"__id__": 19
}
],
"_prefab": {
"__id__": 20
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 18
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "6827ca32-0107-4552-bab2-dfb31799bb44"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "8fnKRUXjZLyJ4UJVmmMWBw",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "checkmark",
"_objFlags": 0,
"_parent": {
"__id__": 17
},
"_children": [],
"_active": true,
"_level": 0,
"_components": [
{
"__id__": 22
}
],
"_prefab": {
"__id__": 23
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 28,
"height": 28
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_position": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_scale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_rotationX": 0,
"_rotationY": 0,
"_quat": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_skewX": 0,
"_skewY": 0,
"_zIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 21
},
"_enabled": true,
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "90004ad6-2f6d-40e1-93ef-b714375c6f06"
},
"_type": 0,
"_sizeMode": 2,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": false,
"_state": 0,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "042geNzZlJaZQnlnAmTWQR",
"sync": false
},
{
"__type__": "cc.Toggle",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 17
},
"_enabled": true,
"transition": 3,
"pressedColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"hoverColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"duration": 0.1,
"zoomScale": 1.2,
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": false,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 214,
"g": 214,
"b": 214,
"a": 255
},
"_N$disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_N$normalSprite": null,
"_N$pressedSprite": null,
"pressedSprite": null,
"_N$hoverSprite": null,
"hoverSprite": null,
"_N$disabledSprite": null,
"_N$target": {
"__id__": 18
},
"toggleGroup": null,
"checkMark": {
"__id__": 22
},
"checkEvents": [],
"_N$isChecked": true,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "1chntXjNNL/Ioqdgduuap/",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "3b493441-bde8-4113-b111-c410be903cd5"
},
"fileId": "58j/ihCTlH97Y7Fc2AYDLL",
"sync": false
}
]

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "3b493441-bde8-4113-b111-c410be903cd5",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"subMetas": {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.0",
"uuid": "16f94a31-9186-4264-b32c-bf99d53445eb",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"subMetas": {}
}

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "731608ed-fdd6-4eff-ae23-667a860d4c18",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,361 @@
/**
* 实现动态绑定的核心部分,
* 每次修改属性值,都会调用对应函数,并且获取值的路径
*/
const OP = Object.prototype;
const types = {
obj: '[object Object]',
array: '[object Array]'
}
const OAM = ['push', 'pop', 'shift', 'unshift', 'short', 'reverse', 'splice'];
const VM_EMIT_HEAD = 'VC:';
const DEBUG_SHOW_PATH = false;
function setValueFromPath(obj:any,path: string, value: any, tag:string = '') {
let props = path.split('.');
for (let i = 0; i < props.length; i++) {
const propName = props[i];
if (propName in obj === false) { console.error('['+propName + '] not find in ' +tag+'.'+ path); break; }
if (i == props.length - 1) {
obj[propName] = value;
} else {
obj = obj[propName];
}
}
}
//获取路径的值
function getValueFromPath(obj:any,path: string,def?:any, tag:string = ''):any {
let props = path.split('.');
for (let i = 0; i < props.length; i++) {
const propName = props[i];
if ((propName in obj === false)) { console.error('['+propName + '] not find in '+tag+'.'+ path); return def; }
obj = obj[propName];
}
if(obj === null||typeof obj === "undefined")obj = def;//如果g == null 则返回一个默认值
return obj;
}
/**
* 实现属性拦截的类
*/
class JsonOb<T> {
constructor(obj:T, callback: (newVal: any, oldVal: any, pathArray: string[]) => void) {
if (OP.toString.call(obj) !== types.obj && OP.toString.call(obj) !== types.array) {
console.error('请传入一个对象或数组');
}
this._callback = callback;
this.observe(obj);
}
private _callback;
/**对象属性劫持 */
private observe<T>(obj: T, path?) {
if (OP.toString.call(obj) === types.array) {
this.overrideArrayProto(obj, path);
}
Object.keys(obj).forEach((key) => {
let self = this;
let oldVal = obj[key];
let pathArray = path && path.slice();
if (pathArray) {
pathArray.push(key);
}
else {
pathArray = [key];
}
Object.defineProperty(obj, key, {
get: function () {
return oldVal;
},
set: function (newVal) {
//console.log(newVal);
if (oldVal !== newVal) {
if (OP.toString.call(newVal) === '[object Object]') {
self.observe(newVal, pathArray);
}
self._callback(newVal, oldVal, pathArray)
oldVal = newVal
}
}
})
if (OP.toString.call(obj[key]) === types.obj || OP.toString.call(obj[key]) === types.array) {
this.observe(obj[key], pathArray)
}
}, this)
}
/**
* 对数组类型进行动态绑定
* @param array
* @param path
*/
private overrideArrayProto(array: any, path) {
// 保存原始 Array 原型
var originalProto = Array.prototype;
// 通过 Object.create 方法创建一个对象该对象的原型是Array.prototype
var overrideProto = Object.create(Array.prototype);
var self = this;
var result;
// 遍历要重写的数组方法
OAM.forEach((method) => {
Object.defineProperty(overrideProto, method, {
value: function () {
var oldVal = this.slice();
//调用原始原型上的方法
result = originalProto[method].apply(this, arguments);
//继续监听新数组
self.observe(this, path);
self._callback(this, oldVal, path);
return result;
}
})
});
// 最后 让该数组实例的 __proto__ 属性指向 假的原型 overrideProto
array['__proto__'] = overrideProto;
}
}
/**
* ModelViewer 类
*/
class ViewModel<T>{
constructor(data:T,tag:string) {
new JsonOb(data,this._callback.bind(this));
this.$data = data;
this._tag = tag;
}
public $data:T;
//索引值用的标签
private _tag:string = null;
/**激活状态, 将会通过 cc.director.emit 发送值变动的信号 */
public active:boolean = true;
//回调函数 请注意 回调的 path 数组是 引用类型,禁止修改
private _callback(n: any, o: any, path:string[]):void{
if(this.active == true){
let name = VM_EMIT_HEAD + this._tag+'.'+ path.join('.')
if(DEBUG_SHOW_PATH)console.log('>>',n,o,path);
cc.director.emit(name,n,o,[this._tag].concat(path)); //通知末端路径
cc.director.emit(VM_EMIT_HEAD+this._tag,n,o,path);//通知主路径
if(path.length>=2){
for (let i = 0; i < path.length-1; i++) {
const e = path[i];
console.log('中端路径');
}
}
}
}
//通过路径设置数据的方法
public setValue(path: string, value: any) {
setValueFromPath(this.$data,path,value,this._tag);
}
//获取路径的值
public getValue(path: string,def?:any):any {
return getValueFromPath(this.$data,path,def,this._tag);
}
}
/**
* VM 对象管理器(工厂)
*/
class VMManager {
/**静态数组,保存创建的 mv 组件 */
private _mvs:Array<{tag:string,vm:ViewModel<any>}> = [];
public EMIT_HEAD = VM_EMIT_HEAD;
/**
* 绑定一个数据
* @param data 需要绑定的数据
* @param tag 对应该数据的标签(用于识别为哪个VM不允许重复)
*/
add<T>(data:T,tag:string = 'global'){
let vm = new ViewModel<T>(data,tag);
let has = this._mvs.find(v=>v.tag === tag);
if(has){
console.error('already set VM tag:'+ tag);
return;
}
this._mvs.push({tag:tag,vm:vm});
}
/**
* 获取绑定的数据
* @param tag 数据tag
*/
get<T>(tag:string):ViewModel<T>{
let res = this._mvs.find(v => v.tag === tag);
if(res == null){
console.error('cant find VM from:',tag);
}else{
return res.vm;
}
}
/**
* 通过全局路径,而不是 VM 对象来 获取值
* @param path - 全局取值路径
* @param def - 如果取不到值的返回的默认值
*/
getValue(path: string,def?:any):any {
path = path.trim();//防止空格,自动剔除
let rs = path.split('.');
if(rs.length<2){console.error('Cant find path:'+path)};
let vm = this.get(rs[0]);
if(!vm){console.error('Cant Get VM:'+rs[0]);return;};
return vm.getValue(rs.slice(1).join('.'),def);
}
/**
* 通过全局路径,而不是 VM 对象来 设置值
* @param path - 全局取值路径
* @param value - 需要设置的值
*/
setValue(path: string, value: any) {
path = path.trim();//防止空格,自动剔除
let rs = path.split('.');
if(rs.length<2){console.error('Cant find path:'+path)};
let vm = this.get(rs[0]);
if(!vm){console.error('Cant Set VM:'+rs[0]);return;};
vm.setValue(rs.slice(1).join('.'),value);
}
setObjValue = setValueFromPath;
getObjValue = getValueFromPath;
/**等同于 cc.director.on */
bindPath(path: string, callback: Function, target?: any, useCapture?: boolean):void{
path = path.trim();//防止空格,自动剔除
cc.director.on(VM_EMIT_HEAD + path, callback, target, useCapture);
}
/**等同于 cc.director.off */
unbindPath(path: string, callback: Function, target?: any):void{
path = path.trim();//防止空格,自动剔除
cc.director.off(VM_EMIT_HEAD + path, callback, target);
}
/**冻结所有标签的 VM视图将不会受到任何信息 */
inactive():void
inactive(tags:string[]):void
inactive(tag:string):void
/**冻结一系列标签的操作 */
inactive(tag?:any):void{
if(Array.isArray(tag)){
}else{
}
}
/**激活所有标签的 VM*/
active():void
active(tags:string[]):void
active(tag:string):void
/**激活一系列标签的操作 */
active(tag?:any):void{
if(Array.isArray(tag)){
}else{
}
}
}
// 整数、小数、时间、缩写
/**
* 数值格式化函数, 通过语义解析自动设置值的范围
* //整数
* 1:def(0)//显示一个默认值
*/
class FormatFunction {
/** [value:int] 将取值变成整数 */
int(value:number){
return Math.round(value);
}
/** [value:fix2]数值转换为小数*/
fix(value:number,fd:number){
return value.toFixed(fd)
}
/** [value:limit3]字符串长度限制 */
limit(value:string,count:number){
return value.substring(0,count);
}
/** 将数字缩短显示为KMBT单位 大写,目前只支持英文 */
KMBT(value:number,lang:string = 'en'){
//10^4=万, 10^8=亿,10^12=兆,10^16=京,
let counts = [1000,1000000,1000000000,1000000000000];
let units = ['K','M','B','T'];
switch (lang) {
case 'zh':
//10^4=万, 10^8=亿,10^12=兆,10^16=京,
let counts = [10000,100000000,1000000000000,10000000000000000];
let units = ['万','亿','兆','京'];
break;
default:
break;
}
return this.compressUnit(value,counts,units,2);
}
//压缩任意单位的数字,后缀加上单位文字
compressUnit(value,valueArr:number[],unitArr:string[],fixNum:number =2):string{
let counts = valueArr;
let units = unitArr;
let res:string;
let index;
for (index = 0; index < counts.length; index++) {
const e = counts[index];
if(value < e){
res = (value/e).toFixed(fixNum);
break;
}
}
return res + units[index];
}
}
export let VM = new VMManager();

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "000b0d0b-c75f-4a7b-8840-15cf7f4259e1",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,55 @@
import { VM } from './JsonOb';
export class GlobalData {
name: string = '';
info: string = 'xin';
gold: number = 0;
diamond: number = 9000;
progress: number = 0;
icon: number = 0;
check = {
selectA: true,
selectB: false,
selectC: false,
}
obj = {
progress: 0
}
array = [
{ name: 's1', age: 18, sex: 0 },
{ name: 's2', age: 16, sex: 1 },
{ name: 's3', age: 12, sex: 2 },
]
}
class EditorData {
gravity: number = 0;
emissionRate: number = 0;
life: number = 0;
pos = { x: 0, y: 0 }
speed = 0;
speedVar = 0;
startSize = 60
startSizeVar = 0;
endSize = 10
endSizeVar = 5;
}
//原始数据
export let global: GlobalData = new GlobalData();
export let ui: EditorData = new EditorData();
//数据模型绑定,定义后不能修改顺序
VM.add(global, 'game'); //定义全局tag
VM.add(ui, 'editor'); //定义全局tag
//使用注意事项
//VM 得到的回调 onValueChanged ,不能强制修改赋值
//VM 的回调 onValueChanged 中不能直接操作VM数据结构,否则会触发 循环调用

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "663bbba1-3451-4688-85ac-1a007331399e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,161 @@
const { ccclass, property, executeInEditMode, menu } = cc._decorator;
/**
* 用于搜索的MV 组件列表,挂载在父节点后,
* 会遍历搜索下面的所有MV组件, 并且显示其观察值的路径
*/
@ccclass
@executeInEditMode
@menu('ModelViewer/Edit-Comps (快速组件操作)')
export default class MVCompsEdit extends cc.Component {
// LIFE-CYCLE CALLBACKS:
@property({
type:[cc.String]
})
findList:string[] = ["MVCustom", "MVEvent", "MVLabel", "VMModify","VMState","VMParent"];
@property({
tooltip:'勾选后,会自动查找 find list 中填写的组件'
})
public get findTrigger(){
return false;
}
public set findTrigger(v:boolean) {
this.setComponents(0);
}
@property({
tooltip:'勾选后,会批量激活 find list 中填写的组件'
})
public get enableTrigger(){
return false;
}
public set enableTrigger(v:boolean) {
this.setComponents(1);
}
@property({
tooltip:'勾选后,会批量关闭 find list 中填写的组件'
})
public get disableTrigger(){
return false;
}
public set disableTrigger(v:boolean) {
this.setComponents(2);
}
@property({
tooltip:'允许删除节点的组件,确定需要移除请勾选,防止误操作'
})
allowDelete:boolean = false;
@property({
tooltip:'勾选后,会批量删除 find list 中填写的组件',
displayName:'[ X DELETE X ]',
visible:function(){return this.allowDelete}
})
public get deleteTrigger(){
return false;
}
public set deleteTrigger(v:boolean) {
this.setComponents(3);
}
onLoad(){
//不要把脚本挂载运行时的提示
if(!CC_EDITOR){
let path = this.getNodePath(this.node);
console.error('you forget delete MVEditFinder,[path]',path);
}
}
setComponents(state:number){
let array = this.findList;
let title = '搜索到当前节点下面的组件';
switch (state) {
case 0: title = '搜索到当前节点下面的组件';break;
case 1: title = '激活以下节点的组件';break;
case 2: title = '关闭以下节点的组件';break;
case 3: title = '删除以下节点的组件';break;
case 4: title = '替换以下节点的组件';break;
default:
break;
}
cc.log(title)
cc.log('______________________')
array.forEach(name => {
this.searchComponent(name,state)
})
cc.log('______________________')
}
/**
*
* @param className
* @param state 0-查找节点组件 1-激活节点组件 2-关闭节点组件 3-移除节点组件
*/
searchComponent(className: string, state:number = 0) {
let comps = this.node.getComponentsInChildren(className);
if (comps == null || comps.length < 1) return;
cc.log('[' + className + ']:');
comps.forEach(v => {
let ext = v.watchPath?':[Path:' + v.watchPath + ']' : '';
cc.log(this.getNodePath(v.node) + ext);
switch (state) {
case 0://寻找组件
break;
case 1://激活组件
v.enabled = true;
break;
case 2://关闭组件
v.enabled = false;
break;
case 3://删除组件
v.node.removeComponent(v);
break;
default:
break;
}
});
}
getNodePath(node: cc.Node) {
let parent = node;
let array = [];
while (parent) {
let p = parent.getParent();
if (p) {
array.push(parent.name);
parent = p;
} else {
break;
}
}
return array.reverse().join('/');
}
onEnable() {
}
start() {
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "2359e157-285e-4715-84bb-e0aed8d7bfd4",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,173 @@
import { VM } from './JsonOb';
const {ccclass, property,executeInEditMode,menu} = cc._decorator;
/**自动检查识别的数组,你可以准备自己的组件放上去自动识别 */
const COMP_ARRAY_CHECK= [
['BhvRollNumber','targetValue',false],
//组件名、默认属性、controller值
['cc.Label','string',false],
['cc.RichText','string',false],
['cc.EditBox','string',true],
['cc.Slider','progress',true],
['cc.ProgressBar','progress',false],
['cc.Toggle','isChecked',true]
];
/**
* [VM-Custom]
* 自定义数值监听, 可以快速对该节点上任意一个组件上的属性进行双向绑定
*/
@ccclass
@executeInEditMode
@menu('ModelViewer/VM-Custom (自定义VM)')
export default class VMCustom extends cc.Component {
@property
watchPath:string = "";
@property({
tooltip:'激活controller,以开启双向绑定,否则只能接收消息'
})
controller:boolean = false;
@property({
tooltip:'绑定组件的名字'
})
componentName:string = "";
@property({
tooltip:'组件上需要监听的属性'
})
componentProperty:string = "";
@property({
tooltip:'刷新间隔频率(只影响脏检查的频率)',
step:0.01,
range:[0,1],
visible:function(){return this.controller === true}
})
refreshRate:number = 0.1;
//计时器
private _timer = 0;
/**监听的组件对象 */
private _watchComponent:any = null;
/**是否能监听组件的数据 */
private _canWatchComponent:boolean = false;
/**检查的值 */
private _oldValue:any = null;
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.checkEditorComponent();//编辑器检查
//只在运行时检查组件是否缺失可用
if(!CC_EDITOR){
this._watchComponent = this.node.getComponent(this.componentName);
this.checkComponentState();
}
}
onRestore(){
this.checkEditorComponent();
}
//挂在对应节点后,自动获取组件属性和名字
checkEditorComponent(){
if(CC_EDITOR){
let checkArray = COMP_ARRAY_CHECK;
//检查是否是默认数组里的值,如果是才会被编辑器自动改变
// let checkDef = checkArray.find(v=>{
// return v[0] === this.componentName
// })
// if(checkDef == null)return;
this.controller = false;
for (let i = 0; i < checkArray.length; i++) {
const params = checkArray[i];
let comp = this.node.getComponent(params[0] as string);
if(comp){
if(this.componentName =='')this.componentName = params[0] as string;
if(this.componentProperty =='')this.componentProperty = params[1] as string;
if(params[2] !== null)this.controller = params[2] as boolean;
break;
}
}
}
}
start () {
}
onEnable(){
if(this.watchPath == '')return;
VM.bindPath(this.watchPath,this.onValueChanged,this);
}
onDisable(){
if(this.watchPath == '')return;
VM.unbindPath(this.watchPath,this.onValueChanged,this);
}
checkComponentState(){
this._canWatchComponent = false;
if(!this._watchComponent)return;
if(!this.componentProperty)return;
if( this.componentProperty in this._watchComponent === false )return;
this._canWatchComponent = true;
}
getComponentValue(){
return this._watchComponent[this.componentProperty];
}
setComponentValue(value:any){
//如果遇到cc.Toggle 组件就调用上面的方法解决
if(this.componentName == "cc.Toggle"){
if(value == true){
this.node.getComponent(cc.Toggle).check();
}
if(value == false){
this.node.getComponent(cc.Toggle).uncheck();
}
}else{
this._watchComponent[this.componentProperty] = value;
}
}
onValueChanged(n,o,path){
this.setComponentValue(n);
}
update (dt) {
//脏检查(组件是否存在,是否被激活)
if(CC_EDITOR == true)return;
if(!this.controller)return;
if(!this._canWatchComponent||this._canWatchComponent['enabled'] === false)return;
//刷新频率检查
this._timer+=dt;
if(this._timer < this.refreshRate)return;
this._timer = 0;
if(this._oldValue === this.getComponentValue())return;
this._oldValue = this.getComponentValue();
VM.setValue(this.watchPath,this._oldValue);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "ce6627f0-b125-4f2c-aa66-1f1f8aa1c16e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,72 @@
import { VM } from './JsonOb';
//todo
// +普通 label 更新数据的情况,label.string = xxx;
// +frameIndex 插件通过number 数值设置 BhvFrameIndex 来切换当前贴图
// +spriteFrame 直接替换贴图的情况 ,
// 读取本地路径 data.spriteFrame = $res:/pic/com1
// 读取网页路径 data.spriteFrame = $url:http:xxxxxxxxxx.png
// +特殊条件控制
// 比较条件:,如果传入值 > /< />= /<= /== 某值时执行的action类型
const {ccclass, property,executeInEditMode,menu} = cc._decorator;
enum WatchMode {
ccLabel,
ccRichText,
ccSlider,
ccProgressBar,
}
/**
* [VM-Event]
* 提供 ViewModel 的相关基础功能,
* 如果值发生变化将会调用对应的函数方法
*/
@ccclass
@executeInEditMode
@menu('ModelViewer/VM-EventCall(调用函数)')
export default class VMEvent extends cc.Component {
@property({
displayName:'Watch Path',
})
watchPath:string = "";
@property([cc.Component.EventHandler])
changeEvents:cc.Component.EventHandler[] = [];
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
onEnable(){
//this.node.on(this.eventName,this.receiveEvent,this,true);
if(this.watchPath == '')return;
VM.bindPath(this.watchPath,this.valueChanged,this);
}
onDisable(){
if(this.watchPath == '')return;
VM.unbindPath(this.watchPath,this.valueChanged,this);
}
valueChanged(newVar:any,oldVar:any,pathArr:any[]){
if(Array.isArray(this.changeEvents)){
this.changeEvents.forEach(v=>{
v.emit([newVar,oldVar,pathArr]);
})
}
}
start () {
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "a9ce791f-f176-4978-b3e5-4f68969f6cc3",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,230 @@
import { VM } from './JsonOb';
const {ccclass, property,menu,executeInEditMode} = cc._decorator;
const LABEL_TYPE = {
CC_LABEL:'cc.Label',
CC_RICH_TEXT:'cc.RichText',
CC_EDIT_BOX:'cc.EditBox'
}
enum TEMPLATE_MODE {
NONE,
INDEX_NUMBER,
GLOBAL_PATH
}
/**
* [VM-Label]
* 专门处理 Label 相关 的组件,如 ccLabel,ccRichText,ccEditBox
* 可以使用模板化的方式将数据写入,可以处理字符串格式等
* todo 加入i18n 模式,自动解析模板
* todo 加入stringFormat 可以解析转换常见的字符串格式
*/
@ccclass
@executeInEditMode
@menu('ModelViewer/VM-Label(文本VM)')
export default class VMLabel extends cc.Component {
@property({
visible:function(){
return this.templateMode === TEMPLATE_MODE.NONE;
}
})
watchPath:string = "";
@property({
//type:cc.Enum(LABEL_TYPE),
readonly:true
})
private labelType:string = LABEL_TYPE.CC_LABEL;
@property({
type:cc.Enum(TEMPLATE_MODE),
tooltip:'是否启用模板代码,只能在运行时之前设置,\n将会动态解析模板语法 {{name}},并且自动设置监听的路径'
})
private templateMode:TEMPLATE_MODE = TEMPLATE_MODE.NONE;
//按照匹配参数顺序保存的 path 数组
@property({
type:[cc.String],
visible:function(){return this.templateMode === TEMPLATE_MODE.INDEX_NUMBER}
})
private templatePathArr:string[] = [];
//按照匹配参数顺序保存的 值的数组
private templateValueArr:any[] = [];
originText:string = null;
// LIFE-CYCLE CALLBACKS:
onRestore(){
this.checkLabel();
}
onLoad () {
this.checkLabel();
if(!CC_EDITOR){
if(this.templateMode !== TEMPLATE_MODE.NONE){
this.originText = this.getLabelValue();
this.parseTemplate();
}
this.onValueInit();
}
}
onEnable(){
if(this.templateMode !== TEMPLATE_MODE.NONE){
this.setMultPathEvent(true);
return;
}
if(this.watchPath == '')return;
VM.bindPath(this.watchPath,this.onValueChanged,this);
}
onDisable(){
if(this.templateMode !== TEMPLATE_MODE.NONE){
this.setMultPathEvent(false);
return;
}
if(this.watchPath == '')return;
VM.unbindPath(this.watchPath,this.onValueChanged,this);
}
//解析模板
parseTemplate(){
let regexAll = /\{\{(.+?)\}\}/g; //匹配: 所有的{{value}}
let regex = /\{\{(.+?)\}\}/;//匹配: {{value}} 中的 value
let res = this.originText.match(regexAll);//匹配结果数组
if(res==null)return;
let isIndexMode = this.templateMode == TEMPLATE_MODE.INDEX_NUMBER;
for (let i = 0; i < res.length; i++) {
const e = res[i];
let arr = e.match(regex);
let pathName = arr[1];
if(isIndexMode){
let number = parseInt(pathName)||0;
let realPath = this.templatePathArr[number];
this.templateValueArr[i] = VM.getValue(realPath,'?');
}else{
this.templatePathArr[i] = pathName; //缓存path 路径
this.templateValueArr[i] = VM.getValue(pathName,'?'); //初始化通过路径获取的值
}
}
//监听对应的数值变化
this.setMultPathEvent(true);
}
setMultPathEvent(enabled:boolean = true){
if(CC_EDITOR)return;
let arr = this.templatePathArr;
for (let i = 0; i < arr.length; i++) {
const path = arr[i];
if(enabled){
VM.bindPath(path,this.onValueChanged,this);
}else{
VM.unbindPath(path,this.onValueChanged,this);
}
}
}
/**获取解析字符串模板后得到的值 */
getReplaceText(){
let regexAll = /\{\{(.+?)\}\}/g; //匹配: 所有的{{value}}
let regex = /\{\{(.+?)\}\}/;//匹配: {{value}} 中的 value
let res = this.originText.match(regexAll);//匹配结果数组 [{{value}}{{value}}{{value}}]
let str = this.originText;//原始字符串模板 "name:{{0}}"
let isIndexMode = this.templateMode == TEMPLATE_MODE.INDEX_NUMBER;
for (let i = 0; i < res.length; i++) {
const e = res[i];
let getValue;
if(isIndexMode){
let arr = e.match(regex); //匹配到的数组 [{{value}}, value]
let indexNum = parseInt(arr[1]||'0')||0; //取出数组的 value 元素 转换成整数
getValue = this.templateValueArr[indexNum];
str = str.replace(e,getValue);//从路径缓存值获取数据
}else{
getValue = this.templateValueArr[i];//从路径缓存值获取数据
str = str.replace(e,getValue);
}
}
return str;
}
onValueInit(){
//更新信息
if(this.templateMode === TEMPLATE_MODE.NONE){
this.setLabelValue(VM.getValue(this.watchPath)); //
}else{
this.setLabelValue(this.getReplaceText()); // 重新解析
}
}
/**监听数据发生了变动的情况 */
onValueChanged(n,o,pathArr:string[]){
if(this.templateMode === TEMPLATE_MODE.NONE){
this.setLabelValue(n);
}else{
let path = pathArr.join('.');
//寻找缓存位置
let index = this.templatePathArr.findIndex(v=>{
return v === path;
});
if(index >= 0){
//如果是所属的路径,就可以替换文本了
this.templateValueArr[index] = n; //缓存值
this.setLabelValue(this.getReplaceText()); // 重新解析文本
}
}
}
setLabelValue(value){
this.getComponent(this.labelType).string = value;
}
getLabelValue():string{
return this.getComponent(this.labelType).string;
}
checkLabel(){
let checkArray = [
'cc.Label',
'cc.RichText',
'cc.EditBox',
];
for (let i = 0; i < checkArray.length; i++) {
const e = checkArray[i];
let comp = this.node.getComponent(e);
if(comp){
this.labelType = e;
return true;
}
}
cc.error('没有挂载任何label组件');
return false;
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "545c0e57-b06f-460c-98ac-a441962af62f",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,137 @@
import { VM } from './JsonOb';
const {ccclass, property,menu} = cc._decorator;
/**限制值边界范围的模式 */
enum CLAMP_MODE {
MIN,
MAX,
MIN_MAX,
}
/**
* [VM-Modify]
* 动态快速的修改模型的数值,使用按钮 绑定该组件上的函数,即可动态调用
* 修改 Model 的值
*/
@ccclass
@menu('ModelViewer/VM-Modify(修改Model)')
export default class VMModify extends cc.Component {
@property
watchPath:string = "";
@property()
valueClamp:boolean = false;
@property({
type:cc.Enum(CLAMP_MODE),
visible:function(){return this.valueClamp === true}
})
valueClampMode:CLAMP_MODE = CLAMP_MODE.MIN_MAX;
@property({
visible:function(){return this.valueClamp === true && this.valueClampMode !== CLAMP_MODE.MAX}
})
valueMin:number = 0;
@property({
visible:function(){return this.valueClamp === true && this.valueClampMode !== CLAMP_MODE.MIN}
})
valueMax:number = 1;
_vm = VM;
// LIFE-CYCLE CALLBACKS:
start () {
}
//限制最终结果的取值范围
private clampValue(res){
let min = this.valueMin;
let max = this.valueMax;
if(this.valueClamp==false)return res;
switch (this.valueClampMode) {
case CLAMP_MODE.MIN_MAX:
if(res>max)res = max;
if(res<min)res = min;
break;
case CLAMP_MODE.MIN:
if(res<min)res = min;
break;
case CLAMP_MODE.MAX:
if(res>max)res = max;
break;
default:
break;
}
return res;
}
vAddInt(e,data){
this.vAdd(e,data,true);
}
vSubInt(e,data){
this.vSub(e,data,true);
}
vMulInt(e,data){
this.vMul(e,data,true);
}
vDivInt(e,data){
this.vDiv(e,data,true);
}
vAdd(e:cc.Event,data:any,int:boolean = false){
let a = parseFloat(data);
let res = this._vm.getValue(this.watchPath,0) + a;
if(int){res = Math.round(res)}
this._vm.setValue(this.watchPath,this.clampValue(res));
}
vSub(e,data:any,int:boolean = false){
let a = parseFloat(data);
let res = this._vm.getValue(this.watchPath,0) - a;
if(int){res = Math.round(res)}
this._vm.setValue(this.watchPath,this.clampValue(res));
}
vMul(e,data:any,int:boolean = false){
let a = parseFloat(data);
let res = this._vm.getValue(this.watchPath,0) * a;
if(int){res = Math.round(res)}
this._vm.setValue(this.watchPath,this.clampValue(res));
}
vDiv(e,data:any,int:boolean = false){
let a = parseFloat(data);
let res = this._vm.getValue(this.watchPath,0) / a;
if(int){res = Math.round(res)}
this._vm.setValue(this.watchPath,this.clampValue(res));
}
vString(e,data:any){
let a = data;
this._vm.setValue(this.watchPath,a);
}
vNumberInt(e,data:any){
this.vNumber(data,true);
}
vNumber(e,data:any,int:boolean = false){
let a = parseFloat(data);
if(int){a = Math.round(a)}
this._vm.setValue(this.watchPath,this.clampValue(a));
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "7d2a4be8-68e2-4918-9651-5853c6e8193b",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,14 @@
import { VM } from './JsonOb';
//用来处理通知数据的层级
//控制旗下子节点的数据
//目前只是起到一个识别组件的作用,之后会抽象很多功能在这里面
const {ccclass, property,menu} = cc._decorator;
@ccclass
@menu('ModelViewer/VM-Parent (VM父节点)')
export default class VMParent extends cc.Component {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "2f6f3e88-bd47-4f3b-bc72-9e75533e0cdb",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,150 @@
import { VM } from './JsonOb';
const {ccclass, property,menu} = cc._decorator;
/**比较条件 */
enum CONDITION{
"==",
"!=",
">",
">=",
"<",
"<=",
}
enum ACTION {
NODE_ACTIVE, //节点的激活状态 (会影响到容器计算)
NODE_VISIBLE, //节点的显示和隐藏(只是不透明度)
NODE_FADE, //节点的显示和隐藏,包含渐隐的过渡动画
NODE_COLOR, //更改节点的颜色(满足状态/不满足状态)
}
/**
* [VM-State]
* 监听数值状态,根据数值条件设置节点是否激活
*/
@ccclass
@menu('ModelViewer/VM-State (VM状态控制)')
export default class VMState extends cc.Component {
@property
watchPath:string = "";
@property({
type:cc.Enum(CONDITION)
})
condition:CONDITION = CONDITION["=="];
@property({
displayName:'Value: b',
//visible:function(){return this.condition >=2 }
})
value:number = 0;
@property({
type:cc.Enum(ACTION),
tooltip:'一旦满足条件就对节点执行操作'
})
valueAction:ACTION = ACTION.NODE_ACTIVE;
@property({
type:[cc.Node],
tooltip:'需要执行条件的节点,如果不填写则默认会执行本节点下的所有子节点'
})
watchNodes:cc.Node[] = [];
// LIFE-CYCLE CALLBACKS:
onLoad () {
//如果数组里没有监听值,那么默认把所有子节点给监听了
if(this.watchNodes.length == 0){
this.watchNodes = this.watchNodes.concat(this.node.children);
}
this.onValueInit();
}
start () {
}
onEnable(){
if(this.watchPath == '')return;
VM.bindPath(this.watchPath,this.onValueChanged,this);
}
onDisable(){
if(this.watchPath == '')return;
VM.unbindPath(this.watchPath,this.onValueChanged,this);
}
//当值初始化时
private onValueInit(){
let value = VM.getValue(this.watchPath);
let check = this.conditionCheck(value,this.value);
this.setNodesStates(check);
}
//当值被改变时
private onValueChanged(newVar:any,oldVar:any,pathArr:any[]){
let check = this.conditionCheck(newVar,this.value);
this.setNodesStates(check);
}
//更新节点的状态
private setNodesStates(checkState?:boolean){
let nodes = this.watchNodes;
let check = checkState;
nodes.forEach((node)=>{
let n = this.valueAction;
let a = ACTION;
switch (n) {
case a.NODE_ACTIVE: node.active = check?true:false; break;
case a.NODE_VISIBLE: node.opacity = check?255:0; break;
default:
break;
}
})
}
/**条件检查 */
private conditionCheck(a,b):boolean{
let cod = CONDITION;
switch (this.condition) {
case cod["=="]:
if(a == b)return true;
break;
case cod["!="]:
if(a != b)return true;
break;
case cod["<"]:
if(a < b)return true;
break;
case cod[">"]:
if(a > b)return true;
break;
case cod[">="]:
if(a >= b)return true;
break;
case cod["<"]:
if(a < b)return true;
break;
case cod["<="]:
if(a <= b)return true;
break;
default:
break;
}
return false;
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "47052bb0-fd8e-4ed4-b5da-2ce6e3e00471",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "25bbce44-b0ab-411a-88c0-c37eb44880ac",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,84 @@
import { GlobalData } from './../modelView/UserModel';
import { VM } from './../modelView/JsonOb';
import VMParent from '../modelView/VMParent';
const {ccclass, property} = cc._decorator;
class ModelShopShip {
buy = 0;
owns = 15;
progress = 0;
cost = 0;
max = 0;
item = {
name: "神级物品",
price: 150,
max: 99
}
}
let ui_shop: ModelShopShip = new ModelShopShip();
VM.add(ui_shop, 'shop'); //定义全局tag
/**
* 弹窗VM
* 将逻辑判断放在这里
*/
@ccclass
export default class VMPopWindow extends VMParent {
parentPath = 'shop';
private shop:ModelShopShip = VM.get<ModelShopShip>('shop').$data;
private global:GlobalData = VM.get<GlobalData>('game').$data;
onLoad(){
this.init();
}
init(){
this.shop.buy = 0;
this.shop.item.name = '名字不错';
this.shop.item.price = Math.floor( Math.random()*1000 );
this.shop.cost = 0;
//最大能买的数量
let countMax = this.shop.item.max - this.shop.owns;
let valueMax = Math.floor(this.global.diamond/this.shop.item.price);
this.shop.max = Math.min(countMax,valueMax);
}
start () {
}
getResult(){
this.global.diamond -= this.shop.cost;
this.shop.owns += this.shop.buy;
this.node.destroy();
}
close(){
this.node.destroy();
}
onDragProgress(){
this.shop.buy = Math.round(this.shop.progress * this.shop.max);
this.shop.cost = Math.floor(this.shop.buy * this.shop.item.price);
}
onAddItem(e,data:string){
this.shop.buy += parseInt(data);
if(this.shop.buy<0) this.shop.buy = 0;
//限制取值范围,不超过 diamond 数量
if(this.shop.buy > this.shop.max ){
this.shop.buy = this.shop.max;
}
let value = this.shop.buy/this.shop.max
this.shop.progress = Number.isNaN(value)?0:value;
this.shop.cost = Math.floor(this.shop.buy * this.shop.item.price);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "da6c9082-f06a-4e00-9c62-663355750202",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "b6e556c6-c75d-4530-8359-f97db3105f31",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

View File

@@ -0,0 +1,80 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
enum WatchMode {
ccLabel,
ccSlider,
ccProgressBar,
}
@ccclass
export default class BaseWatcher extends cc.Component {
@property
watchPath: string = '';
@property({
type:cc.Enum(WatchMode)
})
watchMode: WatchMode = WatchMode.ccLabel;
oldValue:any = null;
// LIFE-CYCLE CALLBACKS:
onLoad () {
}
start () {
}
onEnable(){
cc.director.on('VC:'+this.watchPath,this.valueChanged,this);
}
onDisable(){
cc.director.off('VC:'+this.watchPath,this.valueChanged,this);
}
valueChanged(v){
//this.node.getComponent(cc.Slider).progress = v;
switch (this.watchMode) {
case WatchMode.ccLabel:
this.node.getComponent(cc.Label).string = v;
break;
case WatchMode.ccSlider:
this.node.getComponent(cc.Slider).progress = v;
break;
case WatchMode.ccProgressBar:
this.node.getComponent(cc.ProgressBar).progress = v;
break;
default:
break;
}
}
valueChanging(){
switch (this.watchMode) {
case WatchMode.ccSlider:
this.node.getComponent(cc.Slider).progress;
break;
default:
break;
}
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "94597351-3f02-4ef6-82f5-f2efad4b6d03",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,38 @@
const {ccclass, property} = cc._decorator;
@ccclass
export default class BaseController extends cc.Component {
// onLoad () {}
public _model:any = {};
start () {
// vm.$data.check = {selectA:true,selectB:true,selectC:true};
}
/**解析模型,遍历修改此模型的所有数值 */
compileModel(){
}
sendEvent(type:string){
let event = new cc.Event.EventCustom(type,true);
event.setUserData({}); //填写数据
this.node.dispatchEvent(event);
}
update (dt) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "0e9dd402-a674-4a81-8d71-1cccd20cd05f",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,31 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
this.getComponent(cc.Label).isSystemFontUsed = true;
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "4d7c4c94-3931-4fd9-9392-2afa8ca17f6d",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,45 @@
import { VM } from './modelView/JsonOb';
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class ParticleCtrl extends cc.Component {
particle:cc.ParticleSystem = null;
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.particle = this.getComponent(cc.ParticleSystem);
}
start () {
}
onValueChange(nv:any,ov:any,pathArr:string[]){
VM.setObjValue(this.particle,pathArr.join('.').replace('pos','posVar'),nv*1000);
}
onEnable(){
}
onDisable(){
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "11403040-ddc0-4a7e-9b8a-12d3edfc49c4",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,36 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
onLoad () {
cc.director.on('VC:game.name',(v)=>{
console.log('收到');
this.getComponent(cc.Label).string = v;
},this);
}
start () {
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "b7496db1-05c9-49a0-b710-1e6c05be49ba",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,44 @@
// Learn TypeScript:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class GlobalWatcher extends cc.Component {
@property({
tooltip:'绑定的属性路径'
})
watcherProp: string = '';
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
}
onEnable(){
}
onDisable(){
}
textChange(){
}
// update (dt) {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "59cc82d1-c16d-4d32-afb7-7a58dc1782f7",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

7
assets/Texture.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "347d6b98-a352-4031-9f2e-f0b88ec9c372",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

7
assets/Texture/icon.meta Normal file
View File

@@ -0,0 +1,7 @@
{
"ver": "1.0.1",
"uuid": "190e6138-56a6-4869-a7f4-66dd746aec3d",
"isSubpackage": false,
"subpackageName": "",
"subMetas": {}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "cb48b8cb-43dd-476f-9b56-a35b14c352ab",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"trea0": {
"ver": "1.0.3",
"uuid": "fb22ae4d-7ca0-462b-8d3c-6b65f6da5233",
"rawTextureUuid": "cb48b8cb-43dd-476f-9b56-a35b14c352ab",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 65,
"height": 96,
"rawWidth": 65,
"rawHeight": 96,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "1478d3fd-222e-4bb9-a565-4e6f5fdce155",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"trea1": {
"ver": "1.0.3",
"uuid": "2754122a-85a7-420a-ab9d-5137b762bd7a",
"rawTextureUuid": "1478d3fd-222e-4bb9-a565-4e6f5fdce155",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 78,
"height": 106,
"rawWidth": 78,
"rawHeight": 106,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "689edcf3-c868-48d8-8d90-40ec112f6bb4",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"trea2": {
"ver": "1.0.3",
"uuid": "66df028a-f057-4d3d-9ea4-4c0fc32f7c93",
"rawTextureUuid": "689edcf3-c868-48d8-8d90-40ec112f6bb4",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 78,
"height": 131,
"rawWidth": 78,
"rawHeight": 131,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "7ef02579-5ed3-4554-a272-ccf9bec868dc",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"trea3": {
"ver": "1.0.3",
"uuid": "a8681f43-cfa5-435b-840e-3eced5658c55",
"rawTextureUuid": "7ef02579-5ed3-4554-a272-ccf9bec868dc",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 100,
"height": 127,
"rawWidth": 100,
"rawHeight": 127,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "a399244b-b3f0-4e9f-b65c-43964610b9bd",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"trea4": {
"ver": "1.0.3",
"uuid": "beb9e32a-cfac-45fe-b1ba-e5adcced47c3",
"rawTextureUuid": "a399244b-b3f0-4e9f-b65c-43964610b9bd",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 141,
"height": 123,
"rawWidth": 141,
"rawHeight": 123,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -0,0 +1,31 @@
{
"ver": "2.2.0",
"uuid": "47cd07f4-9345-41a4-951e-4f77faa09edd",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"subMetas": {
"particle5": {
"ver": "1.0.3",
"uuid": "0682e69f-bfe2-4517-9fee-3f98c5884adf",
"rawTextureUuid": "47cd07f4-9345-41a4-951e-4f77faa09edd",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 3,
"trimY": 5,
"width": 93,
"height": 103,
"rawWidth": 99,
"rawHeight": 113,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

24379
creator.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

15
jsconfig.json Normal file
View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
".vscode",
"library",
"local",
"settings",
"temp"
]
}

4
project.json Normal file
View File

@@ -0,0 +1,4 @@
{
"engine": "cocos-creator-js",
"packages": "packages"
}

28
settings/project.json Normal file
View File

@@ -0,0 +1,28 @@
{
"start-scene": "current",
"group-list": [
"default"
],
"collision-matrix": [
[
true
]
],
"excluded-modules": [],
"design-resolution-width": 960,
"design-resolution-height": 640,
"fit-width": false,
"fit-height": true,
"use-project-simulator-setting": false,
"simulator-orientation": false,
"use-customize-simulator": false,
"simulator-resolution": {
"width": 960,
"height": 640
},
"cocos-analytics": {
"enable": false,
"appID": "13798",
"appSecret": "959b3ac0037d0f3c2fdce94f8421a9b2"
}
}