private void Update() { if (GameManager.instance.isPlaying) { if (Input.GetMouseButton(0)) { //print("Shooting a ray..."); if (waterStorage > 0) { int layerMask = 1 << 8; layerMask = ~layerMask; Vector3 forward = transform.forward; float down = forward.magnitude * Mathf.Tan(sprayAngle * Mathf.Deg2Rad); Vector3 dir = forward + Vector3.down * down; //Debug.DrawRay(transform.position + Vector3.up * handHeight, dir, Color.blue); RaycastHit hit; if (Physics.Raycast(transform.position + Vector3.up * handHeight, dir, out hit, Mathf.Infinity, layerMask)) { //print(hit.point.x.ToString() + " | " + hit.point.z.ToString()); TextureUpdate texture = hit.collider.GetComponent <TextureUpdate>(); if (texture != null) { //texture.Paint(hit.point.x, hit.point.z); texture.Paint(hit.point.x, hit.point.z); } if (waterSplashParticle == null) { waterSplashParticle = Instantiate(waterSplashParticlePrefab, hit.point, Quaternion.identity); } else { waterSplashParticle.transform.position = hit.point; } WaterHitPos = hit.point; } Drain(waterUsage * Time.deltaTime); IsWatering = true; } } if (Input.GetMouseButtonUp(0) || waterStorage <= 0) { if (waterSplashParticle != null) { waterSplashParticle.GetComponent <ParticleSystem>().Stop(); Destroy(waterSplashParticle, 5f); waterSplashParticle = null; } IsWatering = false; } if (IsWatering) { if (!audioManager.IsPlaying("Watering")) { audioManager.Play("Watering"); } } else { audioManager.Stop("Watering"); } if (waterStorage / maxWaterStorage < waterRatioThreshold && !isBlinking) { StartCoroutine(LowOnWaterBlink()); } } }
// Use this for initialization void Start() { topUser = CMainData.TopUser; if (topUser != null) { for (int i = 0; i < topUser.Count; i++) { TextureUpdate t = face[i].GetComponent <TextureUpdate>(); if (t != null) { if (FaceBook.getfriendImages().ContainsKey(topUser[i]["fid"].ToString())) { Texture picture = null; FaceBook.getfriendImages().TryGetValue(topUser[i]["fid"].ToString(), out picture); if (picture != null) { if (face[i] != null) { face[i].mainTexture = picture; } Destroy(t); } else { t.fid = topUser[i]["fid"].ToString(); } } else { t.fid = topUser[i]["fid"].ToString(); FacebookPictureDownloader.EnQueue(topUser[i]["fid"].ToString()); } } /* * string strURL = topUser[i]["fid"].ToString() + "?fields=id,name"; * Debug.Log("FRIEND NAME URL = [ " + strURL + " ]"); * FB.API(strURL, Facebook.HttpMethod.GET, result => * { * if (result.Error == null) * { * Debug.Log("FRIEND NAME RESULT = [ " + result.Text + " ]"); * Dictionary<string, string> friendInfo = Util.DeserializeJSONFriendInfo(result.Text); * friendInfoList.Add(friendInfo["id"],friendInfo["name"]); * } * }); */ FacebookName facebookName = friend_name[i].GetComponent <FacebookName>(); facebookName.fid = topUser[i]["fid"].ToString(); //if (friend_name[i] != null) // friend_name[i].text = topUser[i]["name"].ToString(); if (score[i] != null) { score[i].text = topUser[i]["score"].ToString(); } } for (int i = topUser.Count; i < 10; i++) { face[i].gameObject.SetActive(false); back[i].SetActive(false); friend_name[i].gameObject.SetActive(false); rank[i].gameObject.SetActive(false); score[i].gameObject.SetActive(false); } } else { for (int i = 0; i < 10; i++) { face[i].gameObject.SetActive(false); back[i].SetActive(false); friend_name[i].gameObject.SetActive(false); rank[i].gameObject.SetActive(false); score[i].gameObject.SetActive(false); } } TextureUpdate t_my = face[10].GetComponent <TextureUpdate>(); if (CMainData.UserTexture != null) { face[10].mainTexture = CMainData.UserTexture; Destroy(t_my); } else if (FaceBook.getfriendImages().ContainsKey(FB.UserId)) { Texture picture = null; FaceBook.getfriendImages().TryGetValue(FB.UserId, out picture); if (picture != null) { if (face[10] != null) { face[10].mainTexture = picture; } Destroy(t_my); } else { t_my.fid = FB.UserId; } } else { FacebookPictureDownloader.EnQueue(FB.UserId); } if (CMainData.Username != null) { friend_name[10].text = CMainData.Username; } if (score[10] != null) { score[10].text = CMainData.UserScore.ToString(); } if (rank[10] != null) { rank[10].text = CMainData.UserRanking.ToString(); } }