Пример #1
0
 /// <summary>
 /// Registers the control with events and the UI Manager
 /// </summary>
 public virtual void RegisterControl(vp_UIControl control)
 {
     if (!Controls.Contains(control))
     {
         vp_InputMobile.Register(control);
         Controls.Add(control);
     }
 }
Пример #2
0
    /// <summary>
    /// event when the autopitch checkbox is toggled
    /// </summary>
    public virtual void AutoPitchToggle( vp_UIControl control )
    {
        if(TouchLookPad == null)
            return;

        bool value = ((vp_UIToggle)control).State;

        TouchLookPad.AutoPitchSpeed = value ? m_AutoPitchSpeed == 0 ? 2.75f : m_AutoPitchSpeed : 0;
    }
Пример #3
0
    /// <summary>
    /// event when the tips checkbox is toggled
    /// </summary>
    public virtual void HelpTipsToggle( vp_UIControl control )
    {
        if(SimpleHUD == null)
            return;

        bool value = ((vp_UIToggle)control).State;

        SimpleHUD.ShowTips = value;
    }
Пример #4
0
    /// <summary>
    /// event recieved when a new controller type is chosen from the dropdown
    /// </summary>
    public virtual void ChangeControllerType( vp_UIControl control )
    {
        string value = ((vp_UIDropdownList)control).CurrentItem;

        if(value == "Dynamic Joystick")
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.DynamicJoystick;
        else if(value == "Static Joystick")
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.StaticJoystick;
        else
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.TouchPad;
    }
Пример #5
0
    /// <summary>
    /// event when the autopitch checkbox is toggled
    /// </summary>
    public virtual void AutoPitchToggle(vp_UIControl control)
    {
        if (TouchLookPad == null)
        {
            return;
        }

        bool value = ((vp_UIToggle)control).State;

        TouchLookPad.AutoPitchSpeed = value ? m_AutoPitchSpeed == 0 ? 2.75f : m_AutoPitchSpeed : 0;
    }
Пример #6
0
    /// <summary>
    /// event when the tips checkbox is toggled
    /// </summary>
    public virtual void HelpTipsToggle(vp_UIControl control)
    {
        if (SimpleHUD == null)
        {
            return;
        }

        bool value = ((vp_UIToggle)control).State;

        SimpleHUD.ShowTips = value;
    }
Пример #7
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void OnEnable()
    {
        m_Component = (vp_UIControl)target;

        if (m_Component.Manager == null)
        {
            m_Component.Manager = m_Component.transform.root.GetComponent <vp_UIManager>();
        }

        if (m_Component.Manager)
        {
            m_Component.Manager.ForceUIRefresh();
        }
    }
Пример #8
0
    /// <summary>
    /// event recieved when a new controller type is chosen from the dropdown
    /// </summary>
    public virtual void ChangeControllerType(vp_UIControl control)
    {
        string value = ((vp_UIDropdownList)control).CurrentItem;

        if (value == "Dynamic Joystick")
        {
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.DynamicJoystick;
        }
        else if (value == "Static Joystick")
        {
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.StaticJoystick;
        }
        else
        {
            TouchController.ControllerType = vp_UITouchController.vp_TouchControllerType.TouchPad;
        }
    }
Пример #9
0
    /// <summary>
    /// handles the registering and unregistering
    /// of all the touches events for a control
    /// </summary>
    protected static void ControlRegistration(vp_UIControl control, bool register)
    {
        // get a list of components on the control
        List <MonoBehaviour> components = control.GetComponents <MonoBehaviour>().ToList();

        // loop through the list of components
        for (int n = 0; n < components.Count; n++)
        {
            // get the component
            MonoBehaviour component = components[n];

            // get a array of methodInfos from this component
            MethodInfo[] methodInfos = component.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            // loop through the methods
            foreach (MethodInfo methodInfo in methodInfos)
            {
                // make sure the method doesn't have a return value and the parameter is of type vp_Touch
                if (methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters().FirstOrDefault(p => p.ParameterType == typeof(vp_Touch)) != null && methodInfo.ReturnType == typeof(void) && TouchEventBindings.ContainsKey(methodInfo.Name))
                {
                    string dKey = component.GetInstanceID().ToString() + "." + methodInfo.Name;
                    vp_TouchesEventHandler d = null;
                    if (!TouchesDelegates.TryGetValue(dKey, out d))
                    {
                        d = (vp_TouchesEventHandler)Delegate.CreateDelegate(typeof(vp_TouchesEventHandler), component, methodInfo.Name);
                        TouchesDelegates.Add(dKey, d);
                    }

                    // register or unregister
                    if (register)
                    {
                        TouchEventBindings[methodInfo.Name] += d;
                    }
                    else
                    {
                        TouchEventBindings[methodInfo.Name] -= d;
                    }
                }
            }
        }
    }
