void LoadPrefab() { { GameObject obj = PrefabCache.main.Load("App/Prefab/Game/GameCodeCar"); gameCodeCarPrefab = obj.GetComponent <GameCodeCar>(); Debug.Log("UIGameCodeCar LoadPrefab"); if (gameCodeCarPrefab == null) { Debug.Log("UIGameCodeCar LoadPrefab gameCodeCarPrefab is null"); } } }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { LoadPrefab(); uiCmdBarSelect.uiCmdBarRun = uiCmdBarRun; uiCmdBarRun.uiCmdBarSelect = uiCmdBarSelect; AppSceneBase.main.UpdateWorldBg(AppRes.IMAGE_GAME_BG); gameCodeCar = (GameCodeCar)GameObject.Instantiate(gameCodeCarPrefab); AppSceneBase.main.AddObjToMainWorld(gameCodeCar.gameObject); //必须在设置transform.parent之后重置offsetMin和offsetMax RectTransform rctran = gameCodeCar.GetComponent <RectTransform>(); rctran.offsetMin = new Vector2(0, 0); rctran.offsetMax = new Vector2(0, 0); gameCodeCar.transform.localPosition = Vector3.zero; gameCodeCar.uiCmdBarRun = uiCmdBarRun; }