private void Reset()
 {
     KeyBind(KCode.BackQuote, KModifier.None, "activate console", nameof(SetScreenSpaceCanvas), target: this);
     KeyBind(KCode.Escape, KModifier.None, "deactivate console", nameof(SetWorldSpaceCanvas), target: this);
     EventBind.On(callbacks.WhenThisActivates, this, nameof(Pause));
     EventBind.On(callbacks.WhenThisDeactivates, this, nameof(Unpause));
 }
Exemplo n.º 2
0
 public void BindEvents()
 {
     Init();
     CharacterMove.Callbacks cb = character.move.callbacks;
     EventBind.On(cb.jumped, this, nameof(Jump));
     EventBind.On(cb.stand, this, nameof(Stand));
     EventBind.On(cb.fall, this, nameof(Fall));
     EventBind.On(cb.arrived, this, nameof(Wave));
 }
 public Entry(string text, object target, string methodName, bool valuePersists = true)
 {
     if (!string.IsNullOrEmpty(methodName))
     {
         selectionAction = new UnityEvent();
         EventBind.On(selectionAction, target, methodName);
     }
     this.text = text;
     eventOnly = !valuePersists;
 }
Exemplo n.º 4
0
 /// <param name="et"></param>
 /// <param name="type"></param>
 /// <param name="target">if not null, and in the UnityEditor, will register the event in the UI</param>
 /// <param name="pointerEvent">tip: try to typecast the <see cref="BaseEventData"/> as <see cref="PointerEventData"/></param>
 public static void AddEvent(EventTrigger et, EventTriggerType type, object target, UnityAction <BaseEventData> pointerEvent)
 {
     EventTrigger.Entry entry = et.triggers.Find(t => t.eventID == type);
     if (entry == null)
     {
         entry = new EventTrigger.Entry {
             eventID = type
         };
     }
     EventBind.On(entry.callback, target, pointerEvent);
     et.triggers.Add(entry);
 }
Exemplo n.º 5
0
        private void Init()
        {
            UnityDataSheet uds = UDS();

            if (uds == null)
            {
                return;
            }
            Button b = GetComponent <Button>();

            EventBind.On(b.onClick, uds, uds.RefreshData);
        }
Exemplo n.º 6
0
        private void Reset()
        {
            UnityConsole          console          = GetComponent <UnityConsole>();
            UnityConsoleCommander consoleCommander = GetComponent <UnityConsoleCommander>();

            if (consoleCommander != null)
            {
                EventBind.On(inputListener, consoleCommander, nameof(consoleCommander.DoCommand));
            }
            KeyBind(KCode.Equals, KModifier.AnyCtrl, "+ console font", nameof(console.AddToFontSize), 1f, console);
            KeyBind(KCode.Minus, KModifier.AnyCtrl, "- console font", nameof(console.AddToFontSize), -1f, console);
            KeyBind(KCode.Return, KModifier.NoShift, "submit console input", nameof(FinishCurrentInput), target: this);
            KeyBind(KCode.C, KModifier.AnyCtrl, "copy from command console", nameof(CopyToClipboard), target: this);
            KeyBind(KCode.V, KModifier.AnyCtrl, "paste into command console", nameof(PasteFromClipboard), target: this);
            KeyBind(KCode.UpArrow, KModifier.AnyAlt, "move cursor up", nameof(MoveCursorUp), target: this);
            KeyBind(KCode.LeftArrow, KModifier.AnyAlt, "move cursor left", nameof(MoveCursorLeft), target: this);
            KeyBind(KCode.DownArrow, KModifier.AnyAlt, "move cursor down", nameof(MoveCursorDown), target: this);
            KeyBind(KCode.RightArrow, KModifier.AnyAlt, "move cursor right", nameof(MoveCursorRight), target: this);
            KeyBind(KCode.UpArrow, KModifier.AnyShift, "shift window up", nameof(ShiftWindowUp), target: this);
            KeyBind(KCode.LeftArrow, KModifier.AnyShift, "shift window left", nameof(ShiftWindowLeft), target: this);
            KeyBind(KCode.DownArrow, KModifier.AnyShift, "shift window down", nameof(ShiftWindowDown), target: this);
            KeyBind(KCode.RightArrow, KModifier.AnyShift, "shift window right", nameof(ShiftWindowRight), target: this);
        }
