Example #1
0
    // Update is called once per frame
    protected override void Update()
    {
        if (spriteContainer == null || (spriteContainer != null && !spriteContainer.isReady))
        {
            return;
        }

        if (Application.isEditor)
        {
            lastContainer = spriteContainer;
            lastColor     = tintColor;
            lastMatRef    = materialReference;
            lastDepth     = depth;

            if (wordWrap < 0)
            {
                wordWrap = 0;
            }
        }

        if (_text_ != text || _textFile != textFile || _bytesLines != GetBytes() ||
            _wordWrap != wordWrap || _justify != justify || _lineHeightModifier != lineHeightModifier)
        {
            _text_              = text;
            _text               = text;
            _textFile           = textFile;
            _wordWrap           = wordWrap;
            _justify            = justify;
            _lineHeightModifier = lineHeightModifier;
            meshDirty           = true;
        }

        base.Update();
    }
    static public void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        List <Texture2D> textures = new List <Texture2D>();

        foreach (string str in importedAssets)
        {
            Texture2D tx = AssetDatabase.LoadAssetAtPath(str, typeof(Texture2D)) as Texture2D;
            if (tx != null)
            {
                textures.Add(tx);
            }
        }

        if (textures.Count > 0)
        {
            for (int i = 0; i < textures.Count; i++)
            {
                OTContainer c = OT.ContainerByTexture(textures[i]);
                if (c != null)
                {
                    if (c is OTSpriteAtlasImport)
                    {
                        (c as OTSpriteAtlasImport).reloadData = true;
                        (c as OTSpriteAtlasImport).Reset(true);
                    }
                    else
                    {
                        c.Reset(true);
                    }
                    OT.Reset();
                }
            }
        }
    }
Example #3
0
    //-----------------------------------------------------------------------------
    // class methods
    //-----------------------------------------------------------------------------
    // Use this for initialization


    protected override void Awake()
    {
        if (_frameIndex < 0)
        {
            _frameIndex = 0;
        }

        _spriteContainer_   = spriteContainer;
        _frameIndex_        = frameIndex;
        _frameName_         = frameName;
        _image_             = image;
        _materialReference_ = materialReference;
        _transparent_       = transparent;
        _flipHorizontal_    = flipHorizontal;
        _flipVertical_      = flipVertical;
        _tintColor_         = _tintColor;
        _alpha_             = _alpha;
        isDirty             = true;

        if (image != null)
        {
            baseSize = new Vector2(image.width, image.height);
        }

        if (_spriteContainer != null || image != null)
        {
            _newSprite = false;
        }

        base.Awake();
    }
Example #4
0
    // Update is called once per frame
    protected override void Update()
    {
        if (!OT.isValid)
        {
            return;
        }

        if (spriteInvalid)
        {
            SpriteValid();
        }

        if (image == null && spriteContainer == null && _containerName != "")
        {
            OTContainer c = OT.ContainerByName(_containerName);
            if (c != null && c.isReady)
            {
                spriteContainer = c;
            }
        }

        // check if no material has been assigned yet
        if (!Application.isPlaying)
        {
            Material mat = material;
            if (mat == null)
            {
                mat             = new Material(OT.materialTransparent);
                material        = mat;
                mat.mainTexture = texture;
            }
        }
        base.Update();
    }
    private OTAnimationFrameset CreateFrameset(string name, OTContainer container, int startFrameIndex, int endFrameIndex)
    {
        MZDebug.Log( "Add frameset: " + name );

        OTAnimationFrameset frameset = new OTAnimationFrameset();
        frameset.name = name;
        frameset.container = container;
        frameset.startFrame = startFrameIndex;
        frameset.endFrame = endFrameIndex;

        return frameset;
    }
Example #6
0
    //-----------------------------------------------------------------------------
    // class methods
    //-----------------------------------------------------------------------------
    // Use this for initialization

    /// <exclude />
    protected override void Awake()
    {
        _spriteContainer_   = spriteContainer;
        _frameIndex_        = frameIndex;
        _image_             = image;
        _materialReference_ = materialReference;
        _transparent_       = transparent;
        _flipHorizontal_    = flipHorizontal;
        _flipVertical_      = flipVertical;
        _tintColor_         = _tintColor;
        _alpha_             = _alpha;
        isDirty             = true;
        base.Awake();
    }
Example #7
0
    // Create an walking man animation frameset with 15 images
    // INFO : Because our walking man sprite sheet contains 8 direction
    // animations of 15 frames. We will put these into seperate animation
    // framesets, so they can be played quickly when needed.
    OTAnimationFrameset WalkingFrameset(string name, int row, OTContainer sheet)
    {
        // Create a new frameset
        OTAnimationFrameset frameset = new OTAnimationFrameset();

        // Give this frameset a name for later reference
        frameset.name = name;
        // Link our provided sprite sheet
        frameset.container = sheet;
        // Set the correct start frame
        frameset.startFrame = (row - 1) * 15;
        // Set the correct end frame
        frameset.endFrame = ((row - 1) * 15) + 14;
        // Set this frameset's animation duration that will only
        // be used when the frameset is played as a single animation
        frameset.singleDuration = 0.95f;
        // Return this new frameset
        return(frameset);
    }
    private void AddAnimations(OTContainer container)
    {
        if( _spritesheetContainer == null )
            _spritesheetContainer = new Dictionary<string, OTContainer>();

        spritesheetContainer.Add( container.name, container );

        List<OTAnimationFrameset> framesetsList = new List<OTAnimationFrameset>();
        List<string> frameNamesList = new List<string>();

        SetFramesets( ref framesetsList, ref frameNamesList, container );

        if( cloneAniamtion == null )
        {
            cloneAniamtion = MZResources.InstantiateOrthelloSprite( "Animation" );
            ( (OTAnimation)cloneAniamtion.GetComponent( typeof( OTAnimation ) ) ).name = "AnimationsCollection";
        }

        // suck code here, when add new spritesheet, it will re-new again
        OTAnimation animation = (OTAnimation)cloneAniamtion.GetComponent( typeof( OTAnimation ) );
        List<OTAnimationFrameset> newFramesetsList = new List<OTAnimationFrameset>( animation.framesets );
        newFramesetsList.AddRange( framesetsList );
        animation.framesets = newFramesetsList.ToArray();
    }
