Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
    //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;
    }
Ejemplo n.º 3
0
        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();
                }
            }
        }
Ejemplo n.º 4
0
    // 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 ();
			}
		}
    }
        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;
            }
        }
        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);
            }
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
		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;
			}
		}
Ejemplo n.º 9
0
 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;
   }
 }
Ejemplo n.º 10
0
        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();
        }
        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;
        }
	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);
		}
	}
Ejemplo n.º 13
0
    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);
    }
 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;
     }
 }
Ejemplo n.º 15
0
        private void HandleWindowEvents(Rect resizeRect)
        {
            var theEvent = Event.current;
            if (theEvent != null)
            {
                if (!mouseDown)
                {
                    if (theEvent.type == EventType.MouseDown && theEvent.button == 0 && resizeRect.Contains(theEvent.mousePosition))
                    {
                        mouseDown = true;
                        theEvent.Use();
                    }
                }
                else if (theEvent.type != EventType.Layout)
                {
                    if (Input.GetMouseButton(0))
                    {
                        // Flip the mouse Y so that 0 is at the top
                        float mouseY = Screen.height - Input.mousePosition.y;

                        WindowRect.width = Mathf.Clamp(Input.mousePosition.x - WindowRect.x + (resizeRect.width / 2), 50, Screen.width - WindowRect.x);
                        WindowRect.height = Mathf.Clamp(mouseY - WindowRect.y + (resizeRect.height / 2), 50, Screen.height - WindowRect.y);
                    }
                    else
                    {
                        mouseDown = false;
                    }
                }
            }
        }
Ejemplo n.º 16
0
	public static bool isInScreenRect(Rect rect, Vector2 point) {
		point.y = Screen.height - point.y;
		if(rect.Contains(point)) {
			return true;
		}
		return false;
	}
Ejemplo n.º 17
0
    void CharWindow(int id)
    {
        // window buffer values
        float leftBuffer = 50; // should be same as rightBuffer ...and bottomBuffer?
        float topBuffer = 100;

        // Select Character Button
        float width = (id == 0) ? maleWinRect.width : femaleWinRect.width;
        width -= 2 * leftBuffer;
        float height = GUI.skin.button.CalcHeight(new GUIContent("Male"), width); // doesn't matter, just need some string

        Rect tempRect = new Rect(leftBuffer, topBuffer, width, height);
        if (GUI.Button(tempRect, (id == 0) ? "Male" : "Female"))
        {
            PlayerPrefs.SetInt("Gender", id);
            Application.LoadLevel("Intro");
        }

        // Player Icon
        tempRect = new Rect(leftBuffer, topBuffer + height, width, width);
        GUI.skin.box.alignment = TextAnchor.MiddleCenter;
        GUI.Box(tempRect, (id == 0) ? MaleIcon : FemaleIcon);

        // left click on icon instead of button
        Vector2 pt = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); // pixel to screen space
        tempRect.x += (id == 0) ? maleWinRect.x : femaleWinRect.x;
        tempRect.y += (id == 0) ? maleWinRect.y : femaleWinRect.y;
        if (Input.GetMouseButtonDown(0) && tempRect.Contains(pt))
        {
            PlayerPrefs.SetInt("Gender", id);
            Application.LoadLevel("Intro");
        }
    }
Ejemplo n.º 18
0
    public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent,
	                         GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle)
    {
        int controlID = GUIUtility.GetControlID (popupListHash, FocusType.Passive);
                bool done = false;
                switch (Event.current.GetTypeForControl (controlID)) {
                case EventType.mouseDown:
                        if (position.Contains (Event.current.mousePosition)) {
                                GUIUtility.hotControl = controlID;
                                showList = true;
                        }
                        break;
                case EventType.mouseUp:
                        if (showList) {
                                done = true;
                        }
                        break;
                }

                GUI.Label (position, buttonContent, buttonStyle);
                if (showList) {
                        Rect listRect = new Rect (position.x, position.y, position.width, listStyle.CalcHeight (listContent [0], 1.0f) * listContent.Length);
                        GUI.Box (listRect, "", boxStyle);
                        listEntry = GUI.SelectionGrid (listRect, listEntry, listContent, 1, listStyle);
                }
                if (done) {
                        showList = false;
                }
                return done;
    }
Ejemplo n.º 19
0
    Camera cam; //The camera component of the minimap

    #endregion Fields

    #region Methods

    void OnGUI()
    {
        Event curEvent = Event.current;

        //Calculate the size and positon of the frame around the minimap
        Rect frameRect = new Rect(cam.pixelRect.x, Screen.height - cam.pixelRect.y - cam.pixelRect.height, cam.pixelRect.width, cam.pixelRect.height);
        GUI.DrawTexture(frameRect, minimapFrame);
        GUILayout.BeginArea(frameRect);
        //Calculate the size and positon of the frame around the plus button
        Rect plus = new Rect(frameRect.width * 0.825f, frameRect.height * 0.65f, frameRect.width * 0.15f, frameRect.width * 0.15f);
        //Calculate the size and positon of the frame around the minus button
        Rect minus = new Rect(frameRect.width * 0.675f, frameRect.height * 0.825f, frameRect.width * 0.15f, frameRect.width * 0.15f);
        GUI.DrawTexture(plus, plusButton);
        GUI.DrawTexture(minus, minusButton);

        //If we press the minus button zoom out
        if(plus.Contains(curEvent.mousePosition) && curEvent.type == EventType.MouseUp && curEvent.button == 0 && cam.orthographicSize > minSize) {
            cam.orthographicSize -= 2;
        }
        //If we press the plus button zoom in
        else if(minus.Contains(curEvent.mousePosition) && curEvent.type == EventType.MouseUp && curEvent.button == 0 && cam.orthographicSize < maxSize) {
            cam.orthographicSize += 2;
        }
        GUILayout.EndArea();
    }
