private static int FindChild(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 1; if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string))) { GameObject obj = LuaScriptMgr.GetUnityObject <GameObject>(L, 1); if (obj == null) { LuaScriptMgr.Instance.CallOnTraceBack(); HobaDebuger.LogError("FindChild: param 1 must be GameObject"); LuaDLL.lua_pushnil(L); return(CheckReturnNum(L, count, nRet)); } string childname = LuaScriptMgr.GetString(L, 2); #if UNITY_EDITOR //HobaDebuger.LogFormat("Lua FindChild {0}", childname); #endif GameObject result = null; if (childname.Contains("/")) { Transform cur_node = obj.transform; //Split var sl = HobaText.GetStringList(); var sb = HobaText.GetStringBuilder(); for (int i = 0; i < childname.Length; ++i) { char c = childname[i]; if (c == '/') { sl.Add(sb.ToString()); //use sb.Length = 0; } else { sb.Append(c); } } if (sb.Length > 0) { sl.Add(sb.ToString()); //use sb.Length = 0; } //Use for (int i = 0; i < sl.Count; i++) { cur_node = cur_node.Find(sl[i]); if (cur_node == null) { result = null; break; } if (i == sl.Count - 1) { result = cur_node.gameObject; } } } else { result = Util.FindChildDirect(obj, childname, true); } LuaScriptMgr.Push(L, result); return(CheckReturnNum(L, count, nRet)); } else { LogParamError("FindChild", count); LuaDLL.lua_pushnil(L); return(CheckReturnNum(L, count, nRet)); } }
static int FindChild(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); GameObject obj = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject"); string arg0 = LuaScriptMgr.GetLuaString(L, 2); GameObject g = null; #if UNITY_EDITOR //Debug.LogFormat("GameObject FindChild {0}", arg0); #endif if (arg0.Contains("/")) { Transform cur_node = obj.transform; //Split var sl = HobaText.GetStringList(); var sb = HobaText.GetStringBuilder(); for (int i = 0; i < arg0.Length; ++i) { char c = arg0[i]; if (c == '/') { sl.Add(sb.ToString()); //use sb.Length = 0; } else { sb.Append(c); } } if (sb.Length > 0) { sl.Add(sb.ToString()); //use sb.Length = 0; } //Use for (int i = 0; i < sl.Count; i++) { cur_node = cur_node.Find(sl[i]); if (cur_node == null) { g = null; break; } if (i == sl.Count - 1) { g = cur_node.gameObject; } } } else { Transform t = obj.transform.Find(arg0); if (t != null) { g = t.gameObject; } } LuaScriptMgr.Push(L, g); return(1); }