Example #9
0
    protected override void Start()
    {
        mr          = OT.GetMatRef(materialReference);
        lastMatName = GetMatName();
        base.Start();
        if (!Application.isPlaying || (Application.isPlaying && !assignedMaterial))
        {
            material = GetMat();
        }

        if (Application.isPlaying)
        {
            _frameIndex_ = -1;
        }

        if (image == null && spriteContainer == null && _containerName != "")
        {
            OTContainer c = OT.ContainerByName(_containerName);
            if (c != null)
            {
                spriteContainer = c;
            }
        }
    }
Example #10
0
 //-----------------------------------------------------------------------------
 // class methods
 //-----------------------------------------------------------------------------
 // Use this for initialization
 /// <exclude />
 protected override void Awake()
 {
     _spriteContainer_ = spriteContainer;
     _frameIndex_ = frameIndex;
     _image_ = image;
     _materialReference_ = materialReference;
     _transparent_ = transparent;
     _flipHorizontal_ = flipHorizontal;
     _flipVertical_ = flipVertical;
     _tintColor_ = _tintColor;
     _alpha_ = _alpha;
     isDirty = true;
     base.Awake();
 }
Example #11
0
	public static List<OTSprite> ContainerSprites(OTContainer container)
	{
		if (isValid)
		{
			List<OTSprite> res = new List<OTSprite>();
			for (int o=0; o<instance.objects.Count; o++)
			{
				if (instance.objects[o] is OTSprite && (instance.objects[o] as OTSprite).spriteContainer == container)
					res.Add(instance.objects[o] as OTSprite);
			}
			return res;
		}
		return null;
	}
Example #12
0
    protected override void Clean()
    {
        if (!OT.isValid || mesh == null)
        {
            return;
        }
        base.Clean();

        if (Application.isPlaying && _image != null && _spriteContainer == null)
        {
            if (_defaultImage == null)
            {
                _defaultImage = _image;
            }

            if (OT.textureResourceFolder != "")
            {
                Texture2D tex = OTHelper.ResourceTexture(OT.textureResourceFolder + '/' + _defaultImage.name);
                if (tex != null)
                {
                    _image = tex;
                }
            }
            else
            {
                if (OT.sizeFactor != 1)
                {
                    for (int i = 0; i < sizeImages.Length; i++)
                    {
                        if (sizeImages[i].sizeFactor == OT.sizeFactor)
                        {
                            _image = sizeImages[i].texture;
                        }
                    }
                }
                else
                {
                    if (_defaultImage != null)
                    {
                        _image = _defaultImage;
                    }
                }
            }
        }

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _frameName_ != frameName ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy || cleanSize)
        {
            CleanFrame();
            // keep old and get new material name
            string cMatName = GetMatName();
            if (lastMatName != cMatName)
            {
                // material name has changed to look it up
                Material mat = OT.LookupMaterial(cMatName);
                // if we could not find the material let create a new one
                if (mat == null)
                {
                    mat = InitMaterial();
                }
                else
                {
                    // if we had a previous generated material lets
                    // decrease its use
                    if (lastMat != null && lastMatName != "")
                    {
                        OT.MatDec(lastMat, lastMatName);
                    }
                    otRenderer.material = mat;
                    HandleUV();
                    lastMat     = mat;
                    lastMatName = cMatName;
                }
                // increase the current material's use
                OT.MatInc(mat, cMatName);
            }
            else
            {
                if (_frameIndex_ != frameIndex)
                {
                    HandleUV();
                }
            }

            _spriteContainer_   = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_        = frameIndex;
            _frameName_         = frameName;
            _image_             = image;

            if (tintColor != _tintColor_ || _alpha_ != alpha)
            {
                if (mr == null)
                {
                    mr = OT.GetMatRef(materialReference);
                }

                HandleColors();
                _tintColor_ = tintColor;
                _alpha_     = alpha;
            }

            Changed();
        }


        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
        {
            isDirty = true;
        }

        CheckModifications();
    }
Example #13
0
 void _RegisterContainerLookup(OTContainer container, string oldName)
 {
     if (containerList.Contains(container))
     {
         if (containers.ContainsKey(oldName.ToLower()) && containers[oldName.ToLower()] == container)
             containers.Remove(oldName.ToLower());
         if (containers.ContainsKey(container.name.ToLower()))
             containers.Remove(container.name.ToLower());
         containers.Add(container.name.ToLower(), container);
     }
 }
Example #14
0
	public void Assign()
	{
		this.container = fs.container;
		frameNameMask = fs.frameNameMask;
		nameSort = fs.sortFrameNames;
	}
Example #15
0
 public static void RemoveContainer(OTContainer o)
 {
     if (isValid)
         instance._RemoveContainer(o);
 }
Example #16
0
	void _ResetContainer(OTContainer container)
	{
		container.Reset();
	}
Example #17
0
 public static void RegisterContainerLookup(OTContainer container, string oldName)
 {
     if (isValid)
         instance._RegisterContainerLookup(container, oldName);
 }
Example #18
0
 /// <summary>
 /// Destroys an Orthello container
 /// </summary>
 public static void DestroyContainer(OTContainer container)
 {
     if (isValid)
         instance._DestroyContainer(container);
 }
Example #19
0
 public static void RegisterContainer(OTContainer container)
 {
     if (isValid)
         instance._RegisterContainer(container);
 }
Example #20
0
 void _DestroyContainer(OTContainer container)
 {
     _RemoveContainer(container);
     if (container.gameObject != null)
         Destroy(container.gameObject);
 }
Example #21
0
 void _RemoveContainer(OTContainer container)
 {
     if (containerList.Contains(container))
     {
         string lname = container.name.ToLower();
         if (containers.ContainsKey(lname))
             containers.Remove(lname);
         if (containerList.Contains(container))
             containerList.Remove(container);
     }
 }
