Пример #1
0
	// Update is called once per frame
	void Update ()
	{
		//get mouse position
		Vector3 mousePos = MathTools.ScreenToWorldPosition (Input.mousePosition);
		if (VineDragPlanet != null) {
			if (Vector3.Distance (mousePos, startPos) > VineDragPlanet.maxDragDist
			    || (currentPlanetByMouse != null
			    && (!currentPlanetByMouse.CanConnectVine () || currentPlanetByMouse.connectedPlanets.Contains (VineDragPlanet)))) {
				vine.GetComponent<SpriteRenderer> ().material.color = vineInvalidColor;
			} else {
				if (vineVisible) {
					vineBaseColor.a = 1f;
					vine.GetComponent<SpriteRenderer> ().material.color = vineBaseColor;
				} else {
					vineBaseColor.a = .5f;
					vine.GetComponent<SpriteRenderer> ().material.color = vineBaseColor;
				}
			}
		}


		bool end = false;
		bool destroy = false;

		if (Input.GetMouseButtonUp (0)) {
			if (VineDragPlanet != null) {
				if (currentPlanetByMouse == null
				    || currentPlanetByMouse.connectedPlanets.Contains (VineDragPlanet)
				    || currentPlanetByMouse == VineDragPlanet
				    || !currentPlanetByMouse.CanConnectVine ()
				    || Vector3.Distance (mousePos, startPos) > VineDragPlanet.maxDragDist) {//|| !vine.IsNotColliding ()) {
					destroy = true;
				} else {
					mousePos = currentPlanetByMouse.transform.position;
					OnFlowerDragSuccessfulEnd ();
				}

				end = true;
			}
		}

		//limit their distance
		//var dif = mousePos - startPos;
		//if (flower != null && dif.magnitude > flower.maxDragDist)
		//mousePos = startPos + dif.normalized * flower.maxDragDist;

		if (VineDragPlanet != null) {
			PlaceVine (startPos, mousePos, vine.gameObject);
			/*
			//position the vine between the two points
			Vector3 pos = (startPos + mousePos) / 2f;
			pos.z = .1f;
			vine.gameObject.transform.position = pos;

			//vine facing
			Vector3 dir = mousePos - startPos;
			var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
			vine.gameObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

			//vine stretching
			var scale = vine.gameObject.transform.localScale;
			scale.x = dir.magnitude / 8f;
			scale.y = 2f;
			//Debug.Log (mousePos + " " + startPos + " " + dir.magnitude);
			vine.gameObject.transform.localScale = scale;*/
		}

		if (destroy) {
			GameObject.Destroy (vine.gameObject);
		}
		if (end) {
			VineDragPlanet = null;
			vine = null;
			CameraPanningScript.Enable ();
		}
	}
Пример #2
0
	public static void StartDrag (VinePlanet flo, bool isVisible)
	{
		if (flo == null || flo.gameObject == null) {
			Debug.Log ("ERRORS");
			return;
		}

		if (flo.numBridges <= 0) {
			Debug.Log ("Insufficient bridges");
			return;
		}

		CameraPanningScript.Disable ();
		VineDragPlanet = flo;

		vineVisible = isVisible;
		var v = GameObject.Instantiate (instance.vinePrefab);
		vine = v.GetComponent <PregenVine> ();
		if (VineDragPlanet.planetType == "travelPlanet")
			vine.travelVine = true;
		else
			vine.travelVine = false;
		vine.ends.Add (VineDragPlanet);
		vine.flowerPlanet = VineDragPlanet;
		VineDragPlanet.spawnedVines.Add (vine);
		VineDragPlanet.travelVine = vine;
		vine.gameObject.transform.SetAsFirstSibling ();
		startPos = flo.gameObject.transform.position;
	}