コード例 #1
0
ファイル: ThrowComponent.cs プロジェクト: BLueders/NGJ2016
    void Throw()
    {
        if (holdingObject == null || !canThrow)
        {
            return;
        }
        Rigidbody2D leekRigidbody = holdingObject.GetComponent <Rigidbody2D>();

        Vector2 actualThrowDirection = new Vector2((1 - currentThrowCharge / MaxThrowCharge), currentThrowCharge / MaxThrowCharge);

        Vector3 throwVelocity = actualThrowDirection.normalized * ThrowForce + ThrowMovementFactor * new Vector2(Mathf.Abs(movement.Velocity.x), movement.Velocity.y);

        throwVelocity.x              *= movement.Direction;
        leekRigidbody.velocity        = throwVelocity;
        leekRigidbody.angularVelocity = Random.Range(140, 180) * currentThrowCharge * movement.Direction;
        leekRigidbody.isKinematic     = false;
        holdingObject.GetComponent <Collider2D>().isTrigger = false;
        LeekComponent leek = holdingObject.GetComponent <LeekComponent>();

        if (leek != null)
        {
            leek.IsActive = true;
            leek.owner    = gameObject;
        }
        holdingObject = null;
        canThrow      = false;
        GameManager.Instance.SoundManager.PlaySound(GameManager.Instance.SoundManager.throwSound);
        currentThrowCharge = InitialThrowCharge;
    }
コード例 #2
0
 /// <summary>
 /// 点击丢弃一张图片
 /// </summary>
 public void OnClickBtnThrow()
 {
     if (isHold)
     {
         isHold = false;
         //先清理图片
         InitImage(HoldingObject);
         //根据图片类型处理:是生产区域的图片还要隐藏并放到父物体最后面去
         if (CurHoldImageType == eImageType.factory)
         {
             GenerateImageCount--;                       //丢弃的是生产区的,增加一个空位
             HoldingObject.transform.SetAsLastSibling(); //隐藏的移到父物体最后面
             HoldingObject.SetActive(false);
         }
         else if (CurHoldImageType == eImageType.game)
         {
             int a = int.Parse(HoldingObject.name);
             CurImagesInfo[a].id           = -1;
             CurImagesInfo[a].isMission    = false;
             CurImagesInfo[a].isCommonCard = false;
             HoldingObject.GetComponent <blockEventHandler>().InitImageInfo();
         }
         HoldingObject = null;
     }
 }
コード例 #3
0
    /// <summary>
    /// 生产区的图片放到拼图区
    /// </summary>
    /// <param name="info"></param>
    /// <param name="block"></param>
    public void FactoryToGame(ImageInfo info, int block)
    {
        GenerateImageCount--;
        ImageInfo old = CurImagesInfo[block];

        CurImagesInfo[block] = info;
        //blockCollections[block].GetComponent<Image>().sprite = GetSpriteByImageInfo(info);//仅仅这一句没有同步信息
        //同时设置信息和图片显示
        blockCollections[block].GetComponent <blockEventHandler>().SetImageInfoAndShow(info);

        blockEventHandler handler = HoldingObject.GetComponent <blockEventHandler>();

        if (old.id == -1)
        {
            //如果原本拼图区这一块没有图片,生产区域的图片还要隐藏并放到父物体最后面去
            handler.image.sprite = null;
            handler.transform.SetAsLastSibling();//隐藏的移到父物体最后面
            handler.gameObject.SetActive(false);
        }
        else
        {
            //如果拼图区原本有图片,将其放回架子上
            handler.SetImageInfoAndShow(old);
        }


        if (CheckComplete())
        {                   //判断拼图是否完成
            GameComplete(); //执行拼图完成函数
        }
    }