3d游戏引擎wpf的components组件实现

1.ComponentFactory.cs

using System.Diagnostics;

namespace PrimalEditor.Components
{
    enum ComponentType
    {
        Transform,
        Script,

    }

    static class ComponentFactory
    {

        private static readonly Func[] _function =
            new Func[]
            {
                (entity,data) => new Transform(entity),
                (entity,data) => new Script(entity){ Name = (string)data},

            };

        public static Func GetCreationFunction(ComponentType componentType)
        {

            Debug.Assert((int)componentType < _function.Length);
            return _function[(int)componentType];


        }


        public static ComponentType ToEnumType(this Component component)
        {

            return component switch
            {

                Transform => ComponentType.Transform,
                Script => ComponentType.Script,
                _ => throw new ArgumentException("Unknown component type"),

            };

        }


    }
}

你可能感兴趣的:(3d游戏引擎wpf的components组件实现)