Ejemplo n.º 20
0
    void OnGUI()
    {
        if (gui)
        {
            GUI.skin = skin;
            // get 3d position on screen
            Vector3 v = Camera.main.WorldToScreenPoint(transform.position);

            // convert to gui coordinates
            v = new Vector2(v.x, Screen.height - v.y);

            // creation menu for tower
            int width = 200;
            int height = 40;
            Rect r = new Rect(v.x - width / 2, v.y - height / 2, width, height);
            GUI.contentColor = (Player.gold >= turretPrefab.buildPrice ? Color.green : Color.red);
            GUI.Box(r, "Build " + turretPrefab.name + "(" + turretPrefab.buildPrice + " gold)");

            // mouse not down anymore and mouse over the box? then build the tower
            if (Event.current.type == EventType.MouseUp &&
                r.Contains(Event.current.mousePosition) &&
                Player.gold >= turretPrefab.buildPrice)
            {
                // decrease gold
                Player.gold -= turretPrefab.buildPrice;

                // instantiate
                Instantiate(turretPrefab, transform.position + offset, transform.rotation);

                // disable gameobject
             //   gameObject.SetActive(false);
            }
        }
    }
Ejemplo n.º 21
0
	private void ResizeMenuHorizontal(){
		Rect rect = new Rect (listRect.width - 5, listRect.y, 10, listRect.height);
		EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeHorizontal);
		int controlID = GUIUtility.GetControlID(FocusType.Passive);
		Event ev = Event.current;
		switch (ev.rawType) {
		case EventType.MouseDown:
			if(rect.Contains(ev.mousePosition)){
				GUIUtility.hotControl = controlID;
				ev.Use();
			}
			break;
		case EventType.MouseUp:
			if (GUIUtility.hotControl == controlID)
			{
				GUIUtility.hotControl = 0;
				ev.Use();
			}
			break;
		case EventType.MouseDrag:
			if (GUIUtility.hotControl == controlID)
			{
				listRect.width=ev.mousePosition.x;
				listRect.width=Mathf.Clamp(listRect.width,200,400);
				ev.Use();
			}
			break;
		}
	}
Ejemplo n.º 22
0
    private Rect windowRect; // calculated bounds of the window that holds the scrolling list

    #endregion Fields

    #region Methods

    bool IsTouchInsideList(Vector2 touchPos)
    {
        Vector2 screenPos    = new Vector2(touchPos.x, Screen.height - touchPos.y);  // invert y coordinate
        Rect rAdjustedBounds = new Rect(listMargin.x + windowRect.x, listMargin.y + windowRect.y, listSize.x, listSize.y);

        return rAdjustedBounds.Contains(screenPos);
    }
Ejemplo n.º 23
0
	void CalcCameraPos()
	{
		Rect rectRight = new Rect (Screen.width - lenght, 0, lenght, Screen.height);
		Rect rectLeft = new Rect (0,0,lenght,Screen.height);
		Rect rectDown = new Rect (0, 0, Screen.width, lenght);
		Rect rectUp = new Rect (0, Screen.height - lenght, Screen.width, lenght);

		if(rectRight.Contains(Input.mousePosition))
        {
			offset.x += 0.7f;
		}
		if(rectLeft.Contains(Input.mousePosition))
        {
			offset.x -= 0.7f;
		}
		if(rectUp.Contains(Input.mousePosition))
        {
			offset.z += 0.7f;
		}
		if(rectDown.Contains(Input.mousePosition))
        {
			offset.z -= 0.7f;
		}


        offset.y += Input.GetAxis("Mouse ScrollWheel") * 3;
        if (offset.y <= -8.05f)
        {
            offset.y = -8.05f;
        } else if (offset.y >= 1)
        {
            offset.y = 1;
        }
    }
Ejemplo n.º 24
0
    void OnGUI()
    {
        GUI.skin.button.normal.background = startButton;
        GUI.skin.button.hover.background = startButton;

        float cx = (Screen.width - circlesTexture.width) / 2.0f;
        float cy = (Screen.height - circlesTexture.height) / 2.0f;
        Rect circlesRect = new Rect(cx, cy, circlesTexture.width, circlesTexture.height);
        GUI.DrawTexture (circlesRect, circlesTexture);

        float sbw = 189;
        float sbh = 135;

        float sbx = (Screen.width - sbw) / 2.0f+6;
        float sby = (Screen.height - sbh) / 2.0f;
        Rect sbRect = new Rect (sbx, sby, sbw, sbh);

        Event e = Event.current;

        if (sbRect.Contains (e.mousePosition)) {
            GUI.color = new Color(1f, 1f, 1f, 0.5f);
            if(e.type == EventType.MouseUp ) {
                print ("click");
                startGameButtonPressed();
            }
        }
        GUI.DrawTexture (sbRect, startButton);
    }
