示例#1
0
        protected virtual void RecalcMesh()
        {
            MeshFilter          v_meshFilter      = GetComponent <MeshFilter>();
            SkinnedMeshRenderer v_skinnedRenderer = GetComponent <SkinnedMeshRenderer>();
            UIMeshGraphic       v_uiFilter        = GetComponent <UIMeshGraphic>();

            if (v_uiFilter != null)
            {
                if (!v_uiFilter.enabled || !v_uiFilter.gameObject.activeSelf || !v_uiFilter.gameObject.activeInHierarchy)
                {
                    v_uiFilter.TryApplyBakedMesh(true);
                }
                var v_mesh = v_uiFilter.Mesh;
                if (_mesh != v_mesh)
                {
                    DestroyMesh();
                    _mesh = v_mesh;
                }
            }
            else if (v_skinnedRenderer != null)
            {
                ClearMesh();
                v_skinnedRenderer.BakeMesh(_mesh);
            }
            else if (v_meshFilter != null)
            {
                _mesh = v_meshFilter.sharedMesh;
            }
        }
示例#2
0
        protected virtual void UpdateUIMeshFromComponent(Component p_meshComponent)
        {
            UIMeshGraphic v_meshGraphic = null;

            if (p_meshComponent != null)
            {
                var v_meshFilter      = p_meshComponent as MeshFilter;
                var v_skinnedRenderer = p_meshComponent as SkinnedMeshRenderer;

                if (v_meshFilter != null)
                {
                    v_meshGraphic = v_meshFilter.GetComponent <UIMeshFilter>();
                    if (v_meshGraphic == null)
                    {
                        v_meshGraphic           = v_meshFilter.gameObject.AddComponent <UIMeshFilter>();
                        v_meshGraphic.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
                    }
                    var v_renderer = v_meshFilter.GetComponent <Renderer>();
                    v_meshGraphic.material = TryGetMaterialToReplace(v_renderer != null ? v_renderer.sharedMaterial : null);
                    //Try Pick Color Component From Renderer MaterialPropertyBlock
                    if (v_renderer != null)
                    {
                        MaterialPropertyBlock v_propertyBlock = new MaterialPropertyBlock();
                        v_renderer.GetPropertyBlock(v_propertyBlock);
                        if (!v_propertyBlock.isEmpty)
                        {
                            Vector4 v_colorVector = v_propertyBlock.GetVector("_Color");
                            if (v_colorVector != Vector4.zero)
                            {
                                v_meshGraphic.color = new Color(v_colorVector.x, v_colorVector.y, v_colorVector.z, v_colorVector.w);
                            }
                            v_meshGraphic.Texture = v_propertyBlock.GetTexture("_MainTex") as Texture2D;
                        }
                    }
                }
                if (v_skinnedRenderer != null)
                {
                    v_meshGraphic = v_skinnedRenderer.GetComponent <UISkinnedMeshFilter>();
                    if (v_meshGraphic == null)
                    {
                        v_meshGraphic = v_skinnedRenderer.gameObject.AddComponent <UISkinnedMeshFilter>();
                    }
                    v_meshGraphic.material = TryGetMaterialToReplace(v_skinnedRenderer.sharedMaterial);

                    //Try Pick Color Component From SkinnedRenderer MaterialPropertyBlock
                    MaterialPropertyBlock v_propertyBlock = new MaterialPropertyBlock();
                    v_skinnedRenderer.GetPropertyBlock(v_propertyBlock);
                    if (!v_propertyBlock.isEmpty)
                    {
                        Vector4 v_colorVector = v_propertyBlock.GetVector("_Color");
                        if (v_colorVector != Vector4.zero)
                        {
                            v_meshGraphic.color = new Color(v_colorVector.x, v_colorVector.y, v_colorVector.z, v_colorVector.w);
                        }
                        v_meshGraphic.Texture = v_propertyBlock.GetTexture("_MainTex") as Texture2D;
                    }
                }
            }
        }
示例#3
0
        protected virtual void RecalcMesh()
        {
            UIMeshGraphic v_uiFilter = GetComponent <UIMeshGraphic>();

            if (v_uiFilter != null)
            {
                if (!v_uiFilter.enabled || !v_uiFilter.gameObject.activeSelf || !v_uiFilter.gameObject.activeInHierarchy)
                {
                    v_uiFilter.TryApplyBakedMesh(true);
                }
                var v_mesh = v_uiFilter.Mesh;
                if (_mesh != v_mesh)
                {
                    DestroyMesh();
                    _mesh = v_mesh;
                }
            }
        }
示例#4
0
        protected virtual void CheckRendererActive()
        {
            Renderer      v_renderer = GetComponent <Renderer>();
            UIMeshGraphic v_uiFilter = GetComponent <UIMeshGraphic>();

            //MeshFilter v_meshFilter = GetComponent<MeshFilter>();

            if (v_renderer != null)
            {
                v_renderer.enabled = m_drawMeshGraphics;
            }
            if (v_uiFilter != null)
            {
                v_uiFilter.enabled = m_drawMeshGraphics;
            }
            //if ((v_uiFilter != null && v_uiFilter.Mesh != _mesh) ||
            //    (v_meshFilter != null && v_meshFilter.sharedMesh != _mesh) ||
            //    v_renderer is SkinnedMeshRenderer)
            //{
            SetDirty();
            //}
        }