import UITools from "./UITools";
const {ccclass, property} = cc._decorator;
@ccclass
export default class UITabEx extends cc.Component {
@property(cc.Node)
objCommom: cc.Node = null;
@property(cc.Node)
objPress: cc.Node = null;
callback: Function;
target:any;
mState:boolean;
addButtonEvent(callback: Function, target:any){
this.callback = callback;
this.target = target;
}
onLoad() {
let btn: cc.Button = this.getComponent("Button") as cc.Button;
if(btn == null)
btn = this.addComponent(cc.Button);
UITools.AddButtonEvent(btn,this.onBtnClick,this);
this.UnTab();
}
onBtnClick(){
if(this.mState == false)
{
this.OnclickWithoutMusic();
}
}
OnTab()
{
UITools.SetActive(this.objPress,true);
UITools.SetActive(this.objCommom,false);
if(this.callback != null)
this.callback.call(this.target);
this.mState = true;
}
UnTab()
{
UITools.SetActive(this.objPress,false);
UITools.SetActive(this.objCommom,true);
this.mState = false;
}
/// <summary>
/// 脚本 点击btn
/// </summary>
public OnclickWithoutMusic()
{
this.Set(true);
}
Set( state:boolean)
{
if (state)
{
if (this.node.parent != null)
{
var children = this.node.parent.children;
if(children != null)
{
for (var i = 0;i < children.length;i ++)
{
let script: UITabEx = children[i].getComponent("UITabEx") as UITabEx;
if(script != null)
script.UnTab();
}
}
}
}
if (state)
this.OnTab();
}
}
使用方法:
她们的父节点下,不要有其他node。