MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetDefaultValue

Method GetDefaultValue

Source/Editor/Scripting/TypeUtils.cs:83–118  ·  view source on GitHub ↗

Gets the default value for the given type (can be value type or reference type). The type. The created instance.

(ScriptType type)

Source from the content-addressed store, hash-verified

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.

Callers 11

AddMethod · 0.45
SetMethod · 0.45
OnCopyValueMethod · 0.45
InitDefaultValuesMethod · 0.45
ResizeMethod · 0.45
ResizeMethod · 0.45
AllocateMethod · 0.45
ResizeMethod · 0.45
SetParamTypeMethod · 0.45
AddParameterMethod · 0.45

Calls 3

InitDefaultValuesMethod · 0.80
CreateInstanceMethod · 0.45
IsAssignableFromMethod · 0.45

Tested by

no test coverage detected