Пример #1
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(); //执行拼图完成函数
        }
    }
Пример #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
    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;
    }
Пример #4
0
 public void LooseObject(HoldingObject o)
 {
     if (holdingObject == o)
     {
         holdingObject = null;
     }
 }
Пример #5
0
	// Use this for initialization
	void Awake () {
		if(_instance == null){
			_instance = this;
		}
		if(player == null){
			//TODO: find the player
			player = Camera.main.transform.parent.gameObject;
		}
		holdingObject = player.GetComponentInChildren<HoldingObject>();
		StartCoroutine(PlayFirstClip());
	}
Пример #6
0
    void Drop()
    {
        if (holdingObject == null || (holdingObject.tag != "WaterCan" && holdingObject.tag != "MiscHoldingObject"))
        {
            return;
        }
        Rigidbody2D holdingRigidBody = holdingObject.GetComponent <Rigidbody2D>();

        if (holdingRigidBody)
        {
            holdingRigidBody.velocity = movement.Velocity + new Vector2(movement.Direction * 5, 4);
        }
        holdingObject.owner = null;
        holdingObject       = null;
        canThrow            = false;
    }
Пример #7
0
    private void FixedUpdate()
    {
        if (HoldingObject)
        {
            // We are holding an object, time to rotate & move it

            Ray ray = CenterRay();



            // Rotate the object to remain consistent with any changes in player's rotation
            // HoldingObject.MoveRotation(Quaternion.Euler(rotationDifferenceEuler + transform.rotation.eulerAngles));

            // Get the destination point for the point on the object we grabbed
            Vector3 holdPoint = ray.GetPoint(currentGrabDistance);
            // Debug.DrawLine(ray.origin, holdPoint, Color.blue, Time.fixedDeltaTime);

            // Apply any intentional rotation input made by the player & clear tracked input
            Vector3 currentEuler = HoldingObject.rotation.eulerAngles;
            HoldingObject.transform.RotateAround(holdPoint, transform.right, rotationInput.y);

            HoldingObject.transform.RotateAround(holdPoint, transform.up, -rotationInput.x);


            // Remove all torque, reset rotation input & store the rotation difference for next FixedUpdate call
            HoldingObject.angularVelocity = Vector3.zero;
            rotationInput = Vector2.zero;
            //rotationDifferenceEuler = HoldingObject.transform.rotation.eulerAngles - transform.rotation.eulerAngles;

            // Calculate object's center position based on the offset we stored
            // NOTE: We need to convert the local-space point back to world coordinates
            Vector3 centerDestination = holdPoint - HoldingObject.transform.TransformVector(hitOffsetLocal);

            // Find vector from current position to destination
            Vector3 toDestination = centerDestination - HoldingObject.transform.position;

            // Calculate force
            //Vector3 force = toDestination / Time.fixedDeltaTime;
            Vector3 force = Vector3.Slerp(toDestination, holdPoint, Time.fixedDeltaTime * Vector3.Distance(centerDestination.normalized, HoldingObject.transform.position.normalized)) * SlerpSpeed;



            // Remove any existing velocity and add force to move to final position
            HoldingObject.velocity = Vector3.zero;
            HoldingObject.AddForce(force, ForceMode.VelocityChange);
        }
    }
Пример #8
0
    private void ShootGravGun(float ShotCharge)
    {
        HoldingObject.AddForce((HoldingObject.transform.position - transform.position) * shootForce * ShotCharge, ForceMode.Force);
        HoldingObject.interpolation = initialInterpolationSetting;
        if (shakeInstance != null)
        {
            shakeInstance.StartFadeOut(0.1f);
            shakeInstance = null;
        }

        CameraShaker.Instance.ShakeOnce(chargeValue, 15f, 0.1f, 1f);

        HoldingObject.useGravity = true;
        HoldingObject            = null;
        chargeValue        = 0.0f;
        chargeSlider.value = chargeValue;
    }
Пример #9
0
 void PickUp()
 {
     Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.6f);
     foreach (Collider2D col in colliders)
     {
         if (col.gameObject.tag == "LeekGround")
         {
             GameObject harvest = col.gameObject.GetComponent <Earth>().HarvestLeek();
             if (harvest != null)
             {
                 holdingObject       = harvest.GetComponent <HoldingObject>();
                 holdingObject.owner = gameObject;
                 canThrow            = true;
                 break;
             }
         }
         else if (col.gameObject.tag == "WaterCan")
         {
             holdingObject = col.gameObject.GetComponent <HoldingObject>();
             if (holdingObject.owner != null && holdingObject.owner != gameObject)
             {
                 holdingObject.owner.GetComponent <ThrowComponent>().LooseObject(holdingObject);
             }
             holdingObject.owner = gameObject;
             canThrow            = false;
             break;
         }
         else if (col.gameObject.tag == "MiscHoldingObject")
         {
             holdingObject = col.gameObject.GetComponent <HoldingObject>();
             GameManager.Instance.SoundManager.PlaySound(GameManager.Instance.SoundManager.chickenSound);
             if (holdingObject.owner != null && holdingObject.owner != gameObject)
             {
                 holdingObject.owner.GetComponent <ThrowComponent>().LooseObject(holdingObject);
             }
             holdingObject.owner = gameObject;
             canThrow            = false;
             break;
         }
     }
 }