private GUIGridSizer(GUIContent[] contents, int xCount, GUIStyle buttonStyle, GUILayoutOption[] options)
   : base(0.0f, 0.0f, 0.0f, 0.0f, GUIStyle.none)
 {
   this.m_Count = contents.Length;
   this.m_XCount = xCount;
   this.ApplyStyleSettings(buttonStyle);
   this.ApplyOptions(options);
   if (xCount == 0 || contents.Length == 0)
     return;
   float num1 = (float) (Mathf.Max(buttonStyle.margin.left, buttonStyle.margin.right) * (this.m_XCount - 1));
   float num2 = (float) (Mathf.Max(buttonStyle.margin.top, buttonStyle.margin.bottom) * (this.rows - 1));
   if ((double) buttonStyle.fixedWidth != 0.0)
     this.m_MinButtonWidth = this.m_MaxButtonWidth = buttonStyle.fixedWidth;
   if ((double) buttonStyle.fixedHeight != 0.0)
     this.m_MinButtonHeight = this.m_MaxButtonHeight = buttonStyle.fixedHeight;
   if ((double) this.m_MinButtonWidth == -1.0)
   {
     if ((double) this.minWidth != 0.0)
       this.m_MinButtonWidth = (this.minWidth - num1) / (float) this.m_XCount;
     if ((double) this.maxWidth != 0.0)
       this.m_MaxButtonWidth = (this.maxWidth - num1) / (float) this.m_XCount;
   }
   if ((double) this.m_MinButtonHeight == -1.0)
   {
     if ((double) this.minHeight != 0.0)
       this.m_MinButtonHeight = (this.minHeight - num2) / (float) this.rows;
     if ((double) this.maxHeight != 0.0)
       this.m_MaxButtonHeight = (this.maxHeight - num2) / (float) this.rows;
   }
   if ((double) this.m_MinButtonHeight == -1.0 || (double) this.m_MaxButtonHeight == -1.0 || ((double) this.m_MinButtonWidth == -1.0 || (double) this.m_MaxButtonWidth == -1.0))
   {
     float a1 = 0.0f;
     float a2 = 0.0f;
     foreach (GUIContent content in contents)
     {
       Vector2 vector2 = buttonStyle.CalcSize(content);
       a2 = Mathf.Max(a2, vector2.x);
       a1 = Mathf.Max(a1, vector2.y);
     }
     if ((double) this.m_MinButtonWidth == -1.0)
       this.m_MinButtonWidth = (double) this.m_MaxButtonWidth == -1.0 ? a2 : Mathf.Min(a2, this.m_MaxButtonWidth);
     if ((double) this.m_MaxButtonWidth == -1.0)
       this.m_MaxButtonWidth = (double) this.m_MinButtonWidth == -1.0 ? a2 : Mathf.Max(a2, this.m_MinButtonWidth);
     if ((double) this.m_MinButtonHeight == -1.0)
       this.m_MinButtonHeight = (double) this.m_MaxButtonHeight == -1.0 ? a1 : Mathf.Min(a1, this.m_MaxButtonHeight);
     if ((double) this.m_MaxButtonHeight == -1.0)
     {
       if ((double) this.m_MinButtonHeight != -1.0)
         this.maxHeight = Mathf.Max(this.maxHeight, this.m_MinButtonHeight);
       this.m_MaxButtonHeight = this.maxHeight;
     }
   }
   this.minWidth = this.m_MinButtonWidth * (float) this.m_XCount + num1;
   this.maxWidth = this.m_MaxButtonWidth * (float) this.m_XCount + num1;
   this.minHeight = this.m_MinButtonHeight * (float) this.rows + num2;
   this.maxHeight = this.m_MaxButtonHeight * (float) this.rows + num2;
 }
示例#2
0
        public static int SearchablePopup(Rect launchRect, int mouseButton, int selectionIndex, string[] displayOptions, ref string searchTerms, string label = "")
        {
            var ret       = selectionIndex;
            var controlId = GUIUtility.GetControlID(FocusType.Passive);

            // not Popup Owner
            if (s_popupControlId != controlId)
            {
                var ev  = Event.current;
                var pos = ev.mousePosition;

                if ((ev.type == EventType.MouseUp) &&
                    ((mouseButton < 0) || (ev.button == mouseButton)) &&
                    launchRect.Contains(pos) &&
                    displayOptions != null &&
                    displayOptions.Length > 0
                    )
                {
                    s_searchablePopupWindow.pos = RGUIUtility.GetMouseScreenPos(Vector2.one * 150f);
                    s_popupControlId            = controlId;
                    ev.Use();
                }
            }
            // Active
            else
            {
                var type = Event.current.type;

                var result = s_searchablePopupWindow.result;
                if (s_searchablePopupWindow._searchTerms != null)
                {
                    if (!searchTerms.Equals(s_searchablePopupWindow._searchTerms))
                    {
                        ret = -1;
                    }
                    searchTerms = s_searchablePopupWindow._searchTerms;
                }
                if (result.HasValue && type == EventType.Layout)
                {
                    if (result.Value >= 0) // -1 when the popup is closed by clicking outside the window
                    {
                        ret = result.Value;
                    }
                    s_searchablePopupWindow.result = null;
                    s_popupControlId = 0;
                }
                else
                {
                    if ((type == EventType.Layout) || (type == EventType.Repaint))
                    {
                        var buttonStyle = new GUIStyle(InterfaceMaker.CustomSkin.button)
                        {
                            padding = new RectOffset(24, 48, 2, 2)
                        };
                        var textfieldStyle = InterfaceMaker.CustomSkin.textField;
                        var contentSize    = Vector2.zero;

                        for (var i = 0; i < displayOptions.Length; ++i)
                        {
                            var textSize = buttonStyle.CalcSize(RGUIUtility.TempContent(displayOptions[i]));
                            contentSize.x  = Mathf.Max(contentSize.x, textSize.x);
                            contentSize.y += textSize.y;
                        }

                        if (displayOptions.Length == 0)
                        {
                            contentSize.x += 150;
                        }

                        var margin = buttonStyle.margin;
                        contentSize.y += Mathf.Max(0, displayOptions.Length - 1) * Mathf.Max(margin.top, margin.bottom); // is this right?

                        var vbarSkin   = InterfaceMaker.CustomSkin.verticalScrollbar;
                        var vbarSize   = vbarSkin.CalcScreenSize(Vector2.zero);
                        var vbarMargin = vbarSkin.margin;

                        var hbarSkin   = InterfaceMaker.CustomSkin.horizontalScrollbar;
                        var hbarSize   = hbarSkin.CalcScreenSize(Vector2.zero);
                        var hbarMargin = hbarSkin.margin;

                        const float offset = 5f;
                        contentSize += new Vector2(vbarSize.x + vbarMargin.horizontal, hbarSize.y + hbarMargin.vertical) + Vector2.one * offset;

                        contentSize.y += textfieldStyle.CalcHeight(RGUIUtility.TempContent("t"), contentSize.x);

                        var size    = InterfaceMaker.CustomSkin.GetStyle("popup").CalcScreenSize(contentSize);
                        var maxSize = new Vector2(Screen.width, Screen.height) - s_searchablePopupWindow.pos;

                        s_searchablePopupWindow.size = Vector2.Min(size, maxSize);
                    }

                    s_searchablePopupWindow.SetSearchTerms(searchTerms);
                    s_searchablePopupWindow.label          = label;
                    s_searchablePopupWindow.displayOptions = displayOptions;
                    WindowInvoker.Add(s_searchablePopupWindow);
                }
            }

            return(ret);
        }
示例#3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);

        Action buttonAction      = Action.None;
        int    buttonActionIndex = 0;

        var keyArrayProperty   = property.FindPropertyRelative(KeysFieldName);
        var valueArrayProperty = property.FindPropertyRelative(ValuesFieldName);

        ConflictState conflictState = GetConflictState(property);

        if (conflictState.conflictIndex != -1)
        {
            keyArrayProperty.InsertArrayElementAtIndex(conflictState.conflictIndex);
            var keyProperty = keyArrayProperty.GetArrayElementAtIndex(conflictState.conflictIndex);
            SetPropertyValue(keyProperty, conflictState.conflictKey);
            keyProperty.isExpanded = conflictState.conflictKeyPropertyExpanded;

            if (valueArrayProperty != null)
            {
                valueArrayProperty.InsertArrayElementAtIndex(conflictState.conflictIndex);
                var valueProperty = valueArrayProperty.GetArrayElementAtIndex(conflictState.conflictIndex);
                SetPropertyValue(valueProperty, conflictState.conflictValue);
                valueProperty.isExpanded = conflictState.conflictValuePropertyExpanded;
            }
        }

        var buttonWidth = s_buttonStyle.CalcSize(s_iconPlus).x;

        var labelPosition = position;

        labelPosition.height = EditorGUIUtility.singleLineHeight;
        if (property.isExpanded)
        {
            labelPosition.xMax -= s_buttonStyle.CalcSize(s_iconPlus).x;
        }

        EditorGUI.PropertyField(labelPosition, property, label, false);
        // property.isExpanded = EditorGUI.Foldout(labelPosition, property.isExpanded, label);
        if (property.isExpanded)
        {
            var buttonPosition = position;
            buttonPosition.xMin   = buttonPosition.xMax - buttonWidth;
            buttonPosition.height = EditorGUIUtility.singleLineHeight;
            EditorGUI.BeginDisabledGroup(conflictState.conflictIndex != -1);
            if (GUI.Button(buttonPosition, s_iconPlus, s_buttonStyle))
            {
                buttonAction      = Action.Add;
                buttonActionIndex = keyArrayProperty.arraySize;
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.indentLevel++;
            var linePosition = position;
            linePosition.y    += EditorGUIUtility.singleLineHeight;
            linePosition.xMax -= buttonWidth;

            foreach (var entry in EnumerateEntries(keyArrayProperty, valueArrayProperty))
            {
                var keyProperty   = entry.keyProperty;
                var valueProperty = entry.valueProperty;
                int i             = entry.index;

                float lineHeight = DrawKeyValueLine(keyProperty, valueProperty, linePosition, i);

                buttonPosition        = linePosition;
                buttonPosition.x      = linePosition.xMax;
                buttonPosition.height = EditorGUIUtility.singleLineHeight;
                if (GUI.Button(buttonPosition, s_iconMinus, s_buttonStyle))
                {
                    buttonAction      = Action.Remove;
                    buttonActionIndex = i;
                }

                if (i == conflictState.conflictIndex && conflictState.conflictOtherIndex == -1)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconNull);
                    GUI.Label(iconPosition, s_warningIconNull);
                }
                else if (i == conflictState.conflictIndex)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconConflict);
                    GUI.Label(iconPosition, s_warningIconConflict);
                }
                else if (i == conflictState.conflictOtherIndex)
                {
                    var iconPosition = linePosition;
                    iconPosition.size = s_buttonStyle.CalcSize(s_warningIconOther);
                    GUI.Label(iconPosition, s_warningIconOther);
                }


                linePosition.y += lineHeight;
            }

            EditorGUI.indentLevel--;
        }

        if (buttonAction == Action.Add)
        {
            keyArrayProperty.InsertArrayElementAtIndex(buttonActionIndex);
            if (valueArrayProperty != null)
            {
                valueArrayProperty.InsertArrayElementAtIndex(buttonActionIndex);
            }
        }
        else if (buttonAction == Action.Remove)
        {
            DeleteArrayElementAtIndex(keyArrayProperty, buttonActionIndex);
            if (valueArrayProperty != null)
            {
                DeleteArrayElementAtIndex(valueArrayProperty, buttonActionIndex);
            }
        }

        conflictState.conflictKey                   = null;
        conflictState.conflictValue                 = null;
        conflictState.conflictIndex                 = -1;
        conflictState.conflictOtherIndex            = -1;
        conflictState.conflictLineHeight            = 0f;
        conflictState.conflictKeyPropertyExpanded   = false;
        conflictState.conflictValuePropertyExpanded = false;

        foreach (var entry1 in EnumerateEntries(keyArrayProperty, valueArrayProperty))
        {
            var    keyProperty1      = entry1.keyProperty;
            int    i                 = entry1.index;
            object keyProperty1Value = GetPropertyValue(keyProperty1);

            if (keyProperty1Value == null)
            {
                var valueProperty1 = entry1.valueProperty;
                SaveProperty(keyProperty1, valueProperty1, i, -1, conflictState);
                DeleteArrayElementAtIndex(keyArrayProperty, i);
                if (valueArrayProperty != null)
                {
                    DeleteArrayElementAtIndex(valueArrayProperty, i);
                }

                break;
            }


            foreach (var entry2 in EnumerateEntries(keyArrayProperty, valueArrayProperty, i + 1))
            {
                var    keyProperty2      = entry2.keyProperty;
                int    j                 = entry2.index;
                object keyProperty2Value = GetPropertyValue(keyProperty2);

                if (ComparePropertyValues(keyProperty1Value, keyProperty2Value))
                {
                    var valueProperty2 = entry2.valueProperty;
                    SaveProperty(keyProperty2, valueProperty2, j, i, conflictState);
                    DeleteArrayElementAtIndex(keyArrayProperty, j);
                    if (valueArrayProperty != null)
                    {
                        DeleteArrayElementAtIndex(valueArrayProperty, j);
                    }

                    goto breakLoops;
                }
            }
        }
