示例#1
0
	void Start () 
	{
		// Align the name to the gameObject, so everything is handled the right way
		// Sets the indicator to not represent anything first
		selectionIndicator = SelectionIndicator.none;
		
		// Get all projectors, they're used and referrod to now on as selection
		proj = GetComponentsInChildren<Projector>();
		projIndex = 0;

		foreach (Transform child in transform)
		{
			if (child.name == "GridFieldProjectors")
			{
				Material m = (Material)Instantiate(proj[projIndex].material);
				proj[projIndex].material = m;

				// Make the selection projectors green - currentProjectorColor exists for displaying in inspector, public
				currentProjectorColor = new Color(0, 1, 0);
				m.color = currentProjectorColor;

				projIndex++;
			}
		}

		Layer = 0;									// Ignore "Default" Layer - so we dont hit houses/npc's here
		raycastIgnoreMask = 1 << Layer;				// Set every bit to 1
		raycastIgnoreMask = ~raycastIgnoreMask;		// And invert it

		Screen.showCursor = false; 					// Hide cursor, because it looks fancy
		gotPlaced = false;							// Building is not placed yet!
		Select(); 									// But mark it as selected
		GameController.instance.isBuilding = true;	// Tell globally that we're building now

		buildingPorperties.type = tag;
		switch (buildingPorperties.type) 
		{
		case "Housing":
			// Building properties 
			buildingPorperties.id = GameController.instance.buildingController.buildingList.Count;
			buildingPorperties.needGrids = 8;
			buildingPorperties.usingGridsPosition = new Vector2[buildingPorperties.needGrids];
			buildingPorperties.name = "building_" + buildingPorperties.id;
			buildingPorperties.groundTexture = 0;
			buildingPorperties.cost = 400;
			buildingPorperties.description = "4 or less: +3 income per building\n4 or more: +6 income per building";
			buildingPorperties.maxPeopleAllowed = 4;

			// Initialize the buildings jobs
			homes = new List<Home>();
			InitHomes();

			// Assign the list at last, because it will f**k up indexes from stuff if not
			GameController.instance.buildingController.buildingList.Add (this);
			break;
			
		case "Work":
			// Building properties 
			buildingPorperties.id = GameController.instance.buildingController.buildingList.Count;
			buildingPorperties.needGrids = 8;
			buildingPorperties.usingGridsPosition = new Vector2[buildingPorperties.needGrids];
			buildingPorperties.name = "building_" + buildingPorperties.id;
			buildingPorperties.groundTexture = 0;
			buildingPorperties.cost = 1200;
			buildingPorperties.description = "4 or less: +3 income per building\n4 or more: +6 income per building";
			buildingPorperties.maxPeopleAllowed = 4;

			// Initialize the buildings jobs
			jobs = new List<Job>();
			InitJobs();

			
			// Call our repeating function that calculates and adds cash to our wallet
			InvokeRepeating("AddMoneyToWallet", 3.0f, 3.0f);

			// Assign the list at last, because it will f**k up indexes from stuff if not
			GameController.instance.buildingController.buildingList.Add (this);
			break;
			
		default: 
			// Building properties 
			buildingPorperties.id = GameController.instance.buildingController.buildingList.Count;
			buildingPorperties.needGrids = 8;
			buildingPorperties.usingGridsPosition = new Vector2[buildingPorperties.needGrids];
			buildingPorperties.name = "building_" + buildingPorperties.id;
			buildingPorperties.groundTexture = 0;
			buildingPorperties.cost = 500;
			buildingPorperties.description = "4 or less: +3 income per building\n4 or more: +6 income per building";
			buildingPorperties.maxPeopleAllowed = 4;
			
			// Initialize the buildings jobs
			jobs = new List<Job>();
			InitJobs();

			// Call our repeating function that calculates and adds cash to our wallet
			InvokeRepeating("AddMoneyToWallet", 3.0f, 3.0f);

			// Assign the list at last, because it will f**k up indexes from stuff if not
			GameController.instance.buildingController.buildingList.Add (this);
			break;
		}

		// Assign the building name to the model's gameObject and prefab gameObject - don't change this!
		Transform houseModel = transform.Find("HouseModel");
		houseModel.name = buildingPorperties.name;
		gameObject.name = buildingPorperties.name;
	}
