1
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace MuHua {
|
||||
public class UIFloatField : FloatField {
|
||||
public new class UxmlFactory : UxmlFactory<UIFloatField, UxmlTraits> { }
|
||||
public new class UxmlTraits : FloatField.UxmlTraits { }
|
||||
public VisualElement inputElement;
|
||||
public VisualElement textElement;
|
||||
public UIFloatField() {
|
||||
ClearClassList();
|
||||
AddToClassList("input-field");
|
||||
|
||||
labelElement.ClearClassList();
|
||||
labelElement.AddToClassList("unity-text-element");
|
||||
labelElement.AddToClassList("input-field-label");
|
||||
|
||||
inputElement = this.Q<VisualElement>("unity-text-input");
|
||||
inputElement.ClearClassList();
|
||||
inputElement.AddToClassList("input-field-box");
|
||||
|
||||
textElement = inputElement.Q<VisualElement>("");
|
||||
textElement.ClearClassList();
|
||||
textElement.AddToClassList("unity-text-element");
|
||||
textElement.AddToClassList("input-field-text");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7046acdb2e5ef0c458969a4022ee9ab4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace MuHua {
|
||||
public class UILongField : LongField {
|
||||
public new class UxmlFactory : UxmlFactory<UILongField, UxmlTraits> { }
|
||||
public new class UxmlTraits : LongField.UxmlTraits { }
|
||||
public UILongField() {
|
||||
ClearClassList();
|
||||
AddToClassList("input-field");
|
||||
|
||||
labelElement.ClearClassList();
|
||||
labelElement.AddToClassList("unity-text-element");
|
||||
labelElement.AddToClassList("input-field-label");
|
||||
|
||||
VisualElement inputElement = this.Q<VisualElement>("unity-text-input");
|
||||
inputElement.ClearClassList();
|
||||
inputElement.AddToClassList("input-field-box");
|
||||
|
||||
VisualElement textElement = inputElement.Q<VisualElement>("");
|
||||
textElement.ClearClassList();
|
||||
textElement.AddToClassList("unity-text-element");
|
||||
textElement.AddToClassList("input-field-text");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d30b5caf969d9b4ab1464d329cf16ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace MuHua {
|
||||
public class UITextField : TextField {
|
||||
public new class UxmlFactory : UxmlFactory<UITextField, UxmlTraits> { }
|
||||
public new class UxmlTraits : TextField.UxmlTraits {
|
||||
public UxmlStringAttributeDescription DefaultPrompt = new UxmlStringAttributeDescription {
|
||||
name = "default-prompt"
|
||||
};
|
||||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
|
||||
base.Init(ve, bag, cc);
|
||||
UITextField textField = (UITextField)ve;
|
||||
textField.DefaultPrompt = DefaultPrompt.GetValueFromBag(bag, cc);
|
||||
textField.SetDefaultPrompt();
|
||||
}
|
||||
}
|
||||
public string DefaultPrompt { get; set; }
|
||||
|
||||
public VisualElement inputElement => this.Q<VisualElement>("unity-text-input");
|
||||
public VisualElement textElement => inputElement.Q<VisualElement>("");
|
||||
|
||||
public UITextField() {
|
||||
ClearClassList();
|
||||
AddToClassList("input-field");
|
||||
|
||||
labelElement.ClearClassList();
|
||||
labelElement.AddToClassList("unity-text-element");
|
||||
labelElement.AddToClassList("input-field-label");
|
||||
|
||||
inputElement.ClearClassList();
|
||||
inputElement.AddToClassList("input-field-box");
|
||||
|
||||
textElement.ClearClassList();
|
||||
textElement.AddToClassList("unity-text-element");
|
||||
textElement.AddToClassList("input-field-text");
|
||||
|
||||
RegisterCallback<FocusInEvent>((evt) => { PrepareInput(); });
|
||||
RegisterCallback<FocusOutEvent>((evt) => { SetDefaultPrompt(); });
|
||||
}
|
||||
public void PrepareInput() {
|
||||
textElement.RemoveFromClassList("input-field-text-d");
|
||||
if (text != DefaultPrompt) { return; }
|
||||
text = "";
|
||||
}
|
||||
public void SetDefaultPrompt() {
|
||||
textElement.RemoveFromClassList("input-field-text-d");
|
||||
if (value != "") { return; }
|
||||
text = DefaultPrompt;
|
||||
textElement.AddToClassList("input-field-text-d");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bbf7cc5bf423304dbb4eac4f82b2bee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user