Пример #10
0
    public virtual void ShowEventBindingInspector(vp_UIControl control)
    {
        if (m_Component.Objects.Count == 0)
        {
            m_Component.Objects.Add(null);
            m_Component.MethodIndexes.Add(0);
            m_Component.Methods.Add(null);
        }

        for (int i = 0; i < m_Component.Objects.Count; i++)
        {
            m_Component.Objects[i] = EditorGUILayout.ObjectField("Notify Object", m_Component.Objects[i], typeof(MonoBehaviour), true) as MonoBehaviour;
            if (m_Component.Objects[i] != null)
            {
                GUILayout.Space(-20f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(134f);
                if (m_Component.Objects.Count > 1)
                {
#if UNITY_3_5
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
#else
                    if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f)))
#endif
                    {
                        m_Component.Objects.RemoveAt(i);
                        m_Component.MethodIndexes.RemoveAt(i);
                        m_Component.Methods.RemoveAt(i);
                        return;
                    }
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                if (m_Component.Objects.Count == i + 1)
                {
                    m_Component.Objects.Add(null);
                    m_Component.MethodIndexes.Add(0);
                    m_Component.Methods.Add(null);
                    return;
                }


                List <MonoBehaviour> components  = m_Component.Objects[i].GetComponents <MonoBehaviour>().ToList();
                List <string>        sComponents = new List <string>();
                for (int n = 0; n < components.Count; n++)
                {
                    MonoBehaviour component   = components[n];
                    MethodInfo[]  methodInfos = component.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | ~BindingFlags.SetField);
                    if (control.GetType() == typeof(vp_UITouchButton))
                    {
                        methodInfos = component.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
                    }
                    foreach (MethodInfo methodInfo in methodInfos)
                    {
                        bool valid = control.GetType() == typeof(vp_UITouchButton) ? methodInfo.GetParameters().Length == 0 && methodInfo.ReturnType == typeof(void) : methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters()[0].ParameterType == typeof(vp_UIControl) && methodInfo.ReturnType == typeof(void);
                        if (valid)
                        {
                            if (methodInfo.Name != "StopAllCoroutines" && methodInfo.Name != "CancelInvoke")
                            {
                                sComponents.Add(component.GetType().Name + "." + methodInfo.Name);
                            }
                        }
                    }
                }

                if (sComponents.Count > 0)
                {
                    m_Component.MethodIndexes[i] = EditorGUILayout.Popup("Method", m_Component.MethodIndexes[i], sComponents.ToArray());
                    m_Component.Methods[i]       = sComponents[m_Component.MethodIndexes[i]];
                }
                else
                {
                    EditorGUILayout.HelpBox("No public methods were found in any components on " + m_Component.Objects[i].name + ". Add a public method in any component on " + m_Component.Objects[i].name + " in order to use event binding for this object", MessageType.Info);
                }
            }
            GUILayout.Space(10);
        }
    }