Example #22
0
    protected override void Clean()
    {
        if (!OT.isValid) return;
        base.Clean();

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy)
        {

            if (spriteContainer != null && spriteContainer.isReady)
            {
                if (frameIndex < 0) _frameIndex = 0;
                if (frameIndex > spriteContainer.frameCount - 1) _frameIndex = spriteContainer.frameCount - 1;
                if (spriteContainer is OTSpriteAtlas)
                {
                    OTContainer.Frame fr = CurrentFrame();
                    if ((spriteContainer as OTSpriteAtlas).offsetSizing)
                    {
                        if (Vector2.Equals(oSize, Vector2.zero))
                        {
                            oSize = fr.size * OT.view.sizeFactor;
                            Vector2 nOffset = fr.offset * OT.view.sizeFactor;
                            if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                            {
                                offset = nOffset;
                                position = _position;
                                imageSize = fr.imageSize * OT.view.sizeFactor;
                            }
                        }
                        if (_frameIndex_ != frameIndex || _spriteContainer_ != spriteContainer)
                        {
                            Vector2 sc = new Vector2((size.x / oSize.x) * fr.size.x * OT.view.sizeFactor, (size.y / oSize.y) * fr.size.y * OT.view.sizeFactor);
                            Vector3 sc3 = new Vector3(sc.x, sc.y, 1);

                            _size = sc;
                            if (!Vector3.Equals(transform.localScale, sc3))
                               transform.localScale = sc3;
                            oSize = fr.size * OT.view.sizeFactor;
                            imageSize = fr.imageSize * OT.view.sizeFactor;
                            Vector2 nOffset = fr.offset * OT.view.sizeFactor;
                            if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                            {
                                offset = nOffset;
                                position = _position;
                            }
                        }
                    }
                    else
                    {
                        Vector3[] verts = fr.vertices.Clone() as Vector3[];
                        verts[0] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[1] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[2] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[3] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        mesh.vertices = verts;

                        _size = fr.size;
                        Vector3 sc3 = new Vector3(_size.x, _size.y, 1);
                        if (!Vector3.Equals(transform.localScale, sc3))
                            transform.localScale = sc3;
                    }
                }
            }

            Material mat = LookupMaterial();
            if (mat == null)
            {
                mat = InitMaterial();
            }
            else
            {
                renderer.material = mat;
                HandleUV(mat);
            }
            OT.MatInc(mat);

            _spriteContainer_ = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_ = frameIndex;
            _image_ = image;
            _tintColor_ = tintColor;
            _alpha_ = alpha;
        }

        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
            isDirty = true;
    }
Example #23
0
    // Update is called once per frame
    protected override void Update()
    {
        if (spriteContainer==null || (spriteContainer!=null && !spriteContainer.isReady))
            return;

        if (Application.isEditor)
        {
            lastContainer = spriteContainer;
            lastColor = tintColor;
            lastMatRef = materialReference;
            lastDepth = depth;

            if (wordWrap<0) wordWrap = 0;

        }

        if (_text_!=text || _textFile!=textFile || _bytesLines != GetBytes() ||
            _wordWrap!=wordWrap || _justify!=justify || _lineHeightModifier!=lineHeightModifier)
        {
            _text_ = text;
            _text = text;
            _textFile = textFile;
            _wordWrap = wordWrap;
            _justify = justify;
            _lineHeightModifier = lineHeightModifier;
            meshDirty = true;
        }

        base.Update();
    }
