Esempio n. 1
0
    public void Initialize(GameConstants.eEnergyType flower, GameConstants.eEnergyType stem, GameConstants.eEnergyType bse)
    {
        if (!m_IsBeingHeld)
        {
            base.Initialize();
        }

        // use the energy types to zombie together the final plant
        m_FlowerComponent = Instantiate <GameObject>((GameObject)Resources.Load(string.Format(GameConstants.PLANT_COMPONENT_PREFAB_PATH, GameConstants.eSlot.FLOWER, flower)), m_BaseAnchor).GetComponent <FlowerComponent>();
        m_StemComponent   = Instantiate <GameObject>((GameObject)Resources.Load(string.Format(GameConstants.PLANT_COMPONENT_PREFAB_PATH, GameConstants.eSlot.STEM, stem)), m_BaseAnchor).GetComponent <StemComponent>();
        m_RootComponent   = Instantiate <GameObject>((GameObject)Resources.Load(string.Format(GameConstants.PLANT_COMPONENT_PREFAB_PATH, GameConstants.eSlot.ROOT, bse)), m_BaseAnchor).GetComponent <RootComponent>();
        CreatePlant();
    }
	// Update is called once per frame
	void Update () {
		//get mouse position
		Vector3 mousePos = MathTools.ScreenToWorldPosition(Input.mousePosition);

		bool end = false;
		bool destroy = false;

		if (Input.GetMouseButtonUp (0)) {
			if (flower != null) {
				if (currentPlanetByMouse == null
				    || currentPlanetByMouse.connectedPlanets.Contains (flower.planet)
				    || currentPlanetByMouse == flower.planet
				    || !currentPlanetByMouse.CanConnectVine ()
				    ) {//|| !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 (flower != 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) {
			flower = null;
			vine = null;
			CameraPanningScript.Enable ();
		}
	}
	public static void StartDrag (FlowerComponent flo) {
		if (flo == null || flo.gameObject == null) {
			Debug.Log ("ERRORS");
			return;
		}

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

		CameraPanningScript.Disable ();
		flower = flo;

		var v = GameObject.Instantiate (instance.vinePrefab);
		vine = v.GetComponent <VineComponent> ();
		vine.ends.Add (flower.planet);
		vine.flowerPlanet = flower.planet;
		vine.gameObject.transform.SetAsFirstSibling ();
		startPos = flo.gameObject.transform.parent.position;
	}