void PlaceObject() { if (previewBuildPoints.valid) { //previewObject.name = (previewBuildPoints.type.ToString() + " Placed"); BuildPoints bp = previewBuildPoints; int mountIndex = baseBuildings.mountPoints.Count; bp.mounting.SetTeam(team.team); bp.mounting.SetObjectID(mountIndex); CmdAddMountPoint(bp.mounting, team.team); SyncStructBool tempBools; tempBools.boolList = new bool[0]; foreach (Vector3 v3 in bp.mounting.points) { bool used = false; tempBools.Add(used); } CmdAddPointUsed(tempBools, team.team); ResetMaterials(); CmdAddPlacedObject(previewObject.transform.position - previewBuildPoints.offset, team.team); previewObject.layer = 0; Vector3 poPosition = previewObject.transform.position; Quaternion poRotation = previewObject.transform.rotation; Destroy(previewObject); CmdSpawnBuildingPart(objects[currentObject].ToString(), currentObject, poPosition, poRotation, mountIndex, team.team, snapMountIndex, snapBoolIndex); BuildIdentifier bid = objects[currentObject].GetComponent <BuildIdentifier>(); CmdChangeResources(-bid.woodCost, -bid.stoneCost, -bid.metalCost, team.team); previewObject = null; meshRend = null; } }
void SetpreviewObjectObject(int id) { BuildIdentifier bid = objects[id].GetComponent <BuildIdentifier>(); ResourceBank rba = team.baseObject.GetComponent <ResourceBank>(); if (bid.woodCost <= rba.wood && bid.stoneCost <= rba.stone && bid.metalCost <= rba.metal) { if (previewObject != null) { Destroy(previewObject); } currentObject = id; previewObject = Instantiate(objects[currentObject], baseParent); if (previewObject.transform.childCount > 0) { for (int counter = 0; counter < previewObject.transform.childCount; counter++) { previewObject.transform.GetChild(counter).gameObject.GetComponent <BoxCollider>().enabled = false; } } else { previewObject.GetComponent <BoxCollider>().enabled = false; } meshRend = previewObject.GetComponent <MeshRenderer>(); SaveMaterials(); SetMaterial(invalidMaterial); previewObject.layer = 2; previewBuildPoints = previewObject.GetComponent <BuildPoints>(); previewObject.transform.localEulerAngles = new Vector3(0, 0, 0); } }