Example #24
0
    protected override void Clean()
    {
        if (!OT.isValid || mesh == null)
        {
            return;
        }
        base.Clean();

        if (Application.isPlaying && _image != null && _spriteContainer == null)
        {
            if (_defaultImage == null)
            {
                _defaultImage = _image;
            }

            if (OT.textureResourceFolder != "")
            {
                Texture2D tex = OTHelper.ResourceTexture(OT.textureResourceFolder + '/' + _defaultImage.name);
                if (tex != null)
                {
                    _image = tex;
                }
            }
            else
            {
                if (OT.sizeFactor != 1)
                {
                    for (int i = 0; i < sizeImages.Length; i++)
                    {
                        if (sizeImages[i].sizeFactor == OT.sizeFactor)
                        {
                            _image = sizeImages[i].texture;
                        }
                    }
                }
                else
                {
                    if (_defaultImage != null)
                    {
                        _image = _defaultImage;
                    }
                }
            }
        }

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _frameName_ != frameName ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy)
        {
            if (spriteContainer != null && spriteContainer.isReady)
            {
                if (_frameName_ != frameName)
                {
                    _frameIndex = spriteContainer.GetFrameIndex(frameName);
                }

                if (frameIndex < 0)
                {
                    _frameIndex = 0;
                }
                if (frameIndex > spriteContainer.frameCount - 1)
                {
                    _frameIndex = spriteContainer.frameCount - 1;
                }

                // set frame name
                OTContainer.Frame fr = CurrentFrame();
                if (fr.name != "" && (frameName == "" || fr.name.IndexOf(frameName) != 0))
                {
                    _frameName = fr.name;
                }

                if (spriteContainer is OTSpriteAtlas)
                {
                    if (adjustFrameSize)
                    {
                        if ((spriteContainer as OTSpriteAtlas).offsetSizing)
                        {
                            if (Vector2.Equals(oSize, Vector2.zero))
                            {
                                oSize = fr.size * OT.view.sizeFactor;
                                Vector2 nOffset = fr.offset * OT.view.sizeFactor;

                                if (flipHorizontal)
                                {
                                    nOffset.x = (fr.imageSize.x * OT.view.sizeFactor) - oSize.x - nOffset.x;
                                }
                                if (flipVertical)
                                {
                                    nOffset.y = (fr.imageSize.y * OT.view.sizeFactor) - oSize.y - nOffset.y;
                                }

                                if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                                {
                                    offset    = nOffset;
                                    position  = _position;
                                    imageSize = fr.imageSize * OT.view.sizeFactor;
                                }
                            }
                            if (_frameIndex_ != frameIndex || _spriteContainer_ != spriteContainer)
                            {
                                float   _sx = (size.x / oSize.x);
                                float   _sy = (size.y / oSize.y);
                                Vector2 sc  = new Vector2(_sx * fr.size.x * OT.view.sizeFactor, _sy * fr.size.y * OT.view.sizeFactor);
                                Vector3 sc3 = new Vector3(sc.x, sc.y, 1);

                                _size = sc;
                                if (!Vector3.Equals(otTransform.localScale, sc3))
                                {
                                    otTransform.localScale = sc3;
                                }
                                oSize = fr.size * OT.view.sizeFactor;

                                imageSize = new Vector2(_sx * fr.imageSize.x * OT.view.sizeFactor, _sy * fr.imageSize.y * OT.view.sizeFactor);
                                Vector2 nOffset = new Vector2(_sx * fr.offset.x * OT.view.sizeFactor, _sy * fr.offset.y * OT.view.sizeFactor);

                                if (flipHorizontal)
                                {
                                    nOffset.x = (((fr.imageSize.x * OT.view.sizeFactor) - oSize.x) * _sx) - nOffset.x;
                                }
                                if (flipVertical)
                                {
                                    nOffset.y = (((fr.imageSize.y * OT.view.sizeFactor) - oSize.y) * _sy) - nOffset.y;
                                }

                                offset   = nOffset;
                                position = _position;
                            }
                        }
                        else
                        {
                            Vector3[] verts = fr.vertices.Clone() as Vector3[];
                            verts[0]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[1]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[2]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[3]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            mesh.vertices = verts;

                            _size = fr.size;
                            Vector3 sc3 = new Vector3(_size.x, _size.y, 1);
                            if (!Vector3.Equals(otTransform.localScale, sc3))
                            {
                                otTransform.localScale = sc3;
                            }
                        }
                    }
                }
            }

            // keep old and get new material name
            string cMatName = GetMatName();
            if (lastMatName != cMatName)
            {
                // material name has changed to look it up
                Material mat = OT.LookupMaterial(cMatName);
                // if we could not find the material let create a new one
                if (mat == null)
                {
                    mat = InitMaterial();
                }
                else
                {
                    // if we had a previous generated material lets
                    // decrease its use
                    if (lastMat != null && lastMatName != "")
                    {
                        OT.MatDec(lastMat, lastMatName);
                    }
                    otRenderer.material = mat;
                    HandleUV();
                    lastMat     = mat;
                    lastMatName = cMatName;
                }
                // increase the current material's use
                OT.MatInc(mat, cMatName);
            }
            else
            {
                if (_frameIndex_ != frameIndex)
                {
                    HandleUV();
                }
            }

            _spriteContainer_   = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_        = frameIndex;
            _frameName_         = frameName;
            _image_             = image;

            if (tintColor != _tintColor_ || _alpha_ != alpha)
            {
                if (mr == null)
                {
                    mr = OT.GetMatRef(materialReference);
                }

                HandleColors();
                _tintColor_ = tintColor;
                _alpha_     = alpha;
            }

            Changed();
        }


        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
        {
            isDirty = true;
        }

        CheckModifications();
    }
Example #25
0
 void FrameOffsetSize(OTContainer.Frame fr)
 {
     float _sx = (size.x / oSize.x);
     float _sy = (size.y / oSize.y);
     Vector2 sc = new Vector2(_sx * fr.size.x * OT.view.sizeFactor, _sy * fr.size.y * OT.view.sizeFactor);
     Vector3 sc3 = new Vector3(sc.x, sc.y, 1);
     _size = sc;
     if (!Vector3.Equals(otTransform.localScale, sc3))
        otTransform.localScale = sc3;
     oSize = fr.size * OT.view.sizeFactor;
     FrameOffset(fr);
 }
    private void SetFramesets(ref List<OTAnimationFrameset> framesetsList, ref List<string> frameNamesList, OTContainer container)
    {
        if( framesetsList == null )
            framesetsList = new List<OTAnimationFrameset>();
        if( frameNamesList == null )
            frameNamesList = new List<string>();

        int startFrameIndex = 0;
        int endFrameIndex = -1;
        int index = 0;

        string preClearFrameName = null;

        OTAtlasData[] datas = container.GetComponent<OTSpriteAtlasCocos2D>().atlasData;
        foreach( OTAtlasData data in datas )
        {
            string frameName = data.name;

            string currentClearFrameName = GetFrameNameWithoutIndex( frameName );

            if( preClearFrameName == null )
            {
                preClearFrameName = currentClearFrameName;
            }

            if( currentClearFrameName != preClearFrameName || index == datas.Length - 1 )
            {
                endFrameIndex = ( index == datas.Length - 1 )? index : index - 1;

                OTAnimationFrameset frameset = CreateFrameset( preClearFrameName, container, startFrameIndex, endFrameIndex );

                framesetsList.Add( frameset );
                frameNamesList.Add( preClearFrameName );

                startFrameIndex = index;
                preClearFrameName = currentClearFrameName;
            }

            index++;
        }
    }
Example #27
0
    void _RegisterContainer(OTContainer container)
    {
        if (!containerList.Contains(container))
            containerList.Add(container);
        if (!containers.ContainsKey(container.name.ToLower()))
            containers.Add(container.name.ToLower(), container);
        else
        {
            if (containers[container.name.ToLower()] != container)
                Debug.LogError("More than one SpriteContainer with name '" + container.name + "'");
        }
		
		
		foreach (Transform child in transform)
		{
			if (child.name.ToLower() == "containers")
			{
				container.transform.parent = child.transform;
				break;
			}
		}
		
    }