Пример #11
0
    public virtual void ShowEventBindingInspector( vp_UIControl control )
    {
        if(m_Component.Objects.Count == 0)
        {
            m_Component.Objects.Add(null);
            m_Component.MethodIndexes.Add(0);
            m_Component.Methods.Add(null);
        }

        for(int i = 0; i<m_Component.Objects.Count; i++)
        {
            m_Component.Objects[i] = EditorGUILayout.ObjectField("Notify Object", m_Component.Objects[i], typeof(MonoBehaviour), true) as MonoBehaviour;
            if(m_Component.Objects[i] != null)
            {
                GUILayout.Space(-20f);
                GUILayout.BeginHorizontal();
                GUILayout.Space(134f);
                if(m_Component.Objects.Count > 1)
                {
        #if UNITY_3_5
                    if (GUILayout.Button("X", GUILayout.Width(20f)))
        #else
                    if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f)))
        #endif
                    {
                        m_Component.Objects.RemoveAt(i);
                        m_Component.MethodIndexes.RemoveAt(i);
                        m_Component.Methods.RemoveAt(i);
                        return;
                    }
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                if(m_Component.Objects.Count == i+1)
                {
                    m_Component.Objects.Add(null);
                    m_Component.MethodIndexes.Add(0);
                    m_Component.Methods.Add(null);
                    return;
                }

                List<MonoBehaviour> components = m_Component.Objects[i].GetComponents<MonoBehaviour>().ToList();
                List<string> sComponents = new List<string>();
                for(int n=0;n<components.Count; n++)
                {
                    MonoBehaviour component = components[n];
                    MethodInfo[] methodInfos = component.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | ~BindingFlags.SetField);
                    if(control.GetType() == typeof(vp_UITouchButton))
                        methodInfos = component.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
                    foreach(MethodInfo methodInfo in methodInfos)
                    {
                        bool valid = control.GetType() == typeof(vp_UITouchButton) ? methodInfo.GetParameters().Length == 0 && methodInfo.ReturnType == typeof(void) : methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters()[0].ParameterType == typeof(vp_UIControl) && methodInfo.ReturnType == typeof(void);
                        if(valid)
                            if (methodInfo.Name != "StopAllCoroutines" && methodInfo.Name != "CancelInvoke")
                                sComponents.Add(component.GetType().Name+"."+methodInfo.Name);
                    }
                }

                if(sComponents.Count > 0)
                {
                    m_Component.MethodIndexes[i] = EditorGUILayout.Popup("Method", m_Component.MethodIndexes[i], sComponents.ToArray());
                    m_Component.Methods[i] = sComponents[m_Component.MethodIndexes[i]];
                }
                else
                {
                    EditorGUILayout.HelpBox("No public methods were found in any components on "+m_Component.Objects[i].name+". Add a public method in any component on "+m_Component.Objects[i].name+" in order to use event binding for this object", MessageType.Info);
                }
            }
            GUILayout.Space(10);
        }
    }
Пример #12
0
    /// <summary>
    /// 
    /// </summary>
    protected virtual void OnEnable()
    {
        m_Component = (vp_UIControl)target;

        if(m_Component.Manager == null)
            m_Component.Manager = m_Component.transform.root.GetComponent<vp_UIManager>();

        if(m_Component.Manager)
            m_Component.Manager.ForceUIRefresh();
    }
Пример #13
0
 /// <summary>
 /// Unregister the specified control from the touches event handler
 /// </summary>
 public static void Unregister(vp_UIControl control)
 {
     ControlRegistration(control, false);
 }
Пример #14
0
 /// <summary>
 /// Register the specified control with the touches event handler
 /// </summary>
 public static void Register(vp_UIControl control)
 {
     ControlRegistration(control, true);
 }
Пример #15
0
 /// <summary>
 /// Register the specified control with the touches event handler
 /// </summary>
 public static void Register(vp_UIControl control)
 {
     ControlRegistration(control, true);
 }
Пример #16
0
 /// <summary>
 /// Unregister the specified control from the touches event handler
 /// </summary>
 public static void Unregister(vp_UIControl control)
 {
     ControlRegistration(control, false);
 }
