private void OnGUI() { if (!isLocalPlayer) { return; } var current = Event.current; if (RuntimeDragAndDrop.DraggedProp != null) { Ray ray = camera.ScreenPointToRay(new Vector3(current.mousePosition.x, Screen.height - current.mousePosition.y)); RaycastHit raycastHit; switch (current.type) { case EventType.MouseDrag: if (GUIUtility.hotControl == RuntimeDragAndDrop.DragHash && Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, hitMask)) { ManagePrefabPlacement(raycastHit); } else if (placingProp != null && placingProp.gameObject.activeSelf) { placingProp.gameObject.SetActive(false); } break; case EventType.MouseUp: if (current.button == 0) { if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity, hitMask)) { Quaternion rot = Quaternion.Euler(rotation) * Quaternion.LookRotation(Vector3.forward, raycastHit.normal); WorldManager.instance.CreateObject(new WorldObject() { guid = RuntimeDragAndDrop.DraggedGuid, pos = raycastHit.point, rotation = rot, scale = Vector3.one, color = Color.white }); } RuntimeDragAndDrop.TakeDrag(); } break; case EventType.Ignore: if (GUIUtility.hotControl == RuntimeDragAndDrop.DragHash && placingProp != null && placingProp.gameObject.activeSelf) { placingProp.gameObject.SetActive(false); } break; } } }
private void OnGUI() { RuntimeEditorGUI.ResetGUIState(); GUI.skin = skin; GUI.backgroundColor = new Color(1, 1, 1, opacity); var current = Event.current; if (RuntimeSelection.activeProp != null) { Rect inspectorRect = new Rect(Screen.width - inspectorWidth - margin, margin, inspectorWidth, inspectorHeight - margin * 2 - 32 - 5); RuntimeDragAndDrop.ManageDragTaking(inspectorRect); GUILayout.BeginArea(inspectorRect); GUILayout.BeginHorizontal(new GUIContent(RuntimeSelection.activeProp.name), Styles.inspectorHeaderStyle, GUILayout.Height(32)); GUILayout.Space(8); GUILayout.EndHorizontal(); GUILayout.BeginVertical(Styles.inspectorBg); scroll = GUILayout.BeginScrollView(scroll, GUIStyle.none, Styles.verticalScrollbarMenuStyle, GUILayout.ExpandHeight(true)); DoInspector(RuntimeSelection.activeProp); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginHorizontal(Styles.inspectorFooterStyle, GUILayout.Height(32)); GUILayout.Space(8); GUILayout.EndHorizontal(); GUILayout.EndArea(); if (current.type == EventType.MouseDown && GUIUtility.hotControl == 0 && inspectorRect.Contains(current.mousePosition)) { current.Use(); } } }
private void OnGUI() { GUI.skin = skin; GUI.backgroundColor = new Color(1, 1, 1, chatOpacity); var current = Event.current; if (!Minimized) { Rect inputTextRect = new Rect(margins, Screen.height - inputFieldHeight - margins, inputFieldWidth, 24); currentMessage = GUI.TextField(inputTextRect, currentMessage); if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) { SendMessage(); GUIUtility.ExitGUI(); return; } Rect sendButtonRect = new Rect(inputTextRect.xMax + 5, inputTextRect.y, 64, inputTextRect.height); if (GUI.Button(sendButtonRect, new GUIContent("Send"))) { SendMessage(); GUIUtility.ExitGUI(); return; } Rect chatScrollRect = new Rect(margins, inputTextRect.yMin - 5 - chatScrollHeight, inputFieldWidth + 5 + 64, chatScrollHeight); GUILayout.BeginArea(chatScrollRect, GUI.skin.box); chatScroll = GUILayout.BeginScrollView(chatScroll); foreach (var message in messages) { GUILayout.Label(new GUIContent(message), Styles.chatLabelStyle); } GUILayout.EndScrollView(); GUILayout.EndArea(); Rect chatToggleBtnRect = new Rect(margins, chatScrollRect.yMin - 3 - 32, 32, 32); GUI.contentColor = notificationIconGradient.Evaluate(newMessageTimer / newMessageNotificationTime); if (GUI.Button(chatToggleBtnRect, new GUIContent(chatIcon))) { Minimized = true; } GUI.contentColor = Color.white; Rect fullRect = new Rect(chatScrollRect.xMin, chatScrollRect.yMin, chatScrollRect.xMax - chatScrollRect.xMin, inputTextRect.yMax - chatScrollRect.yMin); RuntimeDragAndDrop.ManageDragTaking(fullRect); if (current.type == EventType.MouseDown && GUIUtility.hotControl == 0 && fullRect.Contains(current.mousePosition)) { current.Use(); } } else { Rect chatToggleBtnRect = new Rect(margins, Screen.height - margins - 32, 32, 32); GUI.contentColor = notificationIconGradient.Evaluate(newMessageTimer / newMessageNotificationTime); if (GUI.Button(chatToggleBtnRect, new GUIContent(chatIcon))) { Minimized = false; } GUI.contentColor = Color.white; Rect lastMessageRect = new Rect(chatToggleBtnRect.xMax + 5, chatToggleBtnRect.yMin, inputFieldWidth, 32); GUIContent lastMessageContent = messages.Count > 0 ? new GUIContent(messages[messages.Count - 1]) : GUIContent.none; GUI.Box(lastMessageRect, lastMessageContent, Styles.lastMessageBoxStyle); Rect fullRect = new Rect(chatToggleBtnRect.xMin, chatToggleBtnRect.yMin, lastMessageRect.xMax - chatToggleBtnRect.xMin, lastMessageRect.yMax - lastMessageRect.yMin); RuntimeDragAndDrop.ManageDragTaking(fullRect); if (current.type == EventType.MouseDown && GUIUtility.hotControl == 0 && fullRect.Contains(current.mousePosition)) { current.Use(); } } }
private void OnGUI() { GUI.skin = skin; GUI.backgroundColor = new Color(1, 1, 1, opacity); var current = Event.current; if (!Minimized) { Rect prefabsScrollRect = new Rect(Screen.width - prefabScrollWidth - margin, Screen.height - prebabScrollHeight - margin, prefabScrollWidth, prebabScrollHeight); //take dragging RuntimeDragAndDrop.ManageDragTaking(prefabsScrollRect); GUILayout.BeginArea(prefabsScrollRect); GUILayout.BeginHorizontal(Styles.inspectorHeaderStyle, GUILayout.ExpandWidth(true)); search = GUILayout.TextField(search, Styles.inputFieldLeftStyle, GUILayout.ExpandWidth(true)); GUILayout.Button(new GUIContent(searchTexture), Styles.blueButtonRightStyle, GUILayout.Height(24), GUILayout.Width(24)); GUILayout.EndHorizontal(); prefabsScroll = GUILayout.BeginScrollView(prefabsScroll, GUIStyle.none, Styles.verticalScrollbarMenuStyle, GUILayout.ExpandHeight(true)); foreach (var prefab in PrefabDatabase.Instance.Prefabs) { var prop = prefab.Prop; if (prop == null || prop.name.IndexOf(search, StringComparison.InvariantCultureIgnoreCase) < 0 || !selectedLabels.Overlaps(prefab.Labels)) { continue; } GUIContent content = new GUIContent(prefab.Icon == null ? missingIconTexture : prefab.Icon) { text = prop.name }; Rect elementRect = GUILayoutUtility.GetRect(content, Styles.menuElementStyle, GUILayout.Height(prefabIconSize)); switch (current.type) { case EventType.MouseDown: if (RuntimeDragAndDrop.DraggedProp == null && elementRect.Contains(current.mousePosition) && current.button == 0 && GUIUtility.hotControl == 0) { RuntimeDragAndDrop.StartDrag(prop, prefab.Guid); } break; case EventType.Repaint: Styles.menuElementStyle.Draw(elementRect, content, elementRect.Contains(current.mousePosition), RuntimeDragAndDrop.DraggedProp == prop, RuntimeDragAndDrop.DraggedProp == prop, false); break; } } GUILayout.BeginVertical(GUIContent.none, Styles.inspectorBg, GUILayout.ExpandHeight(true)); GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(Styles.inspectorFooterStyle); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(prefabsTexture), Styles.miniButton, GUILayout.Height(24), GUILayout.Width(24))) { Minimized = true; } GUILayout.EndHorizontal(); GUILayout.EndArea(); Rect labelsRect = new Rect(prefabsScrollRect.xMin - labelsWidth - 5, prefabsScrollRect.yMin, labelsWidth, prefabsScrollRect.height); GUILayout.BeginArea(labelsRect); GUILayout.BeginVertical(); foreach (var label in PrefabDatabase.Instance.Labels) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUIContent content = new GUIContent(label); Rect elementRect = GUILayoutUtility.GetRect(content, Styles.prefabLabel); switch (current.type) { case EventType.MouseDown: if (elementRect.Contains(current.mousePosition) && current.button == 0 && GUIUtility.hotControl == 0) { if (selectedLabels.Contains(label)) { selectedLabels.Remove(label); } else { selectedLabels.Add(label); } } break; case EventType.Repaint: Styles.prefabLabel.Draw(elementRect, content, elementRect.Contains(current.mousePosition), false, selectedLabels.Contains(label), false); break; } GUILayout.EndHorizontal(); GUILayout.Space(2); } GUILayout.EndVertical(); GUILayout.EndArea(); if (current.type == EventType.MouseDown && GUIUtility.hotControl == 0 && prefabsScrollRect.Contains(current.mousePosition)) { current.Use(); } } else { Rect prefabsBrowserButtonRect = new Rect(Screen.width - margin - 32, Screen.height - margin - 32, 32, 32); if (GUI.Button(prefabsBrowserButtonRect, new GUIContent(prefabsTexture))) { Minimized = false; } } }