コード例 #1
0
 public ProxyFAFQueryMethodAssignerSetter(
     AssignFunc procAssign,
     SetValueFunc procSetValue)
 {
     ProcAssign = procAssign;
     ProcSetValue = procSetValue;
 }
コード例 #2
0
        internal static void SetValue <TColor, TDepth>(this Image <TColor, TDepth> img, TDepth[] valueArr)
            where TColor : IColor
            where TDepth : struct
        {
            if (valueArr.Length > img.ColorInfo.NumberOfChannels)
            {
                throw new Exception("Value array length must be the same as number of channels (or less)!");
            }

            Type depthType = img.ColorInfo.ChannelType;

            SetValueFunc valueSetter = null;

            if (valueSetters.TryGetValue(typeof(TDepth), out valueSetter) == false)
            {
                throw new Exception(string.Format("Setter function can not split image of color depth type {0}", depthType));
            }

            ParallelProcessor <IImage, bool> proc = new ParallelProcessor <IImage, bool>(img.Size,
                                                                                         () =>    //called once
            {
                return(true);
            },

                                                                                         (IImage srcImg, bool dummy, Rectangle area) =>    //called for every thread
            {
                valueSetter(srcImg.GetSubRect(area), valueArr);
            }
                                                                                         /*,new ParallelOptions { ForceSequential = true}*/);

            proc.Process(img); //result is in srcImg
        }
コード例 #3
0
 static void SetAllLayerCollisions(bool flag, SetValueFunc setValue)
 {
     for (int i = 0; i < kMaxLayers; ++i)
     {
         for (int j = i; j < kMaxLayers; ++j)
         {
             setValue(i, j, flag);
         }
     }
 }