Example #28
0
    void FrameOffset(OTContainer.Frame fr)
    {
        float _sx = (size.x / oSize.x);
        float _sy = (size.y / oSize.y);
        imageSize = new Vector2(_sx * fr.imageSize.x * OT.view.sizeFactor, _sy * fr.imageSize.y * OT.view.sizeFactor);
        Vector2 nOffset = new Vector2(_sx * fr.offset.x * OT.view.sizeFactor, _sy * fr.offset.y * OT.view.sizeFactor);

        if (flipHorizontal)
            nOffset.x = (((fr.imageSize.x * OT.view.sizeFactor) - oSize.x) * _sx) - nOffset.x;
        if (flipVertical)
            nOffset.y = (((fr.imageSize.y * OT.view.sizeFactor) - oSize.y) * _sy) - nOffset.y;

        offset = nOffset;
        position = _position;
    }
Example #29
0
    //-----------------------------------------------------------------------------
    // class methods
    //-----------------------------------------------------------------------------
    // Use this for initialization
    protected override void Awake()
    {
        if (_frameIndex<0)
            _frameIndex = 0;

        _spriteContainer_ = spriteContainer;
        _frameIndex_ = frameIndex;
        _frameName_ = frameName;
        _image_ = image;
        _materialReference_ = materialReference;
        _transparent_ = transparent;
        _flipHorizontal_ = flipHorizontal;
        _flipVertical_ = flipVertical;
        _tintColor_ = _tintColor;
        _alpha_ = _alpha;
        isDirty = true;

        if (image!=null)
            baseSize = new Vector2(image.width, image.height);

        if (_spriteContainer != null || image!=null)
            _newSprite = false;

        base.Awake();
    }
Example #30
0
    protected override void Clean()
    {
        if (!OT.isValid || mesh == null) return;
        base.Clean();

        if (Application.isPlaying && _image!=null && _spriteContainer == null)
        {
            if (_defaultImage==null)
                _defaultImage = _image;

            if (OT.textureResourceFolder!="")
            {
                Texture2D tex = OTHelper.ResourceTexture(OT.textureResourceFolder+'/'+_defaultImage.name);
                if (tex!=null)
                    _image = tex;
            }
            else
            {
                if (OT.sizeFactor!=1)
                {
                    for (int i=0; i<sizeImages.Length; i++)
                    {
                        if (sizeImages[i].sizeFactor == OT.sizeFactor)
                            _image = sizeImages[i].texture;
                    }
                }
                else
                {
                    if (_defaultImage!=null)
                        _image = _defaultImage;
                }
            }
        }

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _frameName_ != frameName ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy || cleanSize)
        {

            CleanFrame();
            // keep old and get new material name
            string cMatName = GetMatName();
            if (lastMatName!=cMatName)
            {
                // material name has changed to look it up
                Material mat = OT.LookupMaterial(cMatName);
                // if we could not find the material let create a new one
                if (mat == null)
                    mat = InitMaterial();
                else
                {
                    // if we had a previous generated material lets
                    // decrease its use
                    if (lastMat!=null && lastMatName!="")
                        OT.MatDec(lastMat,lastMatName);
                    otRenderer.material = mat;
                    HandleUV();
                    lastMat = mat;
                    lastMatName = cMatName;
                }
                // increase the current material's use
               	OT.MatInc(mat, cMatName);
            }
            else
            {
                if (_frameIndex_ != frameIndex)
                   HandleUV();
            }

            _spriteContainer_ = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_ = frameIndex;
            _frameName_ = frameName;
            _image_ = image;

            if (tintColor!=_tintColor_ || _alpha_ != alpha)
            {
                if (mr == null)
                   mr = OT.GetMatRef(materialReference);

                HandleColors();
                _tintColor_ = tintColor;
                _alpha_ = alpha;
            }

            Changed();

        }

        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
            isDirty = true;

        CheckModifications();
    }
Example #31
0
 public Tileset(OTContainer s, uint g, string n)
 {
     spritesheet = s;
     firstgid    = g;
     name        = n;
 }
Example #32
0
 // Create an walking man animation frameset with 15 images
 // INFO : Because our walking man sprite sheet contains 8 direction
 // animations of 15 frames. We will put these into seperate animation
 // framesets, so they can be played quickly when needed.
 OTAnimationFrameset WalkingFrameset(string name, int row, OTContainer sheet)
 {
     // Create a new frameset
     OTAnimationFrameset frameset = new OTAnimationFrameset();
     // Give this frameset a name for later reference
     frameset.name = name;
     // Link our provided sprite sheet
     frameset.container = sheet;
     // Set the correct start frame
     frameset.startFrame = (row - 1) * 15;
     // Set the correct end frame
     frameset.endFrame = ((row - 1) * 15) + 14;
     // Set this frameset's animation duration that will only
     // be used when the frameset is played as a single animation
     frameset.singleDuration = 0.95f;
     // Return this new frameset
     return frameset;
 }
Example #33
0
    // Update is called once per frame
    void Update()
    {
        if (!OT.isValid || !Ready())
        {
            return;
        }

        if (!registered || !Application.isPlaying)
        {
            RegisterAnimation();
        }

        if (!Application.isPlaying)
        {
            CheckEditorSettings();
        }
        else
        {
            if (OT.dirtyChecks && framesets.Length > 0)
            {
                if (_framesetSize != framesets.Length)
                {
                    _framesetSize  = framesets.Length;
                    dirtyAnimation = true;
                }
            }
        }

        if (dirtyAnimation)
        {
            bool isOk = true;
            for (int f = 0; f < framesets.Length; f++)
            {
                OTAnimationFrameset fs = framesets[f];
                if (fs.container == null && fs._containerName != "")
                {
                    OTContainer c = OT.ContainerByName(fs._containerName);
                    if (c != null && c.isReady)
                    {
                        fs.container = c;
                    }
                    else
                    {
                        isOk = false;
                        break;
                    }
                }
            }

            if (isOk)
            {
                frames         = GetFrames();
                dirtyAnimation = false;
                if (_duration == _duration_)
                {
                    _duration  = (float)frames.Length / _fps;
                    _duration_ = _duration;
                }
            }
        }

        if (!Application.isPlaying || OT.dirtyChecks)
        {
            if (_duration > 0)
            {
                if (_duration_ != _duration)
                {
                    _duration_ = _duration;
                    _fps       = (float)frames.Length / _duration;
                    _fps_      = _fps;
                }
            }

            if (_fps > 0)
            {
                if (_fps_ != _fps)
                {
                    _fps_      = _fps;
                    _duration  = (float)frames.Length / _fps;
                    _duration_ = _duration;
                }
            }
        }
    }
