コード例 #1
0
ファイル: RulerEditor.cs プロジェクト: arhcy/unityrulers
        void OnGUI()
        {
            CheckInit();

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            #region settings
            EditorGUILayout.BeginVertical(GUI.skin.box);
            showSettings = EditorGUILayout.Foldout(showSettings, settingsStr, groupFoldoutStyle);

            if (showSettings)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(showTooltipsStr, Width50);
                var showTooltips = EditorGUILayout.Toggle(data.showTooltips, Width50);
                if (showTooltips != data.showTooltips)
                {
                    data.showTooltips = showTooltips;
                    InstanceGUIContent();
                    MarkDirty();
                }

                EditorGUILayout.LabelField(enableShortcutsStr, GUILayout.Width(60));
                var enableShortcuts = EditorGUILayout.Toggle(data.enableShortcuts, Width50);
                if (enableShortcuts != data.enableShortcuts)
                {
                    data.enableShortcuts = enableShortcuts;
                    MarkDirty();
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(resetDataGC, GUILayout.Width(100)))
                {
                    ResetData();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.LabelField(rulerThicknessStr);
                CheckDirty(ref data.rulerThickness, EditorGUILayout.IntSlider(data.rulerThickness, 1, 30));

                EditorGUILayout.LabelField(pointThicknessStr);
                CheckDirty(ref data.pointThickness, EditorGUILayout.IntSlider(data.pointThickness, 0, 100));

                EditorGUILayout.LabelField(arrowThicknessStr);
                CheckDirty(ref data.arrowThickness, EditorGUILayout.IntSlider(data.arrowThickness, 0, 50));

                EditorGUILayout.LabelField(rulerColorStr);
                CheckDirty(ref data.rulerColor, EditorGUILayout.ColorField(data.rulerColor));

                EditorGUILayout.LabelField(textSizeStr);
                CheckDirty(ref data.fontSize, EditorGUILayout.IntSlider(data.fontSize, 4, 40));
                labelStyle.fontSize = data.fontSize;

                EditorGUILayout.LabelField(textColorStr);
                CheckDirty(ref data.textColor, EditorGUILayout.ColorField(data.textColor));
                labelStyle.normal.textColor = data.textColor;

                EditorGUILayout.LabelField(displayPrecisionStr);
                var oldPrecision = data.precision;
                CheckDirty(ref data.precision, EditorGUILayout.IntSlider(data.precision, 1, 5));
                if (data.precision != oldPrecision)
                {
                    precisionStr = "0." + new string('0', data.precision);
                }
            }

            EditorGUILayout.EndVertical();
            #endregion settings

            #region filter
            var toolbarSelection = GUILayout.Toolbar(-1, toolbarStrings, toolbarStyle);
            switch (toolbarSelection)
            {
            case 0:
                for (int i = 0; i < data.rulers.Length; ++i)
                {
                    data.rulers[i].isVisible = false;
                }
                MarkDirty();
                break;

            case 1:
                for (int i = 0; i < data.rulers.Length; ++i)
                {
                    data.rulers[i].isVisible = true;
                }
                MarkDirty();
                break;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(filterStr, Width50);
            var filterTransform = (Transform)EditorGUILayout.ObjectField(data.filterTransform, typeof(Transform), true, GUILayout.ExpandWidth(true));
            if (filterTransform != data.filterTransform)
            {
                data.filterTransform = filterTransform;
                MarkDirty();
            }

            if (GUILayout.Button(clearFilterGC, miniButtonStyle, Width20))
            {
                if (data.filterTransform != null)
                {
                    data.filterTransform = null;
                    MarkDirty();
                }
            }

            EditorGUILayout.EndHorizontal();
            #endregion filter

            EditorGUILayout.BeginVertical();
            int removeRulerIndex    = -1;
            int duplicateRulerIndex = -1;
            for (int i = 0; i < data.rulers.Length; ++i)
            {
                var r = data.rulers[i];
                if (data.filterTransform != null && r.a != data.filterTransform && r.b != data.filterTransform)
                {
                    continue;
                }

                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.BeginHorizontal();

                CheckDirty(ref r.isVisible, GUILayout.Toggle(r.isVisible, visibilityGC, toggleStyle));

                if (GUILayout.Button(duplicateRulerGC, miniButtonStyle, Width20))
                {
                    duplicateRulerIndex = i;
                }

                CheckDirty(ref r.color, EditorGUILayout.ColorField(r.color, Width50));
                CheckDirty(ref r.textColor, EditorGUILayout.ColorField(r.textColor, Width50));

                if (GUILayout.Button(r.isLocal ? exDataIsLocalGC : exDataIsGlobalGC, Width20))
                {
                    r.isLocal = !r.isLocal;
                    MarkDirty();
                }

                var showExDist = GUILayout.Toggle(r.showExDist, exDataDistanceGC, ButtonStr);
                if (showExDist != r.showExDist)
                {
                    r.showExDist = showExDist;
                    MarkDirty();
                }

                var showExAngle = GUILayout.Toggle(r.showExAngle, exDataAngleGC, ButtonStr);
                if (showExAngle != r.showExAngle)
                {
                    r.showExAngle = showExAngle;
                    MarkDirty();
                }

                GUILayout.FlexibleSpace();
                if (GUILayout.Button(deleteRulerGC, miniButtonStyle, Width20))
                {
                    removeRulerIndex = i;
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(frameGC, miniButtonStyle, Width20))
                {
                    // search for objects
                    selectedTransform = r.a;
                }
                var aTransform = (Transform)EditorGUILayout.ObjectField(r.a, typeof(Transform), true);
                if (aTransform != r.a)
                {
                    r.a = aTransform;
                    MarkDirty();
                }

                EditorGUILayout.LabelField(r.delta.magnitude.ToString(precisionStr), boldStyle, GUILayout.Width(40));

                if (GUILayout.Button(frameGC, miniButtonStyle, Width20))
                {
                    // search for objects
                    selectedTransform = r.b;
                }

                var bTransform = (Transform)EditorGUILayout.ObjectField(r.b, typeof(Transform), true);
                if (bTransform != r.b)
                {
                    r.b = bTransform;
                    MarkDirty();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }

            if (duplicateRulerIndex != -1)
            {
                var ruler = data.rulers[duplicateRulerIndex];
                var r     = new Ruler();
                r.color     = ruler.color;
                r.textColor = ruler.textColor;
                r.a         = ruler.a;
                r.b         = ruler.b;
                data.Add(r, duplicateRulerIndex + 1);
                MarkDirty();
            }

            if (removeRulerIndex != -1)
            {
                data.RemoveAt(removeRulerIndex);
                MarkDirty();
            }

            if (GUILayout.Button(addRulerGC, miniButtonStyle))
            {
                AddRuler();
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndScrollView();

            CheckShortcuts();
        }
コード例 #2
0
ファイル: RulerEditor.cs プロジェクト: arhcy/unityrulers
        void DrawExDist(Ruler r, StringBuilder sb)
        {
            if (!r.showExDist)
            {
                return;
            }

            var oldColor = Handles.color;
            var delta    = r.delta;

            sb.Append(nlStr);

            if (r.isLocal)
            {
                var rdot  = Vector3.Dot(delta, r.a.right);
                var udot  = Vector3.Dot(delta, r.a.up);
                var fdot  = Vector3.Dot(delta, r.a.forward);
                var rproj = rdot * r.a.right;
                var uproj = udot * r.a.up;
                var fproj = fdot * r.a.forward;

                //right
                Handles.color = distXColor;
                Handles.DrawLine(r.a.position, r.a.position + rproj);

                // up
                Handles.color = distYColor;
                Handles.DrawLine(r.a.position + rproj + fproj, r.a.position + rproj + fproj + uproj);

                // forward
                Handles.color = distZColor;
                Handles.DrawLine(r.a.position + rproj, r.a.position + rproj + fproj);

                sb.Append(deltaRStr);
                sb.AppendLine((rdot < 0 ? "-" : "") + rproj.magnitude.ToString(precisionStr));
                sb.Append(deltaUStr);
                sb.AppendLine((udot < 0 ? "-" : "") + uproj.magnitude.ToString(precisionStr));
                sb.Append(deltaFStr);
                sb.Append((fdot < 0 ? "-" : "") + fproj.magnitude.ToString(precisionStr));
            }
            else
            {
                var rproj = new Vector3(delta.x, 0f, 0f);
                var uproj = new Vector3(0f, delta.y, 0f);
                var fproj = new Vector3(0f, 0f, delta.z);

                //right
                Handles.color = distXColor;
                Handles.DrawLine(r.a.position, r.a.position + rproj);

                // up
                Handles.color = distYColor;
                Handles.DrawLine(r.a.position + rproj + fproj, r.a.position + rproj + fproj + uproj);

                // forward
                Handles.color = distZColor;
                Handles.DrawLine(r.a.position + rproj, r.a.position + rproj + fproj);

                sb.Append(deltaXStr);
                sb.AppendLine(delta.x.ToString(precisionStr));
                sb.Append(deltaYStr);
                sb.AppendLine(delta.y.ToString(precisionStr));
                sb.Append(deltaZStr);
                sb.Append(delta.z.ToString(precisionStr));
            }
            Handles.color = oldColor;
        }
コード例 #3
0
ファイル: RulerEditor.cs プロジェクト: Lu-D/StealthRogue
        void OnGUI()
        {
            CheckInit();

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            #region settings
            EditorGUILayout.BeginVertical(GUI.skin.box);
            showSettings = EditorGUILayout.Foldout(showSettings, settingsStr, groupFoldoutStyle);

            if (showSettings)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(showTooltipsStr, Width50);
                var showTooltips = EditorGUILayout.Toggle(data.showTooltips, Width50);
                if (showTooltips != data.showTooltips)
                {
                    data.showTooltips = showTooltips;
                    InstanceGUIContent();
                    MarkDirty();
                }

                EditorGUILayout.LabelField(enableShortcutsStr, GUILayout.Width(60));
                var enableShortcuts = EditorGUILayout.Toggle(data.enableShortcuts, Width50);
                if (enableShortcuts != data.enableShortcuts)
                {
                    data.enableShortcuts = enableShortcuts;
                    MarkDirty();
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(resetDataGC, GUILayout.Width(100)))
                {
                    ResetData();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.LabelField(rulerThicknessStr);
                CheckDirty(ref data.rulerThickness, EditorGUILayout.IntSlider(data.rulerThickness, 1, 30));

                EditorGUILayout.LabelField(pointSizeStr);
                CheckDirty(ref data.pointSize, EditorGUILayout.IntSlider(data.pointSize, 0, 100));

                EditorGUILayout.LabelField(arrowSizeStr);
                CheckDirty(ref data.arrowSize, EditorGUILayout.IntSlider(data.arrowSize, 0, 50));

                EditorGUILayout.LabelField(rulerColorStr);
                CheckDirty(ref data.rulerColor, EditorGUILayout.ColorField(data.rulerColor));

                EditorGUILayout.LabelField(textSizeStr);
                CheckDirty(ref data.fontSize, EditorGUILayout.IntSlider(data.fontSize, 4, 40));
                labelStyle.fontSize = data.fontSize;

                EditorGUILayout.LabelField(textColorStr);
                CheckDirty(ref data.textColor, EditorGUILayout.ColorField(data.textColor));
                labelStyle.normal.textColor = data.textColor;

                EditorGUILayout.LabelField(displayPrecisionStr);
                var oldPrecision = data.precision;
                CheckDirty(ref data.precision, EditorGUILayout.IntSlider(data.precision, 1, 5));
                if (data.precision != oldPrecision)
                {
                    precisionStr = "0." + new string('0', data.precision);
                }
            }

            EditorGUILayout.EndVertical();
            #endregion settings

            #region filter
            var toolbarSelection = GUILayout.Toolbar(-1, toolbarStrings, toolbarStyle);
            switch (toolbarSelection)
            {
            case 0:
                for (int i = 0; i < data.rulers.Length; ++i)
                {
                    data.rulers[i].isVisible = false;
                }
                MarkDirty();
                break;

            case 1:
                for (int i = 0; i < data.rulers.Length; ++i)
                {
                    data.rulers[i].isVisible = true;
                }
                MarkDirty();
                break;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(filterStr, Width50);
            var filterTransform = (Transform)EditorGUILayout.ObjectField(data.filterTransform, typeof(Transform), true, GUILayout.ExpandWidth(true));
            if (filterTransform != data.filterTransform)
            {
                data.filterTransform = filterTransform;
                MarkDirty();
            }

            if (GUILayout.Button(clearFilterGC, miniButtonStyle, Width20))
            {
                if (data.filterTransform != null)
                {
                    data.filterTransform = null;
                    MarkDirty();
                }
            }

            EditorGUILayout.EndHorizontal();
            #endregion filter

            #region ruler
            EditorGUILayout.BeginVertical();
            int removeRulerIndex    = -1;
            int duplicateRulerIndex = -1;
            for (int i = 0; i < data.rulers.Length; ++i)
            {
                var r = data.rulers[i];
                if (data.filterTransform != null && r.a != data.filterTransform && r.b != data.filterTransform)
                {
                    continue;
                }

                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.BeginHorizontal();

                CheckDirty(ref r.isVisible, GUILayout.Toggle(r.isVisible, visibilityGC, toggleStyle));

                if (GUILayout.Button(duplicateRulerGC, miniButtonStyle, Width20))
                {
                    duplicateRulerIndex = i;
                }

                CheckDirty(ref r.color, EditorGUILayout.ColorField(r.color, Width50));
                CheckDirty(ref r.textColor, EditorGUILayout.ColorField(r.textColor, Width50));

                if (GUILayout.Button(r.isLocal ? exDataIsLocalGC : exDataIsGlobalGC, Width20))
                {
                    r.isLocal = !r.isLocal;
                    MarkDirty();
                }

                var showExDist = GUILayout.Toggle(r.showExDist, exDataDistanceGC, ButtonStr);
                if (showExDist != r.showExDist)
                {
                    r.showExDist = showExDist;
                    MarkDirty();
                }

                var showExAngle = GUILayout.Toggle(r.showExAngle, exDataAngleGC, ButtonStr);
                if (showExAngle != r.showExAngle)
                {
                    r.showExAngle = showExAngle;
                    MarkDirty();
                }

                GUILayout.FlexibleSpace();
                if (GUILayout.Button(deleteRulerGC, miniButtonStyle, Width20))
                {
                    removeRulerIndex = i;
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(frameGC, miniButtonStyle, Width20))
                {
                    // search for objects
                    selectedTransform = r.a;
                }
                var aTransform = (Transform)EditorGUILayout.ObjectField(r.a, typeof(Transform), true);
                if (aTransform != r.a)
                {
                    r.a = aTransform;
                    MarkDirty();
                }

                #region distance editor
                if (r.isDistanceNonzero)
                {
                    if (r.isEditingDistance)
                    {
                        GUI.SetNextControlName("deltaEditor");
                        var oldDistStr = r.delta.magnitude.ToString();
                        var newDistStr = EditorGUILayout.TextField(oldDistStr, GUILayout.Width(40));
                        newDistStr = Regex.Replace(newDistStr, @"[^0-9.-]", ""); // filter for real numbers only

                        if (oldDistStr != newDistStr)
                        {
                            float newDist = 0f;
                            try {
                                newDist = float.Parse(newDistStr);
                            } catch (FormatException e) {
                                // ignore
                            }
                            if (newDist != 0f)
                            {
                                var newDelta = r.delta.normalized * newDist;
                                r.b.position = r.a.position + newDelta;
                                MarkDirty();
                            }
                        }

                        if (Event.current.isKey && Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "deltaEditor")
                        {
                            r.isEditingDistance = false;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(r.delta.magnitude.ToString(precisionStr), boldStyle, GUILayout.Width(40)))
                        {
                            r.isEditingDistance = true;
                        }
                    }
                }
                else
                {
                    r.isEditingDistance = false;
                    EditorGUILayout.LabelField(r.delta.magnitude.ToString(precisionStr), EditorStyles.label, GUILayout.Width(40));
                }
                #endregion delta editor

                if (GUILayout.Button(frameGC, miniButtonStyle, Width20))
                {
                    // search for objects
                    selectedTransform = r.b;
                }

                var bTransform = (Transform)EditorGUILayout.ObjectField(r.b, typeof(Transform), true);
                if (bTransform != r.b)
                {
                    r.b = bTransform;
                    MarkDirty();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }
            #endregion ruler

            if (duplicateRulerIndex != -1)
            {
                var ruler = data.rulers[duplicateRulerIndex];
                var r     = new Ruler();
                r.color     = ruler.color;
                r.textColor = ruler.textColor;
                r.a         = ruler.a;
                r.b         = ruler.b;
                data.Add(r, duplicateRulerIndex + 1);
                MarkDirty();
            }

            if (removeRulerIndex != -1)
            {
                data.RemoveAt(removeRulerIndex);
                MarkDirty();
            }

            if (GUILayout.Button(addRulerGC, miniButtonStyle))
            {
                AddRuler();
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndScrollView();

            CheckShortcuts();
        }