加弹框。修改连接设备样式。
This commit is contained in:
1 parent
07feba912c
commit
5156473bb2
62 files changed
+4963
-5447
No files matched your search
@@ -6,15 +6,13 @@ using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Assets.Scripts.UI.Control
|
||||
{
|
||||
public class PFUIDropdown : PFUIComponentBase
|
||||
{
|
||||
private int mSelectedIndex = -1;
|
||||
|
||||
private object mSelectedValue;
|
||||
|
||||
private int mSelectedIndex = 0;
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
@@ -23,15 +21,41 @@ namespace Assets.Scripts.UI.Control
|
||||
}
|
||||
}
|
||||
|
||||
public int Value
|
||||
//public int Value
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return this.GetComponent<Dropdown>().value;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// this.GetComponent<Dropdown>().value = value;
|
||||
// }
|
||||
//}
|
||||
|
||||
public string SelectedItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetComponent<Dropdown>().value;
|
||||
if(this.mSelectedIndex >= 0)
|
||||
{
|
||||
return this.GetComponent<Dropdown>().options[this.mSelectedIndex].text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private UnityAction<int> mOnValueChange;
|
||||
public UnityAction<int> OnValueChange
|
||||
{
|
||||
get
|
||||
{
|
||||
return mOnValueChange;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.GetComponent<Dropdown>().value = value;
|
||||
mOnValueChange = value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +64,14 @@ namespace Assets.Scripts.UI.Control
|
||||
//this.mSelectedIndex =
|
||||
//UIManager.AddEvent(this.transform.GetComponent<Image>().gameObject, EventTriggerType.Select, new UnityEngine.Events.UnityAction<BaseEventData>(OnSelect));
|
||||
//UIManager.AddEvent(this.transform.GetComponent<Image>().gameObject, EventTriggerType.Deselect, new UnityEngine.Events.UnityAction<BaseEventData>(OnDeselect));
|
||||
|
||||
this.GetComponent<Dropdown>().onValueChanged.AddListener(i => {
|
||||
mSelectedIndex = i;
|
||||
if (OnValueChange != null)
|
||||
{
|
||||
mOnValueChange(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
@@ -57,9 +89,38 @@ namespace Assets.Scripts.UI.Control
|
||||
|
||||
|
||||
public void AddOptions(List<Dropdown.OptionData> options)
|
||||
{
|
||||
this.GetComponent<Dropdown>().AddOptions(options);
|
||||
}
|
||||
|
||||
public void AddOptions(List<string> options)
|
||||
{
|
||||
this.GetComponent<Dropdown>().AddOptions(options);
|
||||
|
||||
}
|
||||
|
||||
public void ClearOptions()
|
||||
{
|
||||
this.GetComponent<Dropdown>().ClearOptions();
|
||||
}
|
||||
|
||||
|
||||
public void SelectIndex(int index)
|
||||
{
|
||||
this.GetComponent<Dropdown>().value = index;
|
||||
this.mSelectedIndex = index;
|
||||
}
|
||||
|
||||
public void SelectValue(string value)
|
||||
{
|
||||
var options = this.GetComponent<Dropdown>().options;
|
||||
for (int i = 0; i < options.Count; i++)
|
||||
{
|
||||
if(options[i].text == value)
|
||||
{
|
||||
SelectIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ namespace Assets.Scripts.UI.Control
|
||||
{
|
||||
[SerializeField]
|
||||
private InputField mInnerInputField;
|
||||
private Outline outline;
|
||||
private bool isSelected = false;
|
||||
|
||||
public string Text
|
||||
{
|
||||
@@ -27,28 +29,95 @@ namespace Assets.Scripts.UI.Control
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (this.gameObject.activeInHierarchy == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isSelected = true;
|
||||
//throw new NotImplementedException();
|
||||
this.mInnerInputField.OnSelect(eventData);
|
||||
var image = this.transform.GetComponent<Image>();
|
||||
var png = Resources.Load<Sprite>("Images/ipt-1");
|
||||
image.sprite = png;
|
||||
//var image = this.transform.GetComponent<Image>();
|
||||
// var png = Resources.Load<Sprite>("Images/ipt-1");
|
||||
//image.sprite = png;
|
||||
outline.enabled = true;
|
||||
ColorUtility.TryParseHtmlString("#F93086", out Color color);
|
||||
|
||||
outline.effectColor = color;
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if(this.gameObject.activeInHierarchy == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isSelected = false;
|
||||
this.mInnerInputField.OnDeselect(eventData);
|
||||
var image = this.transform.GetComponent<Image>();
|
||||
var png1 = Resources.Load<Sprite>("Images/ipt-0");
|
||||
image.sprite = png1;
|
||||
//var image = this.transform.GetComponent<Image>();
|
||||
//var png1 = Resources.Load<Sprite>("Images/ipt-0");
|
||||
//image.sprite = png1;
|
||||
outline.enabled = false;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Material material = null;
|
||||
if (material == null)
|
||||
{
|
||||
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
}
|
||||
var rect = ((RectTransform)transform).rect;
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height*0.5f, 0));
|
||||
gameObject.GetComponent<Image>().material = material;
|
||||
|
||||
outline = this.GetComponent<Outline>();
|
||||
if (outline == null)
|
||||
{
|
||||
outline = this.gameObject.AddComponent<Outline>();
|
||||
outline.effectDistance = new Vector2(2, 2);
|
||||
}
|
||||
|
||||
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerClick, new UnityAction<BaseEventData>(this.OnSelect));
|
||||
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.Select, new UnityAction<BaseEventData>(this.OnSelect));
|
||||
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.Deselect, new UnityAction<BaseEventData>(this.OnDeselect));
|
||||
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerEnter, new UnityAction<BaseEventData>((e) =>
|
||||
{
|
||||
if (isSelected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
outline.enabled = true;
|
||||
ColorUtility.TryParseHtmlString("#6E6E7D", out Color color);
|
||||
outline.effectColor = color;
|
||||
}));
|
||||
|
||||
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerExit, new UnityAction<BaseEventData>(e =>
|
||||
{
|
||||
if (isSelected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//outline = this.gameObject.AddComponent<Outline>();
|
||||
outline.enabled = false;
|
||||
}));
|
||||
}
|
||||
|
||||
public void SetValidate(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
this.mInnerInputField.GetComponent<Text>().color = Color.white;
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#F93086", out Color color);
|
||||
this.mInnerInputField.GetComponent<Text>().color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.UI.Control
|
||||
{
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class PfPrimaryButton : PFUIComponentBase
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Assets.Scripts.UI.Control
|
||||
{
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class PFUIButton : PFUIComponentBase
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
Normal,
|
||||
Border,
|
||||
Primary
|
||||
}
|
||||
|
||||
[SerializeField] Type mType;
|
||||
private Image image;
|
||||
private Text text;
|
||||
private Texture2D cursor;
|
||||
private Outline outline;
|
||||
protected void Awake()
|
||||
{
|
||||
outline = this.GetComponent<Outline>();
|
||||
if (mType == Type.Border && outline == null)
|
||||
{
|
||||
outline = this.gameObject.AddComponent<Outline>();
|
||||
outline.effectDistance = new Vector2(2, 2);
|
||||
}
|
||||
|
||||
//设置光标
|
||||
cursor = Resources.Load<Texture2D>("Images/PointerButtonHover");
|
||||
|
||||
image = gameObject.GetComponent<Image>();
|
||||
text = this.transform.Find("Text").GetComponent<Text>();
|
||||
|
||||
Material material = null;
|
||||
if (material == null)
|
||||
{
|
||||
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
}
|
||||
var rect = ((RectTransform)transform).rect;
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height*0.5f, 0));
|
||||
image.material = material;
|
||||
|
||||
InitColor();
|
||||
BindEvent();
|
||||
}
|
||||
|
||||
private void InitColor()
|
||||
{
|
||||
text.color = Color.white;
|
||||
switch (mType)
|
||||
{
|
||||
case Type.Normal:
|
||||
{
|
||||
image.color = ConvertColor("#353543");
|
||||
}
|
||||
break;
|
||||
case Type.Border:
|
||||
{
|
||||
outline.enabled = true;
|
||||
image.color = ConvertColor("#3D3E4D");
|
||||
}
|
||||
break;
|
||||
case Type.Primary:
|
||||
{
|
||||
image.color = ConvertColor("#F93086");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void BindEvent()
|
||||
{
|
||||
//鼠标进入
|
||||
UIManager.AddEvent(this.gameObject, EventTriggerType.PointerEnter, new UnityEngine.Events.UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto);
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case Type.Normal:
|
||||
{
|
||||
image.color = ConvertColor("#5C5C6E");
|
||||
}
|
||||
break;
|
||||
case Type.Border:
|
||||
{
|
||||
outline.effectColor = Color.white;
|
||||
}
|
||||
break;
|
||||
case Type.Primary:
|
||||
{
|
||||
image.color = ConvertColor("#FF528A");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
|
||||
//鼠标离开
|
||||
UIManager.AddEvent(this.gameObject, EventTriggerType.PointerExit, new UnityEngine.Events.UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
switch (mType)
|
||||
{
|
||||
case Type.Normal:
|
||||
{
|
||||
image.color = ConvertColor("#353543");
|
||||
}
|
||||
break;
|
||||
case Type.Border:
|
||||
{
|
||||
outline.effectColor = ConvertColor("#474759");
|
||||
}
|
||||
break;
|
||||
case Type.Primary:
|
||||
{
|
||||
image.color = ConvertColor("#F93086");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
|
||||
//按下
|
||||
UIManager.AddEvent(this.gameObject, EventTriggerType.PointerDown, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
switch (mType)
|
||||
{
|
||||
case Type.Normal:
|
||||
{
|
||||
image.color = ConvertColor("#23232D");
|
||||
}
|
||||
break;
|
||||
case Type.Border:
|
||||
{
|
||||
outline.effectColor = ConvertColor("#353543");
|
||||
text.color = ConvertColor("#414251");
|
||||
image.color = ConvertColor("#23232D");
|
||||
}
|
||||
break;
|
||||
case Type.Primary:
|
||||
{
|
||||
image.color = ConvertColor("#BD2255");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
|
||||
//松开
|
||||
UIManager.AddEvent(this.gameObject, EventTriggerType.PointerUp, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
|
||||
{
|
||||
if (!this.isActiveAndEnabled) return;
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case Type.Normal:
|
||||
{
|
||||
image.color = ConvertColor("#5C5C6E");
|
||||
}
|
||||
break;
|
||||
case Type.Border:
|
||||
{
|
||||
outline.effectColor = Color.white;
|
||||
text.color = Color.white;
|
||||
}
|
||||
break;
|
||||
case Type.Primary:
|
||||
{
|
||||
image.color = ConvertColor("#FF528A");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
public void SetEnabled(bool value)
|
||||
{
|
||||
base.enabled = value;
|
||||
if (base.enabled)
|
||||
{
|
||||
InitColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
text.color = ConvertColor("#353543");
|
||||
if (outline != null)
|
||||
{
|
||||
outline.enabled = false;
|
||||
}
|
||||
image.color = ConvertColor("#414251");
|
||||
}
|
||||
}
|
||||
|
||||
private Color ConvertColor(string colorStr)
|
||||
{
|
||||
ColorUtility.TryParseHtmlString(colorStr, out Color color);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user