Как решить эту ошибку в Unity? error CS0266

134
26 ноября 2019, 20:00

error CS0266: Cannot implicitly convert type INGUIAtlas' toUIAtlas'. An explicit conversion exists (are you missing a cast?)

В начале была ошибка с NGUI, но после обновления NGUI другая ошибка исчезла, но эта осталась! Искал как решить, но так и не нащел.

Возникает вот в этой части.

private UIAtlas startatlas;
    {
        m_sprite = this.GetComponent<UISprite>();
        startatlas = m_sprite.atlas;
        spritenames = startatlas.GetListOfSprites();
        m_trans = this.transform;
    } 

Вот скрипт полностью!

using UnityEngine; 
using System.Collections; 
 
public enum AnimType 
{ 
    Once, 
    Loop 
} 
public enum Dir 
{ 
    Up=0, 
    Right=90, 
    Down=180, 
    Left=270 
} 
public class StartLogAnim : MonoBehaviour { 
    private UIAtlas startatlas; 
    public AnimType type; 
    public float Delaytime; 
    public int FrameRate; 
    private float timeperframe; 
    public int startindex; 
    public int endindex; 
    private int FrameNum; 
    private int currentframe; 
    private UISprite m_sprite; 
    private BetterList<string> spritenames; 
    public bool NeedRotate; 
    public bool NeedSnap; 
    public bool NeedTranslate; 
    public Dir targettdir; 
    public Dir[] currentdir; 
    private Transform m_trans; 
    public Vector3[] TranPos; 
    void Awake() 
    { 
        m_sprite = this.GetComponent<UISprite>(); 
        startatlas = m_sprite.atlas; 
        spritenames = startatlas.GetListOfSprites(); 
        m_trans = this.transform; 
    } 
    void Start() 
    { 
        currentframe = 0; 
        FrameNum = endindex - startindex; 
        timeperframe = 1f / FrameRate; 
        StartCoroutine("StartAnim"); 
    } 
    IEnumerator StartAnim() 
    { 
        yield return new WaitForSeconds(Delaytime); 
 
        if (type == AnimType.Once) 
        { 
            do 
            { 
                yield return new WaitForSeconds(timeperframe); 
                currentframe++; 
                m_sprite.spriteName = spritenames[currentframe+startindex]; 
                if (NeedSnap) 
                { 
                    UISpriteData temp = startatlas.GetSprite(m_sprite.spriteName); 
                    m_sprite.width = temp.width; 
                    m_sprite.height = temp.height; 
                } 
                if (NeedRotate) 
                { 
                    m_trans.rotation = Quaternion.Euler(Vector3.forward * (int)(currentdir[currentframe] - targettdir)); 
                } 
                if (NeedTranslate) 
                { 
                    m_trans.localPosition = TranPos[currentframe]; 
                } 
            } 
            while (currentframe < FrameNum); 
        } 
        else 
        { 
            do 
            { 
                yield return new WaitForSeconds(timeperframe); 
                currentframe++; 
                if (currentframe == FrameNum) 
                    currentframe = 0; 
                m_sprite.spriteName = spritenames[currentframe+startindex]; 
                if (NeedSnap) 
                { 
                    UISpriteData temp = startatlas.GetSprite(m_sprite.spriteName); 
                    m_sprite.width = temp.width; 
                    m_sprite.height = temp.height; 
 
                } 
                if (NeedRotate) 
                { 
                    m_trans.rotation = Quaternion.Euler(Vector3.forward * (int)(currentdir[currentframe] - targettdir)); 
                } 
                if (NeedTranslate) 
                { 
                    m_trans.localPosition = TranPos[currentframe]; 
                } 
            } 
            while (true); 
        } 
    } 
    void EndAnim() 
    { 
        StopCoroutine("StartAnim"); 
    } 
}

Answer 1

Вы пытаетесь присвоить в переменную типа UIAtlas нечто другого типа, INGUIAtlas судя по ошибке

попробуйте поменять тип переменной c

private UIAtlas startatlas;

на

private INGUIAtlas startatlas;
READ ALSO
DataGrid закрасить ячейку

DataGrid закрасить ячейку

Можно ли в WPF с помощью DataGridRowEventArgs закрасить определеную ячейку?

123
C# парсинг многомерного xml файла

C# парсинг многомерного xml файла

Имею XML файл большой вложенности по протоколу CommerceML Сам файл достаточно большой поэтому выложу его по ссылке XML file

126
Изменение размеров изображения

Изменение размеров изображения

Пользователь выбирает картинку для своего аватара, например с разрешением 1920 на 1080 и нажимает кнопку загрузить изображениеКартинка превращается...

127