Example #34
0
    protected override void Clean()
    {
        if (!OT.isValid)
        {
            return;
        }
        base.Clean();

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy)
        {
            if (spriteContainer != null && spriteContainer.isReady)
            {
                if (frameIndex < 0)
                {
                    _frameIndex = 0;
                }
                if (frameIndex > spriteContainer.frameCount - 1)
                {
                    _frameIndex = spriteContainer.frameCount - 1;
                }
                if (spriteContainer is OTSpriteAtlas)
                {
                    OTContainer.Frame fr = CurrentFrame();
                    if ((spriteContainer as OTSpriteAtlas).offsetSizing)
                    {
                        if (Vector2.Equals(oSize, Vector2.zero))
                        {
                            oSize = fr.size * OT.view.sizeFactor;
                            Vector2 nOffset = fr.offset * OT.view.sizeFactor;
                            if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                            {
                                offset    = nOffset;
                                position  = _position;
                                imageSize = fr.imageSize * OT.view.sizeFactor;
                            }
                        }
                        if (_frameIndex_ != frameIndex || _spriteContainer_ != spriteContainer)
                        {
                            Vector2 sc  = new Vector2((size.x / oSize.x) * fr.size.x * OT.view.sizeFactor, (size.y / oSize.y) * fr.size.y * OT.view.sizeFactor);
                            Vector3 sc3 = new Vector3(sc.x, sc.y, 1);

                            _size = sc;
                            if (!Vector3.Equals(transform.localScale, sc3))
                            {
                                transform.localScale = sc3;
                            }
                            oSize     = fr.size * OT.view.sizeFactor;
                            imageSize = fr.imageSize * OT.view.sizeFactor;
                            Vector2 nOffset = fr.offset * OT.view.sizeFactor;
                            if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                            {
                                offset   = nOffset;
                                position = _position;
                            }
                        }
                    }
                    else
                    {
                        Vector3[] verts = fr.vertices.Clone() as Vector3[];
                        verts[0]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[1]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[2]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        verts[3]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                        mesh.vertices = verts;

                        _size = fr.size;
                        Vector3 sc3 = new Vector3(_size.x, _size.y, 1);
                        if (!Vector3.Equals(transform.localScale, sc3))
                        {
                            transform.localScale = sc3;
                        }
                    }
                }
            }

            Material mat = LookupMaterial();
            if (mat == null)
            {
                mat = InitMaterial();
            }
            else
            {
                renderer.material = mat;
                HandleUV(mat);
            }
            OT.MatInc(mat);

            _spriteContainer_   = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_        = frameIndex;
            _image_             = image;
            _tintColor_         = tintColor;
            _alpha_             = alpha;
        }

        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
        {
            isDirty = true;
        }
    }
Example #35
0
 public void Assign()
 {
     this.container = fs.container;
     frameNameMask  = fs.frameNameMask;
     nameSort       = fs.sortFrameNames;
 }
Example #36
0
    protected override void Clean()
    {
        if (!OT.isValid || mesh == null)
        {
            return;
        }
        base.Clean();

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _frameName_ != frameName ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy)
        {
            if (spriteContainer != null && spriteContainer.isReady)
            {
                if (_frameName_ != frameName)
                {
                    _frameIndex = spriteContainer.GetFrameIndex(frameName);
                }

                if (frameIndex < 0)
                {
                    _frameIndex = 0;
                }
                if (frameIndex > spriteContainer.frameCount - 1)
                {
                    _frameIndex = spriteContainer.frameCount - 1;
                }

                // set frame name
                OTContainer.Frame fr = CurrentFrame();
                if (fr.name != "" && (frameName == "" || fr.name.IndexOf(frameName) != 0))
                {
                    _frameName = fr.name;
                }

                if (spriteContainer is OTSpriteAtlas)
                {
                    if (adjustFrameSize)
                    {
                        if ((spriteContainer as OTSpriteAtlas).offsetSizing)
                        {
                            if (Vector2.Equals(oSize, Vector2.zero))
                            {
                                oSize = fr.size * OT.view.sizeFactor;
                                Vector2 nOffset = fr.offset * OT.view.sizeFactor;
                                if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                                {
                                    offset    = nOffset;
                                    position  = _position;
                                    imageSize = fr.imageSize * OT.view.sizeFactor;
                                }
                            }
                            if (_frameIndex_ != frameIndex || _spriteContainer_ != spriteContainer)
                            {
                                float   _sx = (size.x / oSize.x);
                                float   _sy = (size.y / oSize.y);
                                Vector2 sc  = new Vector2(_sx * fr.size.x * OT.view.sizeFactor, _sy * fr.size.y * OT.view.sizeFactor);
                                Vector3 sc3 = new Vector3(sc.x, sc.y, 1);

                                _size = sc;
                                if (!Vector3.Equals(transform.localScale, sc3))
                                {
                                    transform.localScale = sc3;
                                }
                                oSize = fr.size * OT.view.sizeFactor;

                                imageSize = new Vector2(_sx * fr.imageSize.x * OT.view.sizeFactor, _sy * fr.imageSize.y * OT.view.sizeFactor);
                                Vector2 nOffset = new Vector2(_sx * fr.offset.x * OT.view.sizeFactor, _sy * fr.offset.y * OT.view.sizeFactor);

                                offset   = nOffset;
                                position = _position;
                            }
                        }
                        else
                        {
                            Vector3[] verts = fr.vertices.Clone() as Vector3[];
                            verts[0]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[1]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[2]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[3]     -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            mesh.vertices = verts;

                            _size = fr.size;
                            Vector3 sc3 = new Vector3(_size.x, _size.y, 1);
                            if (!Vector3.Equals(transform.localScale, sc3))
                            {
                                transform.localScale = sc3;
                            }
                        }
                    }
                }
            }

            // keep old and get new material name
            string cMatName = GetMatName();
            if (lastMatName != cMatName)
            {
                // material name has changed to look it up
                Material mat = OT.LookupMaterial(cMatName);
                // if we could not find the material let create a new one
                if (mat == null)
                {
                    mat = InitMaterial();
                }
                else
                {
                    // if we had a previous generated material lets
                    // decrease its use
                    if (lastMat != null && lastMatName != "")
                    {
                        OT.MatDec(lastMat, lastMatName);
                    }
                    renderer.material = mat;
                    HandleUV();
                    lastMat     = mat;
                    lastMatName = cMatName;
                }
                // increase the current material's use
                OT.MatInc(mat, cMatName);
            }
            else
            {
                if (_frameIndex_ != frameIndex)
                {
                    HandleUV();
                }
            }

            _spriteContainer_   = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_        = frameIndex;
            _frameName_         = frameName;
            _image_             = image;
            _tintColor_         = tintColor;
            _alpha_             = alpha;
        }



        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
        {
            isDirty = true;
        }

