Ejemplo n.º 1
0
        public void Init()
        {
            TMPro.TMP_InputField tif = GetComponentInChildren <TMPro.TMP_InputField>();
            if (tif != null)
            {
                EventBind.IfNotAlready(setText, tif, "set_text"); getText = () => tif.text;
            }
            TMPro.TMP_Text tmp = GetComponentInChildren <TMPro.TMP_Text>();
            if (tmp != null)
            {
                EventBind.IfNotAlready(setText, tmp, "set_text"); getText = () => tmp.text;
            }
            InputField inf = GetComponentInChildren <InputField>();

            if (inf != null)
            {
                EventBind.IfNotAlready(setText, inf, "set_text"); getText = () => inf.text;
            }
            Text txt = GetComponentInChildren <Text>();

            if (txt != null)
            {
                EventBind.IfNotAlready(setText, txt, "set_text"); getText = () => txt.text;
            }
            if (UiImage.HasImageHolder(gameObject))
            {
                EventBind.IfNotAlready(setText, this, SetImageByName); getText = GetImageName;
            }
        }
Ejemplo n.º 2
0
        public static bool AddOnButtonClickIfNotAlready(GameObject obj, Object target, UnityAction action)
        {
            Button button = obj.GetComponent <Button>();

            if (button != null)
            {
                EventBind.IfNotAlready(button.onClick, target, action);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static void BindDropdownAction(TMP_Dropdown dd, object ownerOfDropdownHandler, Action <int> action)
        {
            if (ownerOfDropdownHandler == null || action == null)
            {
                return;
            }
            //Show.Log("set " + options.Count + " opt : " + dd + "(" + dd.options.Count + ")\n" + options.Stringify(pretty: true));
#if UNITY_EDITOR
            UnityEngine.Object uObj = ownerOfDropdownHandler as UnityEngine.Object;
            if (uObj != null)
            {
                EventBind.IfNotAlready(dd.onValueChanged, uObj, action.Method.Name);
                return;
            }
#endif
            dd.onValueChanged.RemoveAllListeners();
            dd.onValueChanged.AddListener(action.Invoke);
        }
Ejemplo n.º 4
0
 public void Reset()
 {
     TMPro.TMP_InputField input = GetComponent <TMPro.TMP_InputField>();
     EventBind.IfNotAlready(input.onValueChanged, this, nameof(AssignFromText));
     //EventBind.IfNotAlready(input.onEndEdit, this, nameof(Sort));
 }
Ejemplo n.º 5
0
    public ListItemUi AddMember(GameObject memberObject)
    {
        //Show.Log("adding member " + memberObject);
        if (members == null)
        {
            members = new List <GameObject>();
        }
        // make sure this character adds to the communal inventory! (assuming there is one)
        TeamMember teamMember = memberObject.GetComponent <TeamMember>();

        if (teamMember == null)
        {
            teamMember = memberObject.AddComponent <TeamMember>();
        }
        // add them to the roster
        if (members.IndexOf(memberObject) < 0)
        {
            members.Add(memberObject);
            teamMember.onJoinTeam?.Invoke(this);
            CharacterRoot cr = memberObject.GetComponent <CharacterRoot>();
            if (cr)
            {
                EventBind.IfNotAlready(cr.activateFunction, this, ActivateTeamMember);
            }
        }
        if (members.Count > 1)
        {
            if (prev)
            {
                prev.gameObject.SetActive(true);
            }
            if (next)
            {
                next.gameObject.SetActive(true);
            }
            if (team)
            {
                team.gameObject.SetActive(true);
            }
        }
        if (rosterUi != null)
        {
            ListItemUi result = rosterUi.GetListItemUi(memberObject);
            if (result != null)
            {
                //Show.Log("already ui");
                return(result);
            }
        }
        string name = teamMember != null ? teamMember.name : null;

        if (string.IsNullOrEmpty(name))
        {
            name = memberObject.name;
        }

        Interact3dItem i3i = teamMember.GetComponent <Interact3dItem>();
        //void ActivateTeamMember() {
        //	CharacterControlManager ccm = Global.Get<CharacterControlManager>();
        //	ccm.SetCharacter(memberObject);
        //	i3i.showing = false;
        //}
        Action activateMember = () => ActivateTeamMember(memberObject);

        if (i3i != null)
        {
            i3i.OnInteract             = activateMember;
            i3i.Text                   = "switch";
            i3i.internalState.alwaysOn = true;
        }
        if (rosterUi == null)
        {
            Show.Log("missing roster UI");
            return(null);
        }
        return(rosterUi.AddItem(memberObject, name, activateMember));
    }