Exemplo n.º 1
0
        protected void GetDefaultMaterial()
        {
            if (_lastVectorGraphics != _vectorGraphics)
            {
                if (_lastVectorGraphics != null)
                {
                    _lastVectorGraphics.RemoveReference(this);
                }
                if (_vectorGraphics != null)
                {
                    _vectorGraphics.AddReference(this);
                }
                _lastVectorGraphics = _vectorGraphics;
                Clear();
            }

            if (_vectorGraphics != null)
            {
                if (_defaultMaterial == null)
                {
                    #if UNITY_4 || UNITY_5_0 || UNITY_5_1
                    if (!this.m_IncludeForMasking)
                    {
                        _defaultMaterial = SVGAtlas.Instance.ui;
                    }
                    else
                    {
                        _defaultMaterial = SVGAtlas.Instance.uiMask;
                    }
                    #else
                    _defaultMaterial = _vectorGraphics.sharedUIMaterial;
                    #endif
                }
            }
        }
Exemplo n.º 2
0
 protected override void OnDestroy()
 {
     if (_vectorGraphics != null)
     {
         _vectorGraphics.RemoveReference(this);
     }
     base.OnDestroy();
 }
Exemplo n.º 3
0
        protected void GetDefaultMaterial()
        {
            if (_lastVectorGraphics != _vectorGraphics)
            {
                if (_lastVectorGraphics != null)
                {
                    _lastVectorGraphics.RemoveReference(this);
                }
                if (_vectorGraphics != null)
                {
                    _vectorGraphics.AddReference(this);
                }
                _lastVectorGraphics = _vectorGraphics;
                Clear();
            }

            if (_vectorGraphics != null)
            {
                if (_defaultMaterial == null)
                {
                    _defaultMaterial = _vectorGraphics.sharedUIMaterial;
                }
            }
        }
Exemplo n.º 4
0
        // This is the main rendering method
        protected void PrepareForRendering(bool force = false)
        {
#if UNITY_EDITOR
            if (_lastSortingOrder != _sortingOrder)
            {
                sortingOrder = _sortingOrder;
            }
            if (_lastSortingLayerID != _sortingLayerID)
            {
                sortingLayerID = _sortingLayerID;
            }
#endif
            if (_vectorGraphics == null)
            {
                if (_lastVectorGraphics != null)
                {
                    _lastVectorGraphics.RemoveReference(this);
                    _lastVectorGraphics = null;
                }
                Clear();
            }
            else
            {
                bool meshChanged     = force || _lastType != _type || meshFilter.sharedMesh == null;
                bool colorChanged    = force || _lastColor != _color;
                bool materialChanged = force || _lastOpaqueMaterial != _opaqueMaterial || _lastTransparentMaterial != _transparentMaterial;
#if UNITY_EDITOR
                for (int i = 0; i < meshRenderer.sharedMaterials.Length; i++)
                {
                    if (meshRenderer.sharedMaterials[i] != null)
                    {
                        continue;
                    }
                    materialChanged = true;
                    break;
                }
#endif

                if (_lastVectorGraphics != _vectorGraphics)
                {
                    meshChanged     = true;
                    colorChanged    = true;
                    materialChanged = true;

                    if (_lastVectorGraphics != null)
                    {
                        _lastVectorGraphics.RemoveReference(this);
                    }
                    if (_vectorGraphics != null)
                    {
                        _vectorGraphics.AddReference(this);
                    }
                }

                if (useLayers || !useSharedMesh)
                {
                    if (_lastUseSharedMesh != false)
                    {
                        meshChanged = true;
                    }
                    if (!meshChanged)
                    {
                        if (_type == Type.Sliced && rectTransform != null)
                        {
                            _rectTransformRect = rectTransform.rect;
                            if (_rectTransformRect != _lastRectTransformRect)
                            {
                                meshChanged            = true;
                                _lastRectTransformRect = _rectTransformRect;
                            }
                        }
                    }
                }

                if (useLayers)
                {
                    if (_layers == null)
                    {
                        _layers = _vectorGraphics.layersClone;
                    }
                    if (meshChanged || colorChanged)
                    {
                        InitMesh();
                        materialChanged = true;

                        if (_type == Type.Sliced)
                        {
                            UpdateSlicedMesh();
                        }

                        UpdateColors(force);
                        _lastFrameChanged = Time.frameCount;
                        materialChanged   = true;

                        if (_OnPrepareForRendering != null)
                        {
                            _OnPrepareForRendering(_layers, _vectorGraphics, force);
                        }

                        GenerateMesh();

                        if (meshFilter.sharedMesh != _mesh)
                        {
                            meshFilter.sharedMesh = _mesh;
                        }
                    }
                }
                else
                {
                    if (useSharedMesh)
                    {
                        _sharedMesh           = _vectorGraphics.sharedMesh;
                        meshFilter.sharedMesh = _sharedMesh;
                    }
                    else
                    {
                        // Cache Mesh
                        if (meshChanged)
                        {
                            InitMesh();
                            materialChanged = true;
                            if (_type == Type.Sliced)
                            {
                                UpdateSlicedMesh();
                            }

                            if (onVectorGraphicsChanged != null)
                            {
                                onVectorGraphicsChanged(_vectorGraphics);
                            }
                        }

                        if (meshChanged || colorChanged)
                        {
                            UpdateColors(force);
                            _lastFrameChanged = Time.frameCount;
                            materialChanged   = true;
                        }

                        if (meshFilter.sharedMesh != _mesh)
                        {
                            meshFilter.sharedMesh = _mesh;
                        }
                    }
                }

                if (materialChanged)
                {
                    UpdateMaterials();
                }

                _lastOpaqueMaterial      = _opaqueMaterial;
                _lastTransparentMaterial = _transparentMaterial;
                _lastVectorGraphics      = _vectorGraphics;
                _lastColor         = _color;
                _lastType          = _type;
                _lastUseSharedMesh = useSharedMesh;
            }

#if UNITY_EDITOR
            UpdateTimeStamp();
#endif
        }