private static StyleBlock FindBlock(int name, DrawStates drawStates) { bool isEnabled = GUI.enabled; StyleState stateFlags = 0; if (isEnabled && drawStates.hasKeyboardFocus && GUIView.current.hasFocus) { stateFlags |= StyleState.focus; } if (isEnabled && (drawStates.isActive || GUI.HasMouseControl(drawStates.controlId))) { stateFlags |= StyleState.active; } if (isEnabled && drawStates.isHover) { stateFlags |= StyleState.hover; } if (drawStates.on) { stateFlags |= StyleState.@checked; } if (!isEnabled) { stateFlags |= StyleState.disabled; } return(EditorResources.GetStyle(name, stateFlags, stateFlags & StyleState.disabled, stateFlags & StyleState.active, stateFlags & StyleState.@checked, stateFlags & StyleState.hover, stateFlags & StyleState.focus, StyleState.normal)); }
public void DrawReset() { transform.position = playerChar.transform.position; marker.GetComponent <Renderer>().enabled = true; lineRender.SetVertexCount(0); waypoints.Clear(); state = DrawStates.READY; }
void DrawEnd() { ScaleTime(1.0f); marker.GetComponent <Renderer>().enabled = false; follower.GetComponent <ObjectFollow>().FollowPrime(); state = DrawStates.FOLLOW; box_col.enabled = false; //canvas.SetActive(false); }
void DrawStart() { ScaleTime(0.1f); linePoints = 0; wpNum = 0; timeMark = Time.realtimeSinceStartup; state = DrawStates.DRAW; box_col.enabled = true; //canvas.SetActive(true); }
internal static StyleBlock FindBlock(int name, DrawStates drawStates) { StyleState stateFlags = 0; if (GUI.enabled) { if (drawStates.hasKeyboardFocus && GUIView.current.hasFocus) { stateFlags |= StyleState.focus; } if (drawStates.isActive || GUI.HasMouseControl(drawStates.controlId)) { stateFlags |= StyleState.active; } if (drawStates.isHover && GUIUtility.hotControl == 0 && IsMouseOverGUIView()) { stateFlags |= StyleState.hover; } } else { stateFlags |= StyleState.disabled; } if (drawStates.on) { stateFlags |= StyleState.@checked; } StyleState[] states; if (!s_StatesCache.TryGetValue(stateFlags, out states)) { states = new[] { stateFlags, stateFlags & StyleState.disabled, stateFlags & StyleState.active, stateFlags & StyleState.@checked, stateFlags & StyleState.hover, stateFlags & StyleState.focus, StyleState.normal }.Distinct().Where(s => s != StyleState.none).ToArray(); s_StatesCache.Add(stateFlags, states); } return(EditorResources.GetStyle(name, states)); }
/// <summary> /// Sets which vertex attributes to draw. Must be called after all included buffers are set. /// This operation is fairly expensive and should only be called during initialization. /// </summary> /// <example>SetDrawState(DrawStates.Vertex | DrawStates.TexCoord);</example> /// <param name="state">All the buffers that will be rendered</param> public void SetDrawState(DrawStates state) { this.state = state; //if no buffers will be drawn, no need to validate any buffers. if (state == DrawStates.None) { return; } //validate the buffers try { if ((state & DrawStates.Vertex) == DrawStates.Vertex) { ValidateBuffer(VertexBuffer, "Vertex buffer"); VertexSize = vertexSize; } if ((state & DrawStates.TexCoord) == DrawStates.TexCoord) { ValidateBuffer(TexCoordBuffer, "Texture coordinate buffer"); TexCoordSize = texCoordSize; } if ((state & DrawStates.Normal) == DrawStates.Normal) { ValidateBuffer(NormalBuffer, "Normal buffer"); NormalSize = normalSize; } ValidateBuffer(IndexBuffer, "Index buffer"); } catch { throw; } }
internal static void DrawBlock(GUIStyle basis, StyleBlock block, Rect drawRect, GUIContent content, DrawStates states) { var userRect = drawRect; StyleRect offset = block.GetRect(StyleCatalogKeyword.position); drawRect.xMin += offset.left; drawRect.yMin += offset.top; drawRect.yMax += offset.bottom; drawRect.xMax += offset.right; // Adjust width and height if enforced by style block drawRect.width = basis.fixedWidth == 0f ? drawRect.width : basis.fixedWidth; drawRect.height = basis.fixedHeight == 0f ? drawRect.height : basis.fixedHeight; Color colorTint = GUI.color; if (!GUI.enabled) { colorTint.a *= block.GetFloat(StyleCatalogKeyword.opacity, 0.5f); } var border = new StyleBorder(block); var bgColorTint = GUI.backgroundColor * colorTint; if (!block.Execute(StyleCatalogKeyword.background, DrawGradient, new GradientParams(drawRect, border.radius, bgColorTint))) { // Draw background color var backgroundColor = block.GetColor(StyleCatalogKeyword.backgroundColor); if (backgroundColor.a > 0f) { var smoothCorners = !border.all; GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, false, 0f, backgroundColor * bgColorTint, Vector4.zero, border.radius, smoothCorners); } } // Draw background image if (block.HasValue(StyleCatalogKeyword.backgroundImage)) { DrawBackgroundImage(block, drawRect, bgColorTint); } if (content != null) { var guiContentColor = GUI.contentColor; // Compute content rect Rect contentRect = drawRect; if (block.GetKeyword(StyleCatalogKeyword.padding) == StyleValue.Keyword.Auto) { GetContentCenteredRect(basis, content, ref contentRect); } // Draw content (text & image) bool hasImage = content.image != null; float opacity = hasImage ? block.GetFloat(StyleCatalogKeyword.opacity, 1f) : 1f; float contentImageOffsetX = hasImage ? block.GetFloat(StyleCatalogKeyword.contentImageOffsetX) : 0; float contentImageOffsetY = hasImage ? block.GetFloat(StyleCatalogKeyword.contentImageOffsetY) : 0; basis.Internal_DrawContent(contentRect, content, states.isHover, states.isActive, states.on, states.hasKeyboardFocus, states.hasTextInput, states.drawSelectionAsComposition, states.cursorFirst, states.cursorLast, states.cursorColor, states.selectionColor, guiContentColor * opacity, 0, 0, contentImageOffsetY, contentImageOffsetX, false, false); // Handle tooltip and hovering region if (!String.IsNullOrEmpty(content.tooltip) && contentRect.Contains(Event.current.mousePosition)) { GUIStyle.SetMouseTooltip(content.tooltip, contentRect); } } // Draw border if (border.any) { GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0f, border.borderLeftColor * colorTint, border.borderTopColor * colorTint, border.borderRightColor * colorTint, border.borderBottomColor * colorTint, border.widths, border.radius); } if (block.GetKeyword(k_EnableHovering) == StyleValue.Keyword.True) { var currentView = GUIView.current; if (currentView != null) { currentView.MarkHotRegion(GUIClip.UnclipToWindow(userRect)); } } }
internal static bool DrawStyle(GUIStyle gs, Rect position, GUIContent content, DrawStates states) { if (gs == GUIStyle.none || gs.blockId == -1 || String.IsNullOrEmpty(gs.name) || gs.normal.background != null) { return(false); } if (!GUIClip.visibleRect.Overlaps(position)) { return(true); } if (gs.blockId == 0) { gs.blockId = GUIStyleExtensions.StyleNameToBlockName(gs.name, false).GetHashCode(); } var block = FindBlock(gs.blockId, states); if (!block.IsValid()) { gs.blockId = -1; return(false); } DrawBlock(gs, block, position, content, states); return(true); }
internal static bool DrawStyle(GUIStyle gs, Rect position, GUIContent content, DrawStates states) { if (gs == GUIStyle.none || String.IsNullOrEmpty(gs.name) || gs.normal.background != null) { return(false); } if (!GUIClip.visibleRect.Overlaps(position)) { return(true); } var styleName = gs.name.Replace(' ', '-'); StyleBlock block = FindBlock(styleName.GetHashCode(), states); if (!block.IsValid()) { return(false); } DrawBlock(gs, block, position, content, states); return(true); }
/// <summary> /// Sets which vertex attributes to draw. Must be called after all included buffers are set. /// This operation is fairly expensive and should only be called during initialization. /// </summary> /// <example>SetDrawState(DrawStates.Vertex | DrawStates.TexCoord);</example> /// <param name="state">All the buffers that will be rendered</param> public void SetDrawState(DrawStates state) { this.state = state; //if no buffers will be drawn, no need to validate any buffers. if (state == DrawStates.None) return; //validate the buffers try { if ((state & DrawStates.Vertex) == DrawStates.Vertex) { ValidateBuffer(VertexBuffer, "Vertex buffer"); VertexSize = vertexSize; } if ((state & DrawStates.TexCoord) == DrawStates.TexCoord) { ValidateBuffer(TexCoordBuffer, "Texture coordinate buffer"); TexCoordSize = texCoordSize; } if ((state & DrawStates.Normal) == DrawStates.Normal) { ValidateBuffer(NormalBuffer, "Normal buffer"); NormalSize = normalSize; } ValidateBuffer(IndexBuffer, "Index buffer"); } catch { throw; } }