breakLoops:

        EditorGUI.EndProperty();
    }
示例#4
0
    public void OnGUI()
    {
        //if (resizing)
        //{
        //	Debug.Log(Event.current);
        //	return;
        //}

        if (isTokenTooltip && Event.current.type == EventType.MouseMove ||
            Event.current.type == EventType.ScrollWheel ||
            Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
        {
            EditorApplication.delayCall += Hide;
            return;
        }
        if (this.text == null)
        {
            return;
        }

        var text = this.text;

        if (overloads != null && overloads.Length > 1)
        {
            if (horizontal)
            {
                text = "\u25c4" + (currentOverload + 1).ToString() + " of " + overloads.Length.ToString() + "\u25ba " + text;
            }
            else
            {
                text = "\u25b2" + (currentOverload + 1).ToString() + " of " + overloads.Length.ToString() + "\u25bc " + text;
            }
        }

        //wantsMouseMove = true;

        //if (focusedWindow == this && owner != null)
        //{
        //	owner.Focus();
        ////	GUIUtility.ExitGUI();
        //}

        if (Event.current.type == EventType.Layout)
        {
            var content = new GUIContent(text);
            style.fixedWidth = 0f;
            Vector2 size = style.font != null?style.CalcSize(content) : Vector2.zero;

            if (size.x > 700f)
            {
                size.x           = 700f;
                size.y           = style.CalcHeight(content, size.x);
                style.fixedWidth = size.x;
                //size = style.CalcSize(content);
            }
            SetSize(size.x + 10f, size.y + 10f);
            return;
        }

        //	if (Event.current.type == EventType.Repaint)
        {
            if (SISettings.useStandardColorInPopups)
            {
                //GUI.Label(new Rect(0f, 0f, position.width, position.height), GUIContent.none, textEditor.styles.lineNumbersSeparator);
                GUI.Label(new Rect(1f, 1f, position.width - 2, position.height - 2), GUIContent.none, textEditor.styles.scrollViewStyle);
            }
            else
            {
                GUI.Label(new Rect(0f, 0f, position.width, position.height), GUIContent.none, textEditor.styles.tooltipFrameStyle);
                GUI.Label(new Rect(1f, 1f, position.width - 2, position.height - 2), GUIContent.none, textEditor.styles.tooltipBgStyle);
            }

            if (!isTokenTooltip && textLines == null)
            {
                textLines = text.Split(new [] { '\n' });
            }

            var rc = new Rect(4f, 4f, position.width - 4f, position.height - 4);
            if (isTokenTooltip || currentParameterIndex < 0 ||
                overloads == null || currentOverload < 0 || currentOverload >= overloads.Length ||
                overloads[currentOverload].GetParameters().Count <= currentParameterIndex)
            {
                GUI.Label(rc, text, style);
            }
            else
            {
                for (int i = 0; i < textLines.Length; ++i)
                {
                    var lineContent = new GUIContent(textLines[i]);
                    if (i != currentParameterIndex + 1)
                    {
                        GUI.Label(rc, lineContent, style);
                        rc.yMin += style.CalcHeight(lineContent, rc.width);
                    }
                    else
                    {
                        GUI.Label(rc, lineContent, boldStyle);
                        rc.yMin += boldStyle.CalcHeight(lineContent, rc.width);
                    }
                }
            }
        }
    }
示例#5
0
        /*public static class PartIconGenerator
         * {
         *      private const string IconHiddenTag = "Icon_Hidden";
         *      private const string KerbalEvaSubstring = "kerbal";
         *
         *      private static readonly int GameObjectLayer = LayerMask.NameToLayer ("PartsList_Icons");
         *      // note to future: if creating icons inside editor, you might want to choose a different layer or translate the camera and object out of frame
         *
         *      private static Camera CreateCamera (int pixelWidth, int pixelHeight, Color backgroundColor)
         *      {
         *              //var camGo = new GameObject ("PartIconGenerator.Camera", typeof(Camera));
         *              //var cam = camGo.camera;
         *              Camera cam = new Camera();
         *
         *              cam.enabled = false;
         *              cam.cullingMask = (1 << GameObjectLayer);
         *              cam.clearFlags = ~CameraClearFlags.Nothing;
         *              cam.nearClipPlane = 0.1f;
         *              cam.farClipPlane = 10f;
         *              cam.orthographic = true;
         *              cam.backgroundColor = backgroundColor;
         *              cam.aspect = pixelWidth / (float)pixelHeight;
         *
         *              // Camera Size = x / ((( x / y ) * 2 ) * s )
         *              cam.orthographicSize = pixelWidth / (((pixelWidth / (float)pixelHeight) * 2f) * pixelHeight);
         *              cam.pixelRect = new Rect (0f, 0f, pixelWidth, pixelHeight);
         *
         *              return cam;
         *      }
         *
         *      private static Light CreateLight ()
         *      {
         *              var light = new GameObject ("PartIconGenerator.Light").AddComponent<Light> ();
         *
         *              light.type = LightType.Directional;
         *              light.color = XKCDColors.OffWhite;
         *              light.cullingMask = 1 << GameObjectLayer;
         *              light.intensity = 0.1f;
         *
         *              return light;
         *      }
         *
         *      private static GameObject CreateIcon (AvailablePart part)
         *      {
         *              // kerbalEVA doesn't seem to init at origin if we aren't explicit
         *              var go = UnityEngine.Object.Instantiate (part.iconPrefab, Vector3.zero, Quaternion.identity) as GameObject;
         *
         *              // The kerbals are initially facing along positive Z so we'll be looking at their backs if we don't
         *              // rotate them around
         *              if (part.name.StartsWith (KerbalEvaSubstring))
         *                      go.transform.rotation = Quaternion.AngleAxis (180f, Vector3.up);
         *
         *              go.SetLayerRecursive (GameObjectLayer);
         *              go.SetActive (true);
         *              return go;
         *      }
         *
         *      private static void AdjustScaleAndCameraPosition (GameObject icon, Camera camera)
         *      {
         *              // get size of prefab
         *              var bounds = CalculateBounds (icon);
         *              float sphereDiameter = Mathf.Max (bounds.size.x, bounds.size.y, bounds.size.z);
         *
         *              // rescale to size 1 unit so that object will take up as much viewspace as possible in ortho cam (with ortho size = 0.5)
         *              var currentScale = icon.transform.localScale;
         *              float scaleFactor = 1f / sphereDiameter;
         *              icon.transform.localScale = currentScale * scaleFactor;
         *
         *              icon.transform.position = -bounds.center * scaleFactor;
         *
         *              camera.transform.position = Vector3.zero;
         *
         *              // back out, else we'll be inside the model (which is scaled at 1 unit so this should be plenty)
         *              camera.transform.Translate (new Vector3 (0f, 0f, -5f), Space.Self);
         *              camera.transform.LookAt (Vector3.zero, Vector3.up);
         *      }
         *
         *
         *      public static Texture2D Create2D (AvailablePart part, int width, int height, Quaternion orientation, Color backgroundColor)
         *      {
         *              var cam = CreateCamera (width, height, backgroundColor);
         *              var icon = CreateIcon (part);
         *              var light = CreateLight ();
         *
         *              var texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
         *              var rt = RenderTexture.GetTemporary (width, height, 24);
         *              var prevRt = RenderTexture.active;
         *
         *              RenderTexture.active = rt;
         *
         *              icon.transform.rotation = orientation * icon.transform.rotation;
         *
         *              AdjustScaleAndCameraPosition (icon, cam);
         *
         *              cam.targetTexture = rt;
         *              cam.pixelRect = new Rect (0f, 0f, width, height); // doc says this should be ignored but doesn't seem to be (?) -- rendered area very small once targetTexture is set
         *              cam.Render ();
         *
         *              texture.ReadPixels (new Rect (0f, 0f, width, height), 0, 0, false);
         *              texture.Apply ();
         *
         *              RenderTexture.active = prevRt;
         *              RenderTexture.ReleaseTemporary (rt);
         *              UnityEngine.Object.DestroyImmediate (light);
         *              UnityEngine.Object.DestroyImmediate (cam);
         *              UnityEngine.Object.DestroyImmediate (icon);
         *
         *              return texture;
         *      }
         *
         *      private static Bounds CalculateBounds (GameObject go)
         *      {
         *              var renderers = go.GetComponentsInChildren<Renderer> (true).ToList ();
         *
         *              if (renderers.Count == 0)
         *                      return default(Bounds);
         *
         *              var boundsList = new List<Bounds> ();
         *
         *              renderers.ForEach (r => {
         *                      if (r.tag == IconHiddenTag)
         *                              return;
         *
         *                      if (r is SkinnedMeshRenderer) {
         *                              var smr = r as SkinnedMeshRenderer;
         *
         *                              // the localBounds of the SkinnedMeshRenderer are initially large enough
         *                              // to accomodate all animation frames; they're likely to be far off for
         *                              // parts that do a lot of animation-related movement (like solar panels expanding)
         *                              //
         *                              // We can get correct mesh bounds by baking the current animation into a mesh
         *                              // note: vertex positions in baked mesh are relative to smr.transform; any scaling
         *                              // is already baked in
         *                              var mesh = new Mesh ();
         *                              smr.BakeMesh (mesh);
         *
         *                              // while the mesh bounds will now be correct, they don't consider orientation at all.
         *                              // If a long part is oriented along the wrong axis in world space, the bounds we'd get
         *                              // here could be very wrong. We need to come up with essentially the renderer bounds:
         *                              // a bounding box in world space that encompasses the mesh
         *                              var m = Matrix4x4.TRS (smr.transform.position, smr.transform.rotation, Vector3.one
         *                                              // remember scale already factored in!
         *                                      );
         *                              var vertices = mesh.vertices;
         *
         *                              var smrBounds = new Bounds (m.MultiplyPoint3x4 (vertices [0]), Vector3.zero);
         *
         *                              for (int i = 1; i < vertices.Length; ++i)
         *                                      smrBounds.Encapsulate (m.MultiplyPoint3x4 (vertices [i]));
         *
         *                              UnityEngine.Object.Destroy (mesh);
         *
         *                              boundsList.Add (smrBounds);
         *                      } else if (r is MeshRenderer) { // note: there are ParticleRenderers, LineRenderers, and TrailRenderers
         *                              r.gameObject.GetComponent<MeshFilter> ().sharedMesh.RecalculateBounds ();
         *                              boundsList.Add (r.bounds);
         *                      }
         *              });
         *
         *              Bounds bounds = boundsList [0];
         *
         *              boundsList.Skip (1).ToList ().ForEach (b => bounds.Encapsulate (b));
         *
         *              return bounds;
         *      }
         * }*/

        private void OnGUI()
        {
            if (tooltipstyle == null)
            {
                setStyles();
            }

            if (osdtime > Time.time)
            {
                float osdheight = osdstyle.CalcSize(new GUIContent(osdmessage)).y;
                GUILayout.BeginArea(new Rect(0, Screen.height * 0.1f, Screen.width, osdheight), osdstyle);
                GUILayout.Label(osdmessage, osdstyle);
                GUILayout.EndArea();
            }

            if (visible)
            {
                if (refreshwait > 0)
                {
                    refreshwait = refreshwait - 1;
                }
                else
                {
                    switch (mystate)
                    {
                    case ASPState.IDLE:

                        EditorLogic   editor = EditorLogic.fetch;
                        ShipConstruct ship   = editor.ship;
                        if (ship != null)
                        {
                            List <Part> parts = ship.parts;
                            if ((parts != null) && (parts.Count > 0) && (parts [0] != null))
                            {
                                parts [0].SetHighlight(false, true);
                                if (tanks == null)
                                {
                                    tanks = ASPStaging.findFuelTanks(parts);
                                }
                                else
                                {
                                    if (vizualize)
                                    {
                                        if ((badDestTank != null) && (badStartTank != null))
                                        {
                                            drawLineBetweenBadParts();
                                        }
                                        foreach (Part p in parts)
                                        {
                                            if (p != null)
                                            {
                                                if ((badStartTank != null) && (p == badStartTank))
                                                {
                                                    Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position);
                                                    GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "Start tank");
                                                    badStartTank.SetHighlightColor(Color.blue);
                                                    badStartTank.SetHighlight(true, false);
                                                    badStartTank.highlightType = Part.HighlightType.AlwaysOn;
                                                }
                                                else if ((badDestTank != null) && (p == badDestTank))
                                                {
                                                    Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position);
                                                    GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "Destination tank");
                                                    badDestTank.SetHighlightColor(Color.blue);
                                                    badDestTank.SetHighlight(true, false);
                                                    badDestTank.highlightType = Part.HighlightType.AlwaysOn;
                                                }
                                                else if (blockingTanks.Contains(p))
                                                {
                                                    Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position);
                                                    GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), "X");
                                                    p.SetHighlightColor(Color.red);
                                                    p.SetHighlight(true, false);
                                                    p.highlightType = Part.HighlightType.AlwaysOn;
                                                }
                                                else if (tanks.Contains(p))
                                                {
                                                    // draw labels on the tanks
                                                    Vector3 position = Camera.main.WorldToScreenPoint(p.transform.position);
                                                    string  label    = "L" + ASPFuelLine.countDecouplersToRoot(p).ToString();
#if DEBUG
                                                    //label = label+": "+ASPConsoleStuff.getFriendlyName (p.craftID.ToString ());
#endif
                                                    GUI.Label(new Rect(position.x, Screen.height - position.y, 200, 30), label);
                                                    if ((p != badStartTank) && (p != badDestTank) && (!blockingTanks.Contains(p)))
                                                    {
                                                        p.SetHighlightColor(Color.green);
                                                        p.SetHighlight(true, false);
                                                        p.highlightType = Part.HighlightType.AlwaysOn;
                                                    }
                                                }
                                                else if (ASPStaging.isDecoupler(p))
                                                {
                                                    p.SetHighlightColor(Color.magenta);
                                                    p.SetHighlight(true, false);
                                                    p.highlightType = Part.HighlightType.AlwaysOn;
                                                }
                                                else
                                                {
                                                    p.SetHighlight(false, false);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            windowRect = ClickThruBlocker.GUILayoutWindow(windowID, clampToScreen(windowRect), OnWindow, "AutoAsparagus " + versionString);

                            mousepos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

                            if ((tooltip != null) && (tooltip.Length > 0))
                            {
                                GUI.depth = 0;
                                Vector2 size = tooltipstyle.CalcSize(new GUIContent(tooltip));
                                Rect    rect = new Rect(Input.mousePosition.x + 20, (Screen.height - Input.mousePosition.y) + 20, size.x, size.y);
                                rect = clampToScreen(rect);
                                GUILayout.BeginArea(rect);
                                GUILayout.Label(tooltip, tooltipstyle);
                                GUILayout.EndArea();
                            }
                        }
                        break;

                    case ASPState.ERROR:
                        vizualize = true;
                        mystate   = ASPState.IDLE;
                        break;

                    case ASPState.ADDASP:
                        ASPConsoleStuff.ListTheShip();
                        mystate = ASPState.CONNECT;
                        ASPFuelLine.AddAsparagusFuelLines(partsWeCanUse [partToUseIndex], textureIndex, partTexturePaths [partToUseIndex], partTextureNames [partToUseIndex], rainbow);
                        if (mystate == ASPState.CONNECT)
                        {
                            osd("Connecting parts...");
                        }
                        refreshwait = 100;
                        break;

                    case ASPState.ADDONION:
                        ASPConsoleStuff.ListTheShip();
                        mystate = ASPState.CONNECT;
                        ASPFuelLine.AddOnionFuelLines(partsWeCanUse [partToUseIndex], textureIndex, partTexturePaths [partToUseIndex], partTextureNames [partToUseIndex], rainbow);
                        if (mystate == ASPState.CONNECT)
                        {
                            osd("Connecting parts...");
                        }
                        refreshwait = 100;
                        break;

                    case ASPState.CONNECT:
                        ASPFuelLine.connectFuelLines();
                        refreshwait = 100;
                        osd("Refreshing ship...");
                        mystate = ASPState.AFTERCONNECT;
                        break;

                    case ASPState.AFTERCONNECT:
                        newReloadShip();
                        refreshwait = 100;
                        if (useSmartStage)
                        {
                            mystate = ASPState.SMARTSTAGE;
                            osd("Calling SmartStage...");
                            ASPConsoleStuff.AAprint("Calling SmartStage");
                        }
                        else
                        {
                            mystate = ASPState.ADDSTAGES;
                            osd("Adding empty stages...");
                        }
                        break;

                    case ASPState.ADDSTAGES:
                        ASPStaging.AddEmptyStages();
                        mystate = ASPState.STAGE;
                        osd("Staging decouplers...");
                        refreshwait = 10;
                        break;

                    case ASPState.STAGE:
                        ASPStaging.AsaparagusTheShip(partsWeCanUse [partToUseIndex].name);
                        mystate = ASPState.AFTERSTAGE;
                        osd("Decoupler staging done, refreshing...");
                        refreshwait = 10;
                        break;

                    case ASPState.CLAMPS:
                        if (stageLaunchClamps)
                        {
                            ASPStaging.StageLaunchClamps(launchClampsStage);
                        }
                        mystate = ASPState.FINALREFRESH;
                        osd("Done!");
                        refreshwait = 10;
                        break;

                    case ASPState.DELETEFUEL:
                        ASPConsoleStuff.ListTheShip();
                        int count = ASPFuelLine.DeleteAllFuelLines(partsWeCanUse [partToUseIndex].name);
                        newReloadShip();
                        osd(count.ToString() + " parts deleted.");
                        mystate = ASPState.IDLE;
                        break;

                    case ASPState.FINALREFRESH:
                        newReloadShip();
                        mystate = ASPState.IDLE;
                        osd("Done!");
                                                #if DEBUG
                        tanks = ASPStaging.findFuelTanks(EditorLogic.fetch.ship.Parts);
                                                #endif
                        break;

                    case ASPState.AFTERSTAGE:
                        newReloadShip();
                        if (stageLaunchClamps)
                        {
                            osd("Staging launch clamps...");
                            mystate     = ASPState.CLAMPS;
                            refreshwait = 10;
                        }
                        else
                        {
                            osd("Done!");
                            mystate = ASPState.IDLE;
                        }
                        break;

                    case ASPState.SMARTSTAGE:
                        mystate = ASPState.FINALREFRESH;
                        try {
                            computeStagesMethod.Invoke(null, new object[] { });
                        } catch (Exception e) {
                            UnityEngine.Debug.LogError("Error invoking method\n" + e.StackTrace);
                        }
                        osd("Done!");
                        break;
                    }
                }
            }
        }
    static void OnTwoFactorAuthenticationGUI()
    {
        const int ENTER_2FA_CODE_BORDER_SIZE         = 20;
        const int ENTER_2FA_CODE_BUTTON_WIDTH        = 260;
        const int ENTER_2FA_CODE_VERIFY_BUTTON_WIDTH = ENTER_2FA_CODE_BUTTON_WIDTH / 2;
        const int ENTER_2FA_CODE_ENTRY_REGION_WIDTH  = 130;
        const int ENTER_2FA_CODE_MIN_WINDOW_WIDTH    = ENTER_2FA_CODE_VERIFY_BUTTON_WIDTH + ENTER_2FA_CODE_ENTRY_REGION_WIDTH + (ENTER_2FA_CODE_BORDER_SIZE * 3);

        bool isValidAuthenticationCode = IsValidAuthenticationCodeFormat();


        // Invalid code text
        if (entered2faCodeIsInvalid)
        {
            GUIStyle s = new GUIStyle(EditorStyles.label);
            s.alignment        = TextAnchor.UpperLeft;
            s.normal.textColor = Color.red;
            s.fontSize         = WARNING_FONT_HEIGHT;
            s.padding          = new RectOffset(0, 0, (WARNING_ICON_SIZE - s.fontSize) / 2, 0);
            s.fixedHeight      = WARNING_ICON_SIZE;

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            var textDimensions = s.CalcSize(new GUIContent(ENTER_2FA_CODE_INVALID_CODE_STRING));
            GUILayout.Label(new GUIContent(warningIconGraphic), GUILayout.Width(WARNING_ICON_SIZE), GUILayout.Height(WARNING_ICON_SIZE));
            EditorGUILayout.LabelField(ENTER_2FA_CODE_INVALID_CODE_STRING, s, GUILayout.Width(textDimensions.x));
            EditorGUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
        else if (checkingCode)
        {
            // Display checking code message
            EditorGUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUIStyle s = new GUIStyle(EditorStyles.label);
            s.alignment   = TextAnchor.MiddleCenter;
            s.fixedHeight = WARNING_ICON_SIZE;
            EditorGUILayout.LabelField(CHECKING_2FA_CODE_STRING, s, GUILayout.Height(WARNING_ICON_SIZE));
            EditorGUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
        }
        else
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(ENTER_2FA_CODE_BORDER_SIZE);
            GUILayout.FlexibleSpace();
            GUIStyle titleStyle = new GUIStyle(EditorStyles.label);
            titleStyle.alignment = TextAnchor.MiddleCenter;
            titleStyle.wordWrap  = true;
            EditorGUILayout.LabelField(ENTER_2FA_CODE_TITLE_STRING, titleStyle, GUILayout.Width(ENTER_2FA_CODE_MIN_WINDOW_WIDTH - (2 * ENTER_2FA_CODE_BORDER_SIZE)), GUILayout.Height(WARNING_ICON_SIZE), GUILayout.ExpandHeight(true));
            GUILayout.FlexibleSpace();
            GUILayout.Space(ENTER_2FA_CODE_BORDER_SIZE);
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(ENTER_2FA_CODE_BORDER_SIZE);
        GUILayout.FlexibleSpace();
        Vector2 size = EditorStyles.boldLabel.CalcSize(new GUIContent(ENTER_2FA_CODE_LABEL_STRING));

        EditorGUILayout.LabelField(ENTER_2FA_CODE_LABEL_STRING, EditorStyles.boldLabel, GUILayout.MaxWidth(size.x));
        authenticationCode = EditorGUILayout.TextField(authenticationCode);

        // Verify 2FA code button
        if (GUILayout.Button(ENTER_2FA_CODE_VERIFY_STRING, GUILayout.Width(ENTER_2FA_CODE_VERIFY_BUTTON_WIDTH)))
        {
            checkingCode = true;
            APIUser.VerifyTwoFactorAuthCode(authenticationCode, isValidAuthenticationCode ? API2FA.TIME_BASED_ONE_TIME_PASSWORD_AUTHENTICATION : API2FA.ONE_TIME_PASSWORD_AUTHENTICATION, username, password,
                                            delegate
            {
                // valid 2FA code submitted
                entered2faCodeIsInvalid      = false;
                authorizationCodeWasVerified = true;
                checkingCode = false;
                showTwoFactorAuthenticationEntry = false;
                if (null != onAuthenticationVerifiedAction)
                {
                    onAuthenticationVerifiedAction();
                }
            },
                                            delegate
            {
                entered2faCodeIsInvalid = true;
                checkingCode            = false;
            }
                                            );
        }

        GUILayout.FlexibleSpace();
        GUILayout.Space(ENTER_2FA_CODE_BORDER_SIZE);
        EditorGUILayout.EndHorizontal();

        GUILayout.FlexibleSpace();

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        // after user has entered an invalid code causing the invalid code message to be displayed,
        // edit the code will change it's length meaning it is invalid format, so we can clear the invalid code setting until they resubmit
        if (previousAuthenticationCodeLength != authenticationCode.Length)
        {
            previousAuthenticationCodeLength = authenticationCode.Length;
            entered2faCodeIsInvalid          = false;
        }

        GUI.enabled = true;
        GUILayout.FlexibleSpace();
        GUILayout.Space(ENTER_2FA_CODE_BORDER_SIZE);
        EditorGUILayout.EndHorizontal();

        GUILayout.FlexibleSpace();

        // Two-Factor Authentication Help button
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(ENTER_2FA_CODE_HELP_STRING))
        {
            Application.OpenURL(TWO_FACTOR_AUTHENTICATION_HELP_URL);
        }
        EditorGUILayout.EndHorizontal();

        // Cancel button
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button(ENTER_2FA_CODE_CANCEL_STRING))
        {
            showTwoFactorAuthenticationEntry = false;
            Logout();
        }
        EditorGUILayout.EndHorizontal();
    }
