public override void OnInspectorGUI()
            {
                base.OnInspectorGUI();

                NearInteractionTouchable t  = (NearInteractionTouchable)target;
                RectTransform            rt = t.GetComponent <RectTransform>();

                if (rt != null)
                {
                    // Resize Helper
                    if (rt.sizeDelta != t.bounds)
                    {
                        UnityEditor.EditorGUILayout.HelpBox("Bounds do not match the RectTransform size", UnityEditor.MessageType.Warning);
                        if (GUILayout.Button("Fix Bounds"))
                        {
                            UnityEditor.Undo.RecordObject(t, "Fix Bounds");
                            t.bounds = rt.sizeDelta;
                        }
                    }

                    if (t.GetComponentInParent <Canvas>() != null && t.localForward != new Vector3(0, 0, -1))
                    {
                        UnityEditor.EditorGUILayout.HelpBox("Unity UI generally has forward facing away from the front. The LocalForward direction specified does not match the expected forward direction.", UnityEditor.MessageType.Warning);
                        if (GUILayout.Button("Fix Forward Direction"))
                        {
                            UnityEditor.Undo.RecordObject(t, "Fix Forward Direction");
                            t.localForward = new Vector3(0, 0, -1);
                        }
                    }
                }
            }
示例#2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            NearInteractionTouchable t = (NearInteractionTouchable)target;
            BoxCollider   bc           = t.GetComponent <BoxCollider>();
            RectTransform rt           = t.GetComponent <RectTransform>();

            if (bc != null)
            {
                // project size to local coordinate system
                Vector2 adjustedSize = new Vector2(
                    Math.Abs(Vector3.Dot(bc.size, t.LocalRight)),
                    Math.Abs(Vector3.Dot(bc.size, t.LocalUp)));

                // Resize helper
                if (adjustedSize != t.Bounds)
                {
                    UnityEditor.EditorGUILayout.HelpBox("Bounds do not match the BoxCollider size", UnityEditor.MessageType.Warning);
                    if (GUILayout.Button("Fix Bounds"))
                    {
                        UnityEditor.Undo.RecordObject(t, "Fix Bounds");
                        t.Bounds = adjustedSize;
                    }
                }

                // Recentre helper
                if (t.LocalCenter != bc.center + Vector3.Scale(bc.size / 2.0f, t.LocalForward))
                {
                    UnityEditor.EditorGUILayout.HelpBox("Center does not match the BoxCollider center", UnityEditor.MessageType.Warning);
                    if (GUILayout.Button("Fix Center"))
                    {
                        UnityEditor.Undo.RecordObject(t, "Fix Center");
                        t.LocalCenter = bc.center + Vector3.Scale(bc.size / 2.0f, t.LocalForward);
                    }
                }
            }
            else if (rt != null)
            {
                // Resize Helper
                if (rt.sizeDelta != t.Bounds)
                {
                    UnityEditor.EditorGUILayout.HelpBox("Bounds do not match the RectTransform size", UnityEditor.MessageType.Warning);
                    if (GUILayout.Button("Fix Bounds"))
                    {
                        UnityEditor.Undo.RecordObject(t, "Fix Bounds");
                        t.Bounds = rt.sizeDelta;
                    }
                }

                if (t.GetComponentInParent <Canvas>() != null && t.LocalForward != new Vector3(0, 0, -1))
                {
                    UnityEditor.EditorGUILayout.HelpBox("Unity UI generally has forward facing away from the front. The LocalForward direction specified does not match the expected forward direction.", UnityEditor.MessageType.Warning);
                    if (GUILayout.Button("Fix Forward Direction"))
                    {
                        UnityEditor.Undo.RecordObject(t, "Fix Forward Direction");
                        t.SetLocalForward(new Vector3(0, 0, -1));
                    }
                }
            }

            // Perpendicular forward/up vectors helpers
            if (!t.AreLocalVectorsOrthogonal)
            {
                UnityEditor.EditorGUILayout.HelpBox("Local Forward and Local Up are not perpendicular.", UnityEditor.MessageType.Warning);
                if (GUILayout.Button("Fix Local Up"))
                {
                    UnityEditor.Undo.RecordObject(t, "Fix Local Up");
                    t.SetLocalForward(t.LocalForward);
                }
                if (GUILayout.Button("Fix Local Forward"))
                {
                    UnityEditor.Undo.RecordObject(t, "Fix Local Forward");
                    t.SetLocalUp(t.LocalUp);
                }
            }
        }