コード例 #1
0
    ///

    public void RemoveElement(UAP_BaseElement element)
    {
        if (!m_AllElements.Contains(element))
        {
            m_AllElements.Remove(element);
        }
    }
コード例 #2
0
    //

    void Update()
    {
        // Get current element from Manager and check whether it is a child of this group
        GameObject go = UAP_AccessibilityManager.GetCurrentFocusObject();

        // If the object didn't change, nothing needs to be done
        if (go == m_LastFocusObject)
        {
            return;
        }
        m_LastFocusObject = go;

        bool isSelected = false;

        if (UAP_AccessibilityManager.IsEnabled())
        {
            if (go != null)
            {
                UAP_BaseElement element = go.GetComponent <UAP_BaseElement>();
                if (m_AllElements.Contains(element))
                {
                    isSelected = true;
                }
            }
        }

        if (isSelected != m_Selected)
        {
            m_Selected = isSelected;
            gameObject.BroadcastMessage("Accessibility_Selected", isSelected, SendMessageOptions.DontRequireReceiver);
        }
    }
コード例 #3
0
    //////////////////////////////////////////////////////////////////////////

    public void CheckForRegister(UAP_BaseElement item)
    {
        if (!m_HasStarted)
        {
            return;
        }

        // Is this item not yet known? Refresh List or ignore?
        bool refreshNeeded = true;

        foreach (Accessible_UIElement element in m_AllElements)
        {
            if (element.m_Object == item)
            {
                refreshNeeded = false;

                // But this item might want to be the first start item
                if (item.m_ForceStartHere && item.IsElementActive())
                {
                    m_CurrentStartItem = item;
                }

                break;
            }
        }
        if (refreshNeeded)
        {
            RefreshContainer();
        }
        //      else
        //          Debug.Log("Item " + item.name + " already known. Refresh not needed.");
    }
コード例 #4
0
    ///

    public void AddElement(UAP_BaseElement element)
    {
        if (!m_AllElements.Contains(element))
        {
            m_AllElements.Add(element);
        }
    }
コード例 #5
0
    //////////////////////////////////////////////////////////////////////////

    public void DrawNameSection()
    {
        m_NameLabel         = serializedObject.FindProperty("m_NameLabel");
        m_Text              = serializedObject.FindProperty("m_Text");
        m_Prefix            = serializedObject.FindProperty("m_Prefix");
        m_IsLocalizationKey = serializedObject.FindProperty("m_IsLocalizationKey");

        showNaming = DrawSectionHeader("Name", showNaming);

        if (showNaming)
        {
            // Name editing doesn't work in multi-select
            if (targets.Length > 1)
            {
                EditorGUILayout.LabelField("-- Multiple Values --", myLabelStyle);
                EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
            }
            else
            {
                UAP_BaseElement baseItem = (UAP_BaseElement)targets[0];
                if (!baseItem.m_IsInitialized)
                {
                    baseItem.Initialize();
                }

                EditorGUILayout.PropertyField(m_NameLabel, new GUIContent("Name Label", "If assigned, the plugin will read out the content of the label when this UI element receives focus."));

                if (baseItem.m_NameLabel != null)
                {
                    // Read the element's name from a reference label
                    string nameText = baseItem.GetText();
                    EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
                    EditorGUI.BeginDisabledGroup(baseItem.m_NameLabel != null);
                    EditorGUILayout.TextArea(nameText, myTextAreaInputStyle);
                    EditorGUI.EndDisabledGroup();
                    baseItem.m_TryToReadLabel = true;
                }
                else
                {
                    // Manual setup of the name
                    m_Text.stringValue = EditorGUILayout.TextArea(m_Text.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(baseItem.GetText(), myTextAreaInputStyle);
                        EditorGUI.EndDisabledGroup();
                        --EditorGUI.indentLevel;
                    }
                    baseItem.m_TryToReadLabel = false;
                }
            }
        }
    }