示例#7
0
    void OnGUI()
    {
        // init stuff that HAS to be inside OnGUI()
        if (firstTime)
        {
            firstTime = false;

            GUI.skin.label.wordWrap = true;
            // setup vertical span sizes
            GC          = new GUIContent("Qypjg");
            GS          = "Box";
            GS.font     = Font;
            GS.fontSize = 24;
            VSpanBox    = GS.CalcSize(GC).y;
            GS          = "Button";
            GS.font     = Font;
            GS.fontSize = 16;
            VSpanButton = GS.CalcSize(GC).y;
            GS          = "Label";
            GS.font     = Font;
            GS.fontSize = 16;
            VSpanLabel  = GS.CalcSize(GC).y;
        }

        //setupSkin();
        GUI.skin.button.hover.textColor  = S.ShoutyBlue;
        GUI.skin.button.active.textColor = S.Purple;

        // if screen dimensions changed
        if (oldW != Screen.width ||
            oldH != Screen.height)
        {
            oldW = Screen.width;
            oldH = Screen.height;
            // sizes of UI elements
            midX          = oldW / 2;
            midY          = oldH / 2;
            Window.width  = oldW * (S.GoldenRatio / (1f + S.GoldenRatio));
            Window.height = oldH * (S.GoldenRatio / (1f + S.GoldenRatio));
            Window.x      = (Screen.width - Window.width) / 2;
            Window.y      = (Screen.height - Window.height) / 2;
        }



        // handle all the modes!
        switch (Mode)
        {
        case HudMode.Playing:
            TopOfMaxedLog = playMode.Draw(net, arse, midX, midY, VSpanLabel, this);
            maybePromptClickIn();
            break;

        case HudMode.NewGame:
        case HudMode.MatchSetup:
            matchSetup.Draw(net.InServerMode, net, this, vSpan);
            break;

        case HudMode.SplashLogos:
            showSplashLogos();
            break;

        case HudMode.MainMenu:
            if (!net.Connected)
            {
                avatarView();
            }

            menuMain();
            break;

        case HudMode.About:
            // maybe this should be titled "ABOUT"?  would be more accurate?... and more standard
            menuBegin();

            // if future goals scope changed
            if (aboutMenu.Draw(this))
            {
                scrollPos = Vector2.zero;
            }

            menuEnd();
            break;

        case HudMode.Controls:
            break;

        case HudMode.Settings:
            avatarView();
            drawSettings();
            if (                    //null != net &&
                null != net.LocEnt &&
                null != net.LocEnt.Actor
                )
            {
                net.LocEnt.Actor.FOV = locUser.FOV;
            }
            break;

        case HudMode.Credits:
            credits();
            break;

        case HudMode.ConnectionError:
            drawSimpleWindow(net.Error, Color.red);
            break;

        case HudMode.Connecting:
            drawSimpleWindow("", S.Orange);
            break;

        case HudMode.InitializingServer:
            drawSimpleWindow("", Color.yellow);
            break;

        case HudMode.Wait:
            if (Debug.isDebugBuild)
            {
                S.OutlinedLabel(
                    new Rect(0, 0, Screen.width, Screen.height),
                    "Wait"
                    );
            }
            else
            {
                drawSimpleWindow("", Color.green);
            }
            break;

        // server
        case HudMode.KickAPlayer:
            kickWindow();
            break;
        }

        // intermission countdown til next match
        if (net.Connected &&
            net.gameOver)
        {
            string s = "Next Game in: " + Mathf.FloorToInt(net.IntermissionTimeLeft).ToString() + " seconds.";
            S.SetShoutyColor();
            S.OutlinedLabel(new Rect(midX - 50, 5, 200, 30), s);
        }
    }
