public void OnLDtkSetEntityColor(Color newColor) { if (!_setEntityColor || !(_renderer is SpriteRenderer spriteRenderer) || !CheckRendererIsAssigned()) { return; } //maintain alpha newColor.a = spriteRenderer.color.a; //however, if there exists a field with a color, then use it's color instead if (TryGetComponent(out LDtkFields fields)) { LDtkField field = fields._fields.FirstOrDefault(p => p._data.Any(pp => pp._type == LDtkFieldType.Color)); if (field != null) { LDtkFieldElement element = field._data.FirstOrDefault(p => p._type == LDtkFieldType.Color); if (element != null) { newColor = element.GetColorValue(); } } } spriteRenderer.color = newColor; }
private LDtkField GetFieldFromInstance(FieldInstance fieldInstance) { bool isSingle = !fieldInstance.Type.Contains("Array"); LDtkFieldElement[] elements; if (isSingle) { object single = GetSingle(fieldInstance); elements = new[] { new LDtkFieldElement(single, fieldInstance) }; } else { Array array = GetArray(fieldInstance); elements = array.Cast <object>().Select(p => new LDtkFieldElement(p, fieldInstance)).ToArray(); } LDtkField field = new LDtkField(fieldInstance.Identifier, elements, isSingle); return(field); }