public UI Create(Scene scene, string type, GameObject parent) { try { UI ui = UIResources.Get(type); ui.AddComponent <UILoginComponent>(); return(ui); } catch (Exception e) { Log.Error(e); return(null); } }
public override void Init() { base.Init(); UI.AddComponent(new TextComponent(UI, Program.FontRepository.GetFont("arial.ttf", 65), "Loading...") { Alignment = TextAlignment.Centered }); _progressComponent = new TextComponent(UI, Program.FontRepository.GetFont("arial.ttf", 35), "0/" + _models.Length + " models") { Alignment = TextAlignment.Centered }; _progressComponent.Transform.Translation += new GlmSharp.vec2(0, -100).ScaleToScreen(); UI.AddComponent(_progressComponent); }
public static void ShowUI(string UIDef, System.Object obj = null) { Transform UIRoot = GameObject.Find(Def.UIDef.UIRoot).transform; //Debug.Log("UIRoot = " + Def.UIDef.UIRoot); GameObject UI; string UI_Base = "Assets." + UIDef + "Logic"; Type t = Type.GetType(UI_Base, true, true); //UIBase comp; if (!UIRoot.Find(UIDef + "(Clone)")) { GameObject Prefab = (GameObject)Resources.Load("UI_Prefab/" + UIDef); //Debug.Log("PrefabResourcePath = "+ "UI_Prefab/" + UIDef); //Debug.Log("Prefab Name =" + Prefab.name); UI = Instantiate(Prefab, UIRoot); if (t != null) { comp = (UIBase)UI.AddComponent(t); TSEngine.Instance.ExecuteOnNextUpdate(delegate { comp.OnInit(); }); } else { Debug.LogError("UI_base类型找不到"); comp = null; } } else { UI = UIRoot.Find(UIDef + "(Clone)").gameObject; comp = (UIBase)UI.GetComponent(t); } UI.SetActive(true); //等一帧执行OnShow TSEngine.Instance.ExecuteOnNextUpdate(delegate { comp.OnShow(obj); }); }
public override void Init() { base.Init(); _font = Program.FontRepository.GetFont("orange_juice_2.ttf"); _buttonFont = Program.FontRepository.GetFont("arial.ttf", 50 * Program.Settings.ScreenRatio.x * 1.2f); _sheet = new ScoreSheet(UI, _font); _dice = new DiceManager(Gl); _dice.Populate(5); _dice.OnRolled += _sheet.UpdateRolled; var r = new ImageBlurRenderComponent(Gl, "Resource/Images/UI/Buttons/BlankButton.png"); _rerollButton = new ButtonComponent(UI, ((vec2)r.Image.Size).ScaleToScreen() * .8f, r); _rerollButton.Transform.Translation += new vec2(-745, -150).ScaleToScreen(); _rerollButton.Transform.Depth = .91f; UI.AddComponent(_rerollButton); _rerollButton.OnRelease += OnRerollPress; _rerollText = (TextComponent)UI.AddComponent(new TextComponent(UI, _buttonFont, "Reroll")); _rerollText.Alignment = TextAlignment.Centered; _rerollText.Transform.Translation = _rerollButton.Transform.Translation; _rerollText.Transform.Depth = .9f; _rerollsLeftText = (TextComponent)UI.AddComponent(new TextComponent(UI, _buttonFont, "")); _rerollsLeftText.Alignment = TextAlignment.Centered; _rerollsLeftText.Transform.Translation = _rerollButton.Transform.Translation - new vec2(0, 120).ScaleToScreen(); _rerollsLeftText.Transform.Scale = new vec2(.6f); _rerollsLeftText.Transform.Depth = .9f; _sheet.CanScore = _dice.CanScore; _sheet.OnSelect += onSheetSelect; _dice.OnPrepareRoll += OnPrepare; _dice.OnPrepareRoll += _sheet.ClearFields; _dice.OnRolled += OnRolled; CurrentCamera.Transform.Translation = new vec3(0, 7f, 8f); CreateLevel(); _dice.PrepareRoll(); }
private void SetLayout() { List <ImageJson> uiList = uiData.data; if (uiroot != null) { Transform[] father = new Transform[3]; for (int i = uiList.Count - 1; i >= 0; i--) { father[0] = null; father[1] = null; father[2] = null; if (uiList[i].father.Contains(":")) { //有祖父级别的物体 string[] fatherGroup = uiList[i].father.Split(':'); int fatherLength = fatherGroup.Length; for (int index = fatherLength - 1; index >= 0; index--) { string fatherUIName = fatherGroup[index].StringModify("#", ""); if (fatherUIName.Contains(".psd") || fatherUIName.Contains("Adobe")) { continue; } father[index] = uiroot.SearchforChild(fatherUIName); if (father[index] == null) { if (index == fatherLength - 1) { father[index] = new GameObject(fatherUIName).AddComponent <RectTransform>().transform; father[index].transform.SetParent(uiroot, false); father[index].transform.localPosition = Vector3.zero; } else { father[index] = new GameObject(fatherUIName).AddComponent <RectTransform>().transform; if (father[index + 1] == null) { father[index + 1] = uiroot; } father[index].transform.SetParent(father[index + 1], false); father[index].transform.localPosition = Vector3.zero; } } } } else { string fatherUIName = uiList[i].father.StringModify("#", ""); //只有父物体 father[0] = uiroot.SearchforChild(fatherUIName); if (father[0] == null) { father[0] = new GameObject(fatherUIName).AddComponent <RectTransform>().transform; father[0].transform.SetParent(uiroot, false); father[0].transform.localPosition = Vector3.zero; } } string name = uiList[i].name; string uiName = name.StringModify("#", ""); Transform UIT = null; GameObject UI = null; if ((uiName.Contains("btn") || uiName.Contains("Btn")) && (uiName.Contains("_pressed") || uiName.Contains("_Pressed"))) { string uiBtnName = uiName.StringModify("_pressed", ""); uiBtnName = uiBtnName.StringModify("_Pressed", ""); Debug.Log(uiBtnName); UIT = uiroot.SearchforChild(uiBtnName); if (UIT != null) { Sprite tex = AssetDatabase.LoadAssetAtPath <Sprite>("Assets" + uiAssetsUrl + "/" + name + ".png"); SpriteState _spriteState = new SpriteState(); _spriteState.pressedSprite = tex; UIT.GetComponent <Button>().transition = Selectable.Transition.SpriteSwap; UIT.GetComponent <Button>().spriteState = _spriteState; Debug.Log(name); } continue; } else { UIT = uiroot.SearchforChild(uiName); } if (UIT == null) { UI = new GameObject(uiName); if (father[0] == null) { father[0] = uiroot; } UI.transform.SetParent(father[0], false); if (UI.GetComponent <RectTransform>() == null) { UI.AddComponent <RectTransform>(); } UI.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(uiList[i].x, -uiList[i].y, 0); UI.GetComponent <RectTransform>().sizeDelta = new Vector2(uiList[i].width, uiList[i].height); } else { UI = UIT.gameObject; } if ((uiName.Contains("btn") || uiName.Contains("Btn")) && !uiName.Contains("pressed") && !uiName.Contains("Pressed")) { Image uiImg = UI.GetComponent <Image>() ? UI.GetComponent <Image>() : UI.AddComponent <Image>(); Button button = UI.GetComponent <Button>() ? UI.GetComponent <Button>() : UI.AddComponent <Button>(); Sprite tex = AssetDatabase.LoadAssetAtPath <Sprite>("Assets" + uiAssetsUrl + "/" + name + ".png"); uiImg.sprite = tex; } else if (!uiName.Contains("btn") && !uiName.Contains("Btn")) { RawImage uiRawImg = UI.GetComponent <RawImage>() ? UI.GetComponent <RawImage>() : UI.AddComponent <RawImage>(); Texture tex = AssetDatabase.LoadAssetAtPath <Texture>("Assets" + uiAssetsUrl + "/" + name + ".png"); uiRawImg.texture = tex; } } EditorUtility.DisplayDialog("R.D.UI自动布局", "布局完毕!", "知道了!"); } else { EditorUtility.DisplayDialog("R.D.UI自动布局", "Error:请指定UI根节点", "知道了!"); } }