示例#8
0
 public static Rect GetArea(Rect area, GUIContent c, GUIStyle style)
 {
     return(GetArea(area, style.CalcSize(c), style));
 }
示例#9
0
                private void HeaderUi(int level, bool hasError)
                {
                    var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0));

                    BGEditorUtility.SwapGuiBackgroundColor(color, () =>
                    {
                        BGEditorUtility.Horizontal(headerBoxStyle, () =>
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")",
                                                             descriptor == null ? null : descriptor.Description);
                                var width = headerFoldoutStyle.CalcSize(content).x + 16;

                                BGEditorUtility.SwapLabelWidth((int)width, () =>
                                {
                                    //foldout (we dont use layout version cause it does not support clickin on labels)
                                    Collapsed = EditorGUI.Foldout(
                                        GUILayoutUtility.GetRect(width, 16f),
                                        Collapsed,
                                        content,
                                        true,
                                        Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled);
                                });
                            });

                            GUILayout.FlexibleSpace();

                            // status(error or Ok)
                            EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle);


                            //help url
                            if (!String.IsNullOrEmpty(Cc.HelpURL))
                            {
                                if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGHelp123, "Open help in the browser"))
                                {
                                    Application.OpenURL(Cc.HelpURL);
                                }
                                EditorGUILayout.Separator();
                            }

                            //change visibility
                            if (BGEditorUtility.ButtonWithIcon(Cc.Hidden ? BGBinaryResources.BGHiddenOn123 : BGBinaryResources.BGHiddenOff123, "Hide/Show properties"))
                            {
                                Cc.Hidden = !Cc.Hidden;
                            }
                            EditorGUILayout.Separator();

                            //change name
                            if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCcEditName123, "Change the name"))
                            {
                                BGCcChangeNameWindow.Open(Cc);
                            }
                            EditorGUILayout.Separator();

                            //add a child
                            if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add a component, which is dependant on this component"))
                            {
                                BGCcAddWindow.Open(MyTree.Curve, type =>
                                {
                                    //cache some data
                                    var gameObject    = Cc.Curve.gameObject;
                                    var oldComponents = gameObject.GetComponents <BGCc>();
                                    var currentCcType = Cc.GetType();

                                    //add
                                    var addedCc = AddComponent(MyTree.Curve, type);
                                    if (addedCc == null)
                                    {
                                        return;
                                    }

                                    //we need to process all the way up to the Cc and link Ccs to right (newly created) parents
                                    var parentClass    = addedCc.GetParentClass();
                                    var recursionLimit = 16;
                                    var cc             = addedCc;
                                    while (parentClass != null && recursionLimit-- > 0)
                                    {
                                        if (currentCcType == parentClass)
                                        {
                                            //we reached the current Cc
                                            cc.SetParent(Cc);
                                            break;
                                        }

                                        //going up
                                        var possibleParents = gameObject.GetComponents(parentClass);
                                        var parent          = possibleParents.Where(possibleParent => !oldComponents.Contains(possibleParent)).Cast <BGCc>().FirstOrDefault();

                                        if (parent == null)
                                        {
                                            break;
                                        }

                                        cc.SetParent(parent);
                                        cc          = parent;
                                        parentClass = cc.GetParentClass();
                                    }
                                }, Cc.GetType());
                            }
                            EditorGUILayout.Separator();


                            //enable/disable
                            if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? BGBinaryResources.BGTickYes123 : BGBinaryResources.BGTickNo123, "Enable/disable a component"))
                            {
                                Enable(!Cc.enabled);
                            }
                            EditorGUILayout.Separator();

                            //delete
                            if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Remove this component"))
                            {
                                return;
                            }


                            //remove
                            Delete();

                            EditorUtility.SetDirty(MyTree.Curve.gameObject);

                            //not sure how to make proper exit
                            throw new BGEditorUtility.ExitException();
                        });
                    });
                }
示例#10
0
 public EllipsisStyleMetric(GUIStyle aStyle)
 {
     style     = aStyle;
     pixelSize = aStyle.CalcSize(new GUIContent(ellipsisString));
 }
