// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using System.IO;
using FlaxEditor.Scripting;
using FlaxEngine;
using Newtonsoft.Json;
namespace FlaxEditor.Utilities
{
///
/// Editor utilities and helper functions for Variant type.
///
public static class VariantUtils
{
internal enum VariantType
{
Null = 0,
Void,
Bool,
Int,
Uint,
Int64,
Uint64,
Float,
Double,
Pointer,
String,
Object,
Structure,
Asset,
Blob,
Enum,
Vector2,
Vector3,
Vector4,
Color,
Guid,
BoundingBox,
BoundingSphere,
Quaternion,
Transform,
Rectangle,
Ray,
Matrix,
Array,
Dictionary,
ManagedObject,
Typename,
Int2,
Int3,
Int4,
Int16,
Uint16,
}
internal static VariantType ToVariantType(this Type type)
{
VariantType variantType;
if (type == null)
variantType = VariantType.Null;
else if (type == typeof(void))
variantType = VariantType.Void;
else if (type == typeof(bool))
variantType = VariantType.Bool;
else if (type == typeof(short))
variantType = VariantType.Int16;
else if (type == typeof(ushort))
variantType = VariantType.Uint16;
else if (type == typeof(int))
variantType = VariantType.Int;
else if (type == typeof(uint))
variantType = VariantType.Uint;
else if (type == typeof(long))
variantType = VariantType.Int64;
else if (type == typeof(ulong))
variantType = VariantType.Uint64;
else if (type.IsEnum)
variantType = VariantType.Enum;
else if (type == typeof(float))
variantType = VariantType.Float;
else if (type == typeof(double))
variantType = VariantType.Double;
else if (type == typeof(IntPtr))
variantType = VariantType.Pointer;
else if (type == typeof(string))
variantType = VariantType.String;
else if (type == typeof(Type) || type == typeof(ScriptType))
variantType = VariantType.Typename;
else if (typeof(Asset).IsAssignableFrom(type))
variantType = VariantType.Asset;
else if (typeof(FlaxEngine.Object).IsAssignableFrom(type))
variantType = VariantType.Object;
else if (type == typeof(BoundingBox))
variantType = VariantType.BoundingBox;
else if (type == typeof(Transform))
variantType = VariantType.Transform;
else if (type == typeof(Ray))
variantType = VariantType.Ray;
else if (type == typeof(Matrix))
variantType = VariantType.Matrix;
else if (type == typeof(Vector2))
variantType = VariantType.Vector2;
else if (type == typeof(Vector3))
variantType = VariantType.Vector3;
else if (type == typeof(Vector4))
variantType = VariantType.Vector4;
else if (type == typeof(Int2))
variantType = VariantType.Int2;
else if (type == typeof(Int3))
variantType = VariantType.Int3;
else if (type == typeof(Int4))
variantType = VariantType.Int4;
else if (type == typeof(Color))
variantType = VariantType.Color;
else if (type == typeof(Guid))
variantType = VariantType.Guid;
else if (type == typeof(Quaternion))
variantType = VariantType.Quaternion;
else if (type == typeof(Rectangle))
variantType = VariantType.Rectangle;
else if (type == typeof(BoundingSphere))
variantType = VariantType.BoundingSphere;
else if (type.IsValueType)
variantType = VariantType.Structure;
else if (type == typeof(byte[]))
variantType = VariantType.Blob;
else if (type == typeof(object[]))
variantType = VariantType.Array;
else if (type == typeof(Dictionary