コード例 #6
0
    //////////////////////////////////////////////////////////////////////////

    public void UnRegister(UAP_BaseElement item)
    {
        foreach (Accessible_UIElement element in m_AllElements)
        {
            if (element.m_Object == item)
            {
                //Debug.Log("Unregistering " + item);
                m_AllElements.Remove(element);
                UAP_AccessibilityManager.ElementRemoved(element);
                return;
            }
        }
    }
コード例 #7
0
    //////////////////////////////////////////////////////////////////////////

    public bool SelectItem(UAP_BaseElement element, bool forceRepeatItem = false)
    {
        for (int i = 0; i < m_AllElements.Count; ++i)
        {
            Accessible_UIElement accessElement = m_AllElements[i];
            if (accessElement.m_Object == element)
            {
                m_CurrentItemIndex = i;
                // Notify the Manager that this should be the active container
                return(UAP_AccessibilityManager.MakeActiveContainer(this, forceRepeatItem));
            }
        }
        return(false);
    }
コード例 #8
0
    //////////////////////////////////////////////////////////////////////////

    public void SetAsStartItem(UAP_BaseElement item)
    {
        foreach (Accessible_UIElement element in m_AllElements)
        {
            if (element.m_Object == item)
            {
                // But this item might want to be the first start item
                if (item.m_ForceStartHere && item.IsElementActive())
                {
                    m_CurrentStartItem = item;
                    m_RefreshNextFrame = true;
                }

                return;
            }
        }

        // Item not yet known, so let's register it
        Register_Item(item);
    }
コード例 #9
0
        //////////////////////////////////////////////////////////////////////////

        public Accessible_UIElement(UAP_BaseElement item, EUIElement type, int index)
        {
            m_Type   = type;
            m_Object = item;
            GameObject targetGO = item.GetTargetGameObject();

            // Is this item inside a scroll view?
            if (targetGO.GetComponentInParent <ScrollRect>() != null)
            {
                item.m_IsInsideScrollView = true;
            }
#if ACCESS_NGUI
            if (targetGO.GetComponentInParent <UIScrollView>() != null)
            {
                item.m_IsInsideScrollView = true;
            }
#endif

            CalculatePositionOrder(item, index);
            m_Object.m_PositionOrder  = m_PositionOrder;
            m_Object.m_SecondaryOrder = m_SecondaryOrder;
            m_Object.m_Pos            = m_Pos;
        }
コード例 #10
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;
        }
    }
コード例 #11
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;
                }
            }
        }
コード例 #12
0
    //////////////////////////////////////////////////////////////////////////

    public void DrawNameSection(bool showNameLabel = true)
    {
        m_NameLabel            = serializedObject.FindProperty("m_NameLabel");
        m_AdditionalNameLabels = serializedObject.FindProperty("m_AdditionalNameLabels");
        m_Text                    = serializedObject.FindProperty("m_Text");
        m_Prefix                  = serializedObject.FindProperty("m_Prefix");
        m_IsLocalizationKey       = serializedObject.FindProperty("m_IsLocalizationKey");
        m_PrefixIsLocalizationKey = serializedObject.FindProperty("m_PrefixIsLocalizationKey");
        m_PrefixIsPostFix         = serializedObject.FindProperty("m_PrefixIsPostFix");

        showNaming = DrawSectionHeader("Name", showNaming);

        if (showNaming)
        {
            // Name editing doesn't work in multi-select
            if (targets.Length > 1)
            {
                EditorGUILayout.LabelField("-- Multiple Values --", myLabelStyle);
                EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
            }
            else
            {
                UAP_BaseElement baseItem = (UAP_BaseElement)targets[0];
                if (!baseItem.m_IsInitialized)
                {
                    baseItem.Initialize();
                }

                if (showNameLabel)
                {
                    EditorGUILayout.PropertyField(m_NameLabel, new GUIContent("Name Label", "If assigned, the plugin will read out the content of the label when this UI element receives focus.\nUse {0} in the prefix to place this text."));
                    // Only if at least 1 name label is set, allow the user to set more
                    if (m_NameLabel.objectReferenceValue != null)
                    {
                        EditorGUILayout.PropertyField(m_AdditionalNameLabels, new GUIContent("Combine Labels", "Additional label out of which the resulting text can be combined via {1}, {2}, etc..."), true);
                    }
                }
                else
                {
                    baseItem.m_NameLabel = null;
                }

                if (baseItem.m_NameLabel != null)
                {
                    // Read the element's name from a reference label
                    EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Combine String", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead.\nUse {1}, {2}, ... to access additional labels."));
                    EditorGUILayout.PropertyField(m_PrefixIsLocalizationKey, 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."));
                    if (m_AdditionalNameLabels.arraySize == 0)
                    {
                        EditorGUILayout.PropertyField(m_PrefixIsPostFix, new GUIContent("Is Postfix", "If set to true, the combination string will be add behind the label's content, not in front of it."));
                    }
                    string nameText = baseItem.GetTextToRead();
                    EditorGUI.BeginDisabledGroup(baseItem.m_NameLabel != null);
                    EditorGUILayout.TextArea(nameText, myTextAreaInputStyle);
                    EditorGUI.EndDisabledGroup();
                    baseItem.m_TryToReadLabel = true;
                }
                else
                {
                    // Manual setup of the name
                    m_Text.stringValue = EditorGUILayout.TextArea(m_Text.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(baseItem.GetTextToRead(), myTextAreaInputStyle);
                        EditorGUI.EndDisabledGroup();
                        --EditorGUI.indentLevel;
                    }
                    baseItem.m_TryToReadLabel = false;
                }
            }
        }
    }