示例#11
0
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.Vector2)
            {
                EditorGUI.LabelField(rect, label,
                                     "Invalid property. Use the MinMaxSlider only with Vector2 fields.");
                return;
            }

            rect.height = EditorGUIUtility.singleLineHeight;

            var min = property.vector2Value.x;
            var max = property.vector2Value.y;

            EditorGUI.BeginChangeCheck();

            EditorGUI.MinMaxSlider(rect, label, ref min, ref max, Attribute.minValue, Attribute.maxValue);

            rect.y += EditorGUIUtility.singleLineHeight + 2;

            rect.x     += EditorGUIUtility.labelWidth;
            rect.width -= EditorGUIUtility.labelWidth;

            rect.width = rect.width / 2 - 5;

            var inLabel = new GUIContent("Min");
            var inRect  = rect;

            inRect.width = LabelStyle.CalcSize(inLabel).x + 5;

            EditorGUI.LabelField(inRect, inLabel);

            inRect.x    += inRect.width;
            inRect.width = rect.width - inRect.width;

            if (Attribute.minValueString == null || Mathf.RoundToInt(Attribute.minValue - min) != 0)
            {
                min = EditorGUI.FloatField(inRect, GUIContent.none, min);
            }
            else
            {
                EditorGUI.LabelField(inRect, GUIContent.none, new GUIContent(Attribute.minValueString));
            }

            rect.x += rect.width + 10;

            inRect       = rect;
            inLabel.text = "Max";

            inRect.width = LabelStyle.CalcSize(inLabel).x + 5;

            EditorGUI.LabelField(inRect, inLabel);

            inRect.x    += inRect.width;
            inRect.width = rect.width - inRect.width;

            if (Attribute.maxValueString == null || Mathf.RoundToInt(Attribute.maxValue - max) != 0)
            {
                max = EditorGUI.FloatField(inRect, GUIContent.none, max);
            }
            else
            {
                EditorGUI.LabelField(inRect, GUIContent.none, new GUIContent(Attribute.maxValueString));
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (Attribute.roundValues)
                {
                    min = Mathf.Round(min);
                    max = Mathf.Round(max);
                }

                property.vector2Value = new Vector2(min, max);
            }
        }
        public void DrawItem(Rect position, int index, bool selected, bool focused)
        {
            Command command = this[index].objectReferenceValue as Command;

            if (command == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            var flowchart = (Flowchart)command.GetFlowchart();

            if (flowchart == null)
            {
                return;
            }

            bool isComment = command.GetType() == typeof(Comment);
            bool isLabel   = (command.GetType() == typeof(Label));

            bool   error   = false;
            string summary = command.GetSummary();

            if (summary == null)
            {
                summary = "";
            }
            else
            {
                summary = summary.Replace("\n", "").Replace("\r", "");
            }
            if (summary.StartsWith("Error:"))
            {
                error = true;
            }

            if (isComment || isLabel)
            {
                summary = "<b> " + summary + "</b>";
            }
            else
            {
                summary = "<i>" + summary + "</i>";
            }

            bool commandIsSelected = false;

            foreach (Command selectedCommand in flowchart.SelectedCommands)
            {
                if (selectedCommand == command)
                {
                    commandIsSelected = true;
                    break;
                }
            }

            string commandName = commandInfoAttr.CommandName;

            GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box);

            commandLabelStyle.normal.background = FungusEditorResources.CommandBackground;
            int borderSize = 5;

            commandLabelStyle.border.top    = borderSize;
            commandLabelStyle.border.bottom = borderSize;
            commandLabelStyle.border.left   = borderSize;
            commandLabelStyle.border.right  = borderSize;
            commandLabelStyle.alignment     = TextAnchor.MiddleLeft;
            commandLabelStyle.richText      = true;
            commandLabelStyle.fontSize      = 11;
            commandLabelStyle.padding.top  -= 1;

            float indentSize = 20;

            for (int i = 0; i < command.IndentLevel; ++i)
            {
                Rect indentRect = position;
                indentRect.x       += i * indentSize;// - 21;
                indentRect.width    = indentSize + 1;
                indentRect.y       -= 2;
                indentRect.height  += 5;
                GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f);
                GUI.Box(indentRect, "", commandLabelStyle);
            }

            float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f);
            float indentWidth      = command.IndentLevel * indentSize;

            Rect commandLabelRect = position;

            commandLabelRect.x      += indentWidth;                        // - 21;
            commandLabelRect.y      -= 2;
            commandLabelRect.width  -= (indentSize * command.IndentLevel); // - 22);
            commandLabelRect.height += 5;

            // There's a weird incompatibility between the Reorderable list control used for the command list and
            // the UnityEvent list control used in some commands. In play mode, if you click on the reordering grabber
            // for a command in the list it causes the UnityEvent list to spew null exception errors.
            // The workaround for now is to hide the reordering grabber from mouse clicks by extending the command
            // selection rectangle to cover it. We are planning to totally replace the command list display system.
            Rect clickRect = position;

            //clickRect.x -= 20;
            //clickRect.width += 20;

            // Select command via left click
            if (Event.current.type == EventType.MouseDown &&
                Event.current.button == 0 &&
                clickRect.Contains(Event.current.mousePosition))
            {
                if (flowchart.SelectedCommands.Contains(command) && Event.current.button == 0)
                {
                    // Left click on already selected command
                    // Command key and shift key is not pressed
                    if (!EditorGUI.actionKey && !Event.current.shift)
                    {
                        BlockEditor.actionList.Add(delegate
                        {
                            flowchart.SelectedCommands.Remove(command);
                            flowchart.ClearSelectedCommands();
                        });
                    }

                    // Command key pressed
                    if (EditorGUI.actionKey)
                    {
                        BlockEditor.actionList.Add(delegate
                        {
                            flowchart.SelectedCommands.Remove(command);
                        });
                        Event.current.Use();
                    }
                }
                else
                {
                    bool shift = Event.current.shift;

                    // Left click and no command key
                    if (!shift && !EditorGUI.actionKey && Event.current.button == 0)
                    {
                        BlockEditor.actionList.Add(delegate
                        {
                            flowchart.ClearSelectedCommands();
                        });
                        Event.current.Use();
                    }

                    BlockEditor.actionList.Add(delegate
                    {
                        flowchart.AddSelectedCommand(command);
                    });

                    // Find first and last selected commands
                    int firstSelectedIndex = -1;
                    int lastSelectedIndex  = -1;
                    if (flowchart.SelectedCommands.Count > 0)
                    {
                        if (flowchart.SelectedBlock != null)
                        {
                            for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; i++)
                            {
                                Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
                                foreach (Command selectedCommand in flowchart.SelectedCommands)
                                {
                                    if (commandInBlock == selectedCommand)
                                    {
                                        firstSelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                            for (int i = flowchart.SelectedBlock.CommandList.Count - 1; i >= 0; i--)
                            {
                                Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
                                foreach (Command selectedCommand in flowchart.SelectedCommands)
                                {
                                    if (commandInBlock == selectedCommand)
                                    {
                                        lastSelectedIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (shift)
                    {
                        int currentIndex = command.CommandIndex;
                        if (firstSelectedIndex == -1 ||
                            lastSelectedIndex == -1)
                        {
                            // No selected command found - select entire list
                            firstSelectedIndex = 0;
                            lastSelectedIndex  = currentIndex;
                        }
                        else
                        {
                            if (currentIndex < firstSelectedIndex)
                            {
                                firstSelectedIndex = currentIndex;
                            }
                            if (currentIndex > lastSelectedIndex)
                            {
                                lastSelectedIndex = currentIndex;
                            }
                        }

                        for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i)
                        {
                            var selectedCommand = flowchart.SelectedBlock.CommandList[i];
                            BlockEditor.actionList.Add(delegate
                            {
                                flowchart.AddSelectedCommand(selectedCommand);
                            });
                        }
                    }

                    Event.current.Use();
                }
                GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus)
            }

            Color commandLabelColor = Color.white;

            if (flowchart.ColorCommands)
            {
                commandLabelColor = command.GetButtonColor();
            }

            if (commandIsSelected)
            {
                commandLabelColor = Color.green;
            }
            else if (!command.enabled)
            {
                commandLabelColor = Color.grey;
            }
            else if (error)
            {
                // TODO: Show warning icon
            }

            GUI.backgroundColor = commandLabelColor;

            if (isComment)
            {
                GUI.Label(commandLabelRect, "", commandLabelStyle);
            }
            else
            {
                string commandNameLabel;
                if (flowchart.ShowLineNumbers)
                {
                    commandNameLabel = command.CommandIndex.ToString() + ": " + commandName;
                }
                else
                {
                    commandNameLabel = commandName;
                }

                GUI.Label(commandLabelRect, commandNameLabel, commandLabelStyle);
            }

            if (command.ExecutingIconTimer > Time.realtimeSinceStartup)
            {
                Rect iconRect = new Rect(commandLabelRect);
                iconRect.x     += iconRect.width - commandLabelRect.width - 20;
                iconRect.width  = 20;
                iconRect.height = 20;

                Color storeColor = GUI.color;

                float alpha = (command.ExecutingIconTimer - Time.realtimeSinceStartup) / FungusConstants.ExecutingIconFadeTime;
                alpha = Mathf.Clamp01(alpha);

                GUI.color = new Color(1f, 1f, 1f, alpha);
                GUI.Label(iconRect, FungusEditorResources.PlaySmall, new GUIStyle());

                GUI.color = storeColor;
            }

            Rect summaryRect = new Rect(commandLabelRect);

            if (isComment)
            {
                summaryRect.x += 5;
            }
            else
            {
                summaryRect.x     += commandNameWidth + 5;
                summaryRect.width -= commandNameWidth + 5;
            }

            GUIStyle summaryStyle = new GUIStyle();

            summaryStyle.fontSize       = 10;
            summaryStyle.padding.top   += 5;
            summaryStyle.richText       = true;
            summaryStyle.wordWrap       = false;
            summaryStyle.clipping       = TextClipping.Clip;
            commandLabelStyle.alignment = TextAnchor.MiddleLeft;
            GUI.Label(summaryRect, summary, summaryStyle);

            if (error)
            {
                GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
                Rect    errorRect  = new Rect(summaryRect);
                errorRect.x    += errorRect.width - 20;
                errorRect.y    += 2;
                errorRect.width = 20;
                GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background);
                summaryRect.width -= 20;
            }

            GUI.backgroundColor = Color.white;
        }
示例#13
0
 void Start()
 {
     rect          = new Rect();
     rect.position = buttonPosition;
     rect.size     = buttonBorderStyle.CalcSize(new GUIContent(text));
 }
示例#14
0
 public static int WidthOf(string s, GUIStyle style)
 {
     return((int)style.CalcSize(new GUIContent(s)).x);
 }
示例#15
0
        /*	public static Color SelectionColor {
         *              get {
         *                      if( selectionColor == null )
         *                              selectionColor
         *                      return selectionColor;
         *              }
         *      }*/

        public static int WidthOf(GUIContent s, GUIStyle style)
        {
            return((int)style.CalcSize(s).x);
        }
示例#16
0
 public Vector2 CalcSize()
 {
     return(m_Style.CalcSize(m_Content));
 }
 public Styles()
 {
     labelHeight = new GUIStyle(GUI.skin.label);
     labelHeight.fixedHeight = 64;
     buttonWidth = Mathf.Max(Mathf.Max(button.CalcSize(saveSelected).x, button.CalcSize(saveAll).x), button.CalcSize(dontSave).x);
 }
示例#18
0
 public static Rect GetArea(Rect area, string str, GUIStyle style)
 {
     return(GetArea(area, style.CalcSize(new GUIContent(str)), style));
 }
示例#19
0
        private void OnGUI()
        {
            if (data == null)
            {
                return;
            }

            if (Event.current.type == EventType.layout)
            {
                return;
            }

            if (Event.current.type == EventType.ScrollWheel)
            {
                scrollPosition = Mathf.Clamp(scrollPosition + (int)Event.current.delta.y, 0, filteredData.Count - maxListItems);
                scrollPosition = Mathf.Clamp(scrollPosition, 0, Mathf.Max(0, filteredData.Count - maxListItems));
                Event.current.Use();
            }

            scrollViewRect = new Rect(0f, 0f, position.width, position.height);
            GUI.Label(scrollViewRect, GUIContent.none, textEditor.styles.listFrameStyle);

            scrollViewRect.xMin++;
            scrollViewRect.yMin++;
            scrollViewRect.xMax--;
            scrollViewRect.yMax--;

            GUI.Label(scrollViewRect, GUIContent.none, textEditor.styles.listBgStyle);

            var rcScrollBar = new Rect(scrollViewRect);

            rcScrollBar.xMin = rcScrollBar.xMax - 15f;
            if (filteredData.Count > maxListItems)
            {
                object oldValue = boxedFloat10;
                if (Event.current.isMouse)
                {
                    if (scrollStepSizeField == null)
                    {
                        scrollStepSizeField = typeof(GUI).GetField("scrollStepSize", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
                    }
                    if (scrollStepSizeField != null)
                    {
                        oldValue = scrollStepSizeField.GetValue(null);
                        scrollStepSizeField.SetValue(null, boxedFloat1);
                    }
                }

                scrollPosition = (int)GUI.VerticalScrollbar(rcScrollBar, scrollPosition, maxListItems, 0, filteredData.Count);
                scrollPosition = Mathf.Clamp(scrollPosition, 0, Mathf.Max(0, filteredData.Count - maxListItems));

                if (Event.current.isMouse && scrollStepSizeField != null)
                {
                    scrollStepSizeField.SetValue(null, oldValue);
                }
            }

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 &&
                (filteredData.Count <= maxListItems || Event.current.mousePosition.x < rcScrollBar.x))
            {
                var itemIndex = Mathf.Clamp((int)(Event.current.mousePosition.y / listItemHeight), 0, maxListItems - 1);
                currentItem = Mathf.Clamp(itemIndex + scrollPosition, 0, filteredData.Count - 1);
                //owner.Focus();

                Event.current.Use();

                if (Event.current.clickCount == 2)
                {
                    completeOnUpdate = true;
                    //owner.SendEvent(EditorGUIUtility.CommandEvent("ScriptInspector.Autocomplete=" + filteredData[currentItem].name));
                }

                //Repaint();
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                var width = 100f;
                for (var i = Mathf.Min(filteredData.Count, scrollPosition + maxListItems) - 1; i >= scrollPosition; --i)
                {
                    var itemContent = new GUIContent(ItemDisplayString(filteredData[i], "<b>" + filteredData[i].GetName() + "</b>"));
                    if (filteredData[i].GetTypeParameters() != null)
                    {
                        itemContent.text += "<>";
                    }
                    width = Mathf.Max(width, listItemStyle.CalcSize(itemContent).x);
                }
                var rc = position;
                rc.width  = Mathf.Max(rc.width, width + 24f + (filteredData.Count > maxListItems ? 21f : 2f));
                rc.height = listItemHeight * Mathf.Min(maxListItems, filteredData.Count) + 2f;
                if (!isSizeSet || rc != position)
                {
                    SetSize(rc.width, rc.height);
                    isSizeSet = true;
                }

                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));

                System.Text.StringBuilder sb = null;
                for (var i = Mathf.Min(filteredData.Count, scrollPosition + maxListItems + 1); --i >= scrollPosition;)
                {
                    var rcItem = new Rect(2f, 1f + listItemHeight * (i - scrollPosition), position.width - 3f, listItemHeight);
                    if (filteredData.Count > maxListItems)
                    {
                        rcItem.xMax -= 15f;
                    }

                    var on         = i == currentItem;
                    var focus      = on || ~i == currentItem;
                    var symbol     = filteredData[i];
                    var icon       = GetSymbolIcon(symbol);
                    var styledName = NameOf(filteredData[i]);
                    if (matcher != null)
                    {
                        const string markerStart = "<b>";
                        const string markerEnd   = "</b>";

                        var matches = matcher.GetMatch(styledName);
                        if (matches != null && matches.Length > 0)
                        {
                            sb        = sb ?? new System.Text.StringBuilder();
                            sb.Length = 0;

                            var isMatch = false;
                            var m       = 0;
                            for (var s = 0; s < styledName.Length; ++s)
                            {
                                if (m == matches.Length)
                                {
                                    if (isMatch)
                                    {
                                        isMatch = false;
                                        sb.Append(markerEnd);
                                    }
                                    sb.Append(styledName, s, styledName.Length - s);
                                    break;
                                }
                                if (s == matches[m])
                                {
                                    ++m;
                                    if (!isMatch)
                                    {
                                        sb.Append(markerStart);
                                        isMatch = true;
                                    }
                                }
                                else if (isMatch)
                                {
                                    sb.Append(markerEnd);
                                    isMatch = false;
                                }
                                sb.Append(styledName[s]);
                            }
                            if (isMatch)
                            {
                                sb.Append(markerEnd);
                            }
                            styledName = sb.ToString();
                        }
                    }
                    var displayString = ItemDisplayString(filteredData[i], styledName);
                    var itemContent   = new GUIContent(displayString, icon);
                    if (filteredData[i].GetTypeParameters() != null)
                    {
                        itemContent.text += "<>";
                    }
                    listItemStyle.Draw(rcItem, itemContent, false, focus, focus, on);
                }

                EditorGUIUtility.SetIconSize(Vector2.zero);
            }

            //if (focusedWindow == this && owner != null)
            //	owner.Focus();
            if (Event.current.type == EventType.ExecuteCommand || Event.current.type == EventType.ValidateCommand || Event.current.isKey)
            {
                owner.SendEvent(Event.current);
            }
        }
 private void DoSelectionTooltip(int frameIndex, Rect fullRect)
 {
     if (this.m_SelectedEntry.IsValid() && this.m_SelectedEntry.frameId == frameIndex)
     {
         string        arg           = string.Format(((double)this.m_SelectedEntry.duration < 1.0) ? "{0:f3}ms" : "{0:f2}ms", this.m_SelectedEntry.duration);
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.Append(string.Format("{0}\n{1}", this.m_SelectedEntry.name, arg));
         if (this.m_SelectedEntry.instanceCount > 1)
         {
             string text = string.Format(((double)this.m_SelectedEntry.totalDuration < 1.0) ? "{0:f3}ms" : "{0:f2}ms", this.m_SelectedEntry.totalDuration);
             stringBuilder.Append(string.Format("\n{0}: {1} ({2} {3})", new object[]
             {
                 this.m_LocalizedString_Total,
                 text,
                 this.m_SelectedEntry.instanceCount,
                 this.m_LocalizedString_Instances
             }));
         }
         if (this.m_SelectedEntry.metaData.Length > 0)
         {
             stringBuilder.Append(string.Format("\n{0}", this.m_SelectedEntry.metaData));
         }
         if (this.m_SelectedEntry.callstackInfo.Length > 0)
         {
             stringBuilder.Append(string.Format("\n{0}", this.m_SelectedEntry.callstackInfo));
         }
         float      num       = fullRect.y + this.m_SelectedThreadY + this.m_SelectedEntry.relativeYPos;
         GUIContent content   = new GUIContent(stringBuilder.ToString());
         GUIStyle   tooltip   = ProfilerTimelineGUI.styles.tooltip;
         Vector2    vector    = tooltip.CalcSize(content);
         float      num2      = this.m_TimeArea.TimeToPixel(this.m_SelectedEntry.time + this.m_SelectedEntry.duration * 0.5f, fullRect);
         Rect       position  = new Rect(num2 - 32f, num, 64f, 6f);
         Rect       position2 = new Rect(num2, num + 6f, vector.x, vector.y);
         if (position2.xMax > fullRect.xMax + 16f)
         {
             position2.x = fullRect.xMax - position2.width + 16f;
         }
         if (position.xMax > fullRect.xMax + 20f)
         {
             position.x = fullRect.xMax - position.width + 20f;
         }
         if (position2.xMin < fullRect.xMin + 30f)
         {
             position2.x = fullRect.xMin + 30f;
         }
         if (position.xMin < fullRect.xMin - 20f)
         {
             position.x = fullRect.xMin - 20f;
         }
         float num3 = 16f + position2.height + 2f * position.height;
         bool  flag = num + vector.y + 6f > fullRect.yMax && position2.y - num3 > 0f;
         if (flag)
         {
             position2.y -= num3;
             position.y  -= 16f + 2f * position.height;
         }
         GUI.BeginClip(position);
         Matrix4x4 matrix = GUI.matrix;
         if (flag)
         {
             GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(position.width * 0.5f, position.height));
         }
         GUI.Label(new Rect(0f, 0f, position.width, position.height), GUIContent.none, ProfilerTimelineGUI.styles.tooltipArrow);
         GUI.matrix = matrix;
         GUI.EndClip();
         GUI.Label(position2, content, tooltip);
     }
 }
 /// <summary>
 /// Show a toggle trimmed to the length of the text
 /// </summary>
 /// <param name="value"></param>
 /// <param name="text"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static bool ToggleTrimmed(bool value, string text, GUIStyle style)
 {
     return(GUILayout.Toggle(value, text, style, GUILayout.MaxWidth(style.CalcSize(new GUIContent(text)).x)));
 }
