示例#1
0
        static MaterialPropertyBlock GetMaterialPropertyBlock(CircleInfo circleInfo)
        {
            if (_materialPropertyBlock == null)
            {
                _materialPropertyBlock = new MaterialPropertyBlock();
            }

            _materialPropertyBlock.SetColor(FillColorParam, circleInfo.fillColor);
            _materialPropertyBlock.SetFloat(AASmoothingParam, antiAliasingSmoothing);

            if (circleInfo.bordered)
            {
                _materialPropertyBlock.SetColor(BorderColorParam, circleInfo.borderColor);
                var borderWidthNormalized = circleInfo.borderWidth / circleInfo.radius;
                _materialPropertyBlock.SetFloat(FillWidthParam, 1.0f - borderWidthNormalized);
            }

            if (circleInfo.isSector)
            {
                setSectorAngles(_materialPropertyBlock, circleInfo.sectorInitialAngleInDegrees, circleInfo.sectorArcLengthInDegrees);
            }


            return(_materialPropertyBlock);
        }
示例#2
0
        public static void Draw(CircleInfo circleInfo)
        {
            var mesh = GetCircleMesh();
            var materialPropertyBlock = GetMaterialPropertyBlock(circleInfo);
            var matrix   = GetTRSMatrix(circleInfo);
            var material = GetMaterial(circleInfo);

            Graphics.DrawMesh(mesh, matrix, material, 0, null, 0, materialPropertyBlock);
        }
示例#3
0
        static Material GetMaterial(CircleInfo circleInfo)
        {
            var materialIndex = 0;

            if (circleInfo.bordered)
            {
                materialIndex = 1;
            }

            if (circleInfo.isSector)
            {
                materialIndex = 2;
            }

            if (circleInfo.bordered && circleInfo.isSector)
            {
                materialIndex = 3;
            }


            if (_materials[materialIndex] != null)
            {
                return(_materials[materialIndex]);
            }

            var mat = new Material(Shader.Find("Hidden/Shapes/Circle"));

            if (SystemInfo.supportsInstancing)
            {
                mat.enableInstancing = true;
            }

            var keywords = _materialKeywords[materialIndex];

            if (keywords != null)
            {
                mat.shaderKeywords = keywords;
            }


            _materials[materialIndex] = mat;

            return(mat);
        }
示例#4
0
        static Matrix4x4 GetTRSMatrix(CircleInfo circleInfo)
        {
            var rotation = Quaternion.LookRotation(circleInfo.forward);

            return(Matrix4x4.TRS(circleInfo.center, rotation, new Vector3(circleInfo.radius, circleInfo.radius, 1f)));
        }