变量模块;Element启用控制
This commit is contained in:
@@ -10,7 +10,6 @@ namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIInputFieldUnit : DynamicUICompositeUnit
|
||||
{
|
||||
[FormerlySerializedAs("stringInputField")]
|
||||
public TMP_InputField inputField;
|
||||
|
||||
public override void SetUnit(CompositeParameterWindow window, object itemContent)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIStringIntPairUnit : DynamicUICompositeUnit
|
||||
{
|
||||
public TMP_InputField keyInputField, valueInputField;
|
||||
|
||||
public override void SetUnit(CompositeParameterWindow window, object itemContent)
|
||||
{
|
||||
var pair = (KeyValuePair<string, int>) itemContent;
|
||||
compositeParameterWindow = window;
|
||||
|
||||
keyInputField.text = pair.Key;
|
||||
valueInputField.text = pair.Value.ToString();
|
||||
|
||||
keyInputField.onEndEdit.AddListener(_ => compositeParameterWindow.ApplyParameters());
|
||||
valueInputField.onEndEdit.AddListener(_ => compositeParameterWindow.ApplyParameters());
|
||||
|
||||
removeButton.onClick.AddListener(() =>
|
||||
{
|
||||
compositeParameterWindow.RemoveUnit(this);
|
||||
compositeParameterWindow.ApplyParameters();
|
||||
});
|
||||
}
|
||||
|
||||
public KeyValuePair<string, int> GetValue()
|
||||
{
|
||||
return new KeyValuePair<string, int>(keyInputField.text, int.Parse(valueInputField.text));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c25331c63f94545888c2f71a36d239ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -34,6 +34,11 @@ namespace Ichni.Editor
|
||||
unitList.Remove(unit);
|
||||
Destroy(unit.gameObject);
|
||||
}
|
||||
|
||||
public void AddListenerFunction(UnityAction action)
|
||||
{
|
||||
onQuit = action;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CompositeParameterWindow
|
||||
@@ -254,12 +259,45 @@ namespace Ichni.Editor
|
||||
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, newCurve);
|
||||
};
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
|
||||
public void SetAsStringIntDictionary()
|
||||
{
|
||||
ApplyParameters();
|
||||
//StartCoroutine(WindowAnim.HidePanel(gameObject, true));
|
||||
Destroy(gameObject);
|
||||
//生成Unit
|
||||
void GenerateUnit(KeyValuePair<string, int> content)
|
||||
{
|
||||
DynamicUIStringIntPairUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUIStringIntPairUnit>();
|
||||
unitList.Add(unit);
|
||||
unit.SetUnit(this, content);
|
||||
}
|
||||
|
||||
unitPrefab = EditorManager.instance.basePrefabs.stringIntPairUnit;
|
||||
|
||||
Dictionary<string, int> dictionary = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement) as Dictionary<string, int>;
|
||||
foreach (var pair in dictionary)
|
||||
{
|
||||
GenerateUnit(pair);
|
||||
}
|
||||
|
||||
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||||
|
||||
//为添加新的Unit的按钮设置点击事件
|
||||
addNewUnitButton.onClick.AddListener(() =>
|
||||
{
|
||||
GenerateUnit(new KeyValuePair<string, int>("New Variable", 0));
|
||||
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||||
});
|
||||
|
||||
//将当前所有Unit的值应用到对应的变量中
|
||||
ApplyParameters = () =>
|
||||
{
|
||||
Dictionary<string, int> dictionaryList = new Dictionary<string, int>();
|
||||
foreach (var unit in unitList)
|
||||
{
|
||||
KeyValuePair<string, int> pair = (unit as DynamicUIStringIntPairUnit).GetValue();
|
||||
dictionaryList.Add(pair.Key, pair.Value);
|
||||
}
|
||||
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, dictionaryList);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni;
|
||||
@@ -5,6 +6,7 @@ using Ichni.Editor;
|
||||
using Ichni.RhythmGame;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
@@ -154,8 +156,7 @@ namespace Ichni.Editor
|
||||
return hintText;
|
||||
}
|
||||
|
||||
public DynamicUIHintText GenerateHintText(IBaseElement baseElement, DynamicUIContainer container,
|
||||
System.Func<string> action)
|
||||
public DynamicUIHintText GenerateHintText(IBaseElement baseElement, DynamicUIContainer container, Func<string> action)
|
||||
{
|
||||
DynamicUIHintText hintText = Object.Instantiate(EditorManager.instance.basePrefabs.hintText, container.rect)
|
||||
.GetComponent<DynamicUIHintText>();
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Ichni.Editor
|
||||
public Button closeButton;
|
||||
public TMP_Text title;
|
||||
public UnityAction onCloseWindow;
|
||||
public UnityAction onQuit;
|
||||
|
||||
protected void InitializeWindow(string titleText, UnityAction closeAction = null)
|
||||
{
|
||||
@@ -22,6 +23,7 @@ namespace Ichni.Editor
|
||||
closeButton.onClick.AddListener(() =>
|
||||
{
|
||||
onCloseWindow?.Invoke();
|
||||
onQuit?.Invoke();
|
||||
Destroy(gameObject);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user