예제 #1
0
 private void HandleInputFieldEnter(string text)
 {
     if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
     {
         OnSubmit.Invoke(text);
     }
 }
예제 #2
0
        /// <summary>
        /// 输入反应物
        /// </summary>
        /// <param name="nodeId"></param>
        /// <param name="types"></param>
        /// <param name="onComplete"></param>
        public void Import(int nodeId, string[] types)
        {
            if (!inPortsUsed.Contains(nodeId))
            {
                inPortsUsed.Add(nodeId);
            }
            var import = inPorts.Find(x => x.id == nodeId);

            if (import != null)
            {
                foreach (var item in types)
                {
                    if (Array.Find(import.supportTypes, x => item == x) != null)//.Contains(item))
                    {
                        if (import.active)
                        {
                            if (equations.Count == 0)
                            {
                                OnGenerateNewItem(item);
                            }
                            else
                            {
                                interactPool.AddElements(item);
                            }
                            onElementAppear.Invoke(item);
                        }
                        else
                        {
                            Debug.Log(import.id + "接口关闭");
                            Debug.Log(import.closeinfomation);
                        }
                    }
                    else
                    {
                        Debug.Log(item + "未添加匹配");
                    }
                }
            }
            else
            {
                foreach (var item in types)
                {
                    Debug.Log(name + ":" + item + "未添加匹配");
                }
            }
        }
 private void ShowText()
 {
     if (!string.IsNullOrEmpty(spriteInfoItem.title.text))
     {
         show = true;
         textBody.SetActive(true);
         onGet.Invoke(spriteInfoItem.title.text);
     }
 }
        public void Import(int nodeID, string[] type)
        {
            Debug.Log("imprort to tube:" + name + "port:" + nodeID);
            //判断状态
            Debug.Assert(onExport != null);

            Dictionary <int, List <string> > exportDic = new Dictionary <int, List <string> >();

            var mightExporters = ports.FindAll(x => nodeID != x.id);


            if (mightExporters.Count > 0)
            {
                foreach (var item in mightExporters)
                {
                    if (item.active)
                    {
                        for (int i = 0; i < type.Length; i++)
                        {
                            if (exportDic.ContainsKey(item.id))
                            {
                                exportDic[item.id].Add(type[i]);
                            }
                            else
                            {
                                exportDic[item.id] = new List <string>()
                                {
                                    type[i]
                                };
                            }
                        }
                    }
                    else
                    {
                        Debug.Log(item.id + "接口关闭");
                        Debug.Log(item.closeinfomation);
                    }
                }
            }

            foreach (var item in exportDic)
            {
                var status = onExport.Invoke(this, item.Key, item.Value.ToArray());
                if (!status)
                {
                    for (int i = 0; i < type.Length; i++)
                    {
                        onExportError.Invoke(type[i]);
                        Debug.Log("导出失败:" + type[i]);
                    }
                }
            }
        }
예제 #5
0
 public bool Active(bool force = false)
 {
     if (startActive || force)
     {
         active = true;
         foreach (var item in supports)
         {
             onActiveSupport.Invoke(item);
         }
         return(true);
     }
     return(false);
 }
예제 #6
0
        protected virtual void OpenPromptDialog()
        {
            if (!IsActive() || !IsInteractable())
            {
                return;
            }

            if (string.IsNullOrEmpty(m_CustomDialogPath))
            {
                OpenDefaultPromptDialog();
            }
            else
            {
                DialogManager.ShowCustomDialogAsync <DialogPrompt>(m_CustomDialogPath, (dialog) =>
                {
                    _dialogPrompt = dialog;
                    if (_dialogPrompt != null)
                    {
                        _dialogPrompt.destroyOnHide = true;
                        _dialogPrompt.Initialize(this,
                                                 (value) =>
                        {
                            if (this != null)
                            {
                                value          = string.IsNullOrEmpty(value) ? string.Empty : value;
                                var willChange = m_Text != value;

                                this.text = value;
                                if (willChange && onEndEdit != null)
                                {
                                    onEndEdit.Invoke(m_Text);
                                }
                                if (OnReturnPressed != null)
                                {
                                    OnReturnPressed.Invoke();
                                }
                            }
                        },
                                                 "OK",
                                                 this.hintText,
                                                 null,
                                                 null,
                                                 "Cancel");
                    }
                    else
                    {
                        OpenDefaultPromptDialog();
                    }
                });
            }
        }
