예제 #1
0
    //////////////////////////////////////////////////////////////////////////

    public void DrawContainerNameSection()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.Separator();
        m_ContainerName     = serializedObject.FindProperty("m_ContainerName");
        m_IsLocalizationKey = serializedObject.FindProperty("m_IsLocalizationKey");

        showGroupNaming = DrawSectionHeader("Group Name", showGroupNaming);

        if (showGroupNaming)
        {
            // Name editing doesn't work in multi-select
            if (targets.Length > 1)
            {
                EditorGUILayout.LabelField("-- Multiple Values --", myLabelStyle);
            }
            else
            {
                AccessibleUIGroupRoot container = (AccessibleUIGroupRoot)targets[0];
                // Manual setup of the name
                EditorGUILayout.HelpBox("(Optional) The plugin can read out the name of this UI group if one of it's elements receives focus. The name is not repeated while the focus stays within the container.", MessageType.Info);
                m_ContainerName.stringValue = EditorGUILayout.TextArea(m_ContainerName.stringValue, myTextAreaInputStyle);
                EditorGUILayout.PropertyField(m_IsLocalizationKey, new GUIContent("Is Localization Key", "If set to true, the plugin will treat the name as a localization key and request the localization at runtime."));
                // Display localized text if needed
                if (m_IsLocalizationKey.boolValue)
                {
                    ++EditorGUI.indentLevel;
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.TextArea(container.GetContainerName(), myTextAreaInputStyle);
                    EditorGUI.EndDisabledGroup();
                    --EditorGUI.indentLevel;
                }
            }
        }
    }
예제 #2
0
    //////////////////////////////////////////////////////////////////////////

    private void GetContainer()
    {
        Transform t = transform;

        while (t != null && AUIContainer == null)
        {
            AUIContainer = t.gameObject.GetComponent <AccessibleUIGroupRoot>();
            t            = t.parent;
        }
    }
예제 #3
0
    //////////////////////////////////////////////////////////////////////////

    void Register_Item(UAP_BaseElement item)
    {
        EUIElement type = item.m_Type;

        // Is this the correct container for this element?
        AccessibleUIGroupRoot container = null;
        Transform             tr        = item.transform;

        container = tr.gameObject.GetComponent <AccessibleUIGroupRoot>();
        while (container == null && tr.parent != null)
        {
            tr        = tr.parent;
            container = tr.gameObject.GetComponent <AccessibleUIGroupRoot>();
        }
        if (container != this)
        {
            return;
        }

        // sanity check
        if (container == null)
        {
            Debug.LogError("[Accessibility] A UI element tried to register with " + gameObject.name + " but not only am I not the right container, there seems to be no container in it's parent hierarchy.");
            return;
        }

        // sorted by position, top to bottom, left to right
        // sort it into the list of UI items
        Accessible_UIElement newElement = new Accessible_UIElement(item, type, m_AllElements.Count);
        int  order          = newElement.m_PositionOrder;
        int  secondaryOrder = newElement.m_SecondaryOrder;
        int  count          = m_AllElements.Count;
        bool added          = false;

        for (int i = 0; i < count; ++i)
        {
            if (order < m_AllElements[i].m_PositionOrder)
            {
                m_AllElements.Insert(i, newElement);
                added = true;
                break;
            }
            else if (order == m_AllElements[i].m_PositionOrder)
            {
                // Take Secondary Order into account (for scroll views an the like)
                int difference = m_AllElements[i].m_SecondaryOrder - secondaryOrder;
                //int testVal = m_AllElements[i].m_SecondaryOrder;
                //int currentVal = secondaryOrder;
                if (difference > 0)
                {
                    m_AllElements.Insert(i, newElement);
                    added = true;
                    break;
                }
            }
        }
        if (!added)
        {
            m_AllElements.Add(newElement);
        }

        // Save it if this element is to be the first one to use
        if (item.m_ForceStartHere)
        {
            m_CurrentStartItem = item;
        }
    }