示例#2
0
	void Update () 
	{
		// Is the mouse hovering over a GUI element?
		mouseOverGUI = GUIController.instance.IsMouseOverGUI ();
		if(mouseOverGUI == false)
		{
			#region Left Mouse Button
			if (Input.GetMouseButtonDown (0)) 
			{
				ray = Camera.main.ScreenPointToRay(Input.mousePosition);	
				// Get mouse hit data
				if (Physics.Raycast (ray, out hit)) 
				{
					// Check if the object is hit
					if (gameObject.name == hit.collider.name)
					{
						// Mark selected on hit
						Select (); 
						Debug.Log(gotPlaced);
						// If the house is not placed yet place it now
						if (!gotPlaced) 
						{
							if (Physics.Raycast(transform.position, -Vector3.up, out hit, 1500, raycastIgnoreMask))
							{
								Debug.Log ("Raycast funktioniert");
								bool canPlace = true;

								int childX = 0;
								int childY = 0;

								// Check if placable or not
								foreach (Transform child in transform)
								{
									if (child.name == "GridFieldProjectors")
									{
										Vector2 griddedChildCoord = Helpers.Calculations.Coordinates.GetGriddedCoords (child.transform.position.x, child.transform.position.z, 4);

										childX = Helpers.Calculations.Coordinates.GetGridFieldIndexe(griddedChildCoord.x);
										childY = Helpers.Calculations.Coordinates.GetGridFieldIndexe(griddedChildCoord.y);
										Debug.Log(GameController.instance.gridFieldController.gridFieldList[childX, childY].isPlaceable);
										// If any underlaying gridField is not placeable, forbid to place the building here
										if(GameController.instance.gridFieldController.gridFieldList[childX, childY].isPlaceable == false)
										{
											canPlace = false;
										}
									}
								}

								if(canPlace == true)
								{
									StartCoroutine(BuildingProcess());
								}
							}
						}
					}
				}
			}
			#endregion

			#region Right Mouse Button
			// Right Button
			if (Input.GetMouseButtonDown (1)) 
			{
				// Get mouse hit data
				ray = Camera.main.ScreenPointToRay(Input.mousePosition);
				if (Physics.Raycast (ray, out hit)) 
				{
					// Check if the object is hit
					if (gameObject.name == hit.collider.name)
					{
						if (gotPlaced == false)
						{
							// Destroy the building completely, because the player doesn't want it
							Remove();
						}
					}

					// Unmark everything on rightclick
					Deselect ();
				}
			}
			#endregion
		}

		#region Not placed - Follow Mouse & more ...
		// If the house is not placed yet, make it follow the mouse
		// and be able to rotate it on the y-axis
		// also projectors included now!
		if (!gotPlaced) 
		{
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if (Physics.Raycast (ray, out hit, 1500, raycastIgnoreMask)) 
			{
			}

			// Convert coordinates to gridded coordinates
			Vector2 currentGriddedCoords = Helpers.Calculations.Coordinates.GetGriddedCoords (hit.point.x, hit.point.z, 4);

			// If mouse has changed a gridField, put the house to this position
			if(currentGriddedCoords.x != lastGriddedCoords.x || currentGriddedCoords.y != lastGriddedCoords.y)
			{
				currentGriddedCoords = Helpers.Calculations.Coordinates.GetGriddedCoords (hit.point.x, hit.point.z, 4);
				transform.position = new Vector3(currentGriddedCoords.x, hit.point.y , currentGriddedCoords.y);
			}
			
			// Save the last mousePos on grid
			lastGriddedCoords = currentGriddedCoords;
			
			// Rotation by mousewheel
			if (Input.GetAxis("Mouse ScrollWheel") < 0) // Mousewheel back
			{
				transform.Rotate(new Vector3(transform.rotation.x, 45, transform.rotation.z));
			}
			if (Input.GetAxis("Mouse ScrollWheel") > 0) // Mousewheel forward
			{
				transform.Rotate(new Vector3(transform.rotation.x, -45, transform.rotation.z));
			}

			// Get all projectors for manipulating em
			//Projector[] proj = GetComponentsInChildren<Projector>();
			//int projIndex = 0;
			projIndex = 0;

			// Get all projectors' transform to get their position - not included in the upper components
			// This checks then if placable or not

			// Set it to normal before we check again, so it has a chance to even pass.. if not, it
			// cant get the selector to change to green again
			selectionIndicator = SelectionIndicator.normal;
			foreach (Transform child in transform)
			{
				if (child.name == "GridFieldProjectors")
				{
					Vector3 griddedChildCoord = Helpers.Calculations.Coordinates.GetGriddedCoords (child.transform.position.x, child.transform.position.z, 4);
					
					int childX = Helpers.Calculations.Coordinates.GetGridFieldIndexe(griddedChildCoord.x);
					int childY = Helpers.Calculations.Coordinates.GetGridFieldIndexe(griddedChildCoord.y);

					// If any of those projectors is hovering over a not placable gridField,
					// don't allow to place here
					if(GameController.instance.gridFieldController.gridFieldList[childX, childY].isPlaceable == false)
					{
						currentProjectorColor = new Color(1, 0, 0);
						proj[projIndex].material.color = currentProjectorColor;
						selectionIndicator = SelectionIndicator.notPlaceable;
					}
					else if(selectionIndicator != SelectionIndicator.notPlaceable)
					{
						currentProjectorColor = new Color(0, 1, 0);
						proj[projIndex].material.color = currentProjectorColor;
					}

					projIndex++;
				}
			}
		}
		#endregion
 	}
示例#3
0
 private void Start()
 {
     selectionIndicator = Instantiate(Resources.Load <GameObject>("Prefabs/SelectionIndicator")).GetComponent <SelectionIndicator>();
 }
示例#4
0
    private void SpawnSelectionIndicator(UIButton button)
    {
        SelectionIndicator newSelectionIndicator = Instantiate(prefab_selectionIndicator, button.sprite_ButtonTop.transform.position, Quaternion.identity).GetComponent <SelectionIndicator>();

        newSelectionIndicator.InitializeIndicator(button.sprite_ButtonTop.color, button.sprite_ButtonTop.size);
    }
示例#5
0
    private void SpawnSelectionIndicator(Tile tile)
    {
        SelectionIndicator newSelectionIndicator = Instantiate(prefab_selectionIndicator, tile.spriteTop.transform.position, Quaternion.identity, tile.spriteTop.transform).GetComponent <SelectionIndicator>();

        newSelectionIndicator.InitializeIndicator(tile.spriteTop.color);
    }
 protected virtual void Start()
 {
     Indicator = new SelectionIndicator(gameObject);
 }