public void AddTargets(FieldAtlas at, string target)
 {
     if (!atlasFields.Contains(at.atlasedField))
     {
         atlasFields.Add(at.atlasedField);
     }
     if (!targetFields.Contains(target))
     {
         targetFields.Add(target);
     }
 }
        public void OnChangeMaterial(PlaytimePainter painter)
        {
#if UNITY_EDITOR
            if (originalMaterial != null)
            {
                originalTextures = originalMaterial.GetTextures();
            }

            if ((DestinationMaterial != null) && (DestinationMaterial.HasProperty(PainterDataAndConfig.isAtlasedProperty)))
            {
                List <string> aTextures = DestinationMaterial.GetTextures();
                fields.Clear();
                for (int i = 0; i < aTextures.Count; i++)
                {
                    FieldAtlas ac = new FieldAtlas();
                    fields.Add(ac);
                    ac.atlasedField = aTextures[i];
                }

#if PEGI
                atlasedShader = DestinationMaterial.shader;
#endif

                foreach (var p in MaterialEditor.GetMaterialProperties(new Material[] { DestinationMaterial }))
                {
                    if (p.displayName.Contains(PainterDataAndConfig.isAtlasableDisaplyNameTag))
                    {
                        foreach (var f in fields)
                        {
                            if (f.atlasedField.SameAs(p.name))
                            {
                                f.enabled = true;
                                continue;
                            }
                        }
                    }
                }

                if (AtlasedMaterial == null)
                {
                    for (int i = 0; i < fields.Count; i++)
                    {
                        fields[i].originField = i;
                    }
                }
                else if (originalMaterial != null)
                {
                    var orTexs = originalMaterial.GetTextures();
                    foreach (var f in fields)
                    {
                        for (int i = 0; i < orTexs.Count; i++)
                        {
                            if (orTexs[i].SameAs(f.atlasedField))
                            {
                                f.originField = i;
                            }
                        }
                    }
                }
            }

            if (originalMaterial != null)
            {
                for (int i = 0; i < fields.Count; i++)
                {
                    FindAtlas(i);
                }
            }
#endif
        }