public override void Update() { if (Enabled) { base.Update(); Size = TextureReplacement.GetSizeFromXml(compassBoxTexture, compassBoxFilename, Scale.x, Scale.y); } }
void DrawCompass() { const int boxOutlineSize = 2; // Pixel width of box outline const int boxInterior = 64; // Pixel width of box interior const int nonWrappedPart = 258; // Pixel width of non-wrapped part of compass strip if (!compassBoxTexture || !compassTexture) { return; } // Calculate displacement float percent; if (compassCamera != null) { percent = compassCamera.transform.eulerAngles.y / 360f; } else { percent = eulerAngle; } // Calculate scroll offset int scroll = (int)((float)nonWrappedPart * percent); // Compass box rect Rect compassBoxRect = new Rect(); compassBoxRect.x = Position.x; compassBoxRect.y = Position.y; Vector2 boxRectSize = TextureReplacement.GetSizeFromXml(compassBoxTexture, compassBoxFilename, Scale.x, Scale.y); compassBoxRect.width = boxRectSize.x; compassBoxRect.height = boxRectSize.y; // Get compassTexture size Vector2 compassTextureSize = TextureReplacement.GetSizeFromXml(compassTexture, compassFilename); float compassTextureWidth = compassTextureSize.x; float compassTextureHeight = compassTextureSize.y; // Compass strip source Rect compassSrcRect = new Rect(); compassSrcRect.xMin = scroll / compassTextureWidth; compassSrcRect.yMin = 0; compassSrcRect.xMax = compassSrcRect.xMin + (float)boxInterior / compassTextureWidth; compassSrcRect.yMax = 1; // Compass strip destination Rect compassDstRect = new Rect(); compassDstRect.x = compassBoxRect.x + boxOutlineSize * Scale.x; compassDstRect.y = compassBoxRect.y + boxOutlineSize * Scale.y; compassDstRect.width = compassBoxRect.width - (boxOutlineSize * 2) * Scale.x; compassDstRect.height = compassTextureHeight * Scale.y; GUI.DrawTextureWithTexCoords(compassDstRect, compassTexture, compassSrcRect, false); GUI.DrawTexture(compassBoxRect, compassBoxTexture, ScaleMode.StretchToFill, true); }