예제 #4
0
        //////////////////////////////////////////////////////////////////////////

        public void CalculatePositionOrder(UAP_BaseElement uiElement, int backupIndex)
        {
            GameObject obj = uiElement.gameObject;

            // If no parent transform is set, use the next higher up group root if possible
            if (uiElement.m_ManualPositionParent == null)
            {
                AccessibleUIGroupRoot groupRoot = uiElement.GetUIGroupContainer();
                uiElement.m_ManualPositionParent = (groupRoot != null ? groupRoot.gameObject : null);
            }

            bool hasManualOrder = uiElement.m_ManualPositionOrder >= 0 && uiElement.m_ManualPositionParent != null;

            if (hasManualOrder)
            {
                obj = uiElement.m_ManualPositionParent;
            }

            Vector2 anchorMin            = new Vector2();
            Vector2 anchorMax            = new Vector2();
            Vector2 centerPos            = new Vector2();
            bool    gotValidValues       = false;
            bool    secondaryOrderNeeded = false;

            // Calculation for Unity UI (uUI)
            RectTransform t = obj.GetComponent <RectTransform>();

            if (t != null)
            {
                // Does this ui element lie inside a scroll rect?
                Transform     pt = (Transform)t;
                RectTransform primaryOrderBase = t;
                while (pt.parent != null)
                {
                    if (pt.parent.gameObject.GetComponent <ScrollRect>() != null)
                    {
                        primaryOrderBase     = pt.parent.gameObject.GetComponent <RectTransform>();
                        secondaryOrderNeeded = true;
                        break;
                    }
                    pt = pt.parent;
                }

                // Calculate up until the Canvas is found. Otherwise nested objects won't be correctly sorted
                GetAbsoluteAnchors(primaryOrderBase, out anchorMin, out anchorMax, out centerPos);
                gotValidValues = true;
            }

#if ACCESS_NGUI
            UIWidget widget = obj.GetComponent <UIWidget>();
            if (widget == null)
            {
                widget = obj.GetComponentInChildren <UIWidget>();
            }

            Camera uiCam = (widget != null) ? NGUITools.FindCameraForLayer(widget.gameObject.layer) : null;
            if (widget != null && uiCam != null)
            {
                // Transform from world to screen coordinates, if there is a main camera?
                centerPos = uiCam.WorldToScreenPoint(widget.transform.position);
                anchorMin = uiCam.WorldToScreenPoint(widget.worldCorners[0]);
                anchorMax = uiCam.WorldToScreenPoint(widget.worldCorners[1]);


                gotValidValues = true;
            }
#endif


            if (gotValidValues)
            {
                /*
                 * m_Pos = anchorMin + 0.5f * (anchorMax - anchorMin);
                 * m_PositionOrder = (int)(10.0f * (m_Pos.x + (1000.0f * (1.0f - m_Pos.y))));
                 * if (hasManualOrder)
                 *      m_PositionOrder += uiElement.m_ManualPositionOrder;
                 */

                Vector3 wPos = centerPos;
                m_Pos.x = wPos.x;
                m_Pos.y = wPos.y;
                m_Pos.Scale(new Vector2(1.0f / (float)Screen.width, 1.0f / (float)Screen.height));
                m_PositionOrder = (int)(10.0f * (m_Pos.x + (1000.0f * (1.0f - m_Pos.y))));
                if (hasManualOrder)
                {
                    m_PositionOrder += uiElement.m_ManualPositionOrder;
                }

                // For 2D Navigation this is needed to adjust for the aspect ratio!
                m_Pos.Scale(new Vector2(Screen.width, Screen.height));

                // For the secondary order always use the actual game object (regardless of manual order parent reference)
                obj = uiElement.gameObject;

                // Do we need a secondary order?
                if (secondaryOrderNeeded)
                {
                    // TODO: This might need a different calculation in NGUI

                    Vector2 pos = obj.transform.TransformPoint(new Vector3(0.5f, 0.5f, 0.0f));
                    m_SecondaryOrder = (int)(10.0f * (pos.x + (1000.0f * (1.0f - pos.y))));
                }
            }
            else
            {
                // 3D Objects obviously wouldn't have any UI transforms
                if (uiElement is UAP_BaseElement_3D)
                {
                    if (uiElement.m_ManualPositionOrder >= 0)
                    {
                        m_PositionOrder = uiElement.m_ManualPositionOrder;
                    }
                    else
                    {
                        m_PositionOrder = backupIndex;
                    }
                    m_Pos = obj.transform.position;
                }
                else
                {
                    Debug.LogWarning("[Accessibility] Could not find any UI transforms on UI element " + obj.name + " that the accessibility plugin can understand - ordering UI elements by manual position index (if present) or order of initialization.");
                    if (uiElement.m_ManualPositionOrder >= 0)
                    {
                        m_PositionOrder = uiElement.m_ManualPositionOrder;
                    }
                    else
                    {
                        m_PositionOrder = backupIndex;
                    }
                    m_Pos = obj.transform.position;
                }
            }
        }