using System.Collections.Generic; using BitStrap; using UnityEngine; public class TextOutline : MonoBehaviour { public float pixelSize = 1f; public Color outlineColor = Color.black; public bool resolutionDependant; public int doubleResolution = 1024; public Material outlineMaterial; private TextMesh textMesh; private MeshRenderer meshRenderer; public List outlineChildren = new List(); private void Start() { textMesh = GetComponent(); meshRenderer = GetComponent(); for (int i = 0; i < 8; i++) { GameObject gameObject = new GameObject("outline", typeof(TextMesh)); gameObject.transform.parent = base.transform; gameObject.transform.localScale = new Vector3(1f, 1f, 1f); gameObject.transform.localEulerAngles = Vector3.zero; MeshRenderer component = gameObject.GetComponent(); component.material = outlineMaterial; component.castShadows = false; component.receiveShadows = false; component.sortingLayerID = meshRenderer.sortingLayerID; component.sortingLayerName = meshRenderer.sortingLayerName; TextMesh component2 = gameObject.GetComponent(); component2.color = outlineColor; component2.text = textMesh.text; component2.alignment = textMesh.alignment; component2.anchor = textMesh.anchor; component2.characterSize = textMesh.characterSize; component2.font = textMesh.font; component2.fontSize = textMesh.fontSize; component2.fontStyle = textMesh.fontStyle; component2.richText = textMesh.richText; component2.tabSize = textMesh.tabSize; component2.lineSpacing = textMesh.lineSpacing; component2.offsetZ = textMesh.offsetZ; outlineChildren.Add(component2); } MakeLateUpdate(); } private void LateUpdate() { MakeLateUpdate(); } [Button] public void UpdateText() { for (int i = 0; i < outlineChildren.Count; i++) { TextMesh textMesh = outlineChildren[i]; textMesh.text = this.textMesh.text; } } [Button] public void MakeLateUpdate() { if (!(textMesh == null)) { Vector3 vector = GameController.Instance.fishingPlayer.ufpsCameraCamera.WorldToScreenPoint(base.transform.position); for (int i = 0; i < outlineChildren.Count; i++) { Vector3 position = GameController.Instance.fishingPlayer.ufpsCameraCamera.ScreenToWorldPoint(vector + GetOffset(i) * pixelSize); outlineChildren[i].transform.position = position; } } } private Vector3 GetOffset(int i) { switch (i % 8) { case 0: return new Vector3(0f, 1f, 0f); case 1: return new Vector3(1f, 1f, 0f); case 2: return new Vector3(1f, 0f, 0f); case 3: return new Vector3(1f, -1f, 0f); case 4: return new Vector3(0f, -1f, 0f); case 5: return new Vector3(-1f, -1f, 0f); case 6: return new Vector3(-1f, 0f, 0f); case 7: return new Vector3(-1f, 1f, 0f); default: return Vector3.zero; } } }