コード例 #4
0
        public static void DoGUI(GUIContent label, ref bool show, GetValueFunc getValue, SetValueFunc setValue)
        {
            const int checkboxSize = 16;
            int       labelSize    = 110;
            const int indent       = 30;
            int       numLayers    = 0;

            for (int i = 0; i < kMaxLayers; i++)
            {
                if (LayerMask.LayerToName(i) != "")
                {
                    numLayers++;
                }
            }

            // find the longest label
            for (int i = 0; i < kMaxLayers; i++)
            {
                var textDimensions = GUI.skin.label.CalcSize(new GUIContent(LayerMask.LayerToName(i)));
                if (labelSize < textDimensions.x)
                {
                    labelSize = (int)textDimensions.x;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(0);
            show = EditorGUILayout.Foldout(show, label, true);
            GUILayout.EndHorizontal();

            if (show)
            {
                GUILayout.BeginScrollView(new Vector2(0, 0), GUILayout.Height(labelSize + 15));
                Rect    topLabelRect = GUILayoutUtility.GetRect(checkboxSize * numLayers + labelSize, labelSize);
                Rect    scrollArea   = GUIClip.topmostRect;
                Vector2 topLeft      = GUIClip.Unclip(new Vector2(topLabelRect.x - 10, topLabelRect.y));
                int     y            = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        bool  hidelabel            = false;
                        bool  hidelabelonscrollbar = false;
                        int   defautlabelrectwidth = 311;
                        int   defaultlablecount    = 10;
                        float clipOffset           = labelSize + (checkboxSize * numLayers) + checkboxSize;

                        // hide vertical labels when overlap with the rest of the UI
                        if ((topLeft.x + (clipOffset - checkboxSize * y)) <= 0)
                        {
                            hidelabel = true;
                        }

                        // hide label when it touch horizontal scroll area
                        if (topLabelRect.height > scrollArea.height)
                        {
                            hidelabelonscrollbar = true;
                        }
                        else if (topLabelRect.width != scrollArea.width || topLabelRect.width != scrollArea.width - topLeft.x)
                        {
                            // hide label when it touch vertical scroll area
                            if (topLabelRect.width > defautlabelrectwidth)
                            {
                                float tmp = topLabelRect.width - scrollArea.width;
                                if (tmp > 1)
                                {
                                    if (topLeft.x < 0)
                                    {
                                        tmp += topLeft.x;
                                    }

                                    if (tmp / checkboxSize > y)
                                    {
                                        hidelabelonscrollbar = true;
                                    }
                                }
                            }
                            else
                            {
                                float tmp = defautlabelrectwidth;
                                if (numLayers < defaultlablecount)
                                {
                                    tmp -= checkboxSize * (defaultlablecount - numLayers);
                                }

                                if ((scrollArea.width + y * checkboxSize) + checkboxSize <= tmp)
                                {
                                    hidelabelonscrollbar = true;
                                }

                                //Re-enable the label when we move the scroll bar
                                if (topLeft.x < 0)
                                {
                                    if (topLabelRect.width == scrollArea.width - topLeft.x)
                                    {
                                        hidelabelonscrollbar = false;
                                    }

                                    if (numLayers <= defaultlablecount / 2)
                                    {
                                        if ((tmp - (scrollArea.width - ((topLeft.x - 10) * (y + 1)))) < 0)
                                        {
                                            hidelabelonscrollbar = false;
                                        }
                                    }
                                    else
                                    {
                                        float hiddenlables = (int)(tmp - scrollArea.width) / checkboxSize;
                                        int   res          = (int)((topLeft.x * -1) + 12) / checkboxSize;
                                        if (hiddenlables - res < y)
                                        {
                                            hidelabelonscrollbar = false;
                                        }
                                    }
                                }
                            }
                        }

                        Vector3 translate = new Vector3(labelSize + indent + checkboxSize * (numLayers - y) + topLeft.y + topLeft.x + 10, topLeft.y, 0);
                        GUI.matrix = Matrix4x4.TRS(translate, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 90), Vector3.one);

                        var labelRect = new Rect(2 - topLeft.x, 0, labelSize, checkboxSize + 5);
                        if (hidelabel || hidelabelonscrollbar)
                        {
                            GUI.Label(labelRect, GUIContent.none, Styles.rightLabel);
                        }
                        else
                        {
                            GUI.Label(labelRect, LayerMask.LayerToName(i), Styles.rightLabel);
                            // Empty Transparent label used to indicate highlighted row
                            var checkRect = new Rect(2 - topLeft.x, 1 /*This centers the highlight*/, labelSize + 4 + (y + 1) * checkboxSize, checkboxSize);
                            GUI.Label(checkRect, GUIContent.none, Styles.hoverStyle);

                            checkRect = new Rect(
                                GUI.matrix.MultiplyPoint(new Vector3(checkRect.position.x, checkRect.position.y + 200, 0)),
                                GUI.matrix.MultiplyPoint(new Vector3(checkRect.size.x, checkRect.size.y, 0)));
                            GUIView.current.MarkHotRegion(labelRect);
                            GUIView.current.MarkHotRegion(checkRect);
                        }

                        y++;
                    }
                }
                GUILayout.EndScrollView();

                GUI.matrix = Matrix4x4.identity;
                y          = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        int x         = 0;
                        var r         = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
                        var labelRect = new Rect(r.x + indent, r.y, labelSize, checkboxSize + 5);
                        GUI.Label(labelRect, LayerMask.LayerToName(i), Styles.rightLabel);
                        // Empty Transparent label used to indicate highlighted row
                        var checkRect = new Rect(r.x + indent, r.y, labelSize + (numLayers - y) * checkboxSize, checkboxSize);
                        GUI.Label(checkRect, GUIContent.none, Styles.hoverStyle);
                        GUIView.current.MarkHotRegion(labelRect);
                        GUIView.current.MarkHotRegion(checkRect);

                        for (int j = kMaxLayers - 1; j >= 0; j--)
                        {
                            if (LayerMask.LayerToName(j) != "")
                            {
                                if (x < numLayers - y)
                                {
                                    var  tooltip = new GUIContent("", LayerMask.LayerToName(i) + "/" + LayerMask.LayerToName(j));
                                    bool val     = getValue(i, j);
                                    bool toggle  = GUI.Toggle(new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize, checkboxSize), val, tooltip);
                                    if (toggle != val)
                                    {
                                        setValue(i, j, toggle);
                                    }
                                }
                                x++;
                            }
                        }
                        y++;
                    }
                }

                GUILayout.BeginHorizontal();

                // Padding on the left
                GUILayout.Label(GUIContent.none, GUILayout.Width(labelSize + 23));
                // Made the buttons span the entire matrix of layers
                if (GUILayout.Button("Disable All", GUILayout.MinWidth((checkboxSize * numLayers) / 2), GUILayout.ExpandWidth(false)))
                {
                    SetAllLayerCollisions(false, setValue);
                }

                if (GUILayout.Button("Enable All", GUILayout.MinWidth((checkboxSize * numLayers) / 2), GUILayout.ExpandWidth(false)))
                {
                    SetAllLayerCollisions(true, setValue);
                }

                GUILayout.EndHorizontal();
            }
        }
コード例 #5
0
    public void DoGUI(string title, ref bool show, ref Vector2 scrollPos, GetValueFunc getValue, SetValueFunc setValue)
    {
        const int kMaxLayers   = 32;
        const int checkboxSize = 16;
        int       labelSize    = 100;
        const int indent       = 30;

        int numLayers = 0;

        for (int i = 0; i < kMaxLayers; i++)
        {
            if (LayerToName(i) != "")
            {
                numLayers++;
            }
        }

        // find the longest label
        for (int i = 0; i < kMaxLayers; i++)
        {
            var textDimensions = GUI.skin.label.CalcSize(new GUIContent(LayerToName(i)));
            if (labelSize < textDimensions.x)
            {
                labelSize = (int)textDimensions.x;
            }
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(0);
        show = EditorGUILayout.Foldout(show, title, true);
        GUILayout.EndHorizontal();
        if (show)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MinHeight(labelSize + 20),
                                                  GUILayout.MaxHeight(labelSize + (numLayers + 1) * checkboxSize));
            int  y  = 0;
            int  lx = 0;
            Rect rr = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
            for (int i = 0; i < kMaxLayers; i++)
            {
                if (LayerToName(i) != "")
                {
                    GUI.Label(new Rect(labelSize + indent + rr.x + lx * checkboxSize, rr.y, checkboxSize, checkboxSize),
                              (numLayers - i - 1).ToString(), "RightLabel");
                    lx++;
                }
            }

            GUI.matrix = Matrix4x4.identity;
            y          = 0;
            for (int i = 0; i < kMaxLayers; i++)
            {
                if (LayerToName(i) != "")
                {
                    int  x = 0;
                    Rect r = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
                    GUI.Label(new Rect(r.x + indent, r.y, labelSize, checkboxSize), i + " " + LayerToName(i),
                              "RightLabel");
                    for (int j = kMaxLayers - 1; j >= 0; j--)
                    {
                        if (LayerToName(j) != "")
                        {
                            if (x < numLayers - y)
                            {
                                GUIContent tooltip = new GUIContent("", LayerToName(i) + "/" + LayerToName(j));
                                bool       val     = getValue(i, j);
                                bool       toggle  =
                                    GUI.Toggle(
                                        new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize,
                                                 checkboxSize), val, tooltip);
                                if (toggle != val)
                                {
                                    setValue(i, j, toggle);
                                }
                            }

                            x++;
                        }
                    }

                    y++;
                }
            }

            GUILayout.EndScrollView();
        }
    }
コード例 #6
0
        public static void DoGUI(string title, string[] groupNames, ref bool show, ref Vector2 scrollPos, GetValueFunc getValue, SetValueFunc setValue, bool allowBothCombinations = true)
        {
            int num = 0;

            for (int i = 0; i < groupNames.Length; i++)
            {
                if (!string.IsNullOrEmpty(groupNames[i]))
                {
                    num++;
                }
            }
            if (string.IsNullOrEmpty(title))
            {
                show = true;
            }
            else
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(0f);
                show = EditorGUILayout.Foldout(show, title);
                GUILayout.EndHorizontal();
            }
            if (show)
            {
                scrollPos = GUILayout.BeginScrollView(scrollPos, new GUILayoutOption[]
                {
                    GUILayout.MinHeight(250f),
                    GUILayout.MaxHeight((float)(100 + (num + 1) * 16))
                });
                Rect    rect        = GUILayoutUtility.GetRect((float)(16 * num + 100), 100f);
                Rect    topmostRect = GUIClip_topmostRect();                       //GUIClip.topmostRect;
                Vector2 vector      = GUIClip_Unclip(new Vector2(rect.x, rect.y)); //GUIClip.Unclip(new Vector2(rect.x, rect.y));
                int     num2        = 0;
                for (int j = 0; j < groupNames.Length; j++)
                {
                    if (groupNames[j] != string.Empty)
                    {
                        float num3 = (float)(130 + (num - num2) * 16) - (topmostRect.width + scrollPos.x);
                        if (num3 < 0f)
                        {
                            num3 = 0f;
                        }
                        Vector3 pos = new Vector3((float)(130 + 16 * (num - num2)) + vector.y + vector.x + scrollPos.y - num3, vector.y + scrollPos.y, 0f);
                        GUI.matrix = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, 90f), Vector3.one);
                        if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9.0"))
                        {
                            GUI.matrix *= Matrix4x4.TRS(new Vector3(-0.5f, -0.5f, 0f), Quaternion.identity, Vector3.one);
                        }
                        GUI.Label(new Rect(2f - vector.x - scrollPos.y, scrollPos.y - num3, 100f, 16f), groupNames[j], "RightLabel");
                        num2++;
                    }
                }
                GUI.matrix = Matrix4x4.identity;
                num2       = 0;
                for (int k = 0; k < groupNames.Length; k++)
                {
                    if (groupNames[k] != string.Empty)
                    {
                        int  num4  = 0;
                        Rect rect2 = GUILayoutUtility.GetRect((float)(30 + 16 * num + 100), 16f);
                        GUI.Label(new Rect(rect2.x + 2f, rect2.y, 100f, 16f), groupNames[k], "RightLabel");
                        for (int l = groupNames.Length - 1; l >= 0; l--)
                        {
                            if (groupNames[l] != string.Empty)
                            {
                                //if (num4 < num - num2)
                                {
                                    GUIContent content = new GUIContent(string.Empty, groupNames[k] + "/" + groupNames[l]);
                                    bool       flag    = getValue(k, l);
                                    bool       flag2   = GUI.Toggle(new Rect(130f + rect2.x + (float)(num4 * 16), rect2.y, 16f, 16f), flag, content);
                                    if (flag2 != flag)
                                    {
                                        setValue(k, l, flag2);
                                    }
                                }
                                num4++;
                            }
                        }
                        num2++;
                    }
                }
                GUILayout.EndScrollView();
            }
        }
コード例 #7
0
        public static void DoGUI(string title, ref bool show, ref Vector2 scrollPos, GetValueFunc getValue, SetValueFunc setValue, float width, float height, float xdasd, float ydsda)
        {
            int       kMaxLayers   = InternalEditorUtility.tags.Length;
            const int checkboxSize = 16;
            int       labelSize    = 100;
            const int indent       = 30;

            int numLayers = 0;

            for (int i = 0; i < kMaxLayers; i++)
            {
                //if (LayerMask.LayerToName(i) != "")
                numLayers++;
            }

            // find the longest label
            for (int i = 0; i < kMaxLayers; i++)
            {
                var textDimensions = GUI.skin.label.CalcSize(new GUIContent(InternalEditorUtility.tags[i]));
                if (labelSize < textDimensions.x)
                {
                    labelSize = (int)textDimensions.x;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(0);
            show = EditorGUILayout.Foldout(show, title, true);
            GUILayout.EndHorizontal();
            if (show)
            {
                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.MinHeight(labelSize + 20), GUILayout.MaxHeight(labelSize + (numLayers + 1) * checkboxSize));
                Rect topLabelRect = GUILayoutUtility.GetRect(checkboxSize * numLayers + labelSize, labelSize);
                //topLabelRect.position = new Vector2(xasd , yasd);
                Rect    scrollArea = new Rect(0, 5, width - 10, height - 10);
                Vector2 topLeft    = new Vector2(topLabelRect.x, topLabelRect.y);
                int     y          = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    //if (LayerMask.LayerToName(i) != "")
                    {
                        // Need to do some shifting around here, so the rotated text will still clip correctly
                        float clipOffset = (labelSize + indent + (numLayers - y) * checkboxSize) - (scrollArea.width + scrollPos.x);
                        if (clipOffset < 0)
                        {
                            clipOffset = 0;
                        }

                        Vector3 translate = new Vector3(labelSize + indent + checkboxSize * (numLayers - y) + topLeft.y + topLeft.x + scrollPos.y - clipOffset, topLeft.y + scrollPos.y, 0);
                        GUI.matrix = Matrix4x4.TRS(translate, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(new Vector3(xdasd + 48, ydsda - 360, 0), Quaternion.Euler(0, 0, 90), Vector3.one);

                        GUI.Label(new Rect(2 - topLeft.x - scrollPos.y, scrollPos.y - clipOffset, labelSize, checkboxSize), InternalEditorUtility.tags[i], "RightLabel");
                        y++;
                    }
                }
                GUI.matrix = Matrix4x4.identity;
                y          = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    //if (LayerMask.LayerToName(i) != "")
                    {
                        int  x = 0;
                        Rect r = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
                        GUI.Label(new Rect(r.x + indent, r.y, labelSize, checkboxSize), InternalEditorUtility.tags[i], "RightLabel");
                        for (int j = kMaxLayers - 1; j >= 0; j--)
                        {
                            //if (LayerMask.LayerToName(j) != "")
                            {
                                if (x < numLayers - y)
                                {
                                    GUIContent tooltip = new GUIContent("", InternalEditorUtility.tags[i] + "/" + InternalEditorUtility.tags[j]);
                                    bool       val     = getValue(i, j);
                                    bool       toggle  = GUI.Toggle(new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize, checkboxSize), val, tooltip);
                                    if (toggle != val)
                                    {
                                        setValue(i, j, toggle);
                                    }
                                }
                                x++;
                            }
                        }
                        y++;
                    }
                }
                GUILayout.EndScrollView();
            }
        }