Ejemplo n.º 25
0
 public static Vector2 Drag2D(Vector2 scrollPosition, Rect position)
 {
     int controlID = GUIUtility.GetControlID(PreviewGUI.sliderHash, FocusType.Passive);
     Event current = Event.current;
     switch (current.GetTypeForControl(controlID))
     {
         case EventType.MouseDown:
             if (position.Contains(current.mousePosition) && position.width > 50f)
             {
                 GUIUtility.hotControl = controlID;
                 current.Use();
                 EditorGUIUtility.SetWantsMouseJumping(1);
             }
             break;
         case EventType.MouseUp:
             if (GUIUtility.hotControl == controlID)
             {
                 GUIUtility.hotControl = 0;
             }
             EditorGUIUtility.SetWantsMouseJumping(0);
             break;
         case EventType.MouseDrag:
             if (GUIUtility.hotControl == controlID)
             {
                 scrollPosition -= current.delta * (float)((!current.shift) ? 1 : 3) / Mathf.Min(position.width, position.height) * 140f;
                 scrollPosition.y = Mathf.Clamp(scrollPosition.y, -90f, 90f);
                 current.Use();
                 GUI.changed = true;
             }
             break;
     }
     return scrollPosition;
 }
    public override void OnGUI()
    {
        base.OnGUI();

        for (int i=0; i < Weapon.Weapons.Count; i++) {
            Rect weaponRect = new Rect((Main.NativeWidth / 5) * 2, (Main.NativeHeight / 5) * i, Main.NativeWidth / 5, Main.NativeWidth / 10);
            GUI.DrawTexture(weaponRect, Weapon.Weapons[i].Texture);

            Rect selectWeaponRect = new Rect(((Main.NativeWidth / 5) * 2) - (Main.NativeHeight / 5), (Main.NativeHeight / 5) * i, Main.NativeHeight / 5, Main.NativeHeight / 5);
            if (Main.CurrentWeapon == Weapon.Weapons[i]) {
                GUI.DrawTexture(selectWeaponRect, SelectedTexture);
            } else {
                if (Main.PurchasedWeapons.Contains(Weapon.Weapons[i])) {
                    GUI.DrawTexture(selectWeaponRect, NotSelectedTexture);
                    if (Main.Clicked && selectWeaponRect.Contains (Main.TouchGuiLocation)) {
                        Main.CurrentWeapon = Weapon.Weapons[i];
                    }
                } else {
                    Rect buyWeaponRect = new Rect(((Main.NativeWidth / 5) * 3) + 10, ((Main.NativeHeight / 5) * i) + 10, (Main.NativeHeight / 5) - 20, (Main.NativeHeight / 5) - 20);
                    GUI.DrawTexture(buyWeaponRect, GreyBox);
                    GUI.Label(buyWeaponRect, Weapon.Weapons[i].Cost.ToString(), Weapon.Weapons[i].Cost <= Main.Money? BuyStyle : CantBuyStyle);
                    if (Weapon.Weapons[i].Cost <= Main.Money && Main.Clicked && buyWeaponRect.Contains (Main.TouchGuiLocation)) {
                        Main.PurchasedWeapons.Add(Weapon.Weapons[i]);
                        Main.Money -= Weapon.Weapons[i].Cost;
                    }
                }
            }
        }
    }
 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();
 }
Ejemplo n.º 28
0
		static void HierarchyWindowItemCallback(int pID, Rect pRect)
		{
			GameObject go = EditorUtility.InstanceIDToObject(pID) as GameObject;
			if (go != null && go.GetComponent<ICodeBehaviour>() != null)
			{
				Rect rect = new Rect(pRect.x + pRect.width - 25, pRect.y-3, 25, 25);
				GUI.DrawTexture( rect,FsmEditorStyles.iCodeLogo);
			}

			Event ev = Event.current;
			if (ev.type == EventType.DragPerform){
				DragAndDrop.AcceptDrag();
				var selectedObjects = new List<GameObject>();
				foreach (var objectRef in DragAndDrop.objectReferences){
					if (objectRef is StateMachine){
						if(pRect.Contains(ev.mousePosition)){
							var gameObject = (GameObject)EditorUtility.InstanceIDToObject(pID);
							var componentX = gameObject.AddComponent<ICodeBehaviour>();
							componentX.stateMachine = objectRef as StateMachine;
							selectedObjects.Add(gameObject);
						}
					}
				}

				if (selectedObjects.Count == 0) {
					return;
				}
				Selection.objects = selectedObjects.ToArray();
				ev.Use();
				
			}
		}
Ejemplo n.º 29
0
	// Update is called once per frame
	void Update () {
		Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);
		if(screenRect.Contains(Input.mousePosition) && currentObject != null){
			//Returns a ray going from camera through a screen point.
			//Input.mousePosition gives us our current mouse position in pixel coordinates
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			
			//This object will allow us to get information on the collider our ray hits.
			RaycastHit hit;

			//This if statement will only execute if the raycast hits into something
			if(Physics.Raycast (ray, out hit)){

				//If our mouse is over a platform
				if(hit.collider.tag == "Platform")
				{
					if(!placed)
						currentObject.transform.position = hit.point;

					if(Input.GetMouseButtonDown(0)){
						placed = true;
						currentObject.GetComponent<PlaceableObject>().isPlaced = true;
					}

					if(Input.GetMouseButtonUp(0)){
						GameState.Instance.windmillAmount++;
						currentObject = null;
						placed = false;
					}
				}
			}
		}
	}
Ejemplo n.º 30
0
    protected void saidaDoMouseDoBox(Rect R)
    {
        if(!R.Contains(Event.current.mousePosition)&&qualBox>-1)
            qualBox=-1;

        //print(!R.Contains(Event.current.mousePosition));
    }
Ejemplo n.º 31
0
    private void updateFilteredRGBImage()
    {
        // lut filter here
        Vector3[] corners   = new Vector3[4];
        Vector3[] vpcorners = new Vector3[4];
        gameObject.GetComponent <RectTransform>().GetWorldCorners(corners);
        UnityEngine.Rect screenRect = new UnityEngine.Rect(0, 0, Screen.width, Screen.height);
        bool             onscreen   = screenRect.Contains((Vector2)corners[0]) || screenRect.Contains((Vector2)corners[2]);

        if (onscreen)
        {
            if (lut != null)
            {
                if (lut.filterImage(frame3dgpu, brightness, contrast, filterStrength))
                {
                    textureBinding.Invoke(frame3dgpu.recoloredImages[lut.index]);
                }
            }
            else
            {
                textureBinding.Invoke(frame3dgpu.filteredImage);
            }
        }
    }
