Created
February 7, 2021 01:44
-
-
Save daichangxin/dd69b8325e1bd82756432f4681a566f5 to your computer and use it in GitHub Desktop.
get members of component
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
export function isDefaultName(name: string) { | |
if (!name) return true; | |
const first_char = name.charAt(0); | |
if (first_char == 'n' || first_char == 'c' || first_char == 't') { | |
return !isNaN(parseInt(name.substr(1))); | |
} | |
return false; | |
} | |
/** 获取所有fgui组件中的子对象(非默认命名) */ | |
const getMembersInfo = (skin: fgui.GComponent) => { | |
const result = {}; | |
// children | |
let i = 0; | |
let len = 0; | |
for (i = 0, len = skin.numChildren; i < len; i++) { | |
const child = skin.getChildAt(i); | |
const childName = child.name; | |
// 忽略空命名 | |
if (isDefaultName(childName)) continue; | |
result[childName] = child; | |
} | |
// transition | |
const t_arr: fgui.Transition[] = skin['_transitions']; | |
for (i = 0, len = t_arr.length; i < len; i++) { | |
const t = t_arr[i]; | |
const tName = t.name; | |
// 忽略空命名 | |
if (isDefaultName(tName)) continue; | |
result[tName] = t; | |
} | |
// controller | |
const c_arr: fgui.Controller[] = skin['_controllers']; | |
for (i = 0, len = c_arr.length; i < len; i++) { | |
const c = c_arr[i]; | |
const cName = c.name; | |
// 忽略空命名 | |
if (isDefaultName(cName)) continue; | |
result[cName] = c; | |
} | |
return result; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment