/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> public virtual void OnGUI() { if (!useDefaultGUI) { return; } if (guiStyle == null && (Event.current.type == EventType.Repaint || usable != null)) { SetGuiStyle(); } if (usable != null) { bool inUseRange = (distance <= usable.maxUseDistance); guiStyle.normal.textColor = inUseRange ? inRangeColor : outOfRangeColor; if (string.IsNullOrEmpty(heading)) { heading = usable.GetName(); useMessage = DialogueManager.GetLocalizedText(string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage); } UnityGUITools.DrawText(new Rect(0, 0, Screen.width, Screen.height), heading, guiStyle, textStyle, textStyleColor); UnityGUITools.DrawText(new Rect(0, guiStyleLineHeight, Screen.width, Screen.height), useMessage, guiStyle, textStyle, textStyleColor); Texture2D reticleTexture = inUseRange ? reticle.inRange : reticle.outOfRange; if (reticleTexture != null) { GUI.Label(new Rect(0.5f * (Screen.width - reticle.width), 0.5f * (Screen.height - reticle.height), reticle.width, reticle.height), reticleTexture); } } }
/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> public virtual void OnGUI() { if (useDefaultGUI) { SetGuiStyle(); Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (usable != null) { bool inUseRange = (distance <= usable.maxUseDistance); guiStyle.normal.textColor = inUseRange ? inRangeColor : outOfRangeColor; if (string.IsNullOrEmpty(heading)) { heading = usable.GetName(); useMessage = string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage; /////pene } UnityGUITools.DrawText(screenRect, heading, guiStyle, textStyle, textStyleColor); UnityGUITools.DrawText(new Rect(0, guiStyle.CalcSize(new GUIContent("Ay")).y, Screen.width, Screen.height), useMessage, guiStyle, textStyle, textStyleColor); Texture2D reticleTexture = inUseRange ? reticle.inRange : reticle.outOfRange; if (reticleTexture != null) { GUI.Label(new Rect(0.5f * (Screen.width - reticle.width), 0.5f * (Screen.height - reticle.height), reticle.width, reticle.height), reticleTexture); } } } }
/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> void OnGUI() { if (useDefaultGUI) { GUI.skin = UnityGUITools.GetValidGUISkin(guiSkin); if (guiStyle == null) { guiStyle = new GUIStyle(GUI.skin.label); guiStyle.alignment = TextAnchor.UpperCenter; } Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (usable != null) { bool inUseRange = (distance <= usable.maxUseDistance); guiStyle.normal.textColor = inUseRange ? inRangeColor : outOfRangeColor; string heading = string.IsNullOrEmpty(usable.overrideName) ? usable.name : usable.overrideName; string useMessage = string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage; UnityGUITools.DrawText(screenRect, heading, guiStyle, TextStyle.Shadow); UnityGUITools.DrawText(new Rect(0, guiStyle.CalcSize(new GUIContent("Ay")).y, Screen.width, Screen.height), useMessage, guiStyle, TextStyle.Shadow); Texture2D reticleTexture = inUseRange ? reticle.inRange : reticle.outOfRange; if (reticleTexture != null) { GUI.Label(new Rect(0.5f * (Screen.width - reticle.width), 0.5f * (Screen.height - reticle.height), reticle.width, reticle.height), reticleTexture); } } } }
protected void DrawOnSelection(Usable usable, float distance, Selector.Reticle reticle, GUIStyle guiStyle, string defaultUseMessage, Color inRangeColor, Color outOfRangeColor, TextStyle textStyle, Color textStyleColor) { if (usable == null) { return; } if ((usable != lastUsable) || string.IsNullOrEmpty(heading)) { lastUsable = usable; heading = usable.GetName(); useMessage = string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage; } GameObject selection = usable.gameObject; if (selection != lastSelectionDrawn) { selectionHeight = Tools.GetGameObjectHeight(selection); selectionHeadingSize = guiStyle.CalcSize(new GUIContent(heading)); selectionUseMessageSize = guiStyle.CalcSize(new GUIContent(useMessage)); } // Set text color based on distance: bool inUseRange = (distance <= usable.maxUseDistance); guiStyle.normal.textColor = inUseRange ? inRangeColor : outOfRangeColor; // Draw heading: Vector3 screenPos = UnityEngine.Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * selectionHeight)); screenPos += offset; screenPos = new Vector3(screenPos.x, screenPos.y + selectionUseMessageSize.y + selectionHeadingSize.y, screenPos.z); if (screenPos.z < 0) { return; } Rect rect = new Rect(screenPos.x - (selectionHeadingSize.x / 2), (Screen.height - screenPos.y) - (selectionHeadingSize.y / 2), selectionHeadingSize.x, selectionHeadingSize.y); UnityGUITools.DrawText(rect, heading, guiStyle, textStyle, textStyleColor); // Draw use message: screenPos = UnityEngine.Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * (selectionHeight))); screenPos += offset; screenPos = new Vector3(screenPos.x, screenPos.y + selectionUseMessageSize.y, screenPos.z); rect = new Rect(screenPos.x - (selectionUseMessageSize.x / 2), (Screen.height - screenPos.y) - (selectionUseMessageSize.y / 2), selectionUseMessageSize.x, selectionUseMessageSize.y); UnityGUITools.DrawText(rect, useMessage, guiStyle, textStyle, textStyleColor); // Draw reticle: if (reticle != null) { Texture2D reticleTexture = inUseRange ? reticle.inRange : reticle.outOfRange; if (reticleTexture != null) { screenPos = UnityEngine.Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * 0.5f * selectionHeight)); rect = new Rect(screenPos.x - (reticle.width / 2), (Screen.height - screenPos.y) - (reticle.height / 2), reticle.width, reticle.height); GUI.Label(rect, reticleTexture); } } }
/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> public virtual void OnGUI() { if (useDefaultGUI) { SetGuiStyle(); Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (currentUsable != null) { UnityGUITools.DrawText(screenRect, currentHeading, guiStyle, textStyle, textStyleColor); UnityGUITools.DrawText(new Rect(0, guiStyle.CalcSize(new GUIContent("Ay")).y, Screen.width, Screen.height), currentUseMessage, guiStyle, textStyle, textStyleColor); } } }
/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> public virtual void OnGUI() { if (!useDefaultGUI) { return; } if (guiStyle == null && (Event.current.type == EventType.Repaint || currentUsable != null)) { SetGuiStyle(); } if (currentUsable != null) { GUI.skin = guiSkin; UnityGUITools.DrawText(new Rect(0, 0, Screen.width, Screen.height), currentHeading, guiStyle, textStyle, textStyleColor); UnityGUITools.DrawText(new Rect(0, guiStyleLineHeight, Screen.width, Screen.height), currentUseMessage, guiStyle, textStyle, textStyleColor); } }
/// <summary> /// If useDefaultGUI is <c>true</c> and a usable object has been targeted, this method /// draws a selection message and targeting reticle. /// </summary> void OnGUI() { if (useDefaultGUI) { GUI.skin = UnityGUITools.GetValidGUISkin(guiSkin); if (guiStyle == null) { guiStyle = new GUIStyle(GUI.skin.label); guiStyle.alignment = TextAnchor.UpperCenter; guiStyle.normal.textColor = color; } Rect screenRect = new Rect(0, 0, Screen.width, Screen.height); if (currentUsable != null) { string heading = string.IsNullOrEmpty(currentUsable.overrideName) ? currentUsable.name : currentUsable.overrideName; string useMessage = string.IsNullOrEmpty(currentUsable.overrideUseMessage) ? defaultUseMessage : currentUsable.overrideUseMessage; UnityGUITools.DrawText(screenRect, heading, guiStyle, TextStyle.Shadow); UnityGUITools.DrawText(new Rect(0, guiStyle.CalcSize(new GUIContent("Ay")).y, Screen.width, Screen.height), useMessage, guiStyle, TextStyle.Shadow); } } }