Ejemplo n.º 1
0
    /// <exclude />
    protected override void Start()
    {
        base.Start();
        mr = OT.GetMatRef(materialReference);
        if (Application.isPlaying)
        {
            if (!assignedMaterial)
            {
                Material mat = LookupMaterial();
                if (mat != null)
                {
                    renderer.material = mat;
                    HandleUV(mat);
                }
                else
                {
                    mat = InitMaterial();
                }

                OT.MatInc(mat);
            }
        }
        else
        {
            Material mat = InitMaterial();
            OT.MatInc(mat);
        }

        if (Application.isPlaying)
        {
            _frameIndex_ = -1;
        }
    }
Ejemplo n.º 2
0
    public override void Assign(OTObject protoType)
    {
        base.Assign(protoType);
        OTSprite pSprite = protoType as OTSprite;

        image             = pSprite.image;
        spriteContainer   = pSprite.spriteContainer;
        frameIndex        = pSprite.frameIndex;
        materialReference = pSprite.materialReference;
        mr        = OT.GetMatRef(materialReference);
        tintColor = pSprite.tintColor;
        alpha     = pSprite.alpha;
        HandleColors();
    }
Ejemplo n.º 3
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;
        }
    }
Ejemplo n.º 4
0
    protected virtual void HandleColors()
    {
        if (mesh == null || mesh.vertexCount == 0)
        {
            return;
        }

        if (mr == null)
        {
            mr = OT.GetMatRef(materialReference);
        }


        if (mr.fieldColorTint != "" && (mr.fieldAlphaChannel != "" || mr.fieldAlphaColor != ""))
        {
            if (mesh.colors != null)
            {
                mesh.colors = null;
            }
            return;
        }

        Color c = tintColor;

        if (mr.fieldColorTint != "")
        {
            c = Color.white;
        }

        Color[] colors = new Color[] {};
        if (mesh.vertexCount > 0)
        {
            c.a    = alpha;
            colors = new Color[mesh.vertexCount];
            for (int i = 0; i < mesh.vertexCount; i++)
            {
                colors[i] = c;
            }
        }
        mesh.colors = colors;
    }
Ejemplo n.º 5
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;
            }
        }
    }
Ejemplo n.º 6
0
    override protected void CheckDirty()
    {
        base.CheckDirty();

        if (spriteContainer != null)
        {
            if (spriteContainer.isReady)
            {
                if (_spriteContainer_ != spriteContainer || _frameIndex_ != frameIndex || _frameName_ != frameName)
                {
                    isDirty = true;
                }
            }
        }
        else
        if (_spriteContainer_ != null || image != _image_)
        {
            isDirty = true;
        }

        if (flipHorizontal != _flipHorizontal_ || flipVertical != _flipVertical_)
        {
            _flipHorizontal_ = flipHorizontal;
            _flipVertical_   = flipVertical;
            meshDirty        = true;
        }

        if (!Application.isPlaying)
        {
            if (!isDirty && spriteContainer != null && material.mainTexture != spriteContainer.GetTexture())
            {
                isDirty = true;
            }
        }

        if (transparent != _transparent_ && transparent)
        {
            _additive     = false;
            _additive_    = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
        if (additive != _additive_ && additive)
        {
            _transparent  = false;
            _additive_    = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
        if (!_additive && !_transparent)
        {
            _additive_    = additive;
            _transparent_ = transparent;
            if (_materialReference == "transparent" || _materialReference == "additive")
            {
                _materialReference = "solid";
            }
        }



        if (materialReference != _materialReference_)
        {
            mr = OT.GetMatRef(materialReference);
            if (_materialReference == "transparent")
            {
                _transparent = true;
                _additive    = false;
            }
            else
            if (_materialReference == "additive")
            {
                _transparent = false;
                _additive    = true;
            }
            else
            {
                _transparent = false;
                _additive    = false;
            }
            isDirty = true;
        }

        if (mr != null && (_tintColor_ != tintColor || _alpha_ != alpha))
        {
            isDirty = true;
        }
    }
Ejemplo n.º 7
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();
    }
Ejemplo n.º 8
0
    protected virtual void HandleColors()
    {
        if (mesh == null || mesh.vertexCount==0)
            return;

        if (mr==null)
            mr = OT.GetMatRef(materialReference);

        if (mr.fieldColorTint != "" && (mr.fieldAlphaChannel != "" || mr.fieldAlphaColor != ""))
        {
            if (mesh.colors != null)
                mesh.colors = null;
            return;
        }

        Color c = tintColor;
        if (mr.fieldColorTint != "")
            c = Color.white;

        Color[] colors = new Color[] {};
        if (mesh.vertexCount>0)
        {
            c.a = alpha;
            colors = new Color[mesh.vertexCount];
            for (int i=0; i<mesh.vertexCount; i++)
                colors[i] = c;
        }
        mesh.colors = colors;
    }
Ejemplo n.º 9
0
 public override void Assign(OTObject protoType)
 {
     base.Assign(protoType);
     OTSprite pSprite = protoType as OTSprite;
     image = pSprite.image;
     spriteContainer = pSprite.spriteContainer;
     frameIndex = pSprite.frameIndex;
     materialReference = pSprite.materialReference;
     mr = OT.GetMatRef(materialReference);
     tintColor = pSprite.tintColor;
     alpha = pSprite.alpha;
     HandleColors();
 }
Ejemplo n.º 10
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;
        }
    }
