Gets the default value for the given type (can be value type or reference type). The type. The created instance.
(ScriptType type)
| 81 | /// <param name="type">The type.</param> |
| 82 | /// <returns>The created instance.</returns> |
| 83 | public static object GetDefaultValue(ScriptType type) |
| 84 | { |
| 85 | if (type.Type == typeof(string)) |
| 86 | return string.Empty; |
| 87 | if (type.Type == typeof(Color)) |
| 88 | return Color.White; |
| 89 | if (type.Type == typeof(Quaternion)) |
| 90 | return Quaternion.Identity; |
| 91 | if (type.Type == typeof(Transform)) |
| 92 | return Transform.Identity; |
| 93 | if (type.Type == typeof(Matrix)) |
| 94 | return Matrix.Identity; |
| 95 | if (type.Type == typeof(BoundingBox)) |
| 96 | return BoundingBox.Zero; |
| 97 | if (type.Type == typeof(Rectangle)) |
| 98 | return Rectangle.Empty; |
| 99 | if (type.Type == typeof(ChannelMask)) |
| 100 | return ChannelMask.Red; |
| 101 | if (type.Type == typeof(MaterialSceneTextures)) |
| 102 | return MaterialSceneTextures.BaseColor; |
| 103 | if (type.IsValueType) |
| 104 | { |
| 105 | var value = type.CreateInstance(); |
| 106 | FlaxEditor.Utilities.Utils.InitDefaultValues(value); |
| 107 | return value; |
| 108 | } |
| 109 | if (ScriptType.Object.IsAssignableFrom(type)) |
| 110 | return null; |
| 111 | if (type.CanCreateInstance) |
| 112 | { |
| 113 | var value = type.CreateInstance(); |
| 114 | FlaxEditor.Utilities.Utils.InitDefaultValues(value); |
| 115 | return value; |
| 116 | } |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | /// <summary> |
| 121 | /// Gets all the derived types from the given base type (excluding that type) within the given assembly. |
no test coverage detected