예제 #1
0
 public void Copy(TilesetFlagsMask other)
 {
     if (other.IsUndefined)
     {
         flags = null;
         return;
     }
     else if (this.IsUndefined)
     {
         flags = new int[Tileset.TILESET_FLAGS_COUNT];
     }
     other.flags.CopyTo(flags, 0);
 }
예제 #2
0
        public bool RefreshVertices(bool refreshOrientation = false)
        {
            var quad   = face.ToQuad();
            var colors = new Color[vertices.Length];

            if (refreshOrientation)
            {
                RefreshOrientation(quad, tilesetRenderer.Orientation);
            }

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = mesh.positions[quad[(i + orientationOffset) % 4]];
                colors[i]   = mesh.colors[quad[i]];
            }


            var leftEdge   = vertices[1] - vertices[0];
            var bottomEdge = vertices[3] - vertices[0];

            height = leftEdge.magnitude;
            width  = bottomEdge.magnitude;

            this.position = (vertices[0] + vertices[1] + vertices[2] + vertices[3]) / 4;
            this.normal   = Vector3.Cross(leftEdge, bottomEdge).normalized;

            // Compute flags
            if (tilesetFlags == null)
            {
                tilesetFlags = new TilesetFlagsMask(colors);
            }
            else
            {
                tilesetFlags.FromVertexColors(colors);
            }

            // Check if anything has changed
            bool changed = lastPos != position ||
                           Mathf.Abs(lastWidth - width) > SIZE_MATCH_THRESHOLD ||
                           Mathf.Abs(lastHeight - height) > SIZE_MATCH_THRESHOLD;

            lastPos    = position;
            lastWidth  = width;
            lastHeight = height;

            return(changed);
        }
예제 #3
0
        public bool Matches(TilesetFlagsMask other)
        {
            if (other.IsUndefined)
            {
                return(true);
            }

            for (int i = 0; i < other.flags.Length; i++)
            {
                if (other.flags[i] == 0)
                {
                    continue;
                }
                if (other.flags[i] != this[i])
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
 public bool ShouldHide(TilesetFlagsMask flags)
 {
     return(hideMode == HideMode.HideOnMatch ? flags.Matches(tilesetFlags) : !flags.Matches(tilesetFlags));
 }