コード例 #8
0
        public static void DoGUI(string title, ref bool show, GetValueFunc getValue, SetValueFunc setValue)
        {
            const int kMaxLayers   = 32;
            const int checkboxSize = 16;
            int       labelSize    = 100;
            const int indent       = 30;

            int numLayers = 0;

            for (int i = 0; i < kMaxLayers; i++)
            {
                if (LayerMask.LayerToName(i) != "")
                {
                    numLayers++;
                }
            }

            // find the longest label
            for (int i = 0; i < kMaxLayers; i++)
            {
                var textDimensions = GUI.skin.label.CalcSize(new GUIContent(LayerMask.LayerToName(i)));
                if (labelSize < textDimensions.x)
                {
                    labelSize = (int)textDimensions.x;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(0);
            show = EditorGUILayout.Foldout(show, title, true);
            GUILayout.EndHorizontal();

            if (show)
            {
                GUILayout.BeginScrollView(new Vector2(0, 0), GUILayout.Height(labelSize + 10));
                Rect    topLabelRect = GUILayoutUtility.GetRect(checkboxSize * numLayers + labelSize, labelSize);
                Rect    scrollArea   = GUIClip.topmostRect;
                Vector2 topLeft      = GUIClip.Unclip(new Vector2(topLabelRect.x, topLabelRect.y));
                int     y            = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        // Need to do some shifting around here, so the rotated text will still clip correctly
                        float clipOffset = (labelSize + indent + (numLayers - y) * checkboxSize) - (scrollArea.width);
                        if (clipOffset < 0)
                        {
                            clipOffset = 0;
                        }

                        Vector3 translate = new Vector3(labelSize + indent + checkboxSize * (numLayers - y) + topLeft.y + topLeft.x - clipOffset, topLeft.y, 0);
                        GUI.matrix = Matrix4x4.TRS(translate, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 90), Vector3.one);

                        GUI.Label(new Rect(2 - topLeft.x, -clipOffset, labelSize, checkboxSize), LayerMask.LayerToName(i), "RightLabel");
                        y++;
                    }
                }
                GUILayout.EndScrollView();

                GUI.matrix = Matrix4x4.identity;
                y          = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        int x = 0;
                        var r = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
                        GUI.Label(new Rect(r.x + indent, r.y, labelSize, checkboxSize), LayerMask.LayerToName(i), "RightLabel");
                        for (int j = kMaxLayers - 1; j >= 0; j--)
                        {
                            if (LayerMask.LayerToName(j) != "")
                            {
                                if (x < numLayers - y)
                                {
                                    var  tooltip = new GUIContent("", LayerMask.LayerToName(i) + "/" + LayerMask.LayerToName(j));
                                    bool val     = getValue(i, j);
                                    bool toggle  = GUI.Toggle(new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize, checkboxSize), val, tooltip);
                                    if (toggle != val)
                                    {
                                        setValue(i, j, toggle);
                                    }
                                }
                                x++;
                            }
                        }
                        y++;
                    }
                }
            }
        }
コード例 #9
0
        public static void DoGUI(string title, ref bool show, ref Vector2 scrollPos, GetValueFunc getValue, SetValueFunc setValue)
        {
            int num = 0;

            for (int i = 0; i < 0x20; i++)
            {
                if (LayerMask.LayerToName(i) != "")
                {
                    num++;
                }
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(0f);
            show = EditorGUILayout.Foldout(show, title, true);
            GUILayout.EndHorizontal();
            if (show)
            {
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinHeight(120f), GUILayout.MaxHeight((float)(100 + ((num + 1) * 0x10))) };
                scrollPos = GUILayout.BeginScrollView(scrollPos, options);
                Rect    rect        = GUILayoutUtility.GetRect((float)((0x10 * num) + 100), 100f);
                Rect    topmostRect = GUIClip.topmostRect;
                Vector2 vector      = GUIClip.Unclip(new Vector2(rect.x, rect.y));
                int     num3        = 0;
                for (int j = 0; j < 0x20; j++)
                {
                    if (LayerMask.LayerToName(j) != "")
                    {
                        float num5 = (130 + ((num - num3) * 0x10)) - (topmostRect.width + scrollPos.x);
                        if (num5 < 0f)
                        {
                            num5 = 0f;
                        }
                        Vector3 pos = new Vector3(((((130 + (0x10 * (num - num3))) + vector.y) + vector.x) + scrollPos.y) - num5, vector.y + scrollPos.y, 0f);
                        GUI.matrix = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, 90f), Vector3.one);
                        if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9.0"))
                        {
                            GUI.matrix *= Matrix4x4.TRS(new Vector3(-0.5f, -0.5f, 0f), Quaternion.identity, Vector3.one);
                        }
                        GUI.Label(new Rect((2f - vector.x) - scrollPos.y, scrollPos.y - num5, 100f, 16f), LayerMask.LayerToName(j), "RightLabel");
                        num3++;
                    }
                }
                GUI.matrix = Matrix4x4.identity;
                num3       = 0;
                for (int k = 0; k < 0x20; k++)
                {
                    if (LayerMask.LayerToName(k) != "")
                    {
                        int  num7  = 0;
                        Rect rect3 = GUILayoutUtility.GetRect((float)((30 + (0x10 * num)) + 100), 16f);
                        GUI.Label(new Rect(rect3.x + 30f, rect3.y, 100f, 16f), LayerMask.LayerToName(k), "RightLabel");
                        for (int m = 0x1f; m >= 0; m--)
                        {
                            if (LayerMask.LayerToName(m) != "")
                            {
                                if (num7 < (num - num3))
                                {
                                    GUIContent content = new GUIContent("", LayerMask.LayerToName(k) + "/" + LayerMask.LayerToName(m));
                                    bool       flag    = getValue(k, m);
                                    bool       val     = GUI.Toggle(new Rect((130f + rect3.x) + (num7 * 0x10), rect3.y, 16f, 16f), flag, content);
                                    if (val != flag)
                                    {
                                        setValue(k, m, val);
                                    }
                                }
                                num7++;
                            }
                        }
                        num3++;
                    }
                }
                GUILayout.EndScrollView();
            }
        }
コード例 #10
0
ファイル: LayerMatrixGUI.cs プロジェクト: randomize/VimConfig
 public static void DoGUI(string title, ref bool show, ref Vector2 scrollPos, GetValueFunc getValue, SetValueFunc setValue)
 {
     int num5 = 0;
     for (int i = 0; i < 0x20; i++)
     {
         if (LayerMask.LayerToName(i) != string.Empty)
         {
             num5++;
         }
     }
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     GUILayout.Space(0f);
     show = EditorGUILayout.Foldout(show, title);
     GUILayout.EndHorizontal();
     if (show)
     {
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinHeight(120f), GUILayout.MaxHeight((float) (100 + ((num5 + 1) * 0x10))) };
         scrollPos = GUILayout.BeginScrollView(scrollPos, options);
         Rect rect = GUILayoutUtility.GetRect((float) ((0x10 * num5) + 100), 100f);
         Rect topmostRect = GUIClip.topmostRect;
         Vector2 vector = GUIClip.Unclip(new Vector2(rect.x, rect.y));
         int num7 = 0;
         for (int j = 0; j < 0x20; j++)
         {
             if (LayerMask.LayerToName(j) != string.Empty)
             {
                 float num9 = (130 + ((num5 - num7) * 0x10)) - (topmostRect.width + scrollPos.x);
                 if (num9 < 0f)
                 {
                     num9 = 0f;
                 }
                 Vector3 pos = new Vector3(((((130 + (0x10 * (num5 - num7))) + vector.y) + vector.x) + scrollPos.y) - num9, vector.y + scrollPos.y, 0f);
                 GUI.matrix = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, 90f), Vector3.one);
                 if (SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9.0"))
                 {
                     GUI.matrix *= Matrix4x4.TRS(new Vector3(-0.5f, -0.5f, 0f), Quaternion.identity, Vector3.one);
                 }
                 GUI.Label(new Rect((2f - vector.x) - scrollPos.y, scrollPos.y - num9, 100f, 16f), LayerMask.LayerToName(j), "RightLabel");
                 num7++;
             }
         }
         GUI.matrix = Matrix4x4.identity;
         num7 = 0;
         for (int k = 0; k < 0x20; k++)
         {
             if (LayerMask.LayerToName(k) != string.Empty)
             {
                 int num11 = 0;
                 Rect rect3 = GUILayoutUtility.GetRect((float) ((30 + (0x10 * num5)) + 100), 16f);
                 GUI.Label(new Rect(rect3.x + 30f, rect3.y, 100f, 16f), LayerMask.LayerToName(k), "RightLabel");
                 for (int m = 0x1f; m >= 0; m--)
                 {
                     if (LayerMask.LayerToName(m) != string.Empty)
                     {
                         if (num11 < (num5 - num7))
                         {
                             GUIContent content = new GUIContent(string.Empty, LayerMask.LayerToName(k) + "/" + LayerMask.LayerToName(m));
                             bool flag = getValue(k, m);
                             bool val = GUI.Toggle(new Rect((130f + rect3.x) + (num11 * 0x10), rect3.y, 16f, 16f), flag, content);
                             if (val != flag)
                             {
                                 setValue(k, m, val);
                             }
                         }
                         num11++;
                     }
                 }
                 num7++;
             }
         }
         GUILayout.EndScrollView();
     }
 }
コード例 #11
0
        // Draw the whole collision matrix view.
        public static void Draw(GUIContent label, GetValueFunc getValue, SetValueFunc setValue)
        {
            const int checkboxSize = 16;
            var       labelSize    = 110;
            const int indent       = 30;

            // Count the number of active layers.
            var activeLayerCount = 0;

            for (var i = 0; i < kMaxLayers; ++i)
            {
                if (LayerMask.LayerToName(i) != string.Empty)
                {
                    activeLayerCount++;
                }
            }

            // Find the longest label
            for (var i = 0; i < kMaxLayers; ++i)
            {
                var textDimensions = GUI.skin.label.CalcSize(new GUIContent(LayerMask.LayerToName(i)));
                if (labelSize < textDimensions.x)
                {
                    labelSize = (int)textDimensions.x;
                }
            }

            {
                GUILayout.BeginScrollView(new Vector2(0, 0), GUILayout.Height(labelSize + 15));
                var topLabelRect = GUILayoutUtility.GetRect(checkboxSize * activeLayerCount + labelSize, labelSize);
                var scrollArea   = GUIClip.topmostRect;
                var topLeft      = GUIClip.Unclip(new Vector2(topLabelRect.x - 10, topLabelRect.y));
                var y            = 0;

                for (var i = 0; i < kMaxLayers; ++i)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        var hidelabel            = false;
                        var hidelabelonscrollbar = false;
                        var defautlabelrectwidth = 311;
                        var defaultlablecount    = 10;
                        var clipOffset           = labelSize + (checkboxSize * activeLayerCount) + checkboxSize;

                        // Hide vertical labels when they overlap with the rest of the UI.
                        if ((topLeft.x + (clipOffset - checkboxSize * y)) <= 0)
                        {
                            hidelabel = true;
                        }

                        // Hide label when it touches the horizontal scroll area.
                        if (topLabelRect.height > scrollArea.height)
                        {
                            hidelabelonscrollbar = true;
                        }
                        else if (topLabelRect.width != scrollArea.width || topLabelRect.width != scrollArea.width - topLeft.x)
                        {
                            // Hide label when it touch vertical scroll area.
                            if (topLabelRect.width > defautlabelrectwidth)
                            {
                                var tmp = topLabelRect.width - scrollArea.width;
                                if (tmp > 1)
                                {
                                    if (topLeft.x < 0)
                                    {
                                        tmp += topLeft.x;
                                    }

                                    if (tmp / checkboxSize > y)
                                    {
                                        hidelabelonscrollbar = true;
                                    }
                                }
                            }
                            else
                            {
                                var tmp = defautlabelrectwidth;
                                if (activeLayerCount < defaultlablecount)
                                {
                                    tmp -= checkboxSize * (defaultlablecount - activeLayerCount);
                                }

                                if ((scrollArea.width + y * checkboxSize) + checkboxSize <= tmp)
                                {
                                    hidelabelonscrollbar = true;
                                }

                                // Reenable the label when we move the scroll bar.
                                if (topLeft.x < 0)
                                {
                                    if (topLabelRect.width == scrollArea.width - topLeft.x)
                                    {
                                        hidelabelonscrollbar = false;
                                    }

                                    if (activeLayerCount <= defaultlablecount / 2)
                                    {
                                        if ((tmp - (scrollArea.width - ((topLeft.x - 10) * (y + 1)))) < 0)
                                        {
                                            hidelabelonscrollbar = false;
                                        }
                                    }
                                    else
                                    {
                                        float hiddenlables = (int)(tmp - scrollArea.width) / checkboxSize;
                                        int   res          = (int)((topLeft.x * -1) + 12) / checkboxSize;
                                        if (hiddenlables - res < y)
                                        {
                                            hidelabelonscrollbar = false;
                                        }
                                    }
                                }
                            }
                        }

                        var translate = new Vector3(labelSize + indent + checkboxSize * (activeLayerCount - y) + topLeft.y + topLeft.x + 10, topLeft.y, 0);
                        GUI.matrix = Matrix4x4.TRS(translate, Quaternion.identity, Vector3.one) * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 90), Vector3.one);

                        var labelRect = new Rect(2 - topLeft.x, 0, labelSize, checkboxSize + 5);
                        if (hidelabel || hidelabelonscrollbar)
                        {
                            GUI.Label(labelRect, GUIContent.none, Styles.rightLabel);
                        }
                        else
                        {
                            GUI.Label(labelRect, LayerMask.LayerToName(i), Styles.rightLabel);

                            // Empty Transparent label used to indicate highlighted row
                            var checkRect = new Rect(2 - topLeft.x, 1 /*This centers the highlight*/, labelSize + 4 + (y + 1) * checkboxSize, checkboxSize);
                            GUI.Label(checkRect, GUIContent.none, Styles.hoverStyle);

                            checkRect = new Rect(
                                GUI.matrix.MultiplyPoint(new Vector3(checkRect.position.x, checkRect.position.y + 200, 0)),
                                GUI.matrix.MultiplyPoint(new Vector3(checkRect.size.x, checkRect.size.y, 0)));
                            GUIView.current.MarkHotRegion(labelRect);
                            GUIView.current.MarkHotRegion(checkRect);
                        }

                        ++y;
                    }
                }
                GUILayout.EndScrollView();
            }

            {
                GUI.matrix = Matrix4x4.identity;
                var y = 0;

                for (var i = 0; i < kMaxLayers; ++i)
                {
                    // Is the layer valid?
                    if (LayerMask.LayerToName(i) != string.Empty)
                    {
                        // Yes so draw toggles.
                        var x         = 0;
                        var r         = GUILayoutUtility.GetRect(indent + checkboxSize * activeLayerCount + labelSize, checkboxSize);
                        var labelRect = new Rect(r.x + indent, r.y, labelSize, checkboxSize + 5);
                        GUI.Label(labelRect, LayerMask.LayerToName(i), Styles.rightLabel);

                        // Empty Transparent label used to indicate highlighted row.
                        var checkRect = new Rect(r.x + indent, r.y, labelSize + (activeLayerCount - y) * checkboxSize, checkboxSize);
                        GUI.Label(checkRect, GUIContent.none, Styles.hoverStyle);
                        GUIView.current.MarkHotRegion(labelRect);
                        GUIView.current.MarkHotRegion(checkRect);

                        // Iterate all the layers.
                        for (var j = kMaxLayers - 1; j >= 0; --j)
                        {
                            // Is the layer valid?
                            if (LayerMask.LayerToName(j) != string.Empty)
                            {
                                // Yes, so draw layer toggles.
                                if (x < activeLayerCount - y)
                                {
                                    var tooltip = new GUIContent("", LayerMask.LayerToName(i) + "/" + LayerMask.LayerToName(j));
                                    var val     = getValue(i, j);
                                    var toggle  = GUI.Toggle(new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize, checkboxSize), val, tooltip);

                                    if (toggle != val)
                                    {
                                        setValue(i, j, toggle);
                                    }
                                }
                                ++x;
                            }
                        }
                        ++y;
                    }
                }
            }

            // Buttons.
            {
                EditorGUILayout.Space(8);
                GUILayout.BeginHorizontal();

                // Made the buttons span the entire matrix of layers
                if (GUILayout.Button("Disable All", GUILayout.MinWidth((checkboxSize * activeLayerCount) / 2), GUILayout.ExpandWidth(false)))
                {
                    SetAllLayerCollisions(false, setValue);
                }

                if (GUILayout.Button("Enable All", GUILayout.MinWidth((checkboxSize * activeLayerCount) / 2), GUILayout.ExpandWidth(false)))
                {
                    SetAllLayerCollisions(true, setValue);
                }

                GUILayout.EndHorizontal();
            }
        }
