123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using UnityEngine;
- using System.Collections;
- public class TeamSideBarContainer : MonoBehaviour {
- public enum State
- {
- Showing,
- Shown,
- Hiding,
- Hiden
- }
- public GameObject bar;
- public GameObject flag;
- private CrystalBase crystal;
- public State state = State.Hiding;
- public void setCrystal(CrystalBase crystal)
- {
- this.crystal = crystal;
- if(crystal != null)
- {
- bar.GetComponent<GUITexture>().enabled = flag.GetComponent<GUITexture>().enabled = true;
- }
- else
- {
- bar.GetComponent<GUITexture>().enabled = flag.GetComponent<GUITexture>().enabled = false;
- }
- UpdateBar();
- }
- // Update is called once per frame
- public void UpdateBar ()
- {
- if(crystal != null)
- {
- float powerLevel = (float)crystal.powerLevel;
- TeamUtil.Team team = crystal.team;
- Rect rectBar = bar.GetComponent<GUITexture>().pixelInset;
- Rect rectFlag = flag.GetComponent<GUITexture>().pixelInset;
- if(team == TeamUtil.Team.Blue)
- {
- rectFlag.x = rectBar.x + rectBar.width/2f - (rectBar.width-6f)/10f*powerLevel - rectFlag.width/2f;
- }
- else if(team == TeamUtil.Team.Red)
- {
- rectFlag.x = rectBar.x + rectBar.width/2f + (rectBar.width-6f)/10f*powerLevel - rectFlag.width/2f;
- }
- else
- {
- rectFlag.x = rectBar.x + rectBar.width/2f - rectFlag.width/2f;
- }
- flag.GetComponent<GUITexture>().pixelInset = rectFlag;
- }
- }
- void Update()
- {
- if(state == State.Showing)
- {
- Color color = flag.GetComponent<GUITexture>().color;
- color.a += GameTime.deltaTime;
- if(color.a >= 1f)
- {
- state = State.Shown;
- return;
- }
-
- if(color.a >= 1f)
- {
- color.a = 1f;
- state = State.Shown;
- }
- flag.GetComponent<GUITexture>().color = bar.GetComponent<GUITexture>().color = color;
- }
- else if(state == State.Hiding)
- {
- Color color = flag.GetComponent<GUITexture>().color;
- if(color.a <= 0)
- {
- state = State.Hiden;
- return;
- }
-
- color.a -= GameTime.deltaTime;
- if(color.a <= 0)
- {
- color.a = 0;
- state = State.Hiden;
- }
- flag.GetComponent<GUITexture>().color = bar.GetComponent<GUITexture>().color = color;
- }
- updatePosition();
- }
- private void updatePosition()
- {
- if(crystal == null)
- {
- return;
- }
- Vector3 position = crystal.position;
- position.y += 5f;
- Vector3 screenPosition = Camera.main.WorldToScreenPoint(position);
-
- position.x = screenPosition.x/Screen.width;
- position.y = screenPosition.y/Screen.height;
- position.z = -1f;
-
- this.transform.position = position;
- }
- }
|