예제 #7
0
        /// <summary>
        /// 试图将生成的元素导出
        /// </summary>
        /// <param name="element"></param>
        private void OnGenerateNewItem(string element)
        {
            onElementAppear.Invoke(element);
            //判断状态
            if (onExport == null)
            {
                return;
            }
            if (outPorts.Count == 0)
            {
                return;
            }

            Dictionary <int, List <string> > exportDic = new Dictionary <int, List <string> >();
            var mightExporters = outPorts.FindAll(x => Array.Find(x.supportTypes, y => y == element) != null && !inPortsUsed.Contains(x.id));

            if (mightExporters.Count > 0)
            {
                foreach (var item in mightExporters)
                {
                    if (item.active)
                    {
                        if (exportDic.ContainsKey(item.id))
                        {
                            exportDic[item.id].Add(element);
                        }
                        else
                        {
                            exportDic[item.id] = new List <string>()
                            {
                                element
                            };
                        }
                    }
                    else
                    {
                        Debug.Log(item.id + "接口关闭");
                        Debug.Log(item.closeinfomation);
                    }
                }
            }
            foreach (var item in exportDic)
            {
                var status = onExport.Invoke(this, item.Key, item.Value.ToArray());
                if (!status)
                {
                    onExportError.Invoke(element);
                    Debug.Log("导出失败:" + element, gameObject);
                }
            }
        }
 void Start()
 {
     startBtn.onClick.AddListener(RestartExperiment);
     interactBtn.onClick.AddListener(StartExperiment);
     close.onClick.AddListener(ClosePanel);
     _systemCtrl = new ReactSystemCtrl();
     _systemCtrl.GetConnectedDic  = GetConnectedDic;
     _systemCtrl.GetConnectedList = GetSupportList;
     _systemCtrl.InitExperiment(experimentData.elements);
     _systemCtrl.onComplete     += () => { onComplete.Invoke(); Debug.Log("Complete"); };
     _systemCtrl.onStepBreak    += (x) => { onStepBreak.Invoke("步骤中断!"); Debug.Log("StepBreak" + x.Go.name); };
     _systemCtrl.onStepComplete += NextStep;
     RestartExperiment();
 }
예제 #9
0
 void Update()
 {
     if (EventSystem.current.currentSelectedGameObject == gameObject)
     {
         if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
         {
             OnEnter.Invoke(input.text);
         }
         else if (Input.GetKeyDown(KeyCode.Escape))
         {
             OnCancel.Invoke();
         }
     }
 }
예제 #10
0
 protected void validateInputAgainstAllValidators(string input)
 {
     foreach (AbstractInputValidator validator in validators)
     {
         if (!validator.validateInput(input))
         {
             handleInputFailure(validator.failurmessage);
             onValidationFailure.Invoke();
             return;
         }
     }
     isValidInput   = true;
     validatedInput = input;
     handleInputSuccess();
     onInputValidated.Invoke(input);
 }
예제 #11
0
 private void ShowText()
 {
     if (!string.IsNullOrEmpty(textInfo))
     {
         show = true;
         textBody.SetActive(true);
         textBehaiver.transform.position = position;
         if (fontSize != null)
         {
             textBehaiver.text.fontSize = fontSize ?? 0;                  //?? textBehaiver.text.fontSize;
         }
         if (fontColor != null)
         {
             textBehaiver.text.color = fontColor ?? Color.clear;                   // ?? textBehaiver.text.color;
         }
         textBehaiver.text.text = textInfo;
         onGet.Invoke(textBehaiver.text.text);
     }
 }
예제 #12
0
        public override void HandleAxisX(float value)
        {
            // Get the current value from the text field:
            float curVal = float.Parse(_inputField.text);

            // Add / Sub the value from the controller input:
            curVal += value * valueMultiplicator;

            // Check for min and max borders:
            if (_hasMinValue && curVal < _minValue)
            {
                curVal = _minValue;
            }
            if (_hasMaxValue && curVal > _maxValue)
            {
                curVal = _maxValue;
            }

            // Write the value back to the text field.
            string curValStr = curVal.ToString();

            _inputField.text = curValStr;

            // This will trigger the OnEndEdit callback of this input field, if a method is connected, so that the new input is applied:
            InputField.SubmitEvent submitEvent = _inputField.onEndEdit;
            if (submitEvent.GetPersistentEventCount() > 0)
            {
                submitEvent.Invoke(curValStr);
            }
            // This will trigger the OnValueChanged callback of this input field, if a method is connected, so that the new input is applied:
            InputField.OnChangeEvent changeEvent = _inputField.onValueChanged;
            if (changeEvent.GetPersistentEventCount() > 0)
            {
                changeEvent.Invoke(curValStr);
            }
        }
예제 #13
0
 public void OnRightButtonClick()
 {
     OnRightClick.Invoke("-0.01");
     //Debug.Log("OnRightClick");
 }
예제 #14
0
 public void OnLeftButtonClick()
 {
     OnLeftClick.Invoke("0.01");
     //Debug.Log("OnLeftClick");
 }
예제 #15
0
 public void OnInputFieldEndEdit(string value)
 {
     OnEndEdit.Invoke(value);
     //Debug.Log("OnInputFieldEndEdit");
 }
예제 #16
0
 private void OnEquationActive(string info)
 {
     onEquationActive.Invoke(info);
 }