Задержка при переключении между анимациями в unity 3d - PullRequest
0 голосов
/ 28 мая 2020

Я пытаюсь переключиться между анимацией реактивного двигателя, но анимация ожидает завершения текущей анимации, а затем запускается анимация, щелкнувшая вторым. Есть ли способ перемотать текущую анимацию вперед и сразу переключиться на вторую. ниже приведен код объекта реактивного двигателя.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class mainScript : MonoBehaviour
{

Animator first;
bool firstTrig = false;
bool secondTrig = false;
bool thirdTrig = false;
bool fourthTrig = false;

string temp = "";
string tempOld = "";

private TMP_Text m_TextComponent;
private bool hasTextChanged;
int visibleCount = 0;

void Awake()
{
    ////m_TextComponent = gameObject.GetComponent<TMP_Text>();
    m_TextComponent = GameObject.Find("/information").GetComponent<TMP_Text>();
}

void OnEnable()
{
    // Subscribe to event fired when text object has been regenerated.
    TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}

void OnDisable()
{
    TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}

// Event received when the text object has changed.
void ON_TEXT_CHANGED(Object obj)
{
    hasTextChanged = true;
}

/* /// <summary> */
/// Method revealing the text one character at a time.
/// </summary>
/// <returns></returns>
IEnumerator RevealCharacters(TMP_Text textComponent)
{
    textComponent.ForceMeshUpdate();

    TMP_TextInfo textInfo = textComponent.textInfo;

    int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object
    //int visibleCount = 0;

    while (true)
    {
        if (hasTextChanged)
        {
            totalVisibleCharacters = textInfo.characterCount; // Update visible character count.
            hasTextChanged = false;
        }

        if (visibleCount > totalVisibleCharacters)
        {
            yield return new WaitForSeconds(0.01f);
            //visibleCount = 0;
        }

        textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?

        visibleCount += 1;
        yield return new WaitForSeconds(0.1f);
        yield return null;
    }
}

// Use this for initialization
void Start()
{
    first = GetComponent<Animator>();
    //m_TextComponent = GetComponent<TMP_Text>();

    //TMP_Text m_TextComponent = gameObject.GetComponent(typeof(TMP_Text)) as TMP_Text;
    StartCoroutine(RevealCharacters(m_TextComponent));
}

// Update is called once per frame
void Update()
{

    if (Input.GetMouseButtonDown(0))
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            Debug.Log(hit.collider.name);
            temp = hit.collider.name.ToString();

            if (temp == "Component_001")
            {
                Debug.Log("open trig");
                first.SetTrigger("open");
            }
            if (temp == "Fan_half004")
            {
                //Debug.Log(m_TextComponent.ToString());
                m_TextComponent.text = "FAN \nThe fan is the first component in a turbofan. The large spinning " +
                    "fan sucks in large quantities of air. Most blades of the fan are made of titanium. " +
                    "It then speeds this air up and splits it into two parts. One part continues through the core or centre of the engine, " +
                    "where it is acted upon by the other engine components.The second part bypasses the core of the engine." +
                    "It goes through a duct that surrounds the core to the back of the engine where it produces much of the " +
                    "force that propels the aeroplane forward.This cooler air helps to quiet the engine as well as adding thrust to the engine.";
                if (temp != tempOld)
                {
                    visibleCount = 0;
                }
                tempOld = temp;
                if (firstTrig == false)
                {
                    first.ResetTrigger("part1In");
                    Debug.Log("part1out " + tempOld.ToString());
                    first.SetTrigger("part1out");
                    firstTrig = true;
                    return;
                }
                if (firstTrig)
                {
                    first.ResetTrigger("part1out");
                    Debug.Log("part1In " + tempOld.ToString());
                    first.SetTrigger("part1In");
                    firstTrig = false;
                    return;
                }

            }
            if (temp == "Cylinder074")
            {
                m_TextComponent.text = "Compressor \nThe compressor is the first component in the engine core. " +
                    "The compressor is made up of fans with many blades and attached to a shaft." +
                    " The compressor squeezes the air that enters it into progressively smaller " +
                    "areas, resulting in an increase in the air pressure. This results in an " +
                    "increase in the energy potential of the air. The squashed air is forced into " +
                    "the combustion chamber.";
                if (temp != tempOld)
                {
                    visibleCount = 0;
                }
                tempOld = temp;
                if (secondTrig == false)
                {
                    first.ResetTrigger("part2In");
                    secondTrig = true;
                    Debug.Log("part2out " + tempOld.ToString());
                    first.SetTrigger("part2out");
                    return;
                }
                if (secondTrig)
                {
                    first.ResetTrigger("part2out");
                    Debug.Log("part2In " + tempOld.ToString());
                    first.SetTrigger("part2In");
                    secondTrig = false;
                    return;
                }

            }

            if (temp == "Circle055")
            {
                m_TextComponent.text = "Combustor \nIn the combustor, the air is mixed with fuel and then " +
                    "ignited. There are as many as 20 nozzles to spray fuel into the airstream." +
                    " The mixture of air and fuel catches fire. This provides a high temperature, " +
                    "high-energy airflow. The fuel burns with the oxygen in the compressed air, " +
                    "producing hot expanding gases. The inside of the combustor is often made of " +
                    "ceramic materials to provide a heat-resistant chamber. The heat can reach 2000°C " +
                    "or more.";
                if (temp != tempOld)
                {
                    visibleCount = 0;
                }
                tempOld = temp;
                if (thirdTrig == false)
                {
                    first.ResetTrigger("part3In");
                    thirdTrig = true;
                    Debug.Log("part3Out " + tempOld.ToString());
                    first.SetTrigger("part3Out");
                    return;
                }
                if (thirdTrig)
                {
                    first.ResetTrigger("part3Out");
                    Debug.Log("part3In " + tempOld.ToString());
                    first.SetTrigger("part3In");
                    thirdTrig = false;
                    return;
                }

            }
            if (temp == "Object028" || temp == "Object027")
            {
                m_TextComponent.text = "Nozzle \nThe nozzle is the exhaust duct of the engine. This is " +
                    "the engine part which actually produces the thrust for the plane. The " +
                    "energy depleted airflow that passed the turbine, in addition to the colder " +
                    "air that bypassed the engine core, produces a force when exiting the " +
                    "nozzle that acts to propel the engine, and therefore the aeroplane, " +
                    "forward. The combination of the hot air and cold air are expelled and " +
                    "produce an exhaust, which causes a forward thrust. The nozzle may be " +
                    "preceded by a mixer, which combines the high-temperature air coming from " +
                    "the engine core with the lower temperature air that was bypassed in the " +
                    "fan";
                if (temp != tempOld)
                {
                    visibleCount = 0;
                }
                tempOld = temp;
                if (fourthTrig == false)
                {
                    visibleCount = 0;
                    first.ResetTrigger("part4In");
                    fourthTrig = true;
                    Debug.Log("part4Out " + tempOld.ToString());
                    first.SetTrigger("part4Out");
                    return;
                }
                if (fourthTrig)
                {
                    first.ResetTrigger("part4Out");
                    Debug.Log("part4In " + tempOld.ToString());
                    first.SetTrigger("part4In");
                    fourthTrig = false;
                    return;
                }

            }
            //first.SetActive(false);Fan_half004
        }
    }
}

}

изображения реактивного двигателя и контроллера аниматора прилагаются.

реактивный двигатель

контроллер аниматора

Пожалуйста, помогите мне решить проблему. Заранее спасибо. Ранджит

1 Ответ

1 голос
/ 28 мая 2020

Просто щелкните линию перехода между анимациями в окне Animator, затем снимите флажок имеет время выхода. enter image description here

А также ваши переходы связаны друг с другом, если вы хотите немедленно запускать другую анимацию, вы можете использовать переход из любого состояния в желаемое состояние, поэтому анимация напрямую воспроизводится, когда параметр соответствует условию. enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...