Ejemplo n.º 11
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();
    }
Ejemplo n.º 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)
        {
            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();
    }
Ejemplo n.º 13
0
    /// <exclude />
    protected override void Start()
    {
        base.Start();
        mr = OT.GetMatRef(materialReference);
        if (Application.isPlaying)
        {
            if (!assignedMaterial)
            {
                Material mat = LookupMaterial();
                if (mat != null)
                {
                    renderer.material = mat;
                    HandleUV(mat);
                }
                else
                    mat = InitMaterial();

                OT.MatInc(mat);
            }
        }
        else
        {
            Material mat = InitMaterial();
            OT.MatInc(mat);
        }

        if (Application.isPlaying)
            _frameIndex_ = -1;
    }
Ejemplo n.º 14
0
    /// <exclude />
    protected override void CheckDirty()
    {
        base.CheckDirty();
        if (spriteContainer != null)
        {
            if (spriteContainer.isReady)
            {
                if (_spriteContainer_ != spriteContainer || _frameIndex_ != frameIndex)
                    isDirty = true;
            }
        }
        else
            if (_spriteContainer_ != null || image != _image_)
                isDirty = true;

        if (flipHorizontal != _flipHorizontal_ || flipVertical != _flipVertical_)
        {
            _flipHorizontal_ = flipHorizontal;
            _flipVertical_ = flipVertical;
            meshDirty = true;
        }

        if (!Application.isPlaying)
        {
            if (!isDirty && spriteContainer != null && material.mainTexture != spriteContainer.GetTexture())
                isDirty = true;
        }

        if (transparent != _transparent_ && transparent)
        {
            _additive = false;
            _additive_ = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
            if (additive != _additive_ && additive)
            {
                _transparent = false;
                _additive_ = additive;
                _transparent_ = transparent;
                SetMatReference();
            }
            else
                if (!_additive && !_transparent)
                {
                    _additive_ = additive;
                    _transparent_ = transparent;
                    if (_materialReference == "transparent" || _materialReference == "additive")
                        _materialReference = "solid";
                }

        if (materialReference != _materialReference_)
        {
            mr = OT.GetMatRef(materialReference);
            if (_materialReference == "transparent")
            {
                _transparent = true;
                _additive = false;
            }
            else
                if (_materialReference == "additive")
                {
                    _transparent = false;
                    _additive = true;
                }
                else
                {
                    _transparent = false;
                    _additive = false;
                }
            isDirty = true;
        }

        if (mr != null)
        {
            if (_tintColor_ != tintColor)
            {
                if (mr.fieldColorTint != "")
                    isDirty = true;
                else
                {
                    _tintColor = Color.white;
                    _tintColor_ = _tintColor;
                    Debug.LogWarning("Orthello : TintColor can not be set on this materialReference!");
                }
            }
            if (_alpha_ != alpha)
            {
                if (mr.fieldAlphaColor != "" || mr.fieldAlphaChannel != "")
                    isDirty = true;
                else
                {
                    _alpha = 1;
                    _alpha_ = 1;
                    Debug.LogWarning("Orthello : Alpha value can not be set on this materialReference!");
                }
            }
        }
    }
Ejemplo n.º 15
0
    override protected void CheckDirty()
    {
        base.CheckDirty();

        if (spriteContainer != null)
        {
            if (spriteContainer.isReady)
            {
                if (_spriteContainer_ != spriteContainer || _frameIndex_ != frameIndex || _frameName_ != frameName)
                {
                    isDirty = true;
                }
            }
        }
        else
        if (_spriteContainer_ != null || image != _image_)
        {
            isDirty = true;
        }

        if (flipHorizontal != _flipHorizontal_ || flipVertical != _flipVertical_)
        {
            _flipHorizontal_ = flipHorizontal;
            _flipVertical_   = flipVertical;
            meshDirty        = true;
        }

        if (!Application.isPlaying)
        {
            if (!isDirty && spriteContainer != null && material.mainTexture != spriteContainer.GetTexture())
            {
                isDirty = true;
            }
        }

        if (transparent != _transparent_ && transparent)
        {
            _additive     = false;
            _additive_    = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
        if (additive != _additive_ && additive)
        {
            _transparent  = false;
            _additive_    = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
        if (!_additive && !_transparent)
        {
            _additive_    = additive;
            _transparent_ = transparent;
            if (_materialReference == "transparent" || _materialReference == "additive")
            {
                _materialReference = "solid";
            }
        }



        if (materialReference != _materialReference_)
        {
            mr = OT.GetMatRef(materialReference);
            if (_materialReference == "transparent")
            {
                _transparent = true;
                _additive    = false;
            }
            else
            if (_materialReference == "additive")
            {
                _transparent = false;
                _additive    = true;
            }
            else
            {
                _transparent = false;
                _additive    = false;
            }
            isDirty = true;
        }

        if (mr != null)
        {
            if (_tintColor_ != tintColor)
            {
                if (mr.fieldColorTint != "")
                {
                    isDirty = true;
                }
                else
                {
                    _tintColor  = Color.white;
                    _tintColor_ = _tintColor;
                    Debug.LogWarning("Orthello : TintColor can not be set on this materialReference!");
                }
            }
            if (_alpha_ != alpha)
            {
                if (mr.fieldAlphaColor != "" || mr.fieldAlphaChannel != "")
                {
                    isDirty = true;
                }
                else
                {
                    _alpha  = 1;
                    _alpha_ = 1;
                    Debug.LogWarning("Orthello : Alpha value can not be set on this materialReference!");
                }
            }
        }
    }
Ejemplo n.º 16
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;
    }
Ejemplo n.º 17
0
    protected override void CheckDirty()
    {
        base.CheckDirty();

        if (spriteContainer != null)
        {
            if (spriteContainer.isReady)
            {
                if (_spriteContainer_ != spriteContainer || _frameIndex_ != frameIndex || _frameName_ != frameName)
                    isDirty = true;
            }
        }
        else
            if (_spriteContainer_ != null || image != _image_)
                isDirty = true;

        if (flipHorizontal != _flipHorizontal_ || flipVertical != _flipVertical_)
        {
            _flipHorizontal_ = flipHorizontal;
            _flipVertical_ = flipVertical;
            meshDirty = true;
        }

        if (!Application.isPlaying)
        {
            if (!isDirty && spriteContainer != null && material.mainTexture != spriteContainer.GetTexture())
                isDirty = true;
        }

        if (transparent != _transparent_ && transparent)
        {
            _additive = false;
            _additive_ = additive;
            _transparent_ = transparent;
            SetMatReference();
        }
        else
            if (additive != _additive_ && additive)
            {
                _transparent = false;
                _additive_ = additive;
                _transparent_ = transparent;
                SetMatReference();
            }
            else
                if (!_additive && !_transparent)
                {
                    _additive_ = additive;
                    _transparent_ = transparent;
                    if (_materialReference == "transparent" || _materialReference == "additive")
                        _materialReference = "solid";
                }

        if (materialReference != _materialReference_)
        {
            mr = OT.GetMatRef(materialReference);
            if (_materialReference == "transparent")
            {
                _transparent = true;
                _additive = false;
            }
            else
                if (_materialReference == "additive")
                {
                    _transparent = false;
                    _additive = true;
                }
                else
                {
                    _transparent = false;
                    _additive = false;
                }
            isDirty = true;
        }

        if (mr != null && (_tintColor_ != tintColor || _alpha_ != alpha))
            isDirty = true;
    }
Ejemplo n.º 18
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();
    }