ScriptableObject在CreateAssetMenu中创建破折号的“非”列表

问题描述 投票:0回答:1

我有下面的代码的调色板ScriptableObject

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityForge
{
    [CreateAssetMenu ( fileName = "NewTerrainPallette", menuName = "DwarvenGear/Forge/", order = 0 )]
    public class TerrainPallette : ScriptableObject, IList<TerrainColor>, IEnumerable<TerrainColor>
    {
        #region Fields
        [SerializeField] private List<TerrainColor> m_TerrainColors = new List<TerrainColor> ();
        #endregion
        #region Properties
        public TerrainColor this [string name]
        {
            get
            {
                foreach ( TerrainColor terrainColor in m_TerrainColors )
                    if ( terrainColor.Name == name )
                        return terrainColor;
                return new TerrainColor ( "BLANK", Color.black );
            }
            set
            {
                for ( int i = 0; i < m_TerrainColors.Count; i++ )
                    if ( m_TerrainColors [i].Name == name )
                        m_TerrainColors [i] = value;
            }
        }
        public TerrainColor this [int index]
        {
            get
            {
                if ( index < m_TerrainColors.Count )
                    return m_TerrainColors [index];
                return new TerrainColor ( "BLANK", Color.black );
            }
            set
            {
                m_TerrainColors [index] = value;
            }
        }
        #endregion
        #region Constructors
        public TerrainPallette ()
        {
            m_TerrainColors = new List<TerrainColor> ();
        }
        #endregion
        #region IEnumerable
        public IEnumerator<TerrainColor> GetEnumerator () => m_TerrainColors.GetEnumerator ();
        IEnumerator IEnumerable.GetEnumerator () => m_TerrainColors.GetEnumerator ();
        #endregion
        #region IList
        public int Count { get { return m_TerrainColors.Count; } }
        public bool IsReadOnly { get { return false; } }
        public void Add ( TerrainColor item ) => m_TerrainColors.Add ( item );
        public void Add ( string name, Color color ) => m_TerrainColors.Add ( new TerrainColor ( name, color ) );
        public void Clear () => m_TerrainColors.Clear ();
        public bool Contains ( TerrainColor item ) => m_TerrainColors.Contains ( item );
        public bool Contains ( string name )
        {
            foreach ( TerrainColor terrainColor in m_TerrainColors )
                if ( terrainColor.Name == name )
                    return true;
            return false;
        }
        public void CopyTo ( TerrainColor [] array ) => m_TerrainColors.CopyTo ( array );
        public void CopyTo ( TerrainColor [] array, int arrayIndex ) => m_TerrainColors.CopyTo ( array, arrayIndex );
        public void CopyTo ( int index, TerrainColor [] array, int arrayIndex, int count ) => m_TerrainColors.CopyTo ( index, array, arrayIndex, count );
        public int IndexOf ( TerrainColor item ) => m_TerrainColors.IndexOf ( item );
        public int IndexOf ( TerrainColor item, int index ) => m_TerrainColors.IndexOf ( item, index );
        public int IndexOf ( TerrainColor item, int index, int count ) => m_TerrainColors.IndexOf ( item, index, count );
        public int IndexOf ( string name )
        {
            foreach ( TerrainColor terrainColor in m_TerrainColors )
                if ( terrainColor.Name == name )
                    return m_TerrainColors.IndexOf ( terrainColor );
            return -1;
        }
        public void Insert ( int index, TerrainColor item ) => m_TerrainColors.Insert ( index, item );
        public void Insert ( int index, string name, Color color ) => m_TerrainColors.Insert ( index, new TerrainColor ( name, color ) );
        public void RemoveAt ( int index ) => m_TerrainColors.RemoveAt ( index );
        public bool Remove ( TerrainColor item ) => m_TerrainColors.Remove ( item );
        public bool Remove ( string name )
        {
            foreach ( TerrainColor terrainColor in m_TerrainColors )
                if ( terrainColor.Name == name )
                    return m_TerrainColors.Remove ( terrainColor );
            return false;
        }
        #endregion
    }
}

但是当我创建调色板时,可以在菜单中找到它

enter image description here

我的代码中目前没有其他ScriptableObjects,并且Unity不会引发任何错误,否则我可以挑选出问题代码。有什么我想念的吗?这是完整的代码,但是我尝试删除了索引器,构造函数,IEnumerable继承以及代码,并且与IList相同。

我有一个调色板ScriptableObject,下面的代码使用System.Collections进行编写;使用System.Collections.Generic;使用UnityEngine;命名空间UnityForge {[CreateAssetMenu(fileName =“ ...

unity3d
1个回答
0
投票

删除“ DwarvenGear / Forge /”中的最后一个破折号

© www.soinside.com 2019 - 2024. All rights reserved.