89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class SelectSoundDefDialog : DialogBox
|
|
{
|
|
public void OnEnable()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
public void AddSoundDef(InputField field)
|
|
{
|
|
if (field?.text == null || field.text == "")
|
|
{ return; }
|
|
|
|
if (Workspace.soundDefs.Contains(field.text))
|
|
{ field.text = ""; return; }
|
|
|
|
Workspace.soundDefs.Add(field.text);
|
|
|
|
Initialize(true);
|
|
}
|
|
|
|
public void Initialize(bool addedNewTag = false)
|
|
{
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
foreach (AnimationStage stage in Workspace.animationDef.animationStages)
|
|
{
|
|
foreach (PawnAnimationClip clip in stage.animationClips)
|
|
{
|
|
foreach (string soundDef in clip.keyframes.Select(x => x.soundEffect))
|
|
{
|
|
if (Workspace.soundDefs.Contains(soundDef) == false && soundDef != "")
|
|
{ Workspace.soundDefs.Add(soundDef); }
|
|
}
|
|
}
|
|
}
|
|
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
Reset();
|
|
|
|
for (int i = 0; i < Workspace.soundDefs.Count; i++)
|
|
{
|
|
string soundDef = Workspace.soundDefs[i];
|
|
|
|
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
|
|
_optionToggle.Find("Text").GetComponent<Text>().text = soundDef;
|
|
|
|
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
|
|
toggleComp.isOn = Workspace.animationDef.sexTypes.Contains(soundDef);
|
|
toggleComp.onValueChanged.AddListener(delegate {
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe();
|
|
|
|
if (keyframe != null)
|
|
{ keyframe.soundEffect = soundDef; }
|
|
|
|
Workspace.Instance.RecordEvent("Keyframe sound effect");
|
|
});
|
|
|
|
toggleComp.group = contentWindow.GetComponent<ToggleGroup>();
|
|
|
|
if (addedNewTag && i == Workspace.soundDefs.Count - 1)
|
|
{ toggleComp.isOn = true; }
|
|
}
|
|
|
|
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
|
|
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new sound def...";
|
|
|
|
InputField fieldComp = _optionField.GetComponent<InputField>();
|
|
fieldComp.onEndEdit.AddListener(delegate { AddSoundDef(fieldComp); });
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Transform contentWindow = transform.FindDeepChild("Content");
|
|
RemoveCloneObjectsFromParent(contentWindow);
|
|
}
|
|
}
|
|
}
|