示例#22
0
        public override void draw(GameObject gameObject, QObjectList objectList, Rect selectionRect)
        {
            for (int i = components.Count - componentsToDraw, n = components.Count; i < n; i++)
            {
                Component component = components[i];
                if (component is Transform)
                {
                    continue;
                }

                GUIContent content = EditorGUIUtility.ObjectContent(component, null);

                bool enabled = true;
                try
                {
                    PropertyInfo propertyInfo = component.GetType().GetProperty("enabled");
                    enabled = (bool)propertyInfo.GetGetMethod().Invoke(component, null);
                }
                catch
                {
                }

                Color color = GUI.color;
                color.a   = enabled ? 1f : 0.3f;
                GUI.color = color;
                GUI.DrawTexture(rect, content.image == null ? componentIcon : content.image, ScaleMode.ScaleToFit);
                color.a   = 1;
                GUI.color = color;

                if (rect.Contains(Event.current.mousePosition))
                {
                    string componentName = "Missing script";
                    if (component != null)
                    {
                        componentName = component.GetType().Name;
                    }

                    int labelWidth = Mathf.CeilToInt(hintLabelStyle.CalcSize(new GUIContent(componentName)).x);
                    selectionRect.x       = rect.x - labelWidth / 2 - 4;
                    selectionRect.width   = labelWidth + 8;
                    selectionRect.height -= 1;

                    if (selectionRect.y > 16)
                    {
                        selectionRect.y -= 16;
                    }
                    else
                    {
                        selectionRect.x += labelWidth / 2 + 18;
                    }

                    EditorGUI.DrawRect(selectionRect, backgroundDarkColor);
                    selectionRect.x += 4;
                    selectionRect.y += 1;

                    GUI.Label(selectionRect, componentName, hintLabelStyle);
                }

                rect.x += rect.width;
            }
        }
 /// <summary>
 /// Show a label trimmed to the length of the text
 /// </summary>
 /// <param name="text"></param>
 /// <param name="style"></param>
 public static void LabelTrimmed(string text, GUIStyle style)
 {
     GUILayout.Label(text, style, GUILayout.MaxWidth(style.CalcSize(new GUIContent(text)).x));
 }