#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(this);
        }
#endif
    }
Example #37
0
    // Use this for initialization
    void Start()
    {
        GameObject world = this.transform.parent.gameObject;

        var level = JSON.Parse(levelFile.text);

        int levelHeight = level["height"].AsInt;
        int levelWidth  = level["width"].AsInt;

        collisionDetector = new CollisionDetector(levelWidth, levelHeight);

        Tileset[] tilesets = new Tileset[level["tilesets"].AsArray.Count];
        for (int i = 0; i < level["tilesets"].AsArray.Count; ++i)
        {
            JSONNode tileset = level["tilesets"].AsArray[i];
            string   name    = tileset["name"];

            if (name == "terrain")
            {
                tilesets[i] = new Tileset(terrainSheet, tileset["firstgid"].AsUInt, "terrain");
            }
            else if (name == "objects")
            {
                tilesets[i] = new Tileset(objectsSheet, tileset["firstgid"].AsUInt, "objects");
            }
            else if (name == "collision")
            {
                tilesets[i] = new Tileset(null, tileset["firstgid"].AsUInt, "collision");
            }
            else
            {
                Debug.Log("tileset name: '" + tileset["name"] + "'");
                tilesets[i] = new Tileset(null, tileset["firstgid"].AsUInt, "NO SHEET");
            }
        }

        Array.Reverse(tilesets);

        int depth = -1;

        foreach (JSONNode layer in level["layers"].AsArray)
        {
            for (int i = 0; i < layer["data"].AsArray.Count; ++i)
            {
                uint tileIndex = layer["data"].AsArray[i].AsUInt;

                if (tileIndex == 0)
                {
                    continue;
                }

                int x = i % levelWidth;
                int y = i / levelWidth;
                y = levelHeight - y - 1;

                uint flipped = tileIndex & FLIP_MASK;
                tileIndex = tileIndex & ~FLIP_MASK;

                OTContainer spriteContainer = null;
                foreach (Tileset t in tilesets)
                {
                    if (tileIndex >= t.firstgid)
                    {
                        tileIndex -= t.firstgid;

                        if (t.name == "collision")
                        {
                            collisionDetector.SetCollidable(x, y);
                        }

                        spriteContainer = t.spritesheet;
                        break;
                    }
                }

                if (!layer["visible"].AsBool)
                {
                    continue;
                }

                if (tileIndex == 4 && spriteContainer == objectsSheet)
                {
                    // firefly, add to fireflies manager instead
                    fireflies.SpawnAt(x * 32, y * 32);
                    continue;
                }

                bool flip_x = (flipped & FLIPPED_HORIZONTAL) > 0;
                bool flip_y = (flipped & FLIPPED_VERTICAL) > 0;

                float rotation = 0f;

                if ((flipped & FLIPPED_DIAGONAL) > 0)
                {
                    if ((flipped & FLIPPED_HORIZONTAL) > 0 && (flipped & FLIPPED_VERTICAL) == 0)
                    {
                        rotation = 90f;
                        flip_x   = true;
                    }
                    else if ((flipped & FLIPPED_HORIZONTAL) == 0 && (flipped & FLIPPED_VERTICAL) > 0)
                    {
                        rotation = -90f;
                        flip_y   = true;
                    }
                    else if ((flipped & FLIPPED_HORIZONTAL) == 0 && (flipped & FLIPPED_VERTICAL) == 0)
                    {
                        rotation = -90f;
                        flip_x   = true;
                    }
                    else
                    {
                        rotation = 90f;
                        //flip_y = false;
                        flip_x = true;
                    }
                }

                OTSprite tile = createSprite(x, y, world);                 // random offsets that puts terrain where I want it
                tile.spriteContainer = spriteContainer;
                tile.depth           = depth;
                tile.rotation        = rotation;
                tile.flipHorizontal  = flip_x;
                tile.flipVertical    = flip_y;
                tile.frameIndex      = (int)tileIndex;
            }

            depth -= 1;
        }

        // make the world bob
        Vector3 bobPos  = world.transform.position + new Vector3(0f, 8f, 0f);
        OTTween tweener = new OTTween(world.transform, 3.5f, OTEasing.SineInOut)
                          .Tween("position", bobPos);

        tweener.pingPong  = true;
        tweener.playCount = -1;
    }
