本文整理汇总了C#中UnityEngine.Rect.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Contains方法的具体用法?C# Rect.Contains怎么用?C# Rect.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rect
的用法示例。
在下文中一共展示了Rect.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixedUpdate
private void FixedUpdate()
{
transform.position = (playerOne.position + playerTwo.position) / 2f;
transform.position += transform.forward * -zoom;
var camera = GetComponent<Camera>();
var p1ScreenPos = camera.WorldToScreenPoint(playerOne.position);
var p2ScreenPos = camera.WorldToScreenPoint(playerTwo.position);
p1ScreenPos = camera.ScreenToViewportPoint(p1ScreenPos);
p2ScreenPos = camera.ScreenToViewportPoint(p2ScreenPos);
var zoomOutRect = new Rect(0.1f, 0.1f, 0.9f, 0.9f);
var zoomInRect = new Rect(0.2f, 0.2f, 0.8f, 0.8f);
if (!zoomOutRect.Contains(p1ScreenPos) || !zoomOutRect.Contains(p2ScreenPos))
{
if(zoom < maxZoom)
zoom += zoomFactor;
}
if (zoomInRect.Contains(p1ScreenPos) && zoomInRect.Contains(p2ScreenPos))
{
if (zoom > minZoom)
zoom -= zoomFactor;
}
}
示例2: SetActiveToolTip
internal static string SetActiveToolTip(Rect control, string toolTip, ref bool toolTipActive, float xOffset)
{
// Note: all values are screen point based. (0,0 in lower left). this removes confusion with the gui point of elements (o,o in upper left).
if (!toolTipActive && control.Contains(Event.current.mousePosition))
{
toolTipActive = true;
// Note at this time controlPosition is in Gui Point system and is local position. convert to screenpoint.
Rect newControl = new Rect
{
position = GUIUtility.GUIToScreenPoint(control.position),
width = control.width,
height = control.height
};
// Event.current.mousePosition returns sceen mouseposition. GuI elements return a value in gui position..
// Add the height of parent GUI elements already drawn to y offset to get the correct screen position
if (control.Contains(Event.current.mousePosition))
{
// Let's use the rectangle as a solid anchor and a stable tooltip, forgiving of mouse movement within bounding box...
ToolTipPos = new Vector2(newControl.xMax + xOffset, newControl.y - 10);
ControlRect = newControl;
XOffset = xOffset;
ControlRect.x += xOffset;
ControlRect.y -= 10;
}
else
toolTip = "";
}
// We are in a loop so we don't need the return value from SetUpToolTip. We will assign it instead.
if (!toolTipActive)
toolTip = "";
return toolTip;
}
示例3: DoRepeatButton
private static bool DoRepeatButton(Rect position, GUIContent content, GUIStyle style, FocusType focusType)
{
int controlID = GUIUtility.GetControlID(EditorGUIExt.repeatButtonHash, focusType, position);
EventType typeForControl = Event.current.GetTypeForControl(controlID);
if (typeForControl == EventType.MouseDown)
{
if (position.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = controlID;
Event.current.Use();
}
return false;
}
if (typeForControl != EventType.MouseUp)
{
if (typeForControl != EventType.Repaint)
{
return false;
}
style.Draw(position, content, controlID);
return controlID == GUIUtility.hotControl && position.Contains(Event.current.mousePosition);
}
else
{
if (GUIUtility.hotControl == controlID)
{
GUIUtility.hotControl = 0;
Event.current.Use();
return position.Contains(Event.current.mousePosition);
}
return false;
}
}
示例4: SetActiveTooltip
internal static string SetActiveTooltip(Rect controlRect, Rect WindowPosition, string toolTip, ref bool toolTipActive, float xOffset, float yOffset)
{
if (!toolTipActive && controlRect.Contains(Event.current.mousePosition))
{
toolTipActive = true;
// Since we are using GUILayout, the curent mouse position returns a position with reference to the parent.
// Add the height of parent GUI elements already drawn to y offset to get the correct screen position
if (controlRect.Contains(Event.current.mousePosition))
{
// Let's use the rectangle as a solid anchor and a stable tooltip, forgiving of mouse movement within bounding box...
ControlPos = new Vector2(controlRect.xMax, controlRect.y);
ControlPos.x = ControlPos.x + WindowPosition.x + xOffset;
ControlPos.y = ControlPos.y + WindowPosition.y + yOffset;
ControlRect = controlRect;
X_Offset = xOffset;
ControlRect.x += WindowPosition.x + xOffset;
ControlRect.y += WindowPosition.y + yOffset;
//Utilities.LogMessage(string.Format("Setup Tooltip - Mouse inside Rect: \r\nRectangle data: {0} \r\nWindowPosition: {1}\r\nToolTip: {2}\r\nToolTip Pos: {3}", rect.ToString(), WindowPosition.ToString(), ToolTip, ShipManifestAddon.ToolTipPos.ToString()), "Info", true);
}
else
toolTip = "";
}
// We are in a loop so we don't need the return value from SetUpToolTip. We will assign it instead.
if (!toolTipActive)
toolTip = "";
return toolTip;
}
示例5: DoRepeatButton
private static bool DoRepeatButton(Rect position, GUIContent content, GUIStyle style, FocusType focusType)
{
int controlId = GUIUtility.GetControlID(EditorGUIExt.repeatButtonHash, focusType, position);
switch (Event.current.GetTypeForControl(controlId))
{
case EventType.MouseDown:
if (position.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = controlId;
Event.current.Use();
}
return false;
case EventType.MouseUp:
if (GUIUtility.hotControl != controlId)
return false;
GUIUtility.hotControl = 0;
Event.current.Use();
return position.Contains(Event.current.mousePosition);
case EventType.Repaint:
style.Draw(position, content, controlId);
if (controlId == GUIUtility.hotControl)
return position.Contains(Event.current.mousePosition);
return false;
default:
return false;
}
}
示例6: DropAreaGUI
private void DropAreaGUI(Rect dropArea)
{
var evt = Event.current;
if (evt.type == EventType.DragUpdated)
{
if (dropArea.Contains(evt.mousePosition))
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
}
}
if (evt.type == EventType.DragPerform)
{
if (dropArea.Contains(evt.mousePosition))
{
DragAndDrop.AcceptDrag();
bool changed = false;
UnityEngine.Object[] draggedObjects = DragAndDrop.objectReferences;
for (int i = 0; i < draggedObjects.Length; i++)
{
if (draggedObjects[i])
{
var go = draggedObjects[i] as GameObject;
if (go != null)
{
AddAnimatedBone(go.name);
}
}
}
AssetDatabase.SaveAssets();
}
}
}
示例7: OnMapUpdated
private void OnMapUpdated()
{
Vector2 tl = OnlineMaps.instance.topLeftPosition;
Vector2 br = OnlineMaps.instance.bottomRightPosition;
Rect rect = new Rect(tl.x, br.y, br.x - tl.x, tl.y - br.y);
if (rect.width < 0) rect.width += 360;
foreach (NGUICustomMarkerExample marker in markers)
{
Vector2 p = marker.position;
GameObject go = marker.gameObject;
if (!rect.Contains(p))
{
p.x += 360;
if (!rect.Contains(p))
{
if (go.activeSelf) go.SetActive(false);
continue;
}
}
if (!go.activeSelf) go.SetActive(true);
Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(p);
screenPosition.x -= Screen.width / 2;
screenPosition.y -= Screen.height / 2;
Vector2 buttonOffset = new Vector2(-marker.size.x / 2, 0);
marker.widget.SetRect(screenPosition.x + buttonOffset.x, screenPosition.y + buttonOffset.y, marker.size.x, marker.size.y);
}
}
示例8: IsCursorOnUI
//check for all UI screen space, see if user cursor is within any of them, return true if yes
//this is to prevent user from being able to interact with in game object even when clicking on UI panel and buttons
public bool IsCursorOnUI(Vector3 point)
{
Rect tempRect=new Rect(0, 0, 0, 0);
tempRect=topPanelRect;
tempRect.y=Screen.height-tempRect.y-tempRect.height;
if(tempRect.Contains(point)) return true;
tempRect=bottomPanelRect;
tempRect.y=Screen.height-tempRect.y-tempRect.height;
if(tempRect.Contains(point)) return true;
tempRect=buildListRect;
tempRect.y=Screen.height-tempRect.y-tempRect.height;
if(tempRect.Contains(point)) return true;
tempRect=towerUIRect;
tempRect.y=Screen.height-tempRect.y-tempRect.height;
if(tempRect.Contains(point)) return true;
for(int i=0; i<scatteredRectList.Length; i++){
tempRect=scatteredRectList[i];
tempRect.y=Screen.height-tempRect.y-tempRect.height;
if(tempRect.Contains(point)) return true;
}
return false;
}
示例9: Update
// Update is called once per frame
void Update()
{
weapon_beam.transform.position = player.transform.position;
if (player.facingRight)
weapon_beam.transform.position = new Vector3(player.transform.position.x + 4,
player.transform.position.y,
player.transform.position.z);
else
weapon_beam.transform.position = new Vector3(player.transform.position.x - 4,
player.transform.position.y,
player.transform.position.z);
// Shooter on MouseDown
Rect bounds = new Rect(Screen.width - Screen.width/4, 0, Screen.width, Screen.height/4);
if (Application.platform == RuntimePlatform.WindowsEditor) {
if (Input.GetMouseButtonDown (1) && player.weapon_beam) {
UsePowerUp ();
}
}
else {
if ((Input.GetMouseButtonDown (0) || Input.GetMouseButtonDown (1))
&& (bounds.Contains (Input.GetTouch(0).position) || bounds.Contains(Input.GetTouch(1).position))
&& player.weapon_beam) {
UsePowerUp ();
}
}
}
示例10: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Texture browseIcon = EditorGUIUtility.Load("FMOD/SearchIconBlack.png") as Texture;
SerializedProperty pathProperty = property;
EditorGUI.BeginProperty(position, label, property);
Event e = Event.current;
if (e.type == EventType.dragPerform && position.Contains(e.mousePosition))
{
if (DragAndDrop.objectReferences.Length > 0 &&
DragAndDrop.objectReferences[0] != null &&
DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef))
{
pathProperty.stringValue = ((EditorBankRef)DragAndDrop.objectReferences[0]).Name;
e.Use();
}
}
if (e.type == EventType.DragUpdated && position.Contains(e.mousePosition))
{
if (DragAndDrop.objectReferences.Length > 0 &&
DragAndDrop.objectReferences[0] != null &&
DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef))
{
DragAndDrop.visualMode = DragAndDropVisualMode.Move;
DragAndDrop.AcceptDrag();
e.Use();
}
}
float baseHeight = GUI.skin.textField.CalcSize(new GUIContent()).y;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
var buttonStyle = new GUIStyle(GUI.skin.button);
buttonStyle.padding.top = buttonStyle.padding.bottom = 1;
Rect searchRect = new Rect(position.x + position.width - browseIcon.width - 15, position.y, browseIcon.width + 10, baseHeight);
Rect pathRect = new Rect(position.x, position.y, searchRect.x - position.x - 5, baseHeight);
EditorGUI.PropertyField(pathRect, pathProperty, GUIContent.none);
if (GUI.Button(searchRect, new GUIContent(browseIcon, "Select FMOD Bank"), buttonStyle))
{
var browser = EventBrowser.CreateInstance<EventBrowser>();
#if UNITY_4_6
browser.title = "Select FMOD Bank";
#else
browser.titleContent = new GUIContent("Select FMOD Bank");
#endif
browser.SelectBank(property);
browser.ShowUtility();
}
EditorGUI.EndProperty();
}
示例11: ReorderableList
public static void ReorderableList(IList list, System.Action<int> GUICallback, UnityObject unityObject = null)
{
if (list.Count == 1){
GUICallback(0);
return;
}
if (!pickedObjectList.ContainsKey(list))
pickedObjectList[list] = null;
var e = Event.current;
var lastRect = new Rect();
var picked = pickedObjectList[list];
GUILayout.BeginVertical();
for (var i= 0; i < list.Count; i++){
GUILayout.BeginVertical();
GUICallback(i);
GUILayout.EndVertical();
GUI.color = Color.white;
GUI.backgroundColor = Color.white;
lastRect = GUILayoutUtility.GetLastRect();
EditorGUIUtility.AddCursorRect(lastRect, MouseCursor.MoveArrow);
if (picked != null && picked == list[i])
GUI.Box(lastRect, "");
if (picked != null && lastRect.Contains(e.mousePosition) && picked != list[i]){
var markRect = new Rect(lastRect.x,lastRect.y-2,lastRect.width, 2);
if (list.IndexOf(picked) < i)
markRect.y = lastRect.yMax - 2;
GUI.Box(markRect, "");
if (e.type == EventType.MouseUp){
if (unityObject != null)
Undo.RecordObject(unityObject, "Reorder");
list.Remove(picked);
list.Insert(i, picked);
pickedObjectList[list] = null;
if (unityObject != null)
EditorUtility.SetDirty(unityObject);
}
}
if (lastRect.Contains(e.mousePosition) && e.type == EventType.MouseDown)
pickedObjectList[list] = list[i];
}
GUILayout.EndVertical();
if (e.type == EventType.MouseUp)
pickedObjectList[list] = null;
}
示例12: Draw
public void Draw(Rect r, tk2dSpriteDefinition sprite)
{
Init();
Event ev = Event.current;
switch (ev.type)
{
case EventType.MouseDown:
if (r.Contains(ev.mousePosition))
{
dragging = true;
ev.Use();
}
break;
case EventType.MouseDrag:
if (dragging && r.Contains(ev.mousePosition))
{
translate += ev.delta;
ev.Use();
Repaint();
}
break;
case EventType.MouseUp:
dragging = false;
break;
case EventType.ScrollWheel:
if (r.Contains(ev.mousePosition))
{
scale = Mathf.Clamp(scale + ev.delta.y * 0.1f, 0.1f, 10.0f);
ev.Use();
Repaint();
}
break;
}
tk2dGrid.Draw(r, translate);
// Draw axis
Vector2 axisPos = new Vector2(r.center.x + translate.x, r.center.y + translate.y);
if (axisPos.y > r.yMin && axisPos.y < r.yMax) {
Handles.color = new Color(1, 0, 0, 0.5f);
Handles.DrawLine(new Vector2(r.x, r.center.y + translate.y), new Vector2(r.x + r.width, r.center.y + translate.y));
}
if (axisPos.x > r.xMin && axisPos.x < r.xMax) {
Handles.color = new Color(0, 1, 0, 0.5f);
Handles.DrawLine(new Vector2(r.center.x + translate.x, r.y), new Vector2(r.center.x + translate.x, r.y + r.height));
}
Handles.color = Color.white;
// Draw sprite
if (sprite != null)
{
tk2dSpriteThumbnailCache.DrawSpriteTextureCentered(r, sprite, translate, scale, Color.white);
}
}
示例13: checkClick
protected bool checkClick(Rect rect)
{
Vector2 rightHand = kinectController.getRightHand();
rightHand.x *= screenWidth;
rightHand.y = 1 - rightHand.y;
rightHand.y *= screenHeight;
Vector2 leftHand = kinectController.getLeftHand();
leftHand.x *= screenWidth;
leftHand.y = 1 - leftHand.y;
leftHand.y *= screenHeight;
return rect.Contains(rightHand)||rect.Contains(leftHand);
}
示例14: handleDragInteraction
private void handleDragInteraction(Rect position, AudioTrack track, Vector2 translation, Vector2 scale)
{
Rect controlBackground = new Rect(0, 0, position.width, position.height);
switch (Event.current.type)
{
case EventType.DragUpdated:
if (controlBackground.Contains(Event.current.mousePosition))
{
bool audioFound = false;
foreach (Object objectReference in DragAndDrop.objectReferences)
{
AudioClip clip = objectReference as AudioClip;
if (clip != null)
{
audioFound = true;
break;
}
}
if (audioFound)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Link;
Event.current.Use();
}
}
break;
case EventType.DragPerform:
if (controlBackground.Contains(Event.current.mousePosition))
{
AudioClip clip = null;
foreach (Object objectReference in DragAndDrop.objectReferences)
{
AudioClip audioClip = objectReference as AudioClip;
if (audioClip != null)
{
clip = audioClip;
break;
}
}
if (clip != null)
{
float fireTime = (Event.current.mousePosition.x - translation.x) / scale.x;
CinemaAudio ca = CutsceneItemFactory.CreateCinemaAudio(track, clip, fireTime);
Undo.RegisterCreatedObjectUndo(ca, string.Format("Created {0}", ca.name));
Event.current.Use();
}
}
break;
}
}
示例15: OnRowGUI
public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool selected, bool focused)
{
Event current = Event.current;
this.DoNodeGUI(rowRect, row, node, selected, focused, false);
if ((UnityEngine.Object) this.m_Controller == (UnityEngine.Object) null)
return;
AudioMixerTreeViewNode audioNode = node as AudioMixerTreeViewNode;
if (audioNode == null)
return;
bool visible = this.m_Controller.CurrentViewContainsGroup(audioNode.group.groupID);
float num = 3f;
Rect position = new Rect(rowRect.x + num, rowRect.y, 16f, 16f);
Rect rect1 = new Rect(position.x + 1f, position.y + 1f, position.width - 2f, position.height - 2f);
int userColorIndex = audioNode.group.userColorIndex;
if (userColorIndex > 0)
EditorGUI.DrawRect(new Rect(rowRect.x, rect1.y, 2f, rect1.height), AudioMixerColorCodes.GetColor(userColorIndex));
EditorGUI.DrawRect(rect1, new Color(0.5f, 0.5f, 0.5f, 0.2f));
if (visible)
GUI.DrawTexture(position, (Texture) this.k_VisibleON);
Rect rect2 = new Rect(2f, rowRect.y, rowRect.height, rowRect.height);
if (current.type == EventType.MouseUp && current.button == 0 && (rect2.Contains(current.mousePosition) && this.NodeWasToggled != null))
this.NodeWasToggled(audioNode, !visible);
if (current.type != EventType.ContextClick || !position.Contains(current.mousePosition))
return;
this.OpenGroupContextMenu(audioNode, visible);
current.Use();
}