void Awake() { //#if !UNITY_EDITOR // this.enabled = false; // return; //#endif canvas = GameObject.FindGameObjectWithTag("demo").GetComponent <Canvas>(); logText = ObjUtils.FindChild <Text>(canvas.transform, "LogTxt"); atlasBtn = ObjUtils.FindChild <Button>(canvas.transform, "atlasBtn"); sceneBtn = ObjUtils.FindChild <Button>(canvas.transform, "sceneBtn"); sourceBtn = ObjUtils.FindChild <Button>(canvas.transform, "sourceBtn"); configBtn = ObjUtils.FindChild <Button>(canvas.transform, "configBtn"); uiBtn = ObjUtils.FindChild <Button>(canvas.transform, "uiBtn"); modelBtn = ObjUtils.FindChild <Button>(canvas.transform, "modelBtn"); eventBtn = ObjUtils.FindChild <Button>(canvas.transform, "eventBtn"); wwwImageBtn = ObjUtils.FindChild <Button>(canvas.transform, "wwwImageBtn"); cameraBtn = ObjUtils.FindChild <Button>(canvas.transform, "cameraBtn"); logText.text = ""; logBuilder = new StringBuilder(); atlasBtn.onClick.AddListener(AtlasTest); sceneBtn.onClick.AddListener(() => { StartCoroutine(SceneTest()); }); sourceBtn.onClick.AddListener(SourceTest); configBtn.onClick.AddListener(ConfigTest); uiBtn.onClick.AddListener(UITest); modelBtn.onClick.AddListener(ModelTest); eventBtn.onClick.AddListener(EventTest); wwwImageBtn.onClick.AddListener(() => { Image img = wwwImageBtn.GetComponentInChildren <Image>(); WWWEngine.SetGameAsyncImage(img, "http://u3d-model.oss-cn-beijing.aliyuncs.com/model/Res/Ver3/testimg.jpg"); }); }
/// <summary> /// 停止特定的音效 /// </summary> /// <param name="audioname"></param> public void SoundStop(string audioname) { GameObject obj = ObjUtils.FindChild(this.transform, "audioname").gameObject; if (obj != null) { Destroy(obj); } }
/// <summary> /// 查找子物体 返回Transform /// </summary> public Transform FindChild(string goName) { if (mFrame == null || string.IsNullOrEmpty(goName)) { return(null); } Transform go = ObjUtils.FindChild(mFrame.transform, goName); return(go); }
/// <summary> /// 查找子物体(递归查找) where T : UnityEngine.Object /// </summary> public T FindChild <T>(Transform parent, string goName) where T : UnityEngine.Object { T go = null; if (mFrame == null || string.IsNullOrEmpty(goName)) { return(null); } if (parent != null) { go = ObjUtils.FindChild <T>(parent, goName); } else { go = ObjUtils.FindChild <T>(mFrame.transform, goName); } return(go); }
/** * 添加到父级 */ public void addToParent() { if (_myParent == null || this.Frame == null) { return; } Transform transform = ObjUtils.FindChild(_myParent.transform, "Camera"); //Transform transform = _myParent.transform; if (transform == null) { Debug.Log(" Camera == null"); } this.Frame.transform.SetParent(transform); this.Frame.GetComponent <RectTransform>().offsetMax = Vector3.zero; this.Frame.GetComponent <RectTransform>().offsetMin = Vector3.zero; this.Frame.transform.localScale = Vector3.one; this.Frame.transform.localPosition = Vector3.zero; }