DefaultControl.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. using UnityEditor.ShaderGraph.Internal;
  5. using UnityEngine;
  6. using Object = UnityEngine.Object;
  7. using UnityEngine.UIElements;
  8. namespace UnityEditor.ShaderGraph.Drawing.Controls
  9. {
  10. [AttributeUsage(AttributeTargets.Property)]
  11. class DefaultControlAttribute : Attribute, IControlAttribute
  12. {
  13. public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
  14. {
  15. if (propertyInfo.PropertyType == typeof(Color))
  16. return new ColorControlView(null, ColorMode.Default, node, propertyInfo);
  17. if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType))
  18. return new EnumControlView(null, node, propertyInfo);
  19. if (propertyInfo.PropertyType == typeof(Texture2D))
  20. return new TextureControlView(null, node, propertyInfo);
  21. if (propertyInfo.PropertyType == typeof(Texture2DArray))
  22. return new TextureArrayControlView(null, node, propertyInfo);
  23. if (propertyInfo.PropertyType == typeof(Texture3D))
  24. return new Texture3DControlView(null, node, propertyInfo);
  25. if (MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
  26. return new MultiFloatControlView(null, "X", "Y", "Z", "W", node, propertyInfo);
  27. if (typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
  28. return new ObjectControlView(null, node, propertyInfo);
  29. return null;
  30. }
  31. }
  32. }