示例#24
0
        public void DrawConnection(List <NodeGUI> nodes, Dictionary <string, List <AssetReference> > assetGroups)
        {
            var startNode = nodes.Find(node => node.Id == OutputNodeId);

            if (startNode == null)
            {
                return;
            }

            var endNode = nodes.Find(node => node.Id == InputNodeId);

            if (endNode == null)
            {
                return;
            }

            var startPoint = m_outputPoint.GetGlobalPosition(startNode);
            var startV3    = new Vector3(startPoint.x, startPoint.y, 0f);

            var endPoint = m_inputPoint.GetGlobalPosition(endNode);
            var endV3    = new Vector3(endPoint.x, endPoint.y, 0f);

            var centerPoint   = startPoint + ((endPoint - startPoint) / 2);
            var centerPointV3 = new Vector3(centerPoint.x, centerPoint.y, 0f);

            var pointDistanceX = Model.Settings.GUI.CONNECTION_CURVE_LENGTH;

            var startTan = new Vector3(startPoint.x + pointDistanceX, centerPoint.y, 0f);
            var endTan   = new Vector3(endPoint.x - pointDistanceX, centerPoint.y, 0f);

            var totalAssets = 0;
            var totalGroups = 0;

            if (assetGroups != null)
            {
                totalAssets = assetGroups.Sum(v => v.Value == null ? 0 : v.Value.Count);
                totalGroups = assetGroups.Keys.Count;
            }

            Color lineColor;
            var   lineWidth = (totalAssets > 0) ? 3f : 2f;

            if (IsSelected)
            {
                lineColor = Model.Settings.GUI.COLOR_ENABLED;
            }
            else
            {
                lineColor = (totalAssets > 0) ? Model.Settings.GUI.COLOR_CONNECTED : Model.Settings.GUI.COLOR_NOT_CONNECTED;
            }

            ConnectionGUIUtility.HandleMaterial.SetPass(0);
            Handles.DrawBezier(startV3, endV3, startTan, endTan, lineColor, null, lineWidth);

            // draw connection label if connection's label is not normal.
            GUIStyle labelStyle = new GUIStyle("WhiteMiniLabel");

            labelStyle.alignment = TextAnchor.MiddleLeft;

            switch (Label)
            {
            case Model.Settings.DEFAULT_OUTPUTPOINT_LABEL: {
                // show nothing
                break;
            }

            case Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL: {
                var labelWidth   = labelStyle.CalcSize(new GUIContent(Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL));
                var labelPointV3 = new Vector3(centerPointV3.x - (labelWidth.x / 2), centerPointV3.y - 24f, 0f);
                Handles.Label(labelPointV3, Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL, labelStyle);
                break;
            }

            default: {
                var labelWidth   = labelStyle.CalcSize(new GUIContent(Label));
                var labelPointV3 = new Vector3(centerPointV3.x - (labelWidth.x / 2), centerPointV3.y - 24f, 0f);
                Handles.Label(labelPointV3, Label, labelStyle);
                break;
            }
            }

            string connectionLabel;

            if (totalGroups > 1)
            {
                connectionLabel = string.Format("{0}:{1}", totalAssets, totalGroups);
            }
            else
            {
                connectionLabel = string.Format("{0}", totalAssets);
            }

            var style = new GUIStyle(m_connectionButtonStyle);

            var labelSize = style.CalcSize(new GUIContent(connectionLabel));

            m_buttonRect = new Rect(centerPointV3.x - labelSize.x / 2f, centerPointV3.y - labelSize.y / 2f, labelSize.x, 30f);

            if (
                Event.current.type == EventType.ContextClick ||
                (Event.current.type == EventType.MouseUp && Event.current.button == 1)
                )
            {
                var rightClickPos = Event.current.mousePosition;
                if (m_buttonRect.Contains(rightClickPos))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(
                        new GUIContent("Delete"),
                        false,
                        () => {
                        Delete();
                    }
                        );
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (GUI.Button(m_buttonRect, connectionLabel, style))
            {
                this.m_assetGroups = assetGroups;
                ConnectionGUIUtility.ConnectionEventHandler(new ConnectionEvent(ConnectionEvent.EventType.EVENT_CONNECTION_TAPPED, this));
            }
        }
 /// <summary>
 /// Show a button trimmed to the length of the text
 /// </summary>
 /// <param name="text"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static bool ButtonTrimmed(string text, GUIStyle style)
 {
     return(GUILayout.Button(text, style, GUILayout.MaxWidth(style.CalcSize(new GUIContent(text)).x)));
 }
示例#26
0
文件: CardObj.cs 项目: ymttkuc/dcg
    //カード情報の反映
    public void RefrectState()
    {
        for (int i = 0; i < (int)Card.State.size; ++i)
        {
            int now = 0, orig = 0;   //ステータスの現在値とカードに書かれてある値
            switch ((Card.State)i)
            {
            case Card.State.cost: now = card.GetCost(); orig = card.cost; break;

            case Card.State.power: now = card.GetPower(); orig = card.power; break;

            case Card.State.toughness: now = card.GetToughness(); orig = card.toughness; break;
            }

            child_stateNum[i].GetComponent <Number>().num = now;
            if (now < orig)
            {
                child_stateNum[i].GetComponent <Number>().isBuff   = true;
                child_stateNum[i].GetComponent <Number>().isDebuff = false;
            }
            else if (now > orig)
            {
                child_stateNum[i].GetComponent <Number>().isBuff   = false;
                child_stateNum[i].GetComponent <Number>().isDebuff = true;
            }
            else
            {
                child_stateNum[i].GetComponent <Number>().isBuff   = false;
                child_stateNum[i].GetComponent <Number>().isDebuff = false;
            }
        }
        if (card.damage > 0)
        {
            child_damageView.SetActive(true);
            child_damageNum.GetComponent <Number>().num      = card.damage;
            child_damageNum.GetComponent <Number>().isDebuff = true;
        }
        else
        {
            child_damageView.SetActive(false);
        }

        //名前が未入力のとき(初回)
        if (child_name.GetComponent <TextMesh>().text == "")
        {
            if (card.GetCardType() == Card.Type.character)
            {
                child_stateNum[(int)Card.State.cost].GetComponent <Number>().isVisible = false;
            }
            else
            {
                child_stateNum[(int)Card.State.cost].GetComponent <Number>().isVisible = true;
            }
            var spriteRenderer = child_picture.GetComponent <SpriteRenderer>();
            spriteRenderer.sprite = Resources.Load <Sprite>(card.GetPicName());

            var textMesh = child_name.GetComponent <TextMesh>();
            textMesh.text          = card.GetName();
            textMesh.characterSize = nameSizeMax;

            var gui = new GUIStyle()
            {
                font = this.font
            };
            var x = gui.CalcSize(new GUIContent(textMesh.text)).x;

            if (x > nameSizeBordar)
            {
                textMesh.characterSize = nameSizeMax * nameSizeBordar / x;
            }

            //色シンボルを定義する
            var chromaSymbol = child_chroma.GetComponent <ChromaSymbol>();
            chromaSymbol.type      = card.GetColor();
            chromaSymbol.isVisible = true;
        }
    }
 /// <summary>
 /// Show a button trimmed to the length of the text
 /// </summary>
 /// <param name="text"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static bool ButtonTrimmed(string text, Texture2D texture, GUIStyle style, string tooltip = null)
 {
     if (texture != null)
     {
         return(GUILayout.Button(new GUIContent(text, texture, tooltip), style, GUILayout.MaxWidth(style.CalcSize(new GUIContent(text)).x + texture.width)));
     }
     else
     {
         return(ButtonTrimmed(text, style));
     }
 }
        public void OnGUI()
        {
            var modifiers = Event.current.modifiers & ~(EventModifiers.FunctionKey | EventModifiers.CapsLock | EventModifiers.Numeric);

            var isOSX = Application.platform == RuntimePlatform.OSXEditor;

            if (isOSX)
            {
                if ((modifiers & EventModifiers.Alt) == 0)
                {
                    EditorApplication.delayCall -= CloseAndSwitch;
                    EditorApplication.delayCall += CloseAndSwitch;
                    return;
                }
            }
            else
            {
                if ((modifiers & EventModifiers.Control) == 0)
                {
                    EditorApplication.delayCall -= CloseAndSwitch;
                    EditorApplication.delayCall += CloseAndSwitch;
                    return;
                }
            }

            if (itemStyle == null)
            {
                itemStyle = new GUIStyle("PR Label");
                itemStyle.padding.left  = 2;
                itemStyle.padding.right = 4;
                itemStyle.border        = new RectOffset();
                itemStyle.margin        = new RectOffset();
                itemStyle.fixedWidth    = 0;
                // itemStyle.stretchWidth = false;
                // itemStyle.fixedHeight = itemHeight;

                captionStyle                  = new GUIStyle(EditorStyles.largeLabel);
                captionStyle.fontStyle        = FontStyle.Bold;
                captionStyle.fontSize         = 18;
                captionStyle.padding          = new RectOffset(6, 10, 10, 10);
                captionStyle.normal.textColor = EditorGUIUtility.isProSkin ?
                                                new Color(0.7f, 0.7f, 0.7f, 1f) : new Color(0.4f, 0.4f, 0.4f, 1f);
            }

            if (items == null)
            {
                EditorApplication.delayCall += Close;
                return;
            }

            if (Event.current.type == EventType.KeyDown)
            {
                var newSelected = selected;
                var isTabKey    = Event.current.keyCode == KeyCode.Tab;
                if (Event.current.keyCode == KeyCode.DownArrow || isTabKey && !Event.current.shift)
                {
                    if (++newSelected == items.Length)
                    {
                        newSelected = 0;
                    }
                }
                else if (Event.current.keyCode == KeyCode.UpArrow || isTabKey && Event.current.shift)
                {
                    if (--newSelected < 0)
                    {
                        newSelected = items.Length - 1;
                    }
                }
                else if (items.Length > 10 &&
                         (Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.LeftArrow))
                {
                    newSelected += Event.current.keyCode == KeyCode.RightArrow ? 10 : -10;
                    if (newSelected < 0)
                    {
                        newSelected += ((items.Length + 9) / 10) * 10;
                    }
                    if (newSelected >= items.Length)
                    {
                        if (newSelected / 10 == items.Length / 10)
                        {
                            newSelected = items.Length - 1;
                        }
                        else
                        {
                            newSelected = newSelected % 10;
                        }
                    }
                }
                if (newSelected != selected)
                {
                    selected = newSelected;
                    Repaint();
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.Layout)
            {
                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));

                if (itemsWidth == 0f)
                {
                    EditorGUIUtility.SetIconSize(new Vector2(32f, 32f));
                    for (int i = 0; i < items.Length; ++i)
                    {
                        var size = itemStyle.CalcSize(items[i]);
                        itemsWidth   = Mathf.Max(itemsWidth, size.x);
                        size         = captionStyle.CalcSize(items[i]);
                        captionWidth = Mathf.Max(captionWidth, size.x);
                    }
                    captionHeight = 54f;

                    var width  = Mathf.Max(captionWidth, 8f + itemsWidth * ((items.Length + 9) / 10));
                    var height = 4f + itemHeight * (Mathf.Min(items.Length, 10)) + captionHeight;
                    SetSize(width, height);
                    Repaint();
                }

                EditorGUIUtility.SetIconSize(Vector2.zero);
            }

            EditorGUIUtility.SetIconSize(new Vector2(32f, 32f));
            if (captionStyle != null)
            {
                GUI.Label(new Rect(0f, 0f, captionWidth, captionHeight), items[selected], captionStyle);
            }

            if (Event.current.type == EventType.Repaint)
            {
                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
                for (int i = 0; i < items.Length; ++i)
                {
                    var pos = new Rect(4f + itemsWidth * (i / 10), captionHeight + itemHeight * (i % 10), itemsWidth, itemHeight);
                    itemStyle.Draw(pos, items[i], false, false, i == selected, true);
                }
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
示例#29
0
        internal static Rect GetDropDownButtonRect(GUIContent content, GUIStyle style, float height)
        {
            var size = style.CalcSize(content);

            return(EditorGUILayout.GetControlRect(false, height, style, GUILayout.Width(size.x)));
        }
示例#30
0
        public void Update()
        {
            var screenSizeChanged = false;

            if (Screen.height != height)
            {
                height            = Screen.height;
                screenSizeChanged = true;
            }
            if (Screen.width != width)
            {
                width             = Screen.width;
                screenSizeChanged = true;
            }
            if (!screenSizeChanged)
            {
                return;
            }

            ratio = (1.0f + (width / 1280.0f - 1.0f) * 0.6f);

            // 画面サイズが変更された場合にのみ更新
            fontSize   = FixPx(fontPx);
            fontSizeS  = FixPx(fontPxS);
            fontSizeSS = FixPx(fontPxSS);
            fontSizeL  = FixPx(fontPxL);
            margin     = FixPx(marginPx);
            marginL    = FixPx(marginLPx);
            itemHeight = FixPx(itemHeightPx);
            unitHeight = margin + itemHeight;

            lStyle.fontSize  = fontSize;
            lStyleC.fontSize = fontSize;
            lStyleB.fontSize = fontSize;

            lStyleS.fontSize  = fontSizeS;
            lStyleRS.fontSize = fontSizeS;

            bStyle.fontSize         = fontSize;
            bStyleSC.fontSize       = fontSizeS;
            bStyleL.fontSize        = fontSize;
            tStyle.fontSize         = fontSize;
            tStyleS.fontSize        = fontSizeS;
            tStyleSS.fontSize       = fontSizeSS;
            tStyleL.fontSize        = fontSizeL;
            listStyle.fontSize      = fontSizeS;
            textStyle.fontSize      = fontSize;
            textStyleSC.fontSize    = fontSizeS;
            textAreaStyleS.fontSize = fontSizeS;

            LogUtil.DebugF("screen=({0},{1}),margin={2},height={3},ratio={4})", width, height, margin, itemHeight, ratio);

            winStyle.fontSize    = fontSize;
            tipsStyle.fontSize   = fontSize;
            dialogStyle.fontSize = fontSize;
            InitWinRect();
            InitFBRect();
            InitModalRect();

            subConWidth  = winRect.width - margin * 2;
            optBtnHeight = GUILayout.Height(itemHeight);
            // sub
            optSubConWidth     = GUILayout.Width(subConWidth);
            optSubConHeight    = GUILayout.Height(winRect.height - unitHeight * 3f);
            optSubCon6Height   = GUILayout.Height(winRect.height - unitHeight * 6.6f);
            optSubConHalfWidth = GUILayout.Width((winRect.width - marginL * 2) * 0.5f);        // margin値が小さい前提になってしまっている
            optToggleSWidth    = GUILayout.Width(tStyleS.CalcSize(new GUIContent("XXXXX")).x); // 全角5文字

            mainRect.Set(margin, unitHeight * 5 + margin, winRect.width - margin * 2, winRect.height - unitHeight * 6.5f);
            textureRect.Set(margin, unitHeight, winRect.width - margin * 2, winRect.height - unitHeight * 2.5f);
            var baseWidth = subConWidth - 20;

            optBtnWidth      = GUILayout.Width(baseWidth * 0.09f);
            optDBtnWidth     = GUILayout.Width(bStyle.CalcSize(new GUIContent("XX")).x);               // 全角2文字
            optContentWidth  = GUILayout.MaxWidth(baseWidth * 0.69f);
            optCategoryWidth = GUILayout.MaxWidth(lStyleS.CalcSize(new GUIContent("xxxxxxxxxxxx")).x); // 12文字

            nodeSelectRect.Set(margin, unitHeight * 2, winRect.width - margin * 2, winRect.height - unitHeight * 4.5f);
            colorRect.Set(margin, unitHeight * 2, winRect.width - margin, winRect.height - unitHeight * 5);
            labelRect.Set(0, 0, winRect.width - margin * 2, itemHeight * 1.2f);
            subRect.Set(0, itemHeight, winRect.width - margin * 2, itemHeight);

            foreach (var func in updaters)
            {
                func(this);
            }
        }
示例#31
0
        public static FrameRange ViewRangeBar(Rect rect, FrameRange viewRange, int totalFrames)
        {
            GUISkin previousGUI = GUI.skin;

            GUI.skin = null;

            int leftArrowId  = EditorGUIUtility.GetControlID(FocusType.Passive);
            int rightArrowId = EditorGUIUtility.GetControlID(FocusType.Passive);

            int leftHandleId  = EditorGUIUtility.GetControlID(FocusType.Passive);
            int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            int midHandleId = EditorGUIUtility.GetControlID(FocusType.Passive);

            GUIStyle leftArrowStyle  = GUI.skin.GetStyle("horizontalscrollbarleftbutton");
            GUIStyle rightArrowStyle = GUI.skin.GetStyle("horizontalscrollbarrightbutton");

            GUIStyle timelineScrubberStyle = GUI.skin.GetStyle("HorizontalMinMaxScrollbarThumb");

            Rect leftArrowRect = rect;

            leftArrowRect.width = leftArrowStyle.fixedWidth;

            Rect rightArrowRect = rect;

            rightArrowRect.xMin = rightArrowRect.xMax - rightArrowStyle.fixedWidth;

            Rect scrubberRect = rect;

            scrubberRect.xMin += leftArrowRect.width;
            scrubberRect.xMax -= rightArrowRect.width;

            float scrubberLeftEdge = scrubberRect.xMin;

            float minWidth = 50;
            float maxWith  = scrubberRect.width - minWidth;

            scrubberRect.xMin += ((float)viewRange.Start / totalFrames) * maxWith;
            scrubberRect.width = ((float)viewRange.Length / totalFrames) * maxWith + minWidth;

            Rect leftHandleRect = scrubberRect;

            leftHandleRect.width = timelineScrubberStyle.border.left;

            Rect rightHandRect = scrubberRect;

            rightHandRect.xMin = rightHandRect.xMax - timelineScrubberStyle.border.right;

            switch (Event.current.type)
            {
            case EventType.MouseDown:

                if (Event.current.clickCount > 1)
                {
                    viewRange.Start = 0;
                    viewRange.End   = totalFrames;
                }
                else if (EditorGUIUtility.hotControl == 0)
                {
                    Vector3 mousePos = Event.current.mousePosition;
                    if (leftArrowRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = leftArrowId;
                    }
                    else if (rightArrowRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = rightArrowId;
                    }
                    else if (leftHandleRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = leftHandleId;
                    }
                    else if (rightHandRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = rightHandleId;
                    }
                    else if (scrubberRect.Contains(mousePos))
                    {
                        EditorGUIUtility.hotControl = midHandleId;
                        _offset = Event.current.mousePosition - new Vector2(scrubberRect.xMin, scrubberRect.yMin);
                    }

                    if (EditorGUIUtility.hotControl != 0)
                    {
                        //					cachedMousePos = Input.mousePosition;
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == leftArrowId || EditorGUIUtility.hotControl == rightArrowId ||
                    EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId ||
                    EditorGUIUtility.hotControl == midHandleId)
                {
                    EditorGUIUtility.hotControl = 0;
                    Event.current.Use();
                }
                break;

            case EventType.MouseDrag:
                int delta = 0;

                if (EditorGUIUtility.hotControl == leftHandleId)
                {
                    delta           = Mathf.RoundToInt(((Event.current.mousePosition.x - scrubberLeftEdge) / maxWith) * totalFrames);
                    viewRange.Start = Mathf.Clamp(delta, 0, viewRange.End - 1);
                    GUI.changed     = true;
                    Event.current.Use();
                }
                else if (EditorGUIUtility.hotControl == rightHandleId)
                {
                    delta         = Mathf.RoundToInt(((Event.current.mousePosition.x - (scrubberLeftEdge + minWidth)) / maxWith) * totalFrames);
                    viewRange.End = Mathf.Clamp(delta, viewRange.Start + 1, totalFrames);
                    GUI.changed   = true;
                    Event.current.Use();
                }
                else if (EditorGUIUtility.hotControl == midHandleId)
                {
                    //				int startX = Mathf.RoundToInt(((cachedMousePos.x-scrubberLeftEdge)/maxWith)*totalFrames);
                    delta = Mathf.RoundToInt(((Event.current.mousePosition.x - _offset.x - scrubberLeftEdge) / maxWith) * totalFrames);
                    int x = delta - viewRange.Start;
                    viewRange.Start = delta;
                    viewRange.End  += x;
                    if (viewRange.Start < 0)
                    {
                        int diff = -viewRange.Start;
                        viewRange.Start += diff;
                        viewRange.End   += diff;
                    }
                    if (viewRange.End > totalFrames)
                    {
                        int diff = viewRange.End - totalFrames;
                        viewRange.Start -= diff;
                        viewRange.End   -= diff;
                    }
                    GUI.changed = true;
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:

                GUIStyle bar = GUI.skin.GetStyle("horizontalscrollbar");

                bar.Draw(rect, false, false, false, false);

                leftArrowStyle.Draw(leftArrowRect, true, EditorGUIUtility.hotControl == leftArrowId, false, false);

                rightArrowStyle.Draw(rightArrowRect, true, EditorGUIUtility.hotControl == rightArrowId, false, false);

                timelineScrubberStyle.Draw(scrubberRect, false, false, false, false);

                GUIStyle label = new GUIStyle(EditorStyles.boldLabel);

                string viewRangeStartStr  = viewRange.Start.ToString();
                string viewRangeEndStr    = viewRange.End.ToString();
                string viewRangeLengthStr = viewRange.Length.ToString();

                scrubberRect.xMin += 20;
                scrubberRect.xMax -= 20;
                Vector2 sizeAllLabels = label.CalcSize(new GUIContent(viewRangeStartStr + viewRangeEndStr + viewRangeLengthStr));

                if (scrubberRect.width > sizeAllLabels.x + 40)
                {
                    label.Draw(scrubberRect, new GUIContent(viewRangeStartStr), 0);

                    label.alignment = TextAnchor.MiddleRight;
                    label.Draw(scrubberRect, new GUIContent(viewRangeEndStr), 0);
                }

                label.alignment = TextAnchor.MiddleCenter;
                label.Draw(scrubberRect, new GUIContent(viewRangeLengthStr), 0);

                //			GUI.HorizontalScrollbar( rect, 0, 100, 0, 100);

                break;
            }

            GUI.skin = previousGUI;

            return(viewRange);
        }