private void AddAtlas(FAtlas atlas) { int elementCount = atlas.elements.Count; for (int e = 0; e < elementCount; ++e) { FAtlasElement element = atlas.elements[e]; element.indexInManager = _allElements.Count; element.atlas = atlas; element.atlasIndex = atlas.index; _allElements.Add(element); if (_allElementsByName.ContainsKey(element.name)) { throw new Exception("Duplicate element name found! All element names must be unique!"); } else { _allElementsByName.Add(element.name, element); } } _atlases.Add(atlas); }
public FAtlasElement GetElementForChar(char character) { FCharInfo charInfo; if (!_charInfosByID.TryGetValue(character, out charInfo)) { return(null); } FAtlasElement charElement = new FAtlasElement(); charElement.atlas = _element.atlas; charElement.atlasIndex = _element.atlasIndex; charElement.indexInAtlas = -1; charElement.isTrimmed = true; charElement.name = ""; //_name + "_" + character.ToString(); charElement.uvRect = charInfo.uvRect; charElement.sourceRect = new Rect(0, 0, charInfo.width, charInfo.height); charElement.sourceSize = new Vector2(charInfo.width, charInfo.height); charElement.sourcePixelSize = new Vector2(charInfo.width * Futile.resourceScale, charInfo.height * Futile.resourceScale); Rect uvRect = charElement.uvRect; charElement.uvTopLeft.Set(uvRect.xMin, uvRect.yMax); charElement.uvTopRight.Set(uvRect.xMax, uvRect.yMax); charElement.uvBottomRight.Set(uvRect.xMax, uvRect.yMin); charElement.uvBottomLeft.Set(uvRect.xMin, uvRect.yMin); return(charElement); }
public TargetCursor(PlayerInterface menu) : base(menu) { _sprites = new FSprite[5]; _sprites[0] = new FSprite("targetcenter"); FAtlasElement corner = Futile.atlasManager.GetElementWithName("targetcorner"); _sprites[1] = new FSprite(corner); _sprites[2] = new FSprite(corner); _sprites[2].scaleX = -1f; _sprites[3] = new FSprite(corner); _sprites[3].scaleY = -1f; _sprites[4] = new FSprite(corner); _sprites[4].scaleX = -1f; _sprites[4].scaleY = -1f; for (int index = 0; index < _sprites.Length; index++) { AddElement(_sprites[index]); } _targetInspector = new TargetInspector(menu); _targetInspector.position = new Vector2(0f, 32f); AddElement(_targetInspector); }
public FButton(string upElementName, string downElementName, string overElementName, string clickSoundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); if (overElementName != null) { _overElement = Futile.atlasManager.GetElementWithName(overElementName); _supportsOver = true; } _sprite = new FSprite(_upElement.name); _sprite.anchorX = _anchorX; _sprite.anchorY = _anchorY; AddChild(_sprite); _hitRect = _sprite.textureRect; _clickSoundName = clickSoundName; EnableSingleTouch(); if (_supportsOver) { ListenForUpdate(HandleUpdate); } }
public void ActuallyUnloadAtlasOrImage(string name) { int atlasCount = _atlases.Count; for (int a = 0; a < atlasCount; ++a) { FAtlas atlas = _atlases[a]; if (atlas.name == name) { for (int e = _allElements.Count - 1; e >= 0; e--) { FAtlasElement element = _allElements[e]; if (element.atlas == atlas) { _allElements.RemoveAt(e); _allElementsByName.Remove(element.name); } } atlas.Unload(); _atlases.RemoveAt(a); } } }
public Car(FAtlasElement element, FContainer grid) : base(element) { ListenForUpdate(Update); Speed = 0; Colliders = grid; FSoundManager.PlayMusic("loop_0"); }
public RegionAttachment NewRegionAttachment(Skin skin, String name, String path) { FAtlasElement element = Futile.atlasManager.GetElementWithName(name); RegionAttachment attachment = new RegionAttachment(name); if (element != null) { attachment.RendererObject = element; attachment.SetUVs(element.uvBottomLeft.x, element.uvBottomLeft.y, element.uvTopRight.x, element.uvTopRight.y, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = element.sourceSize.x; attachment.RegionHeight = element.sourceSize.y; attachment.RegionOriginalWidth = element.sourceSize.x; attachment.RegionOriginalHeight = element.sourceSize.y; } else { attachment.RendererObject = null; attachment.SetUVs(0.0f, 0.0f, 0.0f, 0.0f, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = 0.0f; attachment.RegionHeight = 0.0f; attachment.RegionOriginalWidth = 0.0f; attachment.RegionOriginalHeight = 0.0f; Debug.Log("Element [" + name + "] not found in Futile.AtlasManager"); } return(attachment); }
public void ActuallyLoadAtlasOrImage(string name, string imagePath, string dataPath) { int atlasCount = _atlases.Count; for (int a = 0; a < atlasCount; ++a) { if (_atlases[a].name == name) { return; //don't load this atlas if we already have one with the same name } } //if dataPath is empty, load it as a single image bool isSingleImage = (dataPath == ""); FAtlas atlas = new FAtlas(name, imagePath, dataPath, _atlases.Count, isSingleImage); int elementCount = atlas.elements.Count; for (int e = 0; e < elementCount; ++e) { FAtlasElement element = atlas.elements[e]; element.indexInManager = _allElements.Count; element.atlas = atlas; element.atlasIndex = atlas.index; _allElements.Add(element); _allElementsByName.Add(element.name, element); } _atlases.Add(atlas); }
public void SetHole1(FAtlasElement holeElement,FAtlasElement toDigElement) { _elementHole1=holeElement; _elementToDig1=toDigElement; _hole1Offset=_elementHole1.uvTopLeft-_elementToDig1.uvTopLeft; needsApply = true; }
private void CreateAtlasFromSingleImage() { FAtlasElement element = new FAtlasElement(); element.name = _name; element.indexInAtlas = 0; //TODO: may have to offset the rect slightly float scaleInverse = Futile.resourceScaleInverse; Rect uvRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin, uvRect.yMax); element.uvTopRight.Set(uvRect.xMax, uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax, uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin, uvRect.yMin); element.sourceSize = new Vector2(_textureSize.x * scaleInverse, _textureSize.y * scaleInverse); element.sourcePixelSize = new Vector2(_textureSize.x, _textureSize.y); element.sourceRect = new Rect(0, 0, _textureSize.x * scaleInverse, _textureSize.y * scaleInverse); element.isTrimmed = false; _elements.Add(element); _elementsByName.Add(element.name, element); }
private void CreateDefaultAtlases() { //atlas of plain white Texture2D plainWhiteTex = new Texture2D(16, 16); plainWhiteTex.filterMode = FilterMode.Bilinear; plainWhiteTex.wrapMode = TextureWrapMode.Clamp; Color white = Futile.white; //Color clear = new Color(1,1,1,0); for (int r = 0; r < 16; r++) { for (int c = 0; c < 16; c++) { // if(c == 0 || r == 0) //clear the 0 edges // { // plainWhiteTex.SetPixel(c,r,clear); // } // else // { plainWhiteTex.SetPixel(c, r, white); // } } } plainWhiteTex.Apply(); atlasManager.LoadAtlasFromTexture("Futile_White", plainWhiteTex); whiteElement = atlasManager.GetElementWithName("Futile_White"); }
public FButton (string upElementName, string downElementName, string overElementName, string clickSoundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); if(overElementName != null) { _overElement = Futile.atlasManager.GetElementWithName(overElementName); _supportsOver = true; } _sprite = new FSprite(_upElement.name); _sprite.anchorX = _anchorX; _sprite.anchorY = _anchorY; AddChild(_sprite); _hitRect = _sprite.textureRect; _clickSoundName = clickSoundName; EnableSingleTouch(); if(_supportsOver) { ListenForUpdate(HandleUpdate); } }
public void SetHole0(FAtlasElement holeElement,FAtlasElement toDigElement) { _elementHole0=holeElement; _elementToDig0=toDigElement; _hole0Offset=_elementHole0.uvTopLeft-_elementToDig0.uvTopLeft; needsApply = true; }
public FAtlasElement Clone() { FAtlasElement element = new FAtlasElement(); element.name = name; element.indexInAtlas = indexInAtlas; element.indexInManager = indexInManager; element.atlas = atlas; element.atlasIndex = atlasIndex; element.uvRect = uvRect; element.uvTopLeft = uvTopLeft; element.uvTopRight = uvTopRight; element.uvBottomRight = uvBottomRight; element.uvBottomLeft = uvBottomLeft; element.sourceRect = sourceRect; element.sourceSize = sourceSize; element.isTrimmed = isTrimmed; element.isRotated = isRotated; return(element); }
private void LoadAtlasData() { string textAsset = File.ReadAllText(RootFolderDirectory() + "Assets" + Path.DirectorySeparatorChar + "Futile" + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + _dataPath + ".txt"); Dictionary <string, object> dictionary = textAsset.dictionaryFromJson(); if (dictionary == null) { throw new FutileException("The atlas at " + _dataPath + " was not a proper JSON file. Make sure to select \"Unity3D\" in TexturePacker."); } Dictionary <string, object> dictionary2 = (Dictionary <string, object>)dictionary["frames"]; float resourceScaleInverse = Futile.resourceScaleInverse; int num = 0; foreach (KeyValuePair <string, object> keyValuePair in dictionary2) { FAtlasElement fatlasElement = new FAtlasElement(); fatlasElement.indexInAtlas = num++; string text = keyValuePair.Key; if (Futile.shouldRemoveAtlasElementFileExtensions) { int num2 = text.LastIndexOf("."); if (num2 >= 0) { text = text.Substring(0, num2); } } fatlasElement.name = text; IDictionary dictionary3 = (IDictionary)keyValuePair.Value; fatlasElement.isTrimmed = (bool)dictionary3["trimmed"]; if ((bool)dictionary3["rotated"]) { throw new NotSupportedException("Futile no longer supports TexturePacker's \"rotated\" flag. Please disable it when creating the " + _dataPath + " atlas."); } IDictionary dictionary4 = (IDictionary)dictionary3["frame"]; float num3 = float.Parse(dictionary4["x"].ToString()); float num4 = float.Parse(dictionary4["y"].ToString()); float num5 = float.Parse(dictionary4["w"].ToString()); float num6 = float.Parse(dictionary4["h"].ToString()); Rect uvRect = new Rect(num3 / _textureSize.x, (_textureSize.y - num4 - num6) / _textureSize.y, num5 / _textureSize.x, num6 / _textureSize.y); fatlasElement.uvRect = uvRect; fatlasElement.uvTopLeft.Set(uvRect.xMin, uvRect.yMax); fatlasElement.uvTopRight.Set(uvRect.xMax, uvRect.yMax); fatlasElement.uvBottomRight.Set(uvRect.xMax, uvRect.yMin); fatlasElement.uvBottomLeft.Set(uvRect.xMin, uvRect.yMin); IDictionary dictionary5 = (IDictionary)dictionary3["sourceSize"]; fatlasElement.sourcePixelSize.x = float.Parse(dictionary5["w"].ToString()); fatlasElement.sourcePixelSize.y = float.Parse(dictionary5["h"].ToString()); fatlasElement.sourceSize.x = fatlasElement.sourcePixelSize.x * resourceScaleInverse; fatlasElement.sourceSize.y = fatlasElement.sourcePixelSize.y * resourceScaleInverse; IDictionary dictionary6 = (IDictionary)dictionary3["spriteSourceSize"]; float left = float.Parse(dictionary6["x"].ToString()) * resourceScaleInverse; float top = float.Parse(dictionary6["y"].ToString()) * resourceScaleInverse; float width = float.Parse(dictionary6["w"].ToString()) * resourceScaleInverse; float height = float.Parse(dictionary6["h"].ToString()) * resourceScaleInverse; fatlasElement.sourceRect = new Rect(left, top, width, height); _elements.Add(fatlasElement); _elementsByName.Add(fatlasElement.name, fatlasElement); } }
public void LoadFont(string name, string elementName, string configPath, FTextParams fontTextParams) { FAtlasElement element = _allElementsByName[elementName]; FFont font = new FFont(name, element, configPath, fontTextParams); _fonts.Add(font); _fontsByName.Add(name, font); }
protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded) { _element = element; base.Init(facetType, _element.atlas, numberOfFacetsNeeded); HandleElementChanged(); }
protected void Init(FAtlasElement element, int numberOfQuadsNeeded) { _element = element; _shader = FShader.defaultShader; _numberOfQuadsNeeded = numberOfQuadsNeeded; HandleElementChanged(); }
protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded) { _element = element; base.Init(facetType,_element.atlas,numberOfFacetsNeeded); HandleElementChanged(); }
public void UpdateToDig0(FAtlasElement toDigElement) { if (_elementHole0!=null) { _elementToDig0=toDigElement; _hole0Offset=_elementHole0.uvTopLeft-_elementToDig0.uvTopLeft; needsApply = true; } }
public void LoadFont(string name, string elementName, string configPath, float offsetX, float offsetY, FTextParams textParams) { FAtlasElement element = GetElementWithName(elementName); FFont font = new FFont(name, element, configPath, offsetX, offsetY, textParams); _fonts.Add(font); _fontsByName.Add(name, font); }
public WTAnimation(string name, FAtlasElement[] spriteFrames, float minFrameDuration, float maxFrameDuration, bool isLooping) { this.spriteFrames = spriteFrames; this.name = name; this.isLooping = isLooping; this.minFrameDuration = minFrameDuration; this.maxFrameDuration = maxFrameDuration; this.frameDuration = this.minFrameDuration; }
public FFont(string name, FAtlasElement element, string configPath, FTextParams fontTextParams) { _name = name; _element = element; _configPath = configPath; _fontTextParams = fontTextParams; LoadAndParseConfigFile(); }
public FSplitSprite(FAtlasElement element) : base() { Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call SetupSlices(); _isAlphaDirty = true; UpdateLocalVertices(); }
public FSprite (FAtlasElement element) : base() { _localVertices = new Vector2[4]; Init(FFacetType.Quad, element,1); _isAlphaDirty = true; UpdateLocalVertices(); }
protected void Init(FMeshData meshData, FAtlasElement element) { _meshData = meshData; _previousMeshDataVersion = _meshData.version; Init(_meshData.facetType, element, meshData.facets.Count); _isMeshDirty = true; _isAlphaDirty = true; }
protected void Init(FMeshData meshData, FAtlasElement element) { _meshData = meshData; _previousMeshDataVersion = _meshData.version; Init(_meshData.facetType, element,meshData.facets.Count); _isMeshDirty = true; _isAlphaDirty = true; }
public FSprite(FAtlasElement element, bool quadType = true) : base() { _localVertices = new Vector2[4]; Init(FFacetType.Quad, element, quadType ? 1 : 2); _isAlphaDirty = true; UpdateLocalVertices(); }
//It's recommended to use myAtlas.CreateElement() instead of this public void AddElement(FAtlasElement element) { if(_allElementsByName.ContainsKey(element.name)) { throw new FutileException("Duplicate element name '" + element.name +"' found! All element names must be unique!"); } else { _allElementsByName.Add (element.name, element); } }
public FFont(string name, FAtlasElement element, string configPath, float offsetX, float offsetY, FTextParams textParams) { _name = name; _element = element; _configPath = configPath; _textParams = textParams; _offsetX = offsetX; _offsetY = offsetY; LoadAndParseConfigFile(); }
public FFont(string name, FAtlasElement element, string configPath, float offsetX, float offsetY, FTextParams textParams) { _name = name; _element = element; _configPath = configPath; _textParams = textParams; _offsetX = offsetX * Futile.displayScale / Futile.resourceScale; _offsetY = offsetY * Futile.displayScale / Futile.resourceScale; LoadAndParseConfigFile(); }
public FButton(string upElementName, string downElementName, string soundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); _bg = new FSprite(_upElement.name); _bg.anchorX = _anchorX; _bg.anchorY = _anchorY; AddChild(_bg); _soundName = soundName; }
public void AddElement(FAtlasElement element) //It's recommended to use myAtlas.CreateElement() instead of this { if (_allElementsByName.ContainsKey(element.name)) { throw new FutileException("Duplicate element name '" + element.name + "' found! All element names must be unique!"); } else { _allElementsByName.Add(element.name, element); } }
public FButton (string upElementName, string downElementName, string soundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); _bg = new FSprite(_upElement.name); _bg.anchorX = _anchorX; _bg.anchorY = _anchorY; AddChild(_bg); _soundName = soundName; }
public FShadowSprite(FAtlasElement element, float shadowOffsetX, float shadowOffsetY) : base() { _shadowOffsetX = shadowOffsetX; _shadowOffsetY = shadowOffsetY; Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call SetupSlices(); _isAlphaDirty = true; UpdateLocalVertices(); }
public FMaskedSprite(string elementName, string maskName) : base(elementName) { if (maskName.Length <= 0) { _maskElement = null; } else { _maskElement = Futile.atlasManager.GetElementWithName(maskName); } shader = FShader.MaskedShader; }
public void Move() { // Update RT and camera int rtW = Mathf.RoundToInt(_rtBounds.width); int rtH = Mathf.RoundToInt(_rtBounds.height); if (_rt == null) { _rt = new RenderTexture(rtW, rtH, 16); _rt.filterMode = FilterMode.Point; _rt.generateMips = false; if (displaySprite != null) { Futile.atlasManager.UnloadAtlas("InputDisplay_" + cam.cameraNumber); displaySprite?.RemoveFromContainer(); } FAtlasElement element = Futile.atlasManager.LoadAtlasFromTexture("InputDisplay_" + cam.cameraNumber, _rt).elements[0]; displaySprite = new FSprite(element) { anchorX = 0f, anchorY = 0f, alpha = alpha }; _rtCam.targetTexture = _rt; } if (_rt.width != rtW || _rt.height != rtH) { _rt.width = rtW; _rt.height = rtH; } // Update display sprite displaySprite.SetPosition(origin + _rtBounds.min - Vector2.one * 0.5f); // Update components Vector2 drawOrigin = DrawOrigin; _lerpBarBack.x = drawOrigin.x; _lerpBarBack.y = drawOrigin.y - 8f; _lerpBar.x = drawOrigin.x; _lerpBar.y = drawOrigin.y - 8f; foreach (InputButton button in buttons) { button.Move(drawOrigin); } _analogBack.SetPosition(drawOrigin + _analogRelPos); _analogFront.x = drawOrigin.x + _analogRelPos.x + 1f; _analogFront.y = drawOrigin.y + _analogRelPos.y + 1f; _rtCam.transform.position = (Vector3)(drawOrigin + _rtBounds.center) + Vector3.forward * -10f; _rtCam.orthographicSize = _rtBounds.height / 2f; }
public CosmeticRenderer(FAtlasElement element) { _element = element; _worldPosition = Vector3.zero; _positionOffset = Vector2.zero; _rotation = 0f; _doesFlip = true; _viewAngle = 0f; _sortZOffset = 0f; _color = Color.white; _scale = Vector2.one; _shader = FShader.defaultShader; }
public FAtlasElement CreateUnnamedElement(float leftX, float bottomY, float pixelWidth, float pixelHeight) { //note that this element has no name, so it is not stored in the atlas or atlasmanager FAtlasElement element = new FAtlasElement(); element.atlas = this; element.atlasIndex = _index; UpdateElement(element, leftX, bottomY, pixelWidth, pixelHeight); return(element); }
public FDrawingSprite(FAtlasElement element) : base() { _quads = new LinkedList <FDrawingQuad>(); _cursor = new FDrawingCursor(_quads); _firstLineCursor = null; _previousLineCursor = null; Init(FFacetType.Quad, element, 0); //this will call HandleElementChanged(), which will call Setup(); _isAlphaDirty = true; UpdateLocalVertices(); }
public void SetAnimationFrame(HumanAnimation ani, int frame) { this.ani = ani; this.currentFrame = frame % ani.numFrames; //wrap it FAtlasElement newElement = ani.frames[currentFrame]; if (bodySprite.element != newElement) { bodySprite.element = newElement; didAnimationChange = true; } }
protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded) { _facetType = facetType; _element = element; if (_shader == null) { _shader = FShader.defaultShader; } _numberOfFacetsNeeded = numberOfFacetsNeeded; HandleElementChanged(); }
public FractalElement(float size,bool root,int maxChainCount,FAtlasElement atlasElement=null,float spriteScaleRatio=1f) { _size=size; _root=root; _spriteScaleRatio=spriteScaleRatio; _maxChaincount=maxChainCount; _atlasElement=atlasElement; if (_atlasElement==null) { _atlasElement=Futile.atlasManager.GetElementWithName("Futile_White"); } _elements=new List<FractalElement>(); Build(); }
public FSliceButton(float width, float height, string upElementName, string downElementName, Color upColor, Color downColor, string soundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); _upColor = upColor; _downColor = downColor; _soundName = soundName; _bg = new FSliceSprite(_upElement.name, width, height, 16, 16, 16, 16); _bg.anchorX = _anchorX; _bg.anchorY = _anchorY; _bg.color = _upColor; AddChild(_bg); }
public CircularParticleSystem(FAtlasElement element, float innerRadius, float lifetime, float speed, float particlesPerSecond, int maxParticleCount) : base(maxParticleCount) { this.element = element; this.innerRadius = innerRadius; this.lifetime = lifetime; this.speed = speed; this.timePerParticle = 1.0f / particlesPerSecond; timeUntilNextParticle = timePerParticle; particleDef = new FParticleDefinition (element); particleDef.endColor = Color.white.CloneWithNewAlpha (0.0f); ListenForAfterUpdate (HandleUpdate); }
public FSliceSprite (FAtlasElement element, float width, float height, float insetTop, float insetRight, float insetBottom, float insetLeft) : base() { _width = width; _height = height; _insetTop = insetTop; _insetRight = insetRight; _insetBottom = insetBottom; _insetLeft = insetLeft; Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call SetupSlices(); _isAlphaDirty = true; UpdateLocalVertices(); }
//a simple tile map that takes an array of elements and renders it //note: the elements must all belong to the same atlas //note: elements.Length should equal cols*rows public FSimpleTileMap (FAtlasElement[] elements, int cols, int rows, float tileWidth, float tileHeight) : base() { _elements = elements; _cols = cols; _rows = rows; _tileWidth = tileWidth; _tileHeight = tileHeight; if(_elements.Length != _cols*_rows) { throw new FutileException("FSimpleTileMap - the number of elements does not match the number of rows and columns. It should be cols*rows = elements.Length"); } Init(new FMeshData(FFacetType.Quad), _elements[0].atlas.fullElement); UpdateMesh(); }
public BorderBox(float width, float height, float borderThickness, FAtlasElement element) : base(FFacetType.Quad, element) { _width = width; _height = height; _borderThickness = borderThickness; _innerVertices = new FMeshVertex[]{new FMeshVertex(0,0,0,1),new FMeshVertex(0,0,1,1),new FMeshVertex(0,0,1,0),new FMeshVertex(0,0,0,0)}; _outerVertices = new FMeshVertex[]{new FMeshVertex(0,0,0,1),new FMeshVertex(0,0,1,1),new FMeshVertex(0,0,1,0),new FMeshVertex(0,0,0,0)}; _meshData.AddQuad(_outerVertices[0],_outerVertices[1],_innerVertices[1],_innerVertices[0]); _meshData.AddQuad(_outerVertices[1],_outerVertices[2],_innerVertices[2],_innerVertices[1]); _meshData.AddQuad(_outerVertices[2],_outerVertices[3],_innerVertices[3],_innerVertices[2]); _meshData.AddQuad(_outerVertices[3],_outerVertices[0],_innerVertices[0],_innerVertices[3]); _meshData.AddQuad().SetColorForAllVertices(new Color(1,1,1,0.5f)); UpdateMesh(); }
public FButton(string upElementName, string downElementName, string overElementName, string clickSoundName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); if(overElementName != null) { _overElement = Futile.atlasManager.GetElementWithName(overElementName); _supportsOver = true; } _bg = new FSprite(_upElement.name); _bg.anchorX = _anchorX; _bg.anchorY = _anchorY; AddChild(_bg); _hitRect = _bg.textureRect; _clickSoundName = clickSoundName; }
virtual public void SetElements(string upElementName, string downElementName, string overElementName) { _upElement = Futile.atlasManager.GetElementWithName(upElementName); _downElement = Futile.atlasManager.GetElementWithName(downElementName); if(overElementName != null) { _overElement = Futile.atlasManager.GetElementWithName(overElementName); _supportsOver = true; } if(_isTouchDown) { _sprite.element = _downElement; } else { _sprite.element = _upElement; } }
//public bool isRotated; public FAtlasElement Clone() { FAtlasElement element = new FAtlasElement(); element.name = name; element.indexInAtlas = indexInAtlas; element.atlas = atlas; element.atlasIndex = atlasIndex; element.uvRect = uvRect; element.uvTopLeft = uvTopLeft; element.uvTopRight = uvTopRight; element.uvBottomRight = uvBottomRight; element.uvBottomLeft = uvBottomLeft; element.sourceRect = sourceRect; element.sourceSize = sourceSize; element.isTrimmed = isTrimmed; return element; }
public FAtlasElement CreateNamedElement (string elementName, float leftX, float bottomY, float pixelWidth, float pixelHeight) { FAtlasElement element = _elementsByName[elementName]; if(element == null) //it doesn't exist, so create it (if it does exist we just update it) { element = new FAtlasElement(); element.name = elementName; element.atlas = this; element.atlasIndex = _index; _elementsByName.Add(elementName,element); _elements.Add(element); Futile.atlasManager.AddElement(element); } UpdateElement(element,leftX,bottomY,pixelWidth,pixelHeight); return element; }
public FAtlasElement CreateUnnamedElement (float leftX, float bottomY, float pixelWidth, float pixelHeight) { //note that this element has no name, so it is not stored in the atlas or atlasmanager FAtlasElement element = new FAtlasElement(); element.atlas = this; element.atlasIndex = _index; UpdateElement(element,leftX,bottomY,pixelWidth,pixelHeight); return element; }
public void UpdateElement (FAtlasElement element, float leftX, float bottomY, float pixelWidth, float pixelHeight) { // TODO: decide whether to scale by resScale or not // float resScale = Futile.resourceScale; // leftX *= resScale; // bottomY *= resScale; // pixelWidth *= resScale; // pixelHeight *= resScale; element.atlas = this; element.atlasIndex = _index; float scaleInverse = Futile.resourceScaleInverse; //the uv coordinate rectangle within the atlas Rect uvRect = new Rect ( leftX/_textureSize.x, bottomY/_textureSize.y, pixelWidth/_textureSize.x, pixelHeight/_textureSize.y ); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin,uvRect.yMax); element.uvTopRight.Set(uvRect.xMax,uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax,uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin,uvRect.yMin); //the source size is the untrimmed size element.sourcePixelSize.x = pixelWidth; element.sourcePixelSize.y = pixelHeight; element.sourceSize.x = element.sourcePixelSize.x * scaleInverse; element.sourceSize.y = element.sourcePixelSize.y * scaleInverse; //sourceRect is the trimmed rect, inside the other rect, for now always as if untrimmed element.sourceRect = new Rect(0,0,pixelWidth*scaleInverse,pixelHeight*scaleInverse); }
private void CreateElementForEntireAtlas() { FAtlasElement element = new FAtlasElement(); element.name = _name; element.indexInAtlas = 0; //TODO: may have to offset the rect slightly float scaleInverse = Futile.resourceScaleInverse; Rect uvRect = new Rect(0.0f,0.0f,1.0f,1.0f); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin,uvRect.yMax); element.uvTopRight.Set(uvRect.xMax,uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax,uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin,uvRect.yMin); element.sourceSize = new Vector2(_textureSize.x*scaleInverse,_textureSize.y*scaleInverse); element.sourcePixelSize = new Vector2(_textureSize.x,_textureSize.y); element.sourceRect = new Rect(0,0,_textureSize.x*scaleInverse,_textureSize.y*scaleInverse); element.isTrimmed = false; _elements.Add (element); _elementsByName.Add (element.name, element); _fullElement = element; }
private void LoadAtlasData() { TextAsset dataAsset = Resources.Load (_dataPath, typeof(TextAsset)) as TextAsset; if(dataAsset == null) { throw new FutileException("Couldn't load the atlas data from: " + _dataPath); } Dictionary<string,object> dict = dataAsset.text.dictionaryFromJson(); if(dict == null) { throw new FutileException("The atlas at " + _dataPath + " was not a proper JSON file. Make sure to select \"Unity3D\" in TexturePacker."); } Dictionary<string,object> frames = (Dictionary<string,object>) dict["frames"]; float scaleInverse = Futile.resourceScaleInverse; int index = 0; foreach(KeyValuePair<string,object> item in frames) { FAtlasElement element = new FAtlasElement(); element.indexInAtlas = index++; string name = (string) item.Key; if(Futile.shouldRemoveAtlasElementFileExtensions) { int extensionPosition = name.LastIndexOf("."); if (extensionPosition >= 0) name = name.Substring(0, extensionPosition); } element.name = name; IDictionary itemDict = (IDictionary)item.Value; element.isTrimmed = (bool)itemDict["trimmed"]; if((bool)itemDict["rotated"]) { throw new NotSupportedException("Futile no longer supports TexturePacker's \"rotated\" flag. Please disable it when creating the "+_dataPath+" atlas."); } //the uv coordinate rectangle within the atlas IDictionary frame = (IDictionary)itemDict["frame"]; float frameX = float.Parse(frame["x"].ToString()); float frameY = float.Parse(frame["y"].ToString()); float frameW = float.Parse(frame["w"].ToString()); float frameH = float.Parse(frame["h"].ToString()); Rect uvRect = new Rect ( frameX/_textureSize.x, ((_textureSize.y - frameY - frameH)/_textureSize.y), frameW/_textureSize.x, frameH/_textureSize.y ); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin,uvRect.yMax); element.uvTopRight.Set(uvRect.xMax,uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax,uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin,uvRect.yMin); //the source size is the untrimmed size IDictionary sourcePixelSize = (IDictionary)itemDict["sourceSize"]; element.sourcePixelSize.x = float.Parse(sourcePixelSize["w"].ToString()); element.sourcePixelSize.y = float.Parse(sourcePixelSize["h"].ToString()); element.sourceSize.x = element.sourcePixelSize.x * scaleInverse; element.sourceSize.y = element.sourcePixelSize.y * scaleInverse; //this rect is the trimmed size and position relative to the untrimmed rect IDictionary sourceRect = (IDictionary)itemDict["spriteSourceSize"]; float rectX = float.Parse(sourceRect["x"].ToString()) * scaleInverse; float rectY = float.Parse(sourceRect["y"].ToString()) * scaleInverse; float rectW = float.Parse(sourceRect["w"].ToString()) * scaleInverse; float rectH = float.Parse(sourceRect["h"].ToString()) * scaleInverse; element.sourceRect = new Rect(rectX,rectY,rectW,rectH); _elements.Add (element); _elementsByName.Add(element.name, element); } Resources.UnloadAsset(dataAsset); }
public void SetElementByName(string elementName) { this.element = Futile.atlasManager.GetElementWithName(elementName); }
public FParticleDefinition(FAtlasElement element) { this.element = element; }