Ejemplo n.º 32
0
        private void DrawItem(UnityEngine.Rect rect, EntityItem item, RowGUIArgs args)
        {
            using (new GuiColorScope(item.Node.EnabledInHierarchy ? UnityEngine.Color.white : HierarchyColors.Hierarchy.Disabled))
            {
                if (!args.selected && rect.Contains(Event.current.mousePosition))
                {
                    HierarchyGui.BackgroundColor(rect, HierarchyColors.Hierarchy.Hover);
                    if (Event.current.type == EventType.Layout)
                    {
                        m_CurrentHoveredRect = rect;
                    }
                }

                CenterRectUsingSingleLineHeight(ref args.rowRect);
                base.RowGUI(args);
            }
        }
Ejemplo n.º 33
0
    /** Background subtraction and check if mouse selected a target */
    private OpenCVForUnity.Rect BgSub()
    {
        Mat fgmaskMat = new Mat();

        roiRect = null;
        OpenCVForUnity.Rect output;

        //Background Subtraction
        backgroundSubstractorMOG2.apply(frame, fgmaskMat);

        //Closure   *it is done to remove noise and close gaps that bgsub may leave where we don't want to
        Mat structuringElement = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(closingSize, closingSize));

        Imgproc.dilate(fgmaskMat, fgmaskMat, structuringElement);
        Imgproc.erode(fgmaskMat, fgmaskMat, structuringElement);

        //Make mask binary
        Mat maskBinary = new Mat();

        Imgproc.threshold(fgmaskMat, maskBinary, 123, 255, Imgproc.THRESH_BINARY);

        //Get Contours
        List <MatOfPoint> contours = new List <MatOfPoint>();

        OpenCVForUnity.Mat hierarchy = new OpenCVForUnity.Mat();
        Imgproc.findContours(maskBinary, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

        foreach (MatOfPoint contour in contours)
        {
            output = Imgproc.boundingRect(new MatOfPoint(contour.toArray()));

            Imgproc.rectangle(frame, output.tl(), output.br(), new Scalar(255, 0, 0), 2);
            rectanglesToPrint.Add(new ColoredRect(output, Color.white));

            UnityEngine.Rect check_pos = CVtoUnityRect(output);
            if (Input.GetMouseButton(0) && check_pos.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
            {
                Debug.Log("Selected a target box");
                Debug.Log(output);
                return(output);
            }
        }
        return(null);
    }
Ejemplo n.º 34
0
    static int Contains(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Vector3>(L, 2))
            {
                UnityEngine.Rect    obj  = (UnityEngine.Rect)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rect));
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
                bool o = obj.Contains(arg0);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.SetBack(L, 1, obj);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <UnityEngine.Vector2>(L, 2))
            {
                UnityEngine.Rect    obj  = (UnityEngine.Rect)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rect));
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
                bool o = obj.Contains(arg0);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.SetBack(L, 1, obj);
                return(1);
            }
            else if (count == 3)
            {
                UnityEngine.Rect    obj  = (UnityEngine.Rect)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rect));
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2);
                bool arg1 = LuaDLL.luaL_checkboolean(L, 3);
                bool o    = obj.Contains(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.SetBack(L, 1, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rect.Contains"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 35
0
 static int QPYX_Contains_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 2 && TypeChecker.CheckTypes <UnityEngine.Vector3>(L_YXQP, 2))
         {
             UnityEngine.Rect    QPYX_obj_YXQP  = (UnityEngine.Rect)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Rect));
             UnityEngine.Vector3 QPYX_arg0_YXQP = ToLua.ToVector3(L_YXQP, 2);
             bool QPYX_o_YXQP = QPYX_obj_YXQP.Contains(QPYX_arg0_YXQP);
             LuaDLL.lua_pushboolean(L_YXQP, QPYX_o_YXQP);
             ToLua.SetBack(L_YXQP, 1, QPYX_obj_YXQP);
             return(1);
         }
         else if (QPYX_count_YXQP == 2 && TypeChecker.CheckTypes <UnityEngine.Vector2>(L_YXQP, 2))
         {
             UnityEngine.Rect    QPYX_obj_YXQP  = (UnityEngine.Rect)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Rect));
             UnityEngine.Vector2 QPYX_arg0_YXQP = ToLua.ToVector2(L_YXQP, 2);
             bool QPYX_o_YXQP = QPYX_obj_YXQP.Contains(QPYX_arg0_YXQP);
             LuaDLL.lua_pushboolean(L_YXQP, QPYX_o_YXQP);
             ToLua.SetBack(L_YXQP, 1, QPYX_obj_YXQP);
             return(1);
         }
         else if (QPYX_count_YXQP == 3)
         {
             UnityEngine.Rect    QPYX_obj_YXQP  = (UnityEngine.Rect)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Rect));
             UnityEngine.Vector3 QPYX_arg0_YXQP = ToLua.ToVector3(L_YXQP, 2);
             bool QPYX_arg1_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 3);
             bool QPYX_o_YXQP    = QPYX_obj_YXQP.Contains(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             LuaDLL.lua_pushboolean(L_YXQP, QPYX_o_YXQP);
             ToLua.SetBack(L_YXQP, 1, QPYX_obj_YXQP);
             return(1);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: UnityEngine.Rect.Contains"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Ejemplo n.º 36
0
 static public int Contains(IntPtr l)
 {
     try{
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(UnityEngine.Vector2)))
         {
             UnityEngine.Rect    self = (UnityEngine.Rect)checkSelf(l);
             UnityEngine.Vector2 a1;
             checkType(l, 2, out a1);
             System.Boolean ret = self.Contains(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Rect    self = (UnityEngine.Rect)checkSelf(l);
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             System.Boolean ret = self.Contains(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Rect    self = (UnityEngine.Rect)checkSelf(l);
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             System.Boolean ret = self.Contains(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Ejemplo n.º 37
0
    public virtual void UpdateTrackContents(DirectorControlState state, UnityEngine.Rect position)
    {
        this.state     = state;
        this.trackArea = position;
        List <KeyValuePair <int, TimelineItemWrapper> > list = new List <KeyValuePair <int, TimelineItemWrapper> >();

        foreach (TimelineItemWrapper wrapper in this.itemMap.Keys)
        {
            TrackItemControl control = this.itemMap[wrapper];
            control.Wrapper = wrapper;
            control.Track   = this.TargetTrack;
            control.PreUpdate(state, position);
            KeyValuePair <int, TimelineItemWrapper> item = new KeyValuePair <int, TimelineItemWrapper>(control.DrawPriority, wrapper);
            list.Add(item);
        }
        list.Sort(new Comparison <KeyValuePair <int, TimelineItemWrapper> >(TimelineTrackControl.Comparison));
        foreach (KeyValuePair <int, TimelineItemWrapper> pair2 in list)
        {
            this.itemMap[pair2.Value].HandleInput(state, position);
        }
        list.Reverse();
        foreach (KeyValuePair <int, TimelineItemWrapper> pair3 in list)
        {
            TrackItemControl local1 = this.itemMap[pair3.Value];
            local1.Draw(state);
            local1.PostUpdate(state);
        }
        UnityEngine.Rect rect = new UnityEngine.Rect(0f, 0f, position.width, position.height);
        int num = GUIUtility.GetControlID(this.TargetTrack.Behaviour.GetInstanceID(), (FocusType)2, rect);

        if ((((Event.current.GetTypeForControl(num) == EventType.MouseUp) && rect.Contains(Event.current.mousePosition)) && ((Event.current.button == 1) && !Event.current.alt)) && (!Event.current.shift && !Event.current.control))
        {
            this.showBodyContextMenu(Event.current);
            Event.current.Use();
        }
    }
Ejemplo n.º 38
0
 private static int DrawFacesList(UnityEngine.Texture texture, UnityEngine.Rect[] faces, string[] names, int selected)
 {
     UnityEngine.GUILayout.BeginHorizontal(UnityEngine.GUI.skin.box);
     UnityEngine.GUILayout.FlexibleSpace();
     {
         UnityEngine.GUILayout.BeginVertical();
         {
             UnityEngine.Rect rect = UnityEngine.GUILayoutUtility.GetAspectRect(faces.Length, UnityEngine.GUILayout.MaxWidth(64 * faces.Length));
             rect.width /= faces.Length;
             for (int i = 0; i < faces.Length; i++)
             {
                 UnityEngine.GUI.DrawTextureWithTexCoords(rect, texture, faces[i]);
                 if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDown && rect.Contains(UnityEngine.Event.current.mousePosition))
                 {
                     selected = i;
                     UnityEngine.Event.current.Use();
                 }
                 rect.x += rect.width;
             }
             if (names.Length > 1)
             {
                 UnityEngine.GUILayout.Space(4);
                 UnityEngine.Rect toolbarRect = UnityEngine.GUILayoutUtility.GetRect(0, UnityEngine.GUI.skin.button.CalcHeight(UnityEngine.GUIContent.none, 0), UnityEngine.GUILayout.MaxWidth(64 * faces.Length));
                 selected = UnityEngine.GUI.Toolbar(toolbarRect, selected, names);
             }
         }
         UnityEngine.GUILayout.EndVertical();
     }
     UnityEngine.GUILayout.FlexibleSpace();
     UnityEngine.GUILayout.EndHorizontal();
     return(selected);
 }
Ejemplo n.º 39
0
 private void CheckIfAreaContainsMouse()
 {
     UnityEngine.Vector2 mouse = UnityEngine.Event.current.mousePosition;
     UnityEngine.Rect    r     = area;
     areaContainsMouse = r.Contains(mouse);
 }
Ejemplo n.º 40
0
        private static bool ButtonBase(UnityEngine.Rect bounds, GUIContent content, bool on, GUIStyle style, bool forceOnTop)
        {
            Contract.ArgumentNotNull("style", style);

            int  controlID   = GUIUtility.GetControlID(content, FocusType.Passive);
            bool isMouseOver = bounds.Contains(Event.current.mousePosition);
            int  depth       = (1000 - GUI.depth) * 1000 + (forceOnTop ? 10000 : controlID);

            if (isMouseOver && depth > highestDepthID)
            {
                highestDepthID = depth;
            }

            bool isTopmostMouseOver = (highestDepthID == depth);

    #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
            bool paintMouseOver = isTopmostMouseOver && (Input.touchCount > 0);
    #else
            bool paintMouseOver = isTopmostMouseOver;
    #endif

            if (Event.current.type == EventType.Layout && lastEventType != EventType.Layout)
            {
                highestDepthID = 0;
                frame++;
            }

            lastEventType = Event.current.type;
            if (Event.current.type == EventType.Repaint)
            {
                bool isDown = (GUIUtility.hotControl == controlID);
                style.Draw(bounds, content, paintMouseOver, isDown, on, false);
            }

    #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
            if (Input.touchCount > 0)
            {
                Touch touch = Input.GetTouch(0);
                if (touch.phase == TouchPhase.Began)
                {
                    touchBeganPosition = touch.position;
                    wasDragging        = true;
                }
                else if (touch.phase == TouchPhase.Ended &&
                         ((Mathf.Abs(touch.position.x - touchBeganPosition.x) > 15) ||
                          (Mathf.Abs(touch.position.y - touchBeganPosition.y) > 15)))
                {
                    wasDragging = true;
                }
                else
                {
                    wasDragging = false;
                }
            }
            else if (Event.current.type == EventType.Repaint)
            {
                wasDragging = false;
            }
    #endif

            // Workaround:
            // ignore duplicate mouseUp events. These can occur when running
            // unity editor with unity remote on iOS ... (anybody knows WHY?)
            if (frame <= (1 + lastEventFrame))
            {
                return(false);
            }

            if (isMouseOver)
            {
                switch (Event.current.GetTypeForControl(controlID))
                {
                case EventType.mouseDown:
                {
                    //DebugLog.Info("UnityButton: Mouse DOWN over controlID={0} isTopmostMouseOver={1} depth={2} highest depth={3} wasDragging={4} content={5}",
                    //controlID, isTopmostMouseOver, depth, highestDepthID, wasDragging, content.text);
                    if (isTopmostMouseOver && !wasDragging)
                    {
                        GUIUtility.hotControl = controlID;
                        Event.current.Use();
                    }
                    break;
                }

                case EventType.mouseUp:
                {
                    //DebugLog.Info("UnityButton: Mouse UP over controlID={0} isTopmostMouseOver={1} depth={2} highest depth={3} wasDragging={4} content={5}",
                    //controlID, isTopmostMouseOver, depth, highestDepthID, wasDragging, content.text);
                    if (isTopmostMouseOver && !wasDragging)
                    {
                        GUIUtility.hotControl = 0;
                        lastEventFrame        = frame;
                        Event.current.Use();
                        return(true);
                    }
                    break;
                }
                }
            }

            return(false);
        }
Ejemplo n.º 41
0
    public virtual void UpdateHeaderContents(DirectorControlState state, UnityEngine.Rect position, UnityEngine.Rect headerBackground)
    {
        UnityEngine.Rect rect        = new UnityEngine.Rect(position.x + 14f, position.y, 14f, position.height);
        float            introduced8 = rect.x;

        UnityEngine.Rect rect2 = new UnityEngine.Rect(introduced8 + rect.width, position.y, ((position.width - 14f) - 96f) - 14f, position.height);
        string           str   = this.TargetTrack.Behaviour.name;
        bool             flag  = EditorGUI.Foldout(rect, base.isExpanded, GUIContent.none, false);

        if (flag != base.isExpanded)
        {
            base.isExpanded = flag;
            EditorPrefs.SetBool(base.IsExpandedKey, base.isExpanded);
        }
        this.updateHeaderControl1(new UnityEngine.Rect(position.width - 80f, position.y, 16f, 16f));
        this.updateHeaderControl2(new UnityEngine.Rect(position.width - 64f, position.y, 16f, 16f));
        this.updateHeaderControl3(new UnityEngine.Rect(position.width - 48f, position.y, 16f, 16f));
        this.updateHeaderControl4(new UnityEngine.Rect(position.width - 32f, position.y, 16f, 16f));
        this.updateHeaderControl5(new UnityEngine.Rect(position.width - 16f, position.y, 16f, 16f));
        this.updateHeaderControl6(new UnityEngine.Rect(position.width - 96, position.y, 16f, 16f));
        int num = GUIUtility.GetControlID(this.TargetTrack.Behaviour.GetInstanceID(), (FocusType)2, position);

        if (this.isRenaming)
        {
            GUI.SetNextControlName("TrackRename");
            str = EditorGUI.TextField(rect2, GUIContent.none, str);
            if (this.renameRequested)
            {
                EditorGUI.FocusTextInControl("TrackRename");
                this.renameRequested = false;
                this.renameControlID = GUIUtility.keyboardControl;
            }
            if ((!EditorGUIUtility.editingTextField || (this.renameControlID != GUIUtility.keyboardControl)) || ((Event.current.keyCode == (KeyCode)13) || ((Event.current.type == EventType.MouseDown) && !rect2.Contains(Event.current.mousePosition))))
            {
                this.isRenaming                   = false;
                GUIUtility.hotControl             = (0);
                GUIUtility.keyboardControl        = (0);
                EditorGUIUtility.editingTextField = (false);
            }
        }
        if (this.TargetTrack.Behaviour.name != str)
        {
            Undo.RecordObject(this.TargetTrack.Behaviour.gameObject, string.Format("Renamed {0}", this.TargetTrack.Behaviour.name));
            this.TargetTrack.Behaviour.name = (str);
        }
        if (!this.isRenaming)
        {
            string str2 = str;
            for (Vector2 vector = GUI.skin.label.CalcSize(new GUIContent(str2)); (vector.x > rect2.width) && (str2.Length > 5); vector = GUI.skin.label.CalcSize(new GUIContent(str2)))
            {
                str2 = str2.Substring(0, str2.Length - 4) + "...";
            }
            if (Selection.Contains(this.TargetTrack.Behaviour.gameObject))
            {
                GUI.Label(rect2, str2, EditorStyles.whiteLabel);
            }
            else
            {
                GUI.Label(rect2, str2);
            }
            if (Event.current.GetTypeForControl(num) == EventType.MouseDown)
            {
                if (position.Contains(Event.current.mousePosition) && (Event.current.button == 1))
                {
                    if (!this.IsSelected)
                    {
                        base.RequestSelect();
                    }
                    this.showHeaderContextMenu();
                    Event.current.Use();
                }
                else if (position.Contains(Event.current.mousePosition) && (Event.current.button == 0))
                {
                    base.RequestSelect();
                    Event.current.Use();
                }
            }
        }
    }
Ejemplo n.º 42
0
        private void DrawItem(UnityEngine.Rect rect, SceneItem item, RowGUIArgs args)
        {
            if (null == item)
            {
                return;
            }

            // Draw scene separators and background
            var indent = GetContentIndent(item);

            if (!args.selected)
            {
                var headerRect = rect;
                headerRect.width += 1;

                var topLine = headerRect;
                topLine.height = 1;
                HierarchyGui.BackgroundColor(topLine, HierarchyColors.Hierarchy.SceneSeparator);

                headerRect.y      += 2;
                headerRect.height -= 2;
                HierarchyGui.BackgroundColor(headerRect, HierarchyColors.Hierarchy.SceneItem);
                if (rect.Contains(Event.current.mousePosition))
                {
                    HierarchyGui.BackgroundColor(headerRect, HierarchyColors.Hierarchy.Hover);
                    if (Event.current.type == EventType.Layout)
                    {
                        m_CurrentHoveredRect = rect;
                    }
                }

                var bottomLine = headerRect;
                bottomLine.y     += bottomLine.height - 2;
                bottomLine.height = 1;
                HierarchyGui.BackgroundColor(bottomLine, HierarchyColors.Hierarchy.SceneSeparator);
            }

            // Draw scene icon
            rect.y     += 2;
            rect.x      = indent;
            rect.width -= indent;

            var iconRect = rect;

            iconRect.width = 20;

            var image = ActiveScene == item.Scene ? Icons.ActiveScene : Icons.Scene;

            EditorGUI.LabelField(iconRect, new UnityEngine.GUIContent {
                image = image
            });

            // Draw scene label
            rect.x     += 20;
            rect.width -= 40;

            var style   = ActiveScene == item.Scene ? EditorStyles.boldLabel : UnityEngine.GUI.skin.label;
            var label   = item.displayName;
            var project = Application.AuthoringProject;

            if (!project.GetScenes().Contains(new SceneReference {
                SceneGuid = item.Scene.SceneGuid.Guid
            }))
            {
                label += $" (Not in {project.Name})";
            }
            EditorGUI.LabelField(rect, label, style);

            // Draw scene context menu button
            rect.x    += rect.width;
            rect.width = 16;
            if (UnityEngine.GUI.Button(rect, Icons.Settings, GUI.skin.label))
            {
                ShowSceneContextMenu(item);
            }
        }
Ejemplo n.º 43
0
    private OpenCVForUnity.Rect BgSub()
    {
        backgroundSubstractorMOG2.apply(rgbMat, fgmaskMat);

        roiRect      = null;
        fgmaskMatRoi = fgmaskMat;

        Mat kernelD = new Mat(40, 40, CvType.CV_8UC1, new Scalar(255, 255, 255));
        Mat kernelE = new Mat(20, 20, CvType.CV_8UC1, new Scalar(255, 255, 255));

        Mat kernelDRoi = new Mat(1, 1, CvType.CV_8UC1, new Scalar(255, 255, 255));
        Mat kernelERoi = new Mat(1, 1, CvType.CV_8UC1, new Scalar(255, 255, 255));

        Imgproc.dilate(fgmaskMat, fgmaskMatDilate, kernelD);
        Imgproc.erode(fgmaskMatDilate, fgmaskMatDilate, kernelE);

        Imgproc.dilate(fgmaskMatRoi, fgmaskMatDilateRoi, kernelDRoi);
        Imgproc.erode(fgmaskMatDilateRoi, fgmaskMatDilateRoi, kernelERoi);

        mask_binary    = new OpenCVForUnity.Mat();
        mask_binaryRoi = new OpenCVForUnity.Mat();

        Imgproc.threshold(fgmaskMatDilate, mask_binary, 123, 255, Imgproc.THRESH_BINARY);
        Imgproc.threshold(fgmaskMatDilateRoi, mask_binaryRoi, 123, 255, Imgproc.THRESH_BINARY);

        List <MatOfPoint> contours = new List <MatOfPoint>();

        OpenCVForUnity.Mat hierarchy = new OpenCVForUnity.Mat();

        Imgproc.findContours(mask_binary, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);

        if (contours.Count == 0)
        {
            return(null);
        }
        else
        {
            int i = 0;
            color1 = new Color(0.8f, 0.8f, 0.95f, 0.25f);
            color2 = new Color(0.8f, 0.8f, 0.95f);
            foreach (MatOfPoint contour in contours)
            {
                //Debug.Log("number of target: " + i);
                MatOfPoint new_mat1 = new MatOfPoint(contour.toArray());
                output = Imgproc.boundingRect(new_mat1);
                rgbMat.copyTo(dest, mask_binaryRoi);
                //SaveMatToFile("mask_binary" + ss, mask_binary);
                //SaveMatToFile("mask_binaryRoi" + ss, mask_binaryRoi);
                Imgproc.rectangle(rgbMat, output.tl(), output.br(), new Scalar(255, 0, 0), 2);
                output_ar.Add(output);
                Vector3          top_left_pos     = new Vector3(output.x, Screen.height - output.y);
                Vector3          bottom_right_pos = new Vector3(output.x + output.width, Screen.height - (output.y + output.height));
                UnityEngine.Rect check_pos        = GetScreenRect(top_left_pos, bottom_right_pos);
                i++;
                if (Input.GetMouseButton(0) && check_pos.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
                {
                    Debug.Log("take it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    //skipFrame = 50;
                    //shouldStartCamShift = true;
                    Debug.Log(output);
                    return(output);
                }

                /*else
                 * {
                 *  MatOfPoint new_mat2 = new MatOfPoint(contours[0].toArray()); //prende il blob più grande, è il primo perchè la funzione findcontours mette in ordine dal più grande al più piccolo.
                 *  output = Imgproc.boundingRect(new_mat2);
                 * }*/
            }
            //OnGUI();
            return(null);
        }
    }
Ejemplo n.º 44
0
    static bool Rect_Contains__Vector3(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Vector3 arg0    = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.Rect    argThis = (UnityEngine.Rect)vc.csObj;                JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(argThis.Contains(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Ejemplo n.º 45
0
        void Update()
        {
            if (player == null)
            {
                return;
            }
            foreach (var targetTip in followTargets)
            {
                if (targetTip.Value.target != null & targetTip.Value.tip != null)
                {
                    //是否可见

                    Vector3 posViewport = UnityEngine.Camera.main.WorldToViewportPoint(targetTip.Value.target.transform.position);
                    var     _rect       = new UnityEngine.Rect(0, 0, 1, 1);
                    bool    _visible    = _rect.Contains(posViewport);
                    targetTip.Value.tip.SetActive(!_visible);

                    float _x = targetTip.Value.target.transform.position.x - player.transform.position.x;
                    float _y = targetTip.Value.target.transform.position.z - player.transform.position.z;

                    //arrow旋转
                    float a = UnityEngine.Mathf.Atan2(_y, _x) * UnityEngine.Mathf.Rad2Deg;
                    targetTip.Value.arrow.transform.localRotation = Quaternion.Euler(0, 0, a - 90);

                    //更新位置
                    float _off_x  = UnityEngine.Screen.width / 2 - targetTip.Value.tip.GetComponent <UnityEngine.RectTransform>().sizeDelta.x / 2;
                    float _off_y  = UnityEngine.Screen.height / 2 - targetTip.Value.tip.GetComponent <UnityEngine.RectTransform>().sizeDelta.y / 2;
                    float delta_x = 1;
                    float delta_y = 1;
                    if (_x < 0)
                    {
                        delta_x = -1;
                    }
                    if (_y >= 0)
                    {
                        //_off_y = _off_y - 115;//减去上下资源条宽度
                    }
                    else
                    {
                        //_off_y = _off_y - 150;
                        delta_y = -1;
                    }

                    float limit = Mathf.Atan2(_off_y, _off_x) * Mathf.Rad2Deg;
                    float _a    = Vector3.Angle(new Vector3(_x, _y, 0), new Vector3(delta_x * 1, 0, 0));
                    if (_a < limit)
                    {
                        float offset = Mathf.Tan(Mathf.Deg2Rad * _a) * _off_x;
                        targetTip.Value.tip.transform.localPosition = new Vector3(delta_x * _off_x, delta_y * offset, 0);
                    }
                    else if (_a > limit)
                    {
                        float offset = Mathf.Tan(Mathf.Deg2Rad * (90 - _a)) * _off_y;
                        targetTip.Value.tip.transform.localPosition = new Vector3(delta_x * offset, delta_y * _off_y, 0);
                    }
                    else
                    {
                        targetTip.Value.tip.transform.localPosition = new Vector3(delta_x * _off_x, delta_y * _off_y, 0);
                    }
                }
            }
        }
Ejemplo n.º 46
0
    private static void DrawFaceEditor(ref int face, OCAtlas atlas, ref UnityEngine.Matrix4x4 matrix)
    {
        UnityEngine.GUILayout.BeginVertical(UnityEngine.GUI.skin.box);
        UnityEngine.Texture texture = atlas.Texture;
        UnityEngine.Rect    rect    = UnityEngine.GUILayoutUtility.GetAspectRect((float)texture.width / texture.height);
        UnityEngine.GUILayout.EndVertical();

        UnityEngine.Matrix4x4 rectMatrix    = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(rect.width, rect.height, 0)) * matrix;
        UnityEngine.Matrix4x4 invRectMatrix = matrix.inverse * UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1 / rect.width, 1 / rect.height, 0));
        UnityEngine.Matrix4x4 invertY       = UnityEngine.Matrix4x4.TRS(new UnityEngine.Vector2(0, 1), UnityEngine.Quaternion.identity, new UnityEngine.Vector2(1, -1));

        bool mouseInRect = rect.Contains(UnityEngine.Event.current.mousePosition);

        UnityEngine.GUI.BeginGroup(rect);
        {
            UnityEngine.Vector2 mouse = invRectMatrix.MultiplyPoint(UnityEngine.Event.current.mousePosition);             // local mouse [0..1]

            if (UnityEngine.Event.current.type == UnityEngine.EventType.Repaint)
            {
                UnityEngine.Rect texturePosition = Mul(new UnityEngine.Rect(0, 0, 1, 1), rectMatrix);
                UnityEngine.Rect faceRet         = atlas.ToRect(face);
                faceRet = Mul(faceRet, rectMatrix * invertY);
                UnityEngine.GUI.DrawTexture(texturePosition, texture);
                BlockEditorUtils.DrawRect(faceRet, UnityEngine.Color.green);
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDown && UnityEngine.Event.current.button == 0 && mouseInRect)
            {
                UnityEngine.Vector2 invMouse = invertY.MultiplyPoint(mouse);
                if (invMouse.x >= 0 && invMouse.x <= 1 && invMouse.y >= 0 && invMouse.y <= 1)
                {
                    int posX = UnityEngine.Mathf.FloorToInt(invMouse.x * atlas.Width);
                    int posY = UnityEngine.Mathf.FloorToInt(invMouse.y * atlas.Height);
                    face = posY * atlas.Width + posX;

                    UnityEngine.GUI.changed = true;
                    UnityEngine.Event.current.Use();
                }
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDrag && UnityEngine.Event.current.button == 1 && mouseInRect)
            {
                UnityEngine.Vector3 delta = UnityEngine.Event.current.delta;
                delta.x /= rect.width;
                delta.y /= rect.height;

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(delta, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix = offsetMatrix * matrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.ScrollWheel && mouseInRect)
            {
                float s = 0.95f;
                if (UnityEngine.Event.current.delta.y < 0)
                {
                    s = 1.0f / s;
                }

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix *= offsetMatrix;

                UnityEngine.Matrix4x4 scaleMatrix = UnityEngine.Matrix4x4.Scale(UnityEngine.Vector3.one * s);
                matrix *= scaleMatrix;

                offsetMatrix = UnityEngine.Matrix4x4.TRS(-mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix      *= offsetMatrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }
        }
        UnityEngine.GUI.EndGroup();
    }