Пример #17
0
    /// <summary>
    /// creates an item for the dropdown list
    /// </summary>
    protected virtual Transform CreateListItem(string itemName, int i)
    {
        // Create the item container
        GameObject item = new GameObject(itemName);

        item.layer                   = Background.gameObject.layer;
        item.transform.parent        = transform;
        item.transform.localPosition = Vector3.zero;
        item.transform.localScale    = Vector3.one;

        // create the background of the item
        GameObject background = new GameObject("Background");

        background.layer            = Background.gameObject.layer;
        background.transform.parent = item.transform;
        MeshRenderer rend   = background.AddComponent <MeshRenderer>();
        MeshFilter   filter = background.AddComponent <MeshFilter>();

        filter.mesh = Background.GetComponent <MeshFilter>().mesh;
        rend.material.mainTexture          = ItemBackground;
        rend.material.shader               = Background.GetComponent <MeshRenderer>().material.shader;
        rend.receiveShadows                = false;
        rend.castShadows                   = false;
        rend.material.color                = Color.white;
        background.transform.localScale    = new Vector3(Background.localScale.x, ItemHeight, 1);
        background.transform.localPosition = new Vector3(Background.localPosition.x, -(background.transform.localScale.y * i), Background.localPosition.z - 20);

        // creates the label for the item
        GameObject textgo = new GameObject("Label");

        textgo.layer            = Background.gameObject.layer;
        textgo.transform.parent = item.transform;
        TextMesh text = textgo.AddComponent <TextMesh>();

        text.GetComponent <Renderer>().material = ItemFont.material;
        text.text                    = itemName;
        text.font                    = ItemFont;
        text.fontSize                = 32;
        text.color                   = Color.black;
        text.anchor                  = TextAnchor.MiddleLeft;
        text.transform.localScale    = Label.transform.localScale * .75f;
        text.transform.localPosition = new Vector3(
            (background.transform.localPosition.x - background.transform.localScale.x * .5f) + ItemLabelPadding.x,
            (background.transform.localPosition.y + text.transform.localScale.y * .5f) - ItemLabelPadding.y,
            Background.localPosition.z - 21
            );

        // add a box collider so the item can handle touch events
        BoxCollider col = item.AddComponent <BoxCollider>();

        col.size   = new Vector3(background.transform.localScale.x, background.transform.localScale.y, 1);
        col.center = background.transform.localPosition;

        // add a uicontrol so the item can register with the ReleaseControl event
        vp_UIControl control = item.AddComponent <vp_UIControl>();

        control.ReleaseControl += () => {
            SelectItem(itemName);
        };

        m_Items.Add(itemName, background);

        return(item.transform);
    }
Пример #18
0
 /// <summary>
 /// Unregisters the control from events and the UI Manager
 /// </summary>
 public virtual void UnregisterControl(vp_UIControl control)
 {
     vp_InputMobile.Unregister(control);
     Controls.Remove(control);
 }
Пример #19
0
    /// <summary>
    /// handles the registering and unregistering
    /// of all the touches events for a control
    /// </summary>
    protected static void ControlRegistration( vp_UIControl control, bool register )
    {
        // get a list of components on the control
        List<MonoBehaviour> components = control.GetComponents<MonoBehaviour>().ToList();

        // loop through the list of components
        for(int n=0;n<components.Count; n++)
        {
            // get the component
            MonoBehaviour component = components[n];

            // get a array of methodInfos from this component
            MethodInfo[] methodInfos = component.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            // loop through the methods
            foreach(MethodInfo methodInfo in methodInfos)
            {
                // make sure the method doesn't have a return value and the parameter is of type vp_Touch
                if (methodInfo.GetParameters().Length == 1 && methodInfo.GetParameters().FirstOrDefault(p => p.ParameterType == typeof(vp_Touch)) != null && methodInfo.ReturnType == typeof(void) && TouchEventBindings.ContainsKey(methodInfo.Name))
                {
                    string dKey = component.GetInstanceID().ToString()+"."+methodInfo.Name;
                    vp_TouchesEventHandler d = null;
                    if(!TouchesDelegates.TryGetValue(dKey, out d))
                    {
                        d = (vp_TouchesEventHandler)Delegate.CreateDelegate(typeof(vp_TouchesEventHandler), component, methodInfo.Name);
                        TouchesDelegates.Add(dKey, d);
                    }

                    // register or unregister
                    if(register)	TouchEventBindings[methodInfo.Name] += d;
                    else 			TouchEventBindings[methodInfo.Name] -= d;
                }
            }
        }
    }