protected override void Start() { if (map == null) { return; } mAnchor = GetComponent <GUIAnchor>(); if (planeRenderer != null) { if (material == null) { //Debug.LogWarning("The UITexture does not have a material assigned", this); } else { if (map.generateMapTexture) { material.mainTexture = map.mapTexture; } //elsematerial // material.mainTexture = map.userMapTexture; //if (maskTexture != null) material.SetTexture("_Mask", maskTexture); material.color = mapColor; } } base.Start(); }
public GUIButtonData(GUIButtonData dataToCopy) { icon = dataToCopy.icon; text = dataToCopy.text; anchor = dataToCopy.anchor; isSelectable = dataToCopy.isSelectable; usePersonalArea = dataToCopy.usePersonalArea; x = dataToCopy.x; y = dataToCopy.y; width = dataToCopy.width; height = dataToCopy.height; }
/// <summary> /// A wrapper for GUILayout.BeginArea that automatically handles sizing /// </summary> /// <param name="width"> /// A <see cref="System.Single"/> /// </param> /// <param name="height"> /// A <see cref="System.Single"/> /// </param> /// <param name="anchor"> /// A <see cref="GUIAnchor"/> /// </param> public static void BeginArea(float width, float height, GUIAnchor anchor) { // ensure width does not exceed screen area width = Mathf.Min(width, Screen.width-2f*viewportPadding); // begin the area GUILayout.BeginArea(new Rect ( (anchor==GUIAnchor.LowerLeft||anchor==GUIAnchor.TopLeft)?viewportPadding:Screen.width-viewportPadding-width, (anchor==GUIAnchor.TopLeft||anchor==GUIAnchor.TopRight)?viewportPadding:Screen.height-viewportPadding-height, width, height)); }
/// <summary> /// A wrapper for GUILayout.BeginArea that automatically handles sizing /// </summary> /// <param name="width"> /// A <see cref="System.Single"/> /// </param> /// <param name="height"> /// A <see cref="System.Single"/> /// </param> /// <param name="anchor"> /// A <see cref="GUIAnchor"/> /// </param> public static void BeginArea(float width, float height, GUIAnchor anchor) { // ensure width does not exceed screen area width = Mathf.Min(width, Screen.width - 2f * viewportPadding); // begin the area GUILayout.BeginArea(new Rect( (anchor == GUIAnchor.LowerLeft || anchor == GUIAnchor.TopLeft)?viewportPadding:Screen.width - viewportPadding - width, (anchor == GUIAnchor.TopLeft || anchor == GUIAnchor.TopRight)?viewportPadding:Screen.height - viewportPadding - height, width, height)); }
/// <summary> /// A wrapper for GUILayout.BeginArea that automatically handles sizing /// </summary> /// <param name="width"> /// A <see cref="System.Single"/> /// </param> /// <param name="anchor"> /// A <see cref="GUIAnchor"/> /// </param> public static void BeginArea(float width, GUIAnchor anchor) { BeginArea(width, Screen.height-2f*viewportPadding, anchor); }
public static bool CompareAnchor(GUIAnchor a, GUIAnchor b) { return ( (a & b) == b ); }
/// <summary> /// Executes any registered scene GUI callbacks. /// </summary> /// <param name="ctx">Object from whose context this method is called.</param> /// <param name="width">Desired width of scene GUI area. 281 is minimum width for sliders to appear.</param> /// <param name="anchor">Corner of the viewport to which the controls should be anchored.</param> public static void Display(ISceneGUIContext ctx, float width = 281f, GUIAnchor anchor = GUIAnchor.TopLeft) { // early out if scene gui is disabled or there are no valid registered contexts if ( !IsEnabled || s_RegisteredContexts.Count == 0 || s_RegisteredContexts.Count(k => k.Target != null && k.Callback != null) == 0 ) { return; } // ensure only the first context invoking this method during a layout phase will display the GUI if (Event.current.type == EventType.Layout) { s_DisplayInvoker = ctx.SceneGUIContext.target; } if (s_DisplayInvoker != ctx.SceneGUIContext.target) { return; } if (Event.current.type != EventType.Layout) { s_DisplayInvoker = null; } // begin gui matrix Handles.BeginGUI(); // begin the area width = Mathf.Min(width, Screen.width - 2f * s_ViewportPadding); float height = Screen.height - 2f * s_ViewportPadding - SceneGUI.SceneViewTabHeight; GUISkin oldSkin = GUI.skin; GUI.skin = Skin; GUILayout.BeginArea( new Rect( (anchor == GUIAnchor.LowerLeft || anchor == GUIAnchor.TopLeft) ? s_ViewportPadding : Screen.width - s_ViewportPadding - width, (anchor == GUIAnchor.TopLeft || anchor == GUIAnchor.TopRight) ? s_ViewportPadding : Screen.height - s_ViewportPadding - height, width, height ) ); { Color oldColor = GUI.color; GUI.color = new Color(oldColor.r, oldColor.g, oldColor.b, oldColor.a * 0.65f); EditorGUILayout.BeginVertical(EditorStylesX.SceneBox); { GUI.color = oldColor; s_ScrollPosition = EditorGUILayout.BeginScrollView(s_ScrollPosition, GUILayout.ExpandHeight(false)); { for (int i = 0; i < s_RegisteredContexts.Count; ++i) { if (s_RegisteredContexts[i].Target == null || s_RegisteredContexts[i].Callback == null) { continue; } FontStyle fontStyle = GUI.skin.label.fontStyle; GUI.skin.label.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField( s_RegisteredContexts[i].Target.GetType().Name.ToWords(), GUI.skin.label ); GUI.skin.label.fontStyle = fontStyle; EditorGUIX.DisplayHorizontalLine(); ++EditorGUI.indentLevel; s_RegisteredContexts[i].Callback.Invoke(); --EditorGUI.indentLevel; } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); } GUILayout.EndArea(); GUI.skin = oldSkin; Handles.EndGUI(); }
/// <summary> /// Update the map's alignment. /// </summary> public override void UpdateAlignment() { base.UpdateAlignment(); if (mCol == null) { mCol = planeRenderer.GetComponent <BoxCollider>(); } if (mAnchor == null) { mAnchor = GetComponent <GUIAnchor>(); } mAnchor.side = (GUIAnchor.Side)pivot; #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 if (rendererTransform.hasChanged) { rendererTransform.hasChanged = false; #else if (mLastPos != rendererTransform.localPosition) { mLastPos = rendererTransform.localPosition; #endif if (iconRoot != null) { iconRoot.localPosition = new Vector3(rendererTransform.localPosition.x, rendererTransform.localPosition.y, -1); } mRect.x = Screen.width / 2 - mapHalfScale.x; mRect.y = Screen.height / 2 - mapHalfScale.y; switch (pivot) { case Pivot.Top: mRect.y = (Screen.height - margin.y) - mapScale.y; break; case Pivot.TopLeft: mRect.x = margin.x; mRect.y = (Screen.height - margin.y) - mapScale.y; break; case Pivot.TopRight: mRect.x = (Screen.width - margin.x) - mapScale.x; mRect.y = (Screen.height - margin.y) - mapScale.y; break; case Pivot.Left: mRect.x = margin.x; break; case Pivot.Right: mRect.x = (Screen.width - margin.x) - mapScale.x; break; case Pivot.Bottom: mRect.y = margin.y; break; case Pivot.BottomLeft: mRect.x = margin.x; mRect.y = margin.y; break; case Pivot.BottomRight: mRect.x = (Screen.width - margin.x) - mapScale.x; mRect.y = margin.y; break; } mRect.width = mapScale.x; mRect.height = mapScale.y; } } #region MapIcon Entry const float mul = 0.0045f;
void Awake() { mAnchor = GetComponent <GUIAnchor>(); }
/// <summary> /// A wrapper for GUILayout.BeginArea that automatically handles sizing /// </summary> /// <param name="width"> /// A <see cref="System.Single"/> /// </param> /// <param name="anchor"> /// A <see cref="GUIAnchor"/> /// </param> public static void BeginArea(float width, GUIAnchor anchor) { BeginArea(width, Screen.height - 2f * viewportPadding, anchor); }
public Vector2 GetAnchorOffset(GUIAnchor anchor) { Vector2 bounds = (_parent != null) ? (GUIObject.ScreenCoordToPercent(_parent.LocalBounds)) : (GUIObject.ScreenCoordToPercent( new Vector2(Screen.width, Screen.height))); // Debug.Log ("bounds : " + bounds); // Debug.Log ( "getting anchor : " + anchor + " " + this); Vector2 pos = Vector2.zero; switch (anchor) { case GUIAnchor.TOP_LEFT: pos = Vector2.zero; break; case GUIAnchor.TOP: pos = new Vector2(bounds.x/2, 0f); break; case GUIAnchor.TOP_RIGHT: pos = new Vector2(bounds.x, 0f); break; case GUIAnchor.BOTTOM: pos = new Vector2( bounds.x/2, bounds.y ); break; case GUIAnchor.BOTTOM_LEFT: pos = new Vector2( 0, bounds.y ); break; case GUIAnchor.BOTTUM_RIGHT: pos = new Vector2( bounds.x, bounds.y ); break; case GUIAnchor.RIGHT: pos = new Vector2( bounds.x, bounds.y/2 ); break; case GUIAnchor.LEFT: pos = new Vector2( 0, bounds.y/2 ); break; case GUIAnchor.CENTER: pos = new Vector2( bounds.x/2, bounds.y/2 ); break; } return pos; }