private GameObject CreateButton( GameObject prefab, string name, UIAnchor anchor, UIPivot pivot, Vector2 offset, out ButtonInfo buttonInfo) { buttonInfo = (ButtonInfo)null; if (Object.op_Equality((Object)prefab, (Object)null)) { return((GameObject)null); } GameObject gameObject = UITools.InstantiateGUIObject <ButtonInfo>(prefab, this.content.get_transform(), name, UIPivot.op_Implicit(pivot), (Vector2)anchor.min, (Vector2)anchor.max, offset); if (Object.op_Equality((Object)gameObject, (Object)null)) { return((GameObject)null); } buttonInfo = (ButtonInfo)gameObject.GetComponent <ButtonInfo>(); if (Object.op_Equality((Object)gameObject.GetComponent <Button>(), (Object)null)) { Debug.Log((object)"Button prefab is missing Button component!"); return((GameObject)null); } if (!Object.op_Equality((Object)buttonInfo, (Object)null)) { return(gameObject); } Debug.Log((object)"Button prefab is missing ButtonInfo component!"); return((GameObject)null); }
private void CreateText( GameObject prefab, ref Text textComponent, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if (Object.op_Equality((Object)prefab, (Object)null) || Object.op_Equality((Object)this.content, (Object)null)) { return; } if (Object.op_Inequality((Object)textComponent, (Object)null)) { Debug.LogError((object)("Window already has " + name + "!")); } else { GameObject gameObject = UITools.InstantiateGUIObject <Text>(prefab, this.content.get_transform(), name, UIPivot.op_Implicit(pivot), (Vector2)anchor.min, (Vector2)anchor.max, offset); if (Object.op_Equality((Object)gameObject, (Object)null)) { return; } textComponent = (Text)gameObject.GetComponent <Text>(); } }
public void AddContentText(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset) { Text textComponent = (Text)null; this.CreateText(prefab, ref textComponent, "Content Text", pivot, anchor, offset); this._contentText.Add(textComponent); }
// Token: 0x060031E3 RID: 12771 RVA: 0x001468A8 File Offset: 0x00144AA8 public void CreateButton(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string buttonText, UnityAction confirmCallback, UnityAction cancelCallback, bool setDefault) { if (prefab == null) { return; } ButtonInfo buttonInfo; GameObject gameObject = this.CreateButton(prefab, "Button", anchor, pivot, offset, out buttonInfo); if (gameObject == null) { return; } Button component = gameObject.GetComponent <Button>(); if (confirmCallback != null) { component.onClick.AddListener(confirmCallback); } CustomButton customButton = component as CustomButton; if (cancelCallback != null && customButton != null) { customButton.CancelEvent += cancelCallback; } if (buttonInfo.text != null) { buttonInfo.text.text = buttonText; } if (setDefault) { this._defaultUIElement = gameObject; } }
// Token: 0x060031DF RID: 12767 RVA: 0x00146878 File Offset: 0x00144A78 public void AddContentText(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset) { Text item = null; this.CreateText(prefab, ref item, "Content Text", pivot, anchor, offset); this._contentText.Add(item); }
public void AddContentText(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset) { Text text = null; CreateText(prefab, ref text, "Content Text", pivot, anchor, offset); _contentText.Add(text); }
// Token: 0x060031EF RID: 12783 RVA: 0x00146A64 File Offset: 0x00144C64 private void CreateImage(GameObject prefab, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if (!(prefab == null) && !(this.content == null)) { UITools.InstantiateGUIObject <Image>(prefab, this.content.transform, name, pivot, anchor.min, anchor.max, offset); return; } }
public void AddContentImage( GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string text) { this.AddContentImage(prefab, pivot, anchor, offset); }
public void AddContentText( GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string text) { this.AddContentText(prefab, pivot, anchor, offset); this.SetContentText(text, this._contentText.Count - 1); }
/// <summary> /// 设置 UI 组件枢轴 /// </summary> /// <param name="rectTransform">UI 组件</param> /// <param name="x">X 轴锚点</param> /// <param name="y">Y 轴锚点</param> public static void SetUIPivot(RectTransform rectTransform, UIPivot pivot) { float x = 0.5f, y = 0.5f; switch (pivot) { case UIPivot.TopLeft: x = 0; y = 1; break; case UIPivot.TopCenter: x = 0.5f; y = 1; break; case UIPivot.TopRight: x = 1; y = 1; break; case UIPivot.CenterLeft: x = 0; y = 0.5f; break; case UIPivot.Center: x = 0.5f; y = 0.5f; break; case UIPivot.CenterRight: x = 1; y = 0.5f; break; case UIPivot.BottomCenter: x = 0.5f; y = 0; break; case UIPivot.BottomLeft: x = 0; y = 0; break; case UIPivot.BottomRight: x = 1; y = 0; break; } rectTransform.pivot = new Vector2(x, y); }
private void CreateImage( GameObject prefab, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if (Object.op_Equality((Object)prefab, (Object)null) || Object.op_Equality((Object)this.content, (Object)null)) { return; } UITools.InstantiateGUIObject <Image>(prefab, this.content.get_transform(), name, UIPivot.op_Implicit(pivot), (Vector2)anchor.min, (Vector2)anchor.max, offset); }
public void CreateButton( GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string buttonText, UnityAction confirmCallback, UnityAction cancelCallback, bool setDefault) { if (Object.op_Equality((Object)prefab, (Object)null)) { return; } ButtonInfo buttonInfo; GameObject button = this.CreateButton(prefab, "Button", anchor, pivot, offset, out buttonInfo); if (Object.op_Equality((Object)button, (Object)null)) { return; } Button component = (Button)button.GetComponent <Button>(); if (confirmCallback != null) { ((UnityEvent)component.get_onClick()).AddListener(confirmCallback); } CustomButton customButton = component as CustomButton; if (cancelCallback != null && Object.op_Inequality((Object)customButton, (Object)null)) { customButton.CancelEvent += cancelCallback; } if (Object.op_Inequality((Object)buttonInfo.text, (Object)null)) { buttonInfo.text.set_text(buttonText); } if (!setDefault) { return; } this._defaultUIElement = button; }
/// <summary> /// 获取 UI 组件枢轴 /// </summary> /// <param name="rectTransform">UI 组件</param> public static UIPivot GetUIPivot(RectTransform rectTransform) { UIPivot uIPivot = UIPivot.None; float x = rectTransform.pivot.x, y = rectTransform.pivot.y; if (x == 0 && y == 1) { uIPivot = UIPivot.TopLeft; } else if (x == 0 && y == 1) { uIPivot = UIPivot.TopCenter; } else if (x == 0.5f && y == 1) { uIPivot = UIPivot.TopRight; } else if (x == 1 && y == 1) { uIPivot = UIPivot.TopLeft; } else if (x == 0 && y == 1) { uIPivot = UIPivot.TopLeft; } else if (x == 0 && y == 1) { uIPivot = UIPivot.TopLeft; } else if (x == 0 && y == 1) { uIPivot = UIPivot.TopLeft; } else if (x == 0 && y == 1) { uIPivot = UIPivot.TopLeft; } return(uIPivot); }
public void CreateButton(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string buttonText, UnityAction confirmCallback, UnityAction cancelCallback, bool setDefault) { if (prefab == null) { return; } ButtonInfo buttonInfo; GameObject instance = CreateButton(prefab, "Button", anchor, pivot, offset, out buttonInfo); if (instance == null) { return; } Button button = instance.GetComponent <Button>(); if (confirmCallback != null) { button.onClick.AddListener(confirmCallback); } // Create a UI cancel event for this button CustomButton customButton = button as CustomButton; if (cancelCallback != null && customButton != null) { customButton.CancelEvent += cancelCallback; } if (buttonInfo.text != null) { buttonInfo.text.text = buttonText; } if (setDefault) { _defaultUIElement = instance; } }
/// <summary> /// 设置 UI 组件枢轴 /// </summary> /// <param name="rectTransform">UI 组件</param> public static void SetUIPivot(RectTransform rectTransform, UIPivot pivot, RectTransform.Axis axis) { float x = rectTransform.pivot.x, y = rectTransform.pivot.y; if (axis == RectTransform.Axis.Vertical) { if ((pivot & UIPivot.Top) == UIPivot.Top) { y = 1; } else if ((pivot & UIPivot.Center) == UIPivot.Center) { y = 0.5f; } else if ((pivot & UIPivot.Bottom) == UIPivot.Bottom) { y = 0; } } else { if ((pivot & UIPivot.Left) == UIPivot.Left) { x = 0; } else if ((pivot & UIPivot.Center) == UIPivot.Center) { x = 0.5f; } else if ((pivot & UIPivot.Right) == UIPivot.Right) { x = 1; } } rectTransform.pivot = new Vector2(x, y); }
public void CreateButton(GameObject prefab, UIPivot pivot, Rewired.UI.UIAnchor anchor, Vector2 offset, string buttonText, UnityAction confirmCallback, UnityAction cancelCallback, bool setDefault) { if (prefab == null) { return; } ButtonInfo buttonInfo; GameObject gameObject = this.CreateButton(prefab, "Button", anchor, pivot, offset, out buttonInfo); if (gameObject == null) { return; } UnityEngine.UI.Button component = gameObject.GetComponent<UnityEngine.UI.Button>(); if (confirmCallback != null) { component.onClick.AddListener(confirmCallback); } CustomButton customButton = component as CustomButton; if (cancelCallback != null && customButton != null) { customButton.CancelEvent += cancelCallback; } if (buttonInfo.text != null) { buttonInfo.text.text = buttonText; } if (setDefault) { this._defaultUIElement = gameObject; } }
public static bool AlignHCenter(UIPivot pivot) { return(pivot == UIPivot.Center || pivot == UIPivot.Top || pivot == UIPivot.Bottom); }
// Private Methods private void CreateText(GameObject prefab, ref Text textComponent, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if(prefab == null || content == null) return; if(textComponent != null) { Debug.LogError("Window already has " + name + "!"); return; } GameObject instance = UITools.InstantiateGUIObject<Text>( prefab, content.transform, name, pivot, anchor.min, anchor.max, offset ); if(instance == null) return; textComponent = instance.GetComponent<Text>(); }
private GameObject CreateButton(GameObject prefab, string name, UIAnchor anchor, UIPivot pivot, Vector2 offset, out ButtonInfo buttonInfo) { buttonInfo = null; if(prefab == null) return null; GameObject instance = UITools.InstantiateGUIObject<ButtonInfo>( prefab, content.transform, name, pivot, anchor.min, anchor.max, offset ); if(instance == null) return null; buttonInfo = instance.GetComponent<ButtonInfo>(); Button button = instance.GetComponent<Button>(); if(button == null) { Debug.Log("Button prefab is missing Button component!"); return null; } if(buttonInfo == null) { Debug.Log("Button prefab is missing ButtonInfo component!"); return null; } return instance; }
/// <summary> /// 动态创建Toggle,包括动态绑定按钮方法 /// </summary> /// <param name="togglesText"></param> /// <param name="gridList"></param> public static GameObject CreateToggleDynamic(string[] togglesText, UIPivot pivot, ToggleType type, string npcName) { int length = togglesText.Length; if (length < 2) { Debug.Log("不需要创建Toggle"); return(null); } //根据不同的选项个数创建不同长度的toggle float toggleHeight = length * 90 - 20; GameObject go = Resources.Load <GameObject>(Consts.PrefabUIDir + "Toggle"); toggleGo = GameObject.Instantiate(go); toggleGo.transform.SetParent(CanvasTrans, false); toggleGo.transform.localScale = new Vector3(1, 1, 1); toggleGo.name = "Toggle"; RectTransform rect = toggleGo.GetComponent <RectTransform>(); rect.sizeDelta = new Vector2(200, toggleHeight); Vector3 initPos = Vector3.zero; //选择创建的位置 switch (pivot) { case UIPivot.Middle: initPos = new Vector3(0, 0, 0); rect.anchorMin = new Vector2(0.5f, 0.5f); rect.anchorMax = new Vector2(0.5f, 0.5f); break; case UIPivot.RightDown: initPos = new Vector3(-190, 130, 0); rect.anchorMin = new Vector2(1, 0); rect.anchorMax = new Vector2(1, 0); break; } toggleGo.GetComponent <RectTransform>().localPosition = initPos; for (int i = 0; i < togglesText.Length; i++) { go = Resources.Load <GameObject>(Consts.PrefabUIDir + "ToggleGrid"); GameObject gridGo = GameObject.Instantiate(go); gridGo.transform.SetParent(toggleGo.transform, false); gridGo.transform.name = i.ToString(); gridGo.GetComponentInChildren <Text>().text = togglesText[i]; if (i == 0) { //选项默认第一个高亮 EventSystem.current.SetSelectedGameObject(gridGo); } //添加事件响应 string gridName = gridGo.GetComponentInChildren <Text>().text; switch (type) { case ToggleType.ToggleCommand: //角色对话时的响应事件 gridGo.GetComponent <Button>().onClick.AddListener(delegate() { StoryManager.Instance.OnToggleCommandClick(gridName, npcName, true); }); break; case ToggleType.BackgroundTab: //起始选择角色背景的Toggle gridGo.GetComponent <Button>().onClick.AddListener(delegate() { StoryManager.Instance.OnBackgroundTabClick(gridName); }); break; case ToggleType.Backpack: //背包里的Toggle,使用或取消 BackpackToggle bt = toggleGo.AddComponent <BackpackToggle>(); gridGo.GetComponent <Button>().onClick.AddListener(delegate() { bt.UseItemDeal(gridName); }); break; } } toggleGo.SetActive(true); return(toggleGo); }
public void AddContentImage(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string text) { AddContentImage(prefab, pivot, anchor, offset); }
// Private Methods private void CreateText(GameObject prefab, ref Text textComponent, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if (prefab == null || content == null) { return; } if (textComponent != null) { Debug.LogError("Window already has " + name + "!"); return; } GameObject instance = UITools.InstantiateGUIObject <Text>( prefab, content.transform, name, pivot, anchor.min, anchor.max, offset ); if (instance == null) { return; } textComponent = instance.GetComponent <Text>(); }
public void AddContentText(GameObject prefab, UIPivot pivot, Rewired.UI.UIAnchor anchor, Vector2 offset, string text) { this.AddContentText(prefab, pivot, anchor, offset); this.SetContentText(text, this._contentText.Count - 1); }
public void AddContentImage(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset) { CreateImage(prefab, "Image", pivot, anchor, offset); }
public static bool AlignLeft(UIPivot pivot) { return(pivot == UIPivot.Left || pivot == UIPivot.TopLeft || pivot == UIPivot.BottomLeft); }
public static bool AlignVCenter(UIPivot pivot) { return(pivot == UIPivot.Center || pivot == UIPivot.Left || pivot == UIPivot.Right); }
public void AddContentText(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string text) { AddContentText(prefab, pivot, anchor, offset); SetContentText(text, _contentText.Count - 1); }
private GameObject CreateButton(GameObject prefab, string name, Rewired.UI.UIAnchor anchor, UIPivot pivot, Vector2 offset, out ButtonInfo buttonInfo) { buttonInfo = null; if (prefab == null) { return(null); } GameObject gameObject = UITools.InstantiateGUIObject <ButtonInfo>(prefab, this.content.transform, name, pivot, anchor.min, anchor.max, offset); if (gameObject == null) { return(null); } buttonInfo = gameObject.GetComponent <ButtonInfo>(); UnityEngine.UI.Button component = gameObject.GetComponent <UnityEngine.UI.Button>(); if (component == null) { UnityEngine.Debug.Log("Button prefab is missing Button component!"); return(null); } if (buttonInfo == null) { UnityEngine.Debug.Log("Button prefab is missing ButtonInfo component!"); return(null); } return(gameObject); }
private void CreateText(GameObject prefab, ref Text textComponent, string name, UIPivot pivot, Rewired.UI.UIAnchor anchor, Vector2 offset) { if (prefab == null || this.content == null) { return; } if (textComponent != null) { UnityEngine.Debug.LogError("Window already has " + name + "!"); return; } GameObject gameObject = UITools.InstantiateGUIObject <Text>(prefab, this.content.transform, name, pivot, anchor.min, anchor.max, offset); if (gameObject == null) { return; } textComponent = gameObject.GetComponent <Text>(); }
public void CreateButton(GameObject prefab, UIPivot pivot, UIAnchor anchor, Vector2 offset, string buttonText, UnityAction confirmCallback, UnityAction cancelCallback, bool setDefault) { if(prefab == null) return; ButtonInfo buttonInfo; GameObject instance = CreateButton(prefab, "Button", anchor, pivot, offset, out buttonInfo); if(instance == null) return; Button button = instance.GetComponent<Button>(); if(confirmCallback != null) button.onClick.AddListener(confirmCallback); // Create a UI cancel event for this button CustomButton customButton = button as CustomButton; if(cancelCallback != null && customButton != null) customButton.CancelEvent += cancelCallback; if(buttonInfo.text != null) buttonInfo.text.text = buttonText; if(setDefault) _defaultUIElement = instance; }
private void CreateText(GameObject prefab, ref Text textComponent, string name, UIPivot pivot, Rewired.UI.UIAnchor anchor, Vector2 offset) { if (prefab == null || this.content == null) { return; } if (textComponent != null) { UnityEngine.Debug.LogError("Window already has " + name + "!"); return; } GameObject gameObject = UITools.InstantiateGUIObject<Text>(prefab, this.content.transform, name, pivot, anchor.min, anchor.max, offset); if (gameObject == null) { return; } textComponent = gameObject.GetComponent<Text>(); }
private void CreateImage(GameObject prefab, string name, UIPivot pivot, UIAnchor anchor, Vector2 offset) { if(prefab == null || content == null) return; UITools.InstantiateGUIObject<Image>( prefab, content.transform, name, pivot, anchor.min, anchor.max, offset ); }
private GameObject CreateButton(GameObject prefab, string name, Rewired.UI.UIAnchor anchor, UIPivot pivot, Vector2 offset, out ButtonInfo buttonInfo) { buttonInfo = null; if (prefab == null) { return null; } GameObject gameObject = UITools.InstantiateGUIObject<ButtonInfo>(prefab, this.content.transform, name, pivot, anchor.min, anchor.max, offset); if (gameObject == null) { return null; } buttonInfo = gameObject.GetComponent<ButtonInfo>(); UnityEngine.UI.Button component = gameObject.GetComponent<UnityEngine.UI.Button>(); if (component == null) { UnityEngine.Debug.Log("Button prefab is missing Button component!"); return null; } if (buttonInfo == null) { UnityEngine.Debug.Log("Button prefab is missing ButtonInfo component!"); return null; } return gameObject; }
public static bool AlignRight(UIPivot pivot) { return(pivot == UIPivot.Right || pivot == UIPivot.TopRight || pivot == UIPivot.BottomRight); }
public void CreateTitleText(GameObject prefab, Vector2 offset) { this.CreateText(prefab, ref this._titleText, "Title Text", UIPivot.get_TopCenter(), UIAnchor.get_TopHStretch(), offset); }
public static bool AlignTop(UIPivot pivot) { return(pivot == UIPivot.Top || pivot == UIPivot.TopLeft || pivot == UIPivot.TopRight); }
public static bool AlignBottom(UIPivot pivot) { return(pivot == UIPivot.Bottom || pivot == UIPivot.BottomLeft || pivot == UIPivot.BottomRight); }
private GameObject CreateButton(GameObject prefab, string name, UIAnchor anchor, UIPivot pivot, Vector2 offset, out ButtonInfo buttonInfo) { buttonInfo = null; if (prefab == null) { return(null); } GameObject instance = UITools.InstantiateGUIObject <ButtonInfo>( prefab, content.transform, name, pivot, anchor.min, anchor.max, offset ); if (instance == null) { return(null); } buttonInfo = instance.GetComponent <ButtonInfo>(); Button button = instance.GetComponent <Button>(); if (button == null) { Debug.Log("Button prefab is missing Button component!"); return(null); } if (buttonInfo == null) { Debug.Log("Button prefab is missing ButtonInfo component!"); return(null); } return(instance); }
public void AddContentText(GameObject prefab, UIPivot pivot, Rewired.UI.UIAnchor anchor, Vector2 offset) { Text item = null; this.CreateText(prefab, ref item, "Content Text", pivot, anchor, offset); this._contentText.Add(item); }