コード例 #12
0
        public static void DoGUI(string title, ref bool show, GetValueFunc getValue, SetValueFunc setValue)
        {
            const int kMaxLayers   = 32;
            const int checkboxSize = 16;
            int       labelSize    = 100;
            const int indent       = 30;

            int numLayers = 0;

            for (int i = 0; i < kMaxLayers; i++)
            {
                if (LayerMask.LayerToName(i) != "")
                {
                    numLayers++;
                }
            }

            // find the longest label
            for (int i = 0; i < kMaxLayers; i++)
            {
                var textDimensions = GUI.skin.label.CalcSize(new GUIContent(LayerMask.LayerToName(i)));
                if (labelSize < textDimensions.x)
                {
                    labelSize = (int)textDimensions.x;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(0);
            show = EditorGUILayout.Foldout(show, title, true);
            GUILayout.EndHorizontal();
            if (show)
            {
                var scrollState          = GUI.GetTopScrollView();
                var scrollStatePosOffset = scrollState?.position.y ?? 0;
                var scrollPos            = scrollState?.scrollPosition ?? Vector2.zero;
                var topLabelRect         = GUILayoutUtility.GetRect(checkboxSize + labelSize, labelSize);
                var topLeft = new Vector2(topLabelRect.x, topLabelRect.y);
                var y       = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        var translate = new Vector3(labelSize + indent + checkboxSize * (numLayers - y) + topLeft.x - scrollPos.x + scrollStatePosOffset, topLeft.y - scrollPos.y + scrollStatePosOffset, 0);
                        GUI.matrix = Matrix4x4.TRS(translate, Quaternion.Euler(0, 0, 90), Vector3.one);
                        GUI.Label(new Rect(scrollPos.x, scrollPos.y, labelSize, checkboxSize), LayerMask.LayerToName(i), "RightLabel");
                        y++;
                    }
                }

                GUI.matrix = Matrix4x4.identity;
                y          = 0;
                for (int i = 0; i < kMaxLayers; i++)
                {
                    if (LayerMask.LayerToName(i) != "")
                    {
                        int x = 0;
                        var r = GUILayoutUtility.GetRect(indent + checkboxSize * numLayers + labelSize, checkboxSize);
                        GUI.Label(new Rect(r.x + indent, r.y, labelSize, checkboxSize), LayerMask.LayerToName(i), "RightLabel");
                        for (int j = kMaxLayers - 1; j >= 0; j--)
                        {
                            if (LayerMask.LayerToName(j) != "")
                            {
                                if (x < numLayers - y)
                                {
                                    var  tooltip = new GUIContent("", LayerMask.LayerToName(i) + "/" + LayerMask.LayerToName(j));
                                    bool val     = getValue(i, j);
                                    bool toggle  = GUI.Toggle(new Rect(labelSize + indent + r.x + x * checkboxSize, r.y, checkboxSize, checkboxSize), val, tooltip);
                                    if (toggle != val)
                                    {
                                        setValue(i, j, toggle);
                                    }
                                }
                                x++;
                            }
                        }
                        y++;
                    }
                }
            }
        }