Пример #1
0
    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);
    }
Пример #2
0
    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);
    }
Пример #3
0
        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);
        }
Пример #4
0
    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);
        }
    }
Пример #5
0
    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);
            }
        }
    }
Пример #6
0
 public Car(FAtlasElement element, FContainer grid) : base(element)
 {
     ListenForUpdate(Update);
     Speed     = 0;
     Colliders = grid;
     FSoundManager.PlayMusic("loop_0");
 }
Пример #7
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);
    }
Пример #8
0
    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);
    }
Пример #9
0
 public void SetHole1(FAtlasElement holeElement,FAtlasElement toDigElement)
 {
     _elementHole1=holeElement;
     _elementToDig1=toDigElement;
     _hole1Offset=_elementHole1.uvTopLeft-_elementToDig1.uvTopLeft;
     needsApply = true;
 }
Пример #10
0
    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);
    }
Пример #11
0
    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");
    }
Пример #12
0
	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);
		}
	}
Пример #13
0
 public void SetHole0(FAtlasElement holeElement,FAtlasElement toDigElement)
 {
     _elementHole0=holeElement;
     _elementToDig0=toDigElement;
     _hole0Offset=_elementHole0.uvTopLeft-_elementToDig0.uvTopLeft;
     needsApply = true;
 }
Пример #14
0
    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);
    }
Пример #15
0
    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);
        }
    }
Пример #16
0
    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);
    }
Пример #17
0
    protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded)
    {
        _element = element;

        base.Init(facetType, _element.atlas, numberOfFacetsNeeded);

        HandleElementChanged();
    }
Пример #18
0
    protected void Init(FAtlasElement element, int numberOfQuadsNeeded)
    {
        _element             = element;
        _shader              = FShader.defaultShader;
        _numberOfQuadsNeeded = numberOfQuadsNeeded;

        HandleElementChanged();
    }
Пример #19
0
    protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded)
    {
        _element = element;

        base.Init(facetType,_element.atlas,numberOfFacetsNeeded);

        HandleElementChanged();
    }
Пример #20
0
 public void UpdateToDig0(FAtlasElement toDigElement)
 {
     if (_elementHole0!=null) {
         _elementToDig0=toDigElement;
         _hole0Offset=_elementHole0.uvTopLeft-_elementToDig0.uvTopLeft;
         needsApply = true;
     }
 }
Пример #21
0
    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);
    }
Пример #22
0
 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;
 }
Пример #23
0
    public FFont(string name, FAtlasElement element, string configPath, FTextParams fontTextParams)
    {
        _name = name;
        _element = element;
        _configPath = configPath;
        _fontTextParams = fontTextParams;

        LoadAndParseConfigFile();
    }
Пример #24
0
    public FFont(string name, FAtlasElement element, string configPath, FTextParams fontTextParams)
    {
        _name           = name;
        _element        = element;
        _configPath     = configPath;
        _fontTextParams = fontTextParams;

        LoadAndParseConfigFile();
    }
Пример #25
0
    public FSplitSprite(FAtlasElement element)
        : base()
    {
        Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call SetupSlices();

        _isAlphaDirty = true;

        UpdateLocalVertices();
    }
Пример #26
0
	public FSprite (FAtlasElement element) : base()
	{
		_localVertices = new Vector2[4];
		
		Init(FFacetType.Quad, element,1);
		
		_isAlphaDirty = true;
		
		UpdateLocalVertices();
	}
Пример #27
0
    protected void Init(FMeshData meshData, FAtlasElement element)
    {
        _meshData = meshData;
        _previousMeshDataVersion = _meshData.version;

        Init(_meshData.facetType, element, meshData.facets.Count);

        _isMeshDirty  = true;
        _isAlphaDirty = true;
    }
Пример #28
0
	protected void Init(FMeshData meshData, FAtlasElement element)
	{
		_meshData = meshData;
		_previousMeshDataVersion = _meshData.version;
		
		Init(_meshData.facetType, element,meshData.facets.Count);

		_isMeshDirty = true;
		_isAlphaDirty = true;
	}
Пример #29
0
    public FSprite(FAtlasElement element, bool quadType = true) : base()
    {
        _localVertices = new Vector2[4];

        Init(FFacetType.Quad, element, quadType ? 1 : 2);

        _isAlphaDirty = true;

        UpdateLocalVertices();
    }
Пример #30
0
 //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);
     }
 }
Пример #31
0
    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();
    }
Пример #32
0
    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();
    }
Пример #33
0
    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;
    }
Пример #34
0
    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();
    }
Пример #35
0
 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);
     }
 }
Пример #36
0
	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;
	}
Пример #37
0
    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();
    }
Пример #38
0
 public FMaskedSprite(string elementName, string maskName) : base(elementName)
 {
     if (maskName.Length <= 0)
     {
         _maskElement = null;
     }
     else
     {
         _maskElement = Futile.atlasManager.GetElementWithName(maskName);
     }
     shader = FShader.MaskedShader;
 }
Пример #39
0
            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;
            }
Пример #40
0
 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;
 }
Пример #41
0
    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);
    }
Пример #42
0
    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();
    }
Пример #43
0
    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;
        }
    }
Пример #44
0
    protected void Init(FFacetType facetType, FAtlasElement element, int numberOfFacetsNeeded)
    {
        _facetType = facetType;

        _element = element;
        if (_shader == null)
        {
            _shader = FShader.defaultShader;
        }
        _numberOfFacetsNeeded = numberOfFacetsNeeded;

        HandleElementChanged();
    }
Пример #45
0
    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();
    }
Пример #46
0
    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);
    }
Пример #47
0
        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);
        }
Пример #48
0
	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();
	}
Пример #49
0
	//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();
	}
Пример #50
0
    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();
    }
Пример #51
0
    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;
    }
Пример #52
0
	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;
		}
	}
Пример #53
0
	//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;
	}
Пример #54
0
	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;
	}
Пример #55
0
	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;
	}
Пример #56
0
	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);
	}
Пример #57
0
	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;
	}
Пример #58
0
	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;
 }