Пример #1
0
 internal static ScriptType GetArrayItemType(Box box, ScriptType type)
 {
     if (type == ScriptType.Null)
     {
         return(box.DefaultType);
     }
     return(box.DefaultType != null ? new ScriptType(type.GetElementType()) : type);
 }
Пример #2
0
 /// <summary>
 /// Gets the color for the connection.
 /// </summary>
 /// <param name="type">The connection type.</param>
 /// <param name="hint">The connection hint.</param>
 /// <param name="color">The color.</param>
 public void GetConnectionColor(ScriptType type, ConnectionsHint hint, out Color color)
 {
     if (type == ScriptType.Null)
     {
         color = Colors.Default;
     }
     else if (type.IsPointer || type.IsReference)
     {
         // Find underlying type without `*` or `&`
         var typeName = type.TypeName;
         type = TypeUtils.GetType(typeName.Substring(0, typeName.Length - 1));
         GetConnectionColor(type, hint, out color);
     }
     else if (type.IsArray)
     {
         GetConnectionColor(new ScriptType(type.GetElementType()), hint, out color);
     }
     else if (type.Type == typeof(void))
     {
         color = Colors.Impulse;
     }
     else if (type.Type == typeof(bool))
     {
         color = Colors.Bool;
     }
     else if (type.Type == typeof(byte) || type.Type == typeof(sbyte) || type.Type == typeof(char) || type.Type == typeof(short) || type.Type == typeof(ushort) || type.Type == typeof(int) || type.Type == typeof(uint) || type.Type == typeof(long) || type.Type == typeof(ulong))
     {
         color = Colors.Integer;
     }
     else if (type.Type == typeof(float) || type.Type == typeof(double) || hint == ConnectionsHint.Scalar)
     {
         color = Colors.Float;
     }
     else if (type.Type == typeof(Vector2) || type.Type == typeof(Vector3) || type.Type == typeof(Vector4) || type.Type == typeof(Color))
     {
         color = Colors.Vector;
     }
     else if (type.Type == typeof(string))
     {
         color = Colors.String;
     }
     else if (type.Type == typeof(Quaternion))
     {
         color = Colors.Rotation;
     }
     else if (type.Type == typeof(Transform))
     {
         color = Colors.Transform;
     }
     else if (type.Type == typeof(BoundingBox) || type.Type == typeof(BoundingSphere) || type.Type == typeof(BoundingFrustum))
     {
         color = Colors.Bounds;
     }
     else if (type.IsEnum || hint == ConnectionsHint.Enum)
     {
         color = Colors.Enum;
     }
     else if (type.IsValueType)
     {
         color = Colors.Structures;
     }
     else if (new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(type) || type.IsInterface)
     {
         color = Colors.Object;
     }
     else if (hint == ConnectionsHint.Vector)
     {
         color = Colors.Vector;
     }
     else
     {
         color = Colors.Default;
     }
 }
Пример #3
0
        private static void GetEntries(MemberInfoPath.Entry member, Stack <MemberInfoPath.Entry> membersPath, List <TypeEntry> result, List <object> values, Stack <object> refStack, ScriptType memberType, object memberValue)
        {
            membersPath.Push(member);
            var path        = new MemberInfoPath(membersPath);
            var beforeCount = result.Count;

            // Check if record object sub members (skip Flax objects)
            // It's used for ref types but not null types and with checking cyclic references
            if ((memberType.IsClass || memberType.IsArray || typeof(IList).IsAssignableFrom(memberType.Type) || typeof(IDictionary).IsAssignableFrom(memberType.Type)) &&
                memberValue != null &&
                !refStack.Contains(memberValue))
            {
                if (memberType.IsArray && !typeof(FlaxEngine.Object).IsAssignableFrom(memberType.GetElementType()))
                {
                    // Array
                    var array       = (Array)memberValue;
                    var elementType = new ScriptType(memberType.GetElementType());
                    var length      = array.Length;
                    refStack.Push(memberValue);
                    for (int i = 0; i < length; i++)
                    {
                        var value = array.GetValue(i);
                        GetEntries(new MemberInfoPath.Entry(member.Member, i), membersPath, result, values, refStack, elementType, value);
                    }
                    refStack.Pop();
                }
                else if (typeof(IList).IsAssignableFrom(memberType.Type) && !typeof(FlaxEngine.Object).IsAssignableFrom(memberType.GetElementType()))
                {
                    // List
                    var list             = (IList)memberValue;
                    var genericArguments = memberType.GetGenericArguments();
                    var elementType      = new ScriptType(genericArguments[0]);
                    var count            = list.Count;
                    refStack.Push(memberValue);
                    for (int i = 0; i < count; i++)
                    {
                        var value = list[i];
                        GetEntries(new MemberInfoPath.Entry(member.Member, i), membersPath, result, values, refStack, elementType, value);
                    }
                    refStack.Pop();
                }
                else if (typeof(IDictionary).IsAssignableFrom(memberType.Type))
                {
                    // Dictionary
                    var dictionary       = (IDictionary)memberValue;
                    var genericArguments = memberType.GetGenericArguments();
                    var valueType        = new ScriptType(genericArguments[1]);
                    foreach (var key in dictionary.Keys)
                    {
                        var value = dictionary[key];
                        GetEntries(new MemberInfoPath.Entry(member.Member, key), membersPath, result, values, refStack, valueType, value);
                    }
                }
                else if (memberType.IsClass && !new ScriptType(typeof(FlaxEngine.Object)).IsAssignableFrom(memberType))
                {
                    // Object
                    refStack.Push(memberValue);
                    GetEntries(memberValue, membersPath, memberType, result, values, refStack);
                    refStack.Pop();
                }
            }

            var afterCount = result.Count;

            result.Add(new TypeEntry(path, afterCount - beforeCount));
            var memberValueType = TypeUtils.GetObjectType(memberValue);

            if (memberValue != null && memberValueType.IsStructure)
            {
                var json  = JsonSerializer.Serialize(memberValue);
                var clone = JsonSerializer.Deserialize(json, memberValueType.Type);
                values.Add(clone);
            }
            else
            {
                values.Add(memberValue);
            }
            membersPath.Pop();
        }