コード例 #13
0
    //////////////////////////////////////////////////////////////////////////

    public void SetTileType(int tileType)
    {
        m_TileType = tileType;

        // Create new tile if needed
        if (m_Tile == null)
        {
            m_Tile = Instantiate(Resources.Load("Button")) as GameObject;
            m_Tile.transform.SetParent(transform, false);
            m_Tile.transform.SetAsFirstSibling();
            m_AccessibilityHelper = m_Tile.GetComponentInChildren <UAP_BaseElement>();
            m_AccessibilityHelper.m_TryToReadLabel = false;
            //m_ButtonLabel = m_Tile.GetComponentInChildren<Text>();
            m_Button = m_Tile.GetComponentInChildren <Button>();

            // React to both - button presses and pointer events
            m_Button.onClick.AddListener(OnButtonPress);
            EventTrigger trigger = m_Button.gameObject.AddComponent <EventTrigger>();
            {
                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.EndDrag;
                entry.callback.AddListener((data) => { OnDragEndDelegate((PointerEventData)data); });
                trigger.triggers.Add(entry);
            }
            {
                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.Drag;
                entry.callback.AddListener((data) => { OnDragUpdateDelegate((PointerEventData)data); });
                trigger.triggers.Add(entry);
            }
            {
                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.PointerDown;
                entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
                trigger.triggers.Add(entry);
            }
            {
                EventTrigger.Entry entry = new EventTrigger.Entry();
                entry.eventID = EventTriggerType.PointerUp;
                entry.callback.AddListener((data) => { OnPointerUpDelegate((PointerEventData)data); });
                trigger.triggers.Add(entry);
            }

            SetBGType(m_BGType);
        }

        if (tileType < 0)
        {
            m_AccessibilityHelper.m_Text = "none";
            //m_ButtonLabel.text = " ";
            //m_ButtonLabel.color = Color.black;
            m_GemImage.sprite = null;
            m_GemImage.gameObject.SetActive(false);
            //m_Button.gameObject.SetActive(false);
        }
        else
        {
            // Set info
            m_AccessibilityHelper.m_Text = GetTileTypeName();
            //m_ButtonLabel.text = " ";// GetTileTypeName().Substring(0, 1);
            //m_ButtonLabel.color = colorList[tileType];
            m_GemImage.sprite = m_GemTextures[tileType];
            m_GemImage.gameObject.SetActive(true);
            //m_Button.gameObject.SetActive(true);

            m_Button.gameObject.name = GetTileTypeName();
            gameObject.name          = GetTileTypeName();
        }
    }