Add Double2, Double3, Double4 to C# scripting API

This commit is contained in:
Wojtek Figat
2022-05-18 23:23:50 +02:00
parent 523d961f28
commit 04c0f19584
9 changed files with 5793 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.ComponentModel;
using System.Globalization;
namespace FlaxEngine.TypeConverters
{
internal class Double2Converter : TypeConverter
{
/// <inheritdoc />
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
/// <inheritdoc />
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string str)
{
string[] v = str.Split(',');
return new Double2(double.Parse(v[0]), double.Parse(v[1]));
}
return base.ConvertFrom(context, culture, value);
}
/// <inheritdoc />
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var v = (Double2)value;
return v.X + "," + v.Y;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.ComponentModel;
using System.Globalization;
namespace FlaxEngine.TypeConverters
{
internal class Double3Converter : TypeConverter
{
/// <inheritdoc />
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
/// <inheritdoc />
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string str)
{
string[] v = str.Split(',');
return new Double3(double.Parse(v[0]), double.Parse(v[1]), double.Parse(v[2]));
}
return base.ConvertFrom(context, culture, value);
}
/// <inheritdoc />
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var v = (Double3)value;
return v.X + "," + v.Y + "," + v.Z;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.ComponentModel;
using System.Globalization;
namespace FlaxEngine.TypeConverters
{
internal class Double4Converter : TypeConverter
{
/// <inheritdoc />
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
/// <inheritdoc />
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string str)
{
string[] v = str.Split(',');
return new Double4(double.Parse(v[0]), double.Parse(v[1]), double.Parse(v[2]), double.Parse(v[3]));
}
return base.ConvertFrom(context, culture, value);
}
/// <inheritdoc />
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var v = (Double4)value;
return v.X + "," + v.Y + "," + v.Z + "," + v.W;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}