/* * */ private PixelSourceLayer CreateLayerInZone(string layerName, string zoneName, PixelSourceLayer newLayer) { TextureZone zone = GetZone(zoneName); /* Create Layer */ PixelSourceLayer addedLayer = AddLayer(layerName, newLayer); /* Does the Layer Clip the Zone? */ if (addedLayer.PixelSource.Width > zone.Area.width + 1 || addedLayer.PixelSource.Height > zone.Area.height + 1) { Console.LogError("LayeredPalette CreateLayerInZone(): Layer " + layerName + " will be clipped when placed in zone " + zoneName); } /* Add Layer to Zone */ zone.AddLayer(newLayer); return(addedLayer); }
/* * Add a TextureZone to which we can add layers */ public void CreateTextureZone(string name, int startX, int startY, int width, int height) { if (HasZone(name)) { Console.LogError("LayeredPalette CreateTextureZone: Zone with name " + name + " already exists in this LayeredPalette."); return; } // Clamp to be within the texture Vector2 zoneStart = new Vector2(Mathf.Clamp(startX, 0, Width - 1), Mathf.Clamp(startY, 0, Height - 1)); Vector2 zoneEnd = new Vector2(Mathf.Clamp(startX + width - 1, 0, Width - 1), Mathf.Clamp(startY + height - 1, 0, Height - 1)); // if the start and end points are inverted if (zoneEnd.magnitude - zoneStart.magnitude < 0) { Console.LogError("LayeredPalette CreateTextureZone(): Start Co-ordinates of " + name + " must be to lower left of End Co-ordinates"); return; } // If this zone overlaps with an existing zone int corner1 = HitTestTextureZones((int)zoneStart.x, (int)zoneStart.y); int corner2 = HitTestTextureZones((int)zoneEnd.x, (int)zoneEnd.y); int corner3 = HitTestTextureZones((int)zoneStart.x, (int)zoneEnd.y); int corner4 = HitTestTextureZones((int)zoneEnd.x, (int)zoneStart.y); if (corner1 + corner2 + corner3 + corner4 != -4) { Console.LogError("LayeredPalette CreateTextureZone(): Given TextureZone Co-ordinates for " + name + " Overlap with an existing TextureZone"); return; } TextureZone newTextureZone = new TextureZone(name, new Rect(zoneStart.x, zoneStart.y, zoneEnd.x - zoneStart.x + 1, zoneEnd.y - zoneStart.y + 1)); mZones.Add(newTextureZone); mZoneLookup[name] = newTextureZone; /* Add All universal layers to this zone */ for (int x = 0; x < mUniversalLayers.Count; ++x) { newTextureZone.AddLayer(mUniversalLayers[x]); } }