private void CreatePlaceableObject(GameObject PlaceableObject, Vector3 location) { currentPlaceableObject = Instantiate(PlaceableObject, location, Quaternion.identity); PlaceablesData DeviceDataScript = currentPlaceableObject.GetComponent <PlaceablesScript>().PlaceablesDataScript; maxPlaceAngle = DeviceDataScript.MaxUpAngle; }
private void DeleteSelected() { if (currentSelectedObject) { PlaceablesScript DeviceMainScript = currentSelectedObject.GetComponent <PlaceablesScript>(); PlaceablesData DeviceDataScript = currentSelectedObject.GetComponent <PlaceablesScript>().PlaceablesDataScript; DeviceMainScript.InvokeDelete(); ColorManager colorManager = currentSelectedObject.GetComponent <ColorManager>(); colorManager.ResetColor(); currentSelectedObject = null; } }
private void Awake() { canvas = GameObject.Find("Canvas"); PlaceablesDataScript = gameObject.GetComponent <PlaceablesData>(); PlaceablesManagerScript = GameObject.Find("DataManager").GetComponent <DataManager>(); maxPlaceAngle = PlaceablesDataScript.MaxUpAngle; if (PlaceablesDataScript.IsWindBasedEnergyProduction == true) { var WindGameObject = Instantiate(WindEffeciencyPrefab, new Vector3(transform.position.x, transform.position.y + transform.localScale.y, transform.position.z), Quaternion.identity); CurrentWindEffeciencyScript = WindGameObject.GetComponent <WindEffeciency>(); WindGameObject.transform.parent = gameObject.transform; } }
private void ReleaseIfClicked() { canPlace = CheckPlacementValidity(); if (Input.GetKeyDown(placeHotkey)) { PlaceablesScript PlaceableScript = currentPlaceableObject.GetComponent <PlaceablesScript>(); PlaceablesData DeviceDataScript = PlaceableScript.PlaceablesDataScript; if (canPlace && currentPlaceableObject.activeSelf) { FixedJoint joint = currentPlaceableObject.gameObject.AddComponent <FixedJoint>(); joint.connectedBody = returnObject.GetComponent <Rigidbody>(); PlaceableScript.PlaceablesManagerScript = DataManagerScript; PlaceableScript.PlacementControllerScript = this; PlaceableScript.InvokePlacement(); HasThesePlaceables.Add(currentPlaceableObject); currentPlaceableObject = null; } } }
void PutItemsInCategory(int category, List <GameObject> items) { //For all the prefabs in list foreach (GameObject item in items) { //Make Hud gameobject GameObject HUDItem = Instantiate(HUDItemTemplate); int index = items.IndexOf(item); HUDItem.name = "HUD-Item." + item.name + index; HUDItem.transform.SetParent(HUD[category].transform); HUDItem.transform.localScale = new Vector3(1f, 1f, 1f); //Give hud button its function HUDItem.GetComponent <Button>().onClick.AddListener(() => SetCategoryIndex(index)); //If has icon sprite PlaceablesData itemData = item.GetComponent <PlaceablesScript>().PlaceablesDataScript; if (itemData.HUDSprite != null) { HUDItem.GetComponent <Image>().sprite = itemData.HUDSprite; } } }
private bool CheckPlacementValidity() { PlaceablesScript PlaceableScript = currentPlaceableObject.GetComponent <PlaceablesScript>(); PlaceablesData DeviceDataScript = PlaceableScript.PlaceablesDataScript; //Is object colliding with another? if (returnObject != null && currentPlaceableObject != null) { if (PlaceableScript.isColliding == false) { float returnObjectAngleX = returnObject.transform.eulerAngles.x; returnObjectAngleX = (returnObjectAngleX > 180) ? returnObjectAngleX - 360 : returnObjectAngleX; float returnObjectAngleZ = returnObject.transform.eulerAngles.z; returnObjectAngleZ = (returnObjectAngleZ > 180) ? returnObjectAngleZ - 360 : returnObjectAngleZ; if (!(maxPlaceAngle >= Mathf.Abs(returnObjectAngleX) && maxPlaceAngle >= Mathf.Abs(returnObjectAngleZ))) { return(false); } } else { return(false); } } //Does the player have enough funds? if (!DataManagerScript.CanAfford(DeviceDataScript.MetalCost, DeviceDataScript.EnergyCost)) { WarningBoxScriptLink.SetWarning("Cannot Place, Not Enough Resources"); return(false); } //Does the player have the required tech? if (DeviceDataScript.RequiresTech != "") { if (!HasTheseTech.Any(t => t.name == DeviceDataScript.RequiresTech + "(Clone)")) { WarningBoxScriptLink.SetWarning("Cannot Place, Player Does Not Have Required Technology"); return(false); } } //Does the player already have the maximum amount? if (DeviceDataScript.LimitOfLikePlaceables != 0) { int AmountOfLike = 0; foreach (GameObject ThePlacables in HasThesePlaceables) { if (ThePlacables != null) { if (ThePlacables.name == currentPlaceableObject.name) { AmountOfLike++; } } } if (AmountOfLike >= DeviceDataScript.LimitOfLikePlaceables) { WarningBoxScriptLink.SetWarning("Cannot Place, Player Already Has The Max Amount Of This Placeable"); return(false); } } return(true); }