Esempio n. 1
0
    private IEnumerator Movement(Transform firstItem, Transform secondItem, SwitchDelegate onSwitched = null)
    {
        var pos1  = firstItem.position;
        var pos2  = secondItem.position;
        var speed = 5f * Time.deltaTime;
        var delay = new WaitForSeconds(0.3f);

        onSwitched = _onSwitched;

        while (true)
        {
            secondItem.position = Vector3.MoveTowards(secondItem.position, pos1, speed);
            firstItem.position  = Vector3.MoveTowards(firstItem.position, pos2, speed);

            // at the end of movement
            if (Vector3.Distance(firstItem.position, pos2) < 0.1f)
            {
                firstItem.position  = pos2;
                secondItem.position = pos1;
                yield return(delay);

                onSwitched?.Invoke();
                Debug.Log("valid");
                yield break;
            }

            yield return(null);
        }
    }
Esempio n. 2
0
 private void SwitchInerror()
 {
     if (this.panelLoading.InvokeRequired || this.panelSelection.InvokeRequired || this.panelError.InvokeRequired)
     {
         SwitchDelegate d = new SwitchDelegate(SwitchInerror);
         this.Invoke(d);
     }
     else
     {
         this.panelSelection.Visible = false;
         this.panelLoading.Visible   = false;
         this.panelError.Visible     = true;
     }
 }
Esempio n. 3
0
 private void SwitchLoadingInit()
 {
     if (this.panelLoading.InvokeRequired || this.panelSelection.InvokeRequired || this.buttonOk.InvokeRequired)
     {
         SwitchDelegate d = new SwitchDelegate(SwitchLoadingInit);
         this.Invoke(d);
     }
     else
     {
         this.panelSelection.Visible = true;
         this.panelLoading.Visible   = false;
         this.buttonOk.Enabled       = true;
     }
 }
Esempio n. 4
0
 public SASwitchButton(string resource, Rectangle[] sourceRects, Vector2 pos, SwitchDelegate switchDel, bool ifOn)
 {
     Init();
     //TODO
     if (ifOn)
     {
         index = 0;
         this.controlStatus = ControlStatus.On;
     }
     else
     {
         index = 2;
         this.controlStatus = ControlStatus.Off;
     }
     this.texture           = SAGraphicManager.GetImage(resource);
     this._sourceRectangles = new Rectangle[4];
     this._sizes            = new Vector2[4];
     this.position          = pos;
     this.switchHandler     = switchDel;
     #region 处理不同的数量
     if (sourceRects.Length == 2)
     {
         this._sourceRectangles[1] = this._sourceRectangles[0] = sourceRects[0];
         this._sourceRectangles[3] = this._sourceRectangles[2] = sourceRects[1];
         for (int i = 0; i < 4; i++)
         {
             this._sizes[i] = new Vector2(_sourceRectangles[i].Width, _sourceRectangles[i].Height);
         }
     }
     else if (sourceRects.Length == 3)
     {
         this._sourceRectangles[0] = sourceRects[0];
         this._sourceRectangles[1] = this._sourceRectangles[3] = sourceRects[1];
         this._sourceRectangles[2] = sourceRects[2];
         for (int i = 0; i < 4; i++)
         {
             this._sizes[i] = new Vector2(_sourceRectangles[i].Width, _sourceRectangles[i].Height);
         }
     }
     else if (sourceRects.Length == 4)
     {
         for (int i = 0; i < 4; i++)
         {
             this._sourceRectangles[i] = sourceRects[i];
             this._sizes[i]            = new Vector2(_sourceRectangles[i].Width, _sourceRectangles[i].Height);
         }
     }
     #endregion
     Add();
 }
Esempio n. 5
0
 /// <summary>
 /// 最全的,想偷懒的话也有技巧
 /// sourceRects长度为2,则开关各一个
 /// 为3,则开关为0,2,1为Touch
 /// 为4,你懂的
 /// </summary>
 public SASwitchButton(string resource, Rectangle[] sourceRects, Vector2 pos, SwitchDelegate switchDel)
     : this(resource, sourceRects, pos, switchDel, true)
 {
 }
Esempio n. 6
0
 //---------------------------------------------------------
 public void RegisterDelegate(SwitchDelegate d)
 {
     m_SwitchDelegate = d;
 }