Example #38
0
    protected override void Clean()
    {
        if (!OT.isValid || mesh == null) return;
        base.Clean();

        if (Application.isPlaying)
        {
            if (OT.sizeFactor!=1)
            {
                for (int i=0; i<sizeImages.Length; i++)
                {
                    if (sizeImages[i].sizeFactor == OT.sizeFactor)
                    {
                        if (_defaultImage==null)
                            _defaultImage = texture;
                        _image = sizeImages[i].texture;
                    }
                }
            }
            else
            {
                if (_defaultImage!=null)
                    _image = _defaultImage;
            }
        }

        if (_spriteContainer_ != spriteContainer ||
            _frameIndex_ != frameIndex ||
            _frameName_ != frameName ||
            _image_ != image ||
            _tintColor_ != tintColor ||
            _alpha_ != alpha ||
            _materialReference_ != _materialReference ||
            isCopy)
        {

            if (spriteContainer != null && spriteContainer.isReady)
            {

                if (_frameName_ != frameName)
                    _frameIndex = spriteContainer.GetFrameIndex(frameName);

                if (frameIndex < 0) _frameIndex = 0;
                if (frameIndex > spriteContainer.frameCount - 1) _frameIndex = spriteContainer.frameCount - 1;

                // set frame name
                OTContainer.Frame fr = CurrentFrame();
                if (fr.name!="" && (frameName == "" || fr.name.IndexOf(frameName)!=0))
                    _frameName = fr.name;

                if (spriteContainer is OTSpriteAtlas)
                {
                    if (adjustFrameSize)
                    {
                        if ((spriteContainer as OTSpriteAtlas).offsetSizing)
                        {
                            if (Vector2.Equals(oSize, Vector2.zero))
                            {
                                oSize = fr.size * OT.view.sizeFactor;
                                Vector2 nOffset = fr.offset * OT.view.sizeFactor;

                                if (flipHorizontal)
                                    nOffset.x = (fr.imageSize.x * OT.view.sizeFactor) - oSize.x - nOffset.x;
                                if (flipVertical)
                                    nOffset.y = (fr.imageSize.y * OT.view.sizeFactor) - oSize.y - nOffset.y;

                                if (_baseOffset.x != nOffset.x || _baseOffset.y != nOffset.y)
                                {
                                    offset = nOffset;
                                    position = _position;
                                    imageSize = fr.imageSize * OT.view.sizeFactor;
                                }
                            }
                            if (_frameIndex_ != frameIndex || _spriteContainer_ != spriteContainer)
                            {
                                float _sx = (size.x / oSize.x);
                                float _sy = (size.y / oSize.y);
                                Vector2 sc = new Vector2(_sx * fr.size.x * OT.view.sizeFactor, _sy * fr.size.y * OT.view.sizeFactor);
                                Vector3 sc3 = new Vector3(sc.x, sc.y, 1);

                                _size = sc;
                                if (!Vector3.Equals(otTransform.localScale, sc3))
                                   otTransform.localScale = sc3;
                                oSize = fr.size * OT.view.sizeFactor;

                                imageSize = new Vector2(_sx * fr.imageSize.x * OT.view.sizeFactor, _sy * fr.imageSize.y * OT.view.sizeFactor);
                                Vector2 nOffset = new Vector2(_sx * fr.offset.x * OT.view.sizeFactor, _sy * fr.offset.y * OT.view.sizeFactor);

                                if (flipHorizontal)
                                    nOffset.x = (fr.imageSize.x * OT.view.sizeFactor) - oSize.x - nOffset.x;
                                if (flipVertical)
                                    nOffset.y = (fr.imageSize.y * OT.view.sizeFactor) - oSize.y - nOffset.y;

                                offset = nOffset;
                                position = _position;
                            }
                        }
                        else
                        {
                            Vector3[] verts = fr.vertices.Clone() as Vector3[];
                            verts[0] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[1] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[2] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            verts[3] -= new Vector3(pivotPoint.x, pivotPoint.y, 0);
                            mesh.vertices = verts;

                            _size = fr.size;
                            Vector3 sc3 = new Vector3(_size.x, _size.y, 1);
                            if (!Vector3.Equals(otTransform.localScale, sc3))
                                otTransform.localScale = sc3;
                        }
                    }
                }

            }

            // keep old and get new material name
            string cMatName = GetMatName();
            if (lastMatName!=cMatName)
            {
                // material name has changed to look it up
                Material mat = OT.LookupMaterial(cMatName);
                // if we could not find the material let create a new one
                if (mat == null)
                    mat = InitMaterial();
                else
                {
                    // if we had a previous generated material lets
                    // decrease its use
                    if (lastMat!=null && lastMatName!="")
                        OT.MatDec(lastMat,lastMatName);
                    otRenderer.material = mat;
                    HandleUV();
                    lastMat = mat;
                    lastMatName = cMatName;
                }
                // increase the current material's use
               	OT.MatInc(mat, cMatName);
            }
            else
            {
                if (_frameIndex_ != frameIndex)
                   HandleUV();
            }

            _spriteContainer_ = spriteContainer;
            _materialReference_ = materialReference;
            _frameIndex_ = frameIndex;
            _frameName_ = frameName;
            _image_ = image;

            if (mr!=null && (tintColor!=_tintColor_ || _alpha_ != alpha))
                HandleColors();

            _tintColor_ = tintColor;
            _alpha_ = alpha;

            Changed();

        }

        isDirty = false;
        if (spriteContainer != null && !spriteContainer.isReady)
            isDirty = true;

        #if UNITY_EDITOR
                if (!Application.isPlaying)
                    UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(this);
        #endif
    }
    private void LoadTile(OgmoTile tile, OTContainer container, float height)
    {
        string tileName = string.Format ("frame{0}", tile.id);
        string tilePath = (zoneFolder ?? "") + tileName;
        var go = GetPrefab (tilePath);
        if (go != null) {
            go = (GameObject)GameObject.Instantiate (go);
            go.transform.parent = lvl.transform;
            OTSprite ot = go.GetComponent<OTSprite> ();

            go.transform.localPosition = new Vector3 (tile.x, height, 15 - tile.y);
            if (ot != null) {
                ot.position = new Vector2 (go.transform.localPosition.x, go.transform.localPosition.z);
                ot.depth = (int)height;
                int id = ot.frameIndex;
                ot.spriteContainer = container;
                ot.frameIndex = id;
                ot.otTransform = ot.transform;
                ot.transform.localScale = Vector3.one;
            }
        }
    }