Exemplo n.º 7
0
        public static void RemoveEvent(EventTrigger et, EventTriggerType type, Object target, UnityAction <BaseEventData> pointerEvent)
        {
            EventTrigger.Entry entry = et.triggers.Find(t => t.eventID == type);
            if (entry == null)
            {
                return;
            }
            entry.callback.RemoveListener(pointerEvent);

            List <int> eventsToRemove = new List <int>();

            for (int i = 0; i < entry.callback.GetPersistentEventCount(); ++i)
            {
                if (entry.callback.GetPersistentTarget(i) == target && entry.callback.GetPersistentMethodName(i) == pointerEvent.Method.Name)
                {
                    eventsToRemove.Add(i);
                }
            }
            if (eventsToRemove.Count < entry.callback.GetPersistentEventCount())
            {
                // for whatever reason, UnityEventTools.RemovePersistentListener() exists, but only in the UnityEditor context.
                // to delete a unity event listener, the entire event must simply be replaced by a new event with the offending listener missing.
                EventTrigger.Entry newEntry = new EventTrigger.Entry {
                    eventID = type
                };
                for (int i = 0; i < entry.callback.GetPersistentEventCount(); ++i)
                {
                    if (!eventsToRemove.Contains(i))
                    {
                        EventBind.On(newEntry.callback, entry.callback.GetPersistentTarget(i), entry.callback.GetPersistentMethodName(i));
                    }
                }
                et.triggers.Remove(entry);
                et.triggers.Add(newEntry);
            }
        }
        public void SetColumnHeader(ColumnHeader columnHeader, UnityDataSheet uds, int column)
        {
            // unregister listeners before values change, since values are about to change.
            ClearInputTextBoxListeners();

            this.uds    = uds;
            this.column = column;
            cHeader     = columnHeader;
            TokenErrorLog errLog = new TokenErrorLog();
            // setup script value
            Token t = cHeader.columnSetting.fieldToken;
            //string textA = t.GetAsSmallText();
            //string textB = t.Stringify();
            //string textC = t.StringifySmall();
            //string textD = t.ToString();
            string text = t.GetAsBasicToken();

            //Show.Log("A: "+textA+"\nB:" + textB + "\nC:" + textC + "\nD:" + textD + "\nE:" + text);
            scriptValue.text = text;
            EventBind.On(scriptValue.onValueChanged, this, OnScriptValueEdit);
            // implicitly setup value types dropdown
            OnScriptValueEdit(text);
            // setup column label
            object labelText = cHeader.columnSetting.data.label.Resolve(errLog, uds.data);

            if (errLog.HasError())
            {
                popup.Set("err", defaultValue.gameObject, errLog.GetErrorString() + Proc.Now); return;
            }
            columnLabel.text = labelText.StringifySmall();
            EventBind.On(columnLabel.onValueChanged, this, OnLabelEdit);
            // setup column width
            columnWidth.text = cHeader.columnSetting.data.widthOfColumn.ToString();
            EventBind.On(columnWidth.onValueChanged, this, OnColumnWidthEdit);
            // setup column index
            columnIndex.text = column.ToString();
            EventBind.On(columnIndex.onValueChanged, this, OnIndexEdit);
            // setup column type
            List <ModalConfirmation.Entry> entries = columnTypes.ConvertAll(c => {
                string dropdownLabel;
                if (c.uiField != null && !string.IsNullOrEmpty(c.name))
                {
                    dropdownLabel = "/*" + c.name + "*/ " + c.uiField.name;
                }
                else
                {
                    dropdownLabel = c.name;
                }
                return(new ModalConfirmation.Entry(dropdownLabel, null));
            });

            t = cHeader.columnSetting.data.columnUi;
            string fieldTypeText = t.ToString();            //cHeader.columnSetting.data.columnUi.GetAsBasicToken();//ResolveString(errLog, null);
            int    currentIndex  = columnTypes.FindIndex(c => fieldTypeText.StartsWith(c.uiField.name)) + 1;

            //Show.Log(currentIndex+" field  " + fieldTypeText);
            DropDownEvent.PopulateDropdown(fieldType, entries, this, SetFieldType, currentIndex, true);
            if (currentIndex == 0)
            {
                DropDownEvent.SetCustomValue(fieldType.gameObject, fieldTypeText);
            }
            TMP_InputField elementUiInputField = fieldType.GetComponentInChildren <TMP_InputField>();

            if (elementUiInputField != null)
            {
                elementUiInputField.onValueChanged.RemoveAllListeners();
                //Show.Log("bind to "+elementUiInputField.name);
                EventBind.On(elementUiInputField.onValueChanged, this, OnSetFieldTypeText);
            }
            // setup default value
            object defVal = cHeader.columnSetting.defaultValue;

            if (defVal != null)
            {
                defaultValue.text = defVal.ToString();
            }
            else
            {
                defaultValue.text = "";
            }
            EventBind.On(defaultValue.onValueChanged, this, OnSetDefaultValue);
            // setup column destroy option
            EventBind.On(trashColumn.onClick, this, ColumnRemove);
            popup.Hide();
        }