Как реализовать изменение системного спрайта в диалоге [дубликат] ⇐ C#

Место общения программистов C#
Anonymous
Как реализовать изменение системного спрайта в диалоге [дубликат]

Сообщение Anonymous »

У меня есть массив спрайтов, и мне нужна помощь в их сортировке и отображении на холсте пользовательского интерфейса в Unity. Не могли бы вы дать рекомендации о том, как лучше всего сортировать и отображать спрайты на холсте в макете? >
помогите, пожалуйста ;-; ;-;
И Unity покажет мне эту ошибку:
нажмите
это мой Massive:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[CreateAssetMenu(menuName ="Dialogue/DialogueObject")]
public class DialogueObject : ScriptableObject
{
[SerializeField] [TextArea] private string nameChar;
[SerializeField] private Sprite[] imgObj;
[SerializeField] [TextArea] private string[] dialogue;
[SerializeField] private Response[] responses;

public Sprite[] ImgObj => imgObj;
public string NameChar => nameChar;

public string[] Dialogue => dialogue;

public bool HasResponses => Responses != null && Responses.Length > 0;

public Response[] Responses => responses;
}

это код для сортировки и отображения:
using UnityEngine;
using TMPro;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class DialogueUI : MonoBehaviour
{
[SerializeField] private GameObject dialogueBox;
[SerializeField] private TMP_Text textLable;
[SerializeField] private TMP_Text textName;
[SerializeField] private Image imgHandler;

public bool IsOpen {get; private set;}

private ResponseHandler responseHandler;
private TypeWriterEffect typeWriterEffect;
private void Start() {
typeWriterEffect=GetComponent();
responseHandler = GetComponent();
imgHandler = GetComponent();

CloseDialogueBox();

}

public void ShowDialogue(DialogueObject dialogueObject){
IsOpen = true;
dialogueBox.SetActive(true);
string nameChar = dialogueObject.NameChar;
textName.text = nameChar;

StartCoroutine(StepTroughtDialogue(dialogueObject));
StartCoroutine (ImgInDialogue(dialogueObject));
}

public void AddResponseEvents(ResponseEvent[] responseEvents){
responseHandler.AddResponseEvents(responseEvents);
}

private IEnumerator ImgInDialogue(DialogueObject dialogueObject){

for (int i = 0; i < dialogueObject.ImgObj.Length; i++ ){
Sprite imgObj = dialogueObject.ImgObj;

imgHandler.sprite = imgObj;

yield return null;
yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Space));
}

}

private IEnumerator StepTroughtDialogue(DialogueObject dialogueObject){

for (int i = 0; i < dialogueObject.Dialogue.Length; i++ ){
string dialogue = dialogueObject.Dialogue;

yield return RunTypingEffect(dialogue);

textLable.text = dialogue;

if (i == dialogueObject.Dialogue.Length - 1 && dialogueObject.HasResponses) break;

yield return null;
yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Space));

}

if (dialogueObject.HasResponses)
{
responseHandler.ShowResponses(dialogueObject.Responses);
}
else
{
CloseDialogueBox();
}

}

private IEnumerator RunTypingEffect(string dialogue){
typeWriterEffect.Run(dialogue, textLable);

while (typeWriterEffect.IsRunning){
yield return null;

if (Input.GetKeyDown(KeyCode.Space)){
typeWriterEffect.Stop();
}
}
}

public void CloseDialogueBox(){
IsOpen = false;
dialogueBox.SetActive(false);
textName.text=string.Empty;
textLable.text=string.Empty;

}

}


Подробнее здесь: https://stackoverflow.com/questions/791 ... n-dialogue

Вернуться в «C#»