// border editing callback private void OnSpriteEdited(PivotEditingResult result, SVGSpriteAssetFile spriteAsset, Vector2 editedPivot, Vector4 editedBorder) { SVGCanvasBehaviour svgCanvas = target as SVGCanvasBehaviour; if ((svgCanvas != null) && (result == PivotEditingResult.Ok)) { SVGUIAtlas uiAtlas = svgCanvas.UIAtlas; if (uiAtlas != null) { // assign the new border uiAtlas.UpdateBorder(spriteAsset, editedBorder); SVGUtils.MarkObjectDirty(uiAtlas); SVGUtils.MarkSceneDirty(); // get the list of instantiated SVG sprites that reference the edited one List <GameObject> spritesInstances = new List <GameObject>(); uiAtlas.GetSpritesInstances(spritesInstances, spriteAsset.SpriteRef); foreach (GameObject gameObj in spritesInstances) { Image uiImage = (Image)gameObj.GetComponent <Image>(); if (uiImage != null) { // the Image component won't recognize the change of sprite border, so in order to refresh // instantiated objects we have to unset-set the sprite property uiImage.sprite = null; uiImage.sprite = spriteAsset.SpriteData.Sprite; } } } } }
private static void ProcessScene() { GameObject[] allObjects = GameObject.FindObjectsOfType <GameObject>(); List <SVGBasicAtlas> unexportedAtlases = new List <SVGBasicAtlas>(); // scan all game objects in the current scene, and keep track of used atlas generators foreach (GameObject gameObj in allObjects) { if (gameObj.activeInHierarchy) { SVGSpriteLoaderBehaviour loader = gameObj.GetComponent <SVGSpriteLoaderBehaviour>(); if (loader != null) { // if this atlas has not been already flagged, lets keep track of it if (!loader.Atlas.Exporting) { unexportedAtlases.Add(loader.Atlas); loader.Atlas.Exporting = true; } } SVGUISpriteLoaderBehaviour uiLoader = gameObj.GetComponent <SVGUISpriteLoaderBehaviour>(); if (uiLoader != null) { // if this atlas has not been already flagged, lets keep track of it if (!uiLoader.UIAtlas.Exporting) { unexportedAtlases.Add(uiLoader.UIAtlas); uiLoader.UIAtlas.Exporting = true; } } SVGCanvasBehaviour uiCanvas = gameObj.GetComponent <SVGCanvasBehaviour>(); if (uiCanvas != null) { // if this atlas has not been already flagged, lets keep track of it if (!uiCanvas.UIAtlas.Exporting) { unexportedAtlases.Add(uiCanvas.UIAtlas); uiCanvas.UIAtlas.Exporting = true; } } } } foreach (SVGBasicAtlas baseAtlas in unexportedAtlases) { SVGBuildProcessor.ProcessAtlas(baseAtlas); // keep track of this atlas in the global list SVGBuildProcessor.m_Atlases.Add(baseAtlas); } }
// Reset is called when the user hits the Reset button in the Inspector's context menu or when adding the component the first time. // This function is only called in editor mode. Reset is most commonly used to give good default values in the inspector. void Reset() { if (this.RequirementsCheck()) { this.UIAtlas = null; this.SpriteReference = null; this.ResizeOnStart = true; Image uiImage = gameObject.GetComponent <Image>(); uiImage.type = Image.Type.Simple; uiImage.material = null; if (uiImage.canvas != null) { // set the atlas associated to the canvas (see SVGCanvasBehaviour) SVGCanvasBehaviour svgCanvas = uiImage.canvas.GetComponent <SVGCanvasBehaviour>(); if (svgCanvas != null) { this.UIAtlas = svgCanvas.UIAtlas; } } } }
public override void OnInspectorGUI() { // get the target object SVGCanvasBehaviour canvasBehaviour = target as SVGCanvasBehaviour; if ((canvasBehaviour != null) && (canvasBehaviour.UIAtlas != null)) { Canvas canvas = canvasBehaviour.GetComponent <Canvas>(); if (canvas != null) { base.OnInspectorGUI(); // maintain the canvas scale factor synched between Canvas an SVGUIAtlas! canvasBehaviour.EnsureCanvasAssigned(); bool isDirty = this.DrawInspector(canvasBehaviour.UIAtlas, canvas); if (isDirty) { SVGUtils.MarkObjectDirty(canvasBehaviour.UIAtlas); SVGUtils.MarkSceneDirty(); } } } }