Merged in develop (pull request #3)
Updated with patches to AimerInputModule and ToolTip, plus editor updatepull/413/head
commit
f2669b546e
|
@ -1,92 +1,167 @@
|
||||||
/// Credit Chris Trueman
|
/// Credit Chris Trueman
|
||||||
/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/
|
/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace UnityEngine.EventSystems.Extensions
|
namespace UnityEngine.EventSystems.Extensions
|
||||||
{
|
{
|
||||||
|
|
||||||
[RequireComponent(typeof(EventSystem))]
|
[RequireComponent(typeof(EventSystem))]
|
||||||
[AddComponentMenu("UI/Extensions/Aimer Input Module")]
|
[AddComponentMenu("UI/Extensions/Aimer Input Module")]
|
||||||
public class AimerInputModule : BaseInputModule
|
public class AimerInputModule : PointerInputModule
|
||||||
{
|
{
|
||||||
public string ActivateAxis = "Interact";
|
/// <summary>
|
||||||
|
/// The Input axis name used to activate the object under the reticle.
|
||||||
|
/// </summary>
|
||||||
|
public string activateAxis = "Interact";
|
||||||
|
|
||||||
public static GameObject ObjectUnderAimer;
|
/// <summary>
|
||||||
|
/// The aimer offset position. Aimer is center screen use this offset to change that.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2 aimerOffset = new Vector2(0, 0);
|
||||||
|
|
||||||
public static Camera CurrentPlayerCamera;
|
/// <summary>
|
||||||
|
/// The object under aimer. A static access field that lets you know what is under the aimer.
|
||||||
|
/// This field can return null.
|
||||||
|
/// </summary>
|
||||||
|
public static GameObject objectUnderAimer;
|
||||||
|
|
||||||
protected AimerInputModule() { }
|
protected AimerInputModule() { }
|
||||||
|
|
||||||
public void Awake()
|
public override void ActivateModule()
|
||||||
{
|
{
|
||||||
var StandAloneSystem = GetComponent<StandaloneInputModule>();
|
StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
|
||||||
if (StandAloneSystem != null)
|
|
||||||
{
|
|
||||||
Debug.LogError("Aimer Input Module is incompatible with the StandAloneInputSystem, please remove it from the Event System in this scene");
|
|
||||||
}
|
|
||||||
if (!CurrentPlayerCamera)
|
|
||||||
{
|
|
||||||
CurrentPlayerCamera = Camera.main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void UpdateModule()
|
if (StandAloneSystem != null && StandAloneSystem.enabled)
|
||||||
{
|
{
|
||||||
GetObjectUnderAimer();
|
Debug.LogError("Aimer Input Module is incompatible with the StandAloneInputSystem, " +
|
||||||
|
"please remove it from the Event System in this scene or disable it when this module is in use");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Process()
|
public override void Process()
|
||||||
{
|
{
|
||||||
if (ObjectUnderAimer)
|
bool pressed = Input.GetButtonDown(activateAxis);
|
||||||
|
bool released = Input.GetButtonUp(activateAxis);
|
||||||
|
|
||||||
|
PointerEventData pointer = GetAimerPointerEventData();
|
||||||
|
|
||||||
|
ProcessInteraction(pointer, pressed, released);
|
||||||
|
|
||||||
|
if (!released)
|
||||||
|
ProcessMove(pointer);
|
||||||
|
else
|
||||||
|
RemovePointerData(pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual PointerEventData GetAimerPointerEventData()
|
||||||
{
|
{
|
||||||
if (Input.GetButtonDown(ActivateAxis))
|
PointerEventData pointerData;
|
||||||
|
|
||||||
|
//Not certain on the use of this.
|
||||||
|
//I know that -1 is the mouse and anything positive would be a finger/touch, 0 being the first finger, 1 beign the second and so one till the system limit is reached.
|
||||||
|
//So that is the reason I choose -2.
|
||||||
|
GetPointerData(-2, out pointerData, true);
|
||||||
|
|
||||||
|
pointerData.Reset();
|
||||||
|
|
||||||
|
pointerData.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f) + aimerOffset;
|
||||||
|
|
||||||
|
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
|
||||||
|
var raycast = FindFirstRaycast(m_RaycastResultCache);
|
||||||
|
pointerData.pointerCurrentRaycast = raycast;
|
||||||
|
m_RaycastResultCache.Clear();
|
||||||
|
return pointerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessInteraction(PointerEventData pointer, bool pressed, bool released)
|
||||||
{
|
{
|
||||||
BaseEventData eventData = GetBaseEventData();
|
var currentOverGo = pointer.pointerCurrentRaycast.gameObject;
|
||||||
eventData.selectedObject = ObjectUnderAimer;
|
|
||||||
ExecuteEvents.Execute(ObjectUnderAimer, eventData, ExecuteEvents.submitHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<RaycastResult> results = new List<RaycastResult>();
|
objectUnderAimer = ExecuteEvents.GetEventHandler<ISubmitHandler>(currentOverGo);//we only want objects that we can submit on.
|
||||||
|
|
||||||
private bool GetObjectUnderAimer()
|
if (pressed)
|
||||||
{
|
{
|
||||||
PointerEventData pointerData = new PointerEventData(eventSystem);
|
pointer.eligibleForClick = true;
|
||||||
pointerData.worldPosition = CurrentPlayerCamera.transform.position;
|
pointer.delta = Vector2.zero;
|
||||||
|
pointer.pressPosition = pointer.position;
|
||||||
|
pointer.pointerPressRaycast = pointer.pointerCurrentRaycast;
|
||||||
|
|
||||||
eventSystem.RaycastAll(pointerData, results);
|
// search for the control that will receive the press
|
||||||
|
// if we can't find a press handler set the press
|
||||||
|
// handler to be what would receive a click.
|
||||||
|
var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.submitHandler);
|
||||||
|
|
||||||
if (results.Count > 0)
|
// didnt find a press handler... search for a click handler
|
||||||
|
if (newPressed == null)
|
||||||
{
|
{
|
||||||
RaycastResult rayResult = FindFirstRaycast(results);
|
newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.pointerDownHandler);
|
||||||
if (ObjectUnderAimer != rayResult.gameObject)
|
if (newPressed == null)
|
||||||
|
newPressed = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Debug.Log(rayResult.gameObject.name);
|
pointer.eligibleForClick = false;
|
||||||
ObjectUnderAimer = rayResult.gameObject;
|
|
||||||
BaseEventData eData = GetBaseEventData();
|
|
||||||
eData.selectedObject = ObjectUnderAimer;
|
|
||||||
ExecuteEvents.Execute(ObjectUnderAimer, eData, ExecuteEvents.pointerEnterHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results.Clear();
|
if (newPressed != pointer.pointerPress)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//We didn't hit anything
|
|
||||||
|
|
||||||
if (ObjectUnderAimer)
|
|
||||||
{
|
{
|
||||||
BaseEventData eData = GetBaseEventData();
|
pointer.pointerPress = newPressed;
|
||||||
eData.selectedObject = ObjectUnderAimer;
|
pointer.rawPointerPress = currentOverGo;
|
||||||
|
pointer.clickCount = 0;
|
||||||
ExecuteEvents.Execute(ObjectUnderAimer, eData, ExecuteEvents.pointerExitHandler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results.Clear();
|
// Save the drag handler as well
|
||||||
ObjectUnderAimer = null;
|
pointer.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo);
|
||||||
return false;
|
|
||||||
|
if (pointer.pointerDrag != null)
|
||||||
|
ExecuteEvents.Execute<IBeginDragHandler>(pointer.pointerDrag, pointer, ExecuteEvents.beginDragHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (released)
|
||||||
|
{
|
||||||
|
//Debug.Log("Executing pressup on: " + pointer.pointerPress);
|
||||||
|
ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerUpHandler);
|
||||||
|
|
||||||
|
//Debug.Log("KeyCode: " + pointer.eventData.keyCode);
|
||||||
|
|
||||||
|
// see if we mouse up on the same element that we clicked on...
|
||||||
|
var pointerUpHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
|
||||||
|
|
||||||
|
// PointerClick
|
||||||
|
if (pointer.pointerPress == pointerUpHandler && pointer.eligibleForClick)
|
||||||
|
{
|
||||||
|
float time = Time.unscaledTime;
|
||||||
|
|
||||||
|
if (time - pointer.clickTime < 0.3f)
|
||||||
|
++pointer.clickCount;
|
||||||
|
else
|
||||||
|
pointer.clickCount = 1;
|
||||||
|
pointer.clickTime = time;
|
||||||
|
|
||||||
|
ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerClickHandler);
|
||||||
|
}
|
||||||
|
else if (pointer.pointerDrag != null)
|
||||||
|
{
|
||||||
|
ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.dropHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer.eligibleForClick = false;
|
||||||
|
pointer.pointerPress = null;
|
||||||
|
pointer.rawPointerPress = null;
|
||||||
|
|
||||||
|
if (pointer.pointerDrag != null)
|
||||||
|
ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.endDragHandler);
|
||||||
|
|
||||||
|
pointer.pointerDrag = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeactivateModule()
|
||||||
|
{
|
||||||
|
base.DeactivateModule();
|
||||||
|
ClearSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
///Credit Martin Sharkbomb
|
///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com
|
||||||
///Sourced from - http://forum.unity3d.com/threads/tooltips.264395/#post-1957075
|
///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
///Credit Martin Sharkbomb
|
///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com
|
||||||
///Sourced from - http://forum.unity3d.com/threads/tooltips.264395/#post-1957075
|
///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/
|
||||||
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace UnityEditor.UI
|
||||||
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
|
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
|
||||||
|
|
||||||
private static Vector2 s_ThickGUIElementSize = new Vector2(kWidth, kThickHeight);
|
private static Vector2 s_ThickGUIElementSize = new Vector2(kWidth, kThickHeight);
|
||||||
//private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight);
|
private static Vector2 s_ThinGUIElementSize = new Vector2(kWidth, kThinHeight);
|
||||||
private static Vector2 s_ImageGUIElementSize = new Vector2(100f, 100f);
|
private static Vector2 s_ImageGUIElementSize = new Vector2(100f, 100f);
|
||||||
private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
|
private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f);
|
||||||
private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);
|
private static Color s_TextColor = new Color(50f / 255f, 50f / 255f, 50f / 255f, 1f);
|
||||||
|
@ -137,7 +137,6 @@ namespace UnityEditor.UI
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("GameObject/UI/EventSystem", false, 2010)]
|
|
||||||
public static void CreateEventSystem(MenuCommand menuCommand)
|
public static void CreateEventSystem(MenuCommand menuCommand)
|
||||||
{
|
{
|
||||||
GameObject parent = menuCommand.context as GameObject;
|
GameObject parent = menuCommand.context as GameObject;
|
||||||
|
@ -747,6 +746,52 @@ namespace UnityEditor.UI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MenuItem("GameObject/UI/Extensions/Progress Bar", false)]
|
||||||
|
static public void AddSlider(MenuCommand menuCommand)
|
||||||
|
{
|
||||||
|
// Create GOs Hierarchy
|
||||||
|
GameObject root = CreateUIElementRoot("Progress Bar", menuCommand, s_ThinGUIElementSize);
|
||||||
|
|
||||||
|
GameObject background = CreateUIObject("Background", root);
|
||||||
|
GameObject fillArea = CreateUIObject("Fill Area", root);
|
||||||
|
GameObject fill = CreateUIObject("Fill", fillArea);
|
||||||
|
|
||||||
|
// Background
|
||||||
|
Image backgroundImage = background.AddComponent<Image>();
|
||||||
|
backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpriteResourcePath);
|
||||||
|
backgroundImage.type = Image.Type.Sliced;
|
||||||
|
backgroundImage.color = s_DefaultSelectableColor;
|
||||||
|
RectTransform backgroundRect = background.GetComponent<RectTransform>();
|
||||||
|
backgroundRect.anchorMin = new Vector2(0, 0.25f);
|
||||||
|
backgroundRect.anchorMax = new Vector2(1, 0.75f);
|
||||||
|
backgroundRect.sizeDelta = new Vector2(0, 0);
|
||||||
|
|
||||||
|
// Fill Area
|
||||||
|
RectTransform fillAreaRect = fillArea.GetComponent<RectTransform>();
|
||||||
|
fillAreaRect.anchorMin = new Vector2(0, 0.25f);
|
||||||
|
fillAreaRect.anchorMax = new Vector2(1, 0.75f);
|
||||||
|
fillAreaRect.anchoredPosition = Vector2.zero;
|
||||||
|
fillAreaRect.sizeDelta = Vector2.zero;
|
||||||
|
|
||||||
|
// Fill
|
||||||
|
Image fillImage = fill.AddComponent<Image>();
|
||||||
|
fillImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
|
||||||
|
fillImage.type = Image.Type.Sliced;
|
||||||
|
fillImage.color = s_DefaultSelectableColor;
|
||||||
|
|
||||||
|
RectTransform fillRect = fill.GetComponent<RectTransform>();
|
||||||
|
fillRect.sizeDelta = Vector2.zero;
|
||||||
|
|
||||||
|
// Setup slider component
|
||||||
|
Slider slider = root.AddComponent<Slider>();
|
||||||
|
slider.value = 0;
|
||||||
|
slider.fillRect = fill.GetComponent<RectTransform>();
|
||||||
|
slider.targetGraphic = fillImage;
|
||||||
|
slider.direction = Slider.Direction.LeftToRight;
|
||||||
|
SetDefaultColorTransitionValues(slider);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helper Functions
|
#region Helper Functions
|
||||||
|
|
Loading…
Reference in New Issue