/// <summary> /// Linear fill method. /// </summary> private void LinearFill() { clickPostion = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 rotation = path.transform.eulerAngles; rotation.z -= path.offset; Rect rect = CommonUtil.RectTransformToScreenSpace(path.GetComponent <RectTransform> ()); Vector3 pos1 = Vector3.zero, pos2 = Vector3.zero; if (path.type == Path.ShapeType.Horizontal) { pos1.x = path.transform.position.x - Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f; pos1.y = path.transform.position.y - Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f; pos2.x = path.transform.position.x + Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f; pos2.y = path.transform.position.y + Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.width / 2.0f; } else { pos1.x = path.transform.position.x - Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f; pos1.y = path.transform.position.y - Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f; pos2.x = path.transform.position.x + Mathf.Cos(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f; pos2.y = path.transform.position.y + Mathf.Sin(rotation.z * Mathf.Deg2Rad) * rect.height / 2.0f; } pos1.z = path.transform.position.z; pos2.z = path.transform.position.z; GameObject obj1 = GameObject.Find("obj1"); if (obj1 == null) { obj1 = new GameObject("obj1"); } GameObject obj2 = GameObject.Find("obj2"); if (obj2 == null) { obj2 = new GameObject("obj2"); } if (path.flip) { Vector3 temp = pos2; pos2 = pos1; pos1 = temp; } obj1.transform.position = pos1; obj2.transform.position = pos2; clickPostion.x = Mathf.Clamp(clickPostion.x, Mathf.Min(pos1.x, pos2.x), Mathf.Max(pos1.x, pos2.x)); clickPostion.y = Mathf.Clamp(clickPostion.y, Mathf.Min(pos1.y, pos2.y), Mathf.Max(pos1.y, pos2.y)); fillAmount = Vector2.Distance(clickPostion, pos1) / Vector2.Distance(pos1, pos2); pathFillImage.fillAmount = fillAmount; CheckPathComplete(); }