Ejemplo n.º 1
0
        private static void InjectSingle(LDtkDataField instanceField, LDtkFieldInjectorData fieldToInjectInto)
        {
            string field = instanceField.__value.NullOrEmpty() ? string.Empty : instanceField.__value[0];

            object obj = GetValue(fieldToInjectInto.Info.FieldType, field);

            fieldToInjectInto.Info.SetValue(fieldToInjectInto.ObjectRef, obj);
        }
Ejemplo n.º 2
0
        private static void InjectArray(LDtkDataField instanceField, LDtkFieldInjectorData fieldToInjectInto)
        {
            object[] objs = GetValues(fieldToInjectInto.Info.FieldType, instanceField.__value);

            Type elementType = fieldToInjectInto.Info.FieldType.GetElementType();

            if (elementType == null)
            {
                throw new InvalidOperationException();
            }

            Array array = Array.CreateInstance(elementType, objs.Length);

            Array.Copy(objs, array, objs.Length);

            fieldToInjectInto.Info.SetValue(fieldToInjectInto.ObjectRef, array);
        }
Ejemplo n.º 3
0
        private static void InjectFieldIntoInstance(LDtkDataEntity entity, LDtkDataField instanceField,
                                                    List <LDtkFieldInjectorData> injectableFields)
        {
            string dataFieldIdentifier = instanceField.__identifier;

            LDtkFieldInjectorData fieldToInjectInto = GetInjectableFieldMatchingIdentifier(injectableFields, dataFieldIdentifier);

            if (fieldToInjectInto == null)
            {
                Debug.LogError($"LDtk: '{entity.__identifier}'s LDtk {instanceField.__type} field \"{dataFieldIdentifier}\" could not find a matching Game Code field to inject into. Is the field not public?");
                return;
            }

            if (fieldToInjectInto.Info.FieldType.IsArray)
            {
                InjectArray(instanceField, fieldToInjectInto);
            }
            else
            {
                InjectSingle(instanceField, fieldToInjectInto);
            }
        }