ArenMook

HP bar #4

Jun 24th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. UISprite fg = NGUITools.Draw<UISprite>("fg", delegate(UISprite sp)
  2. {
  3.     sp.depth = 1;
  4.     sp.atlas = Resources.Load<UIAtlas>("UI/Atlas - Windward");
  5.     sp.spriteName = "Flat";
  6.     sp.type = UISprite.Type.Sliced;
  7.     sp.color = new Color(0.25f, 1f, 0f, 1f);
  8.     sp.pivot = UIWidget.Pivot.TopLeft;
  9.     sp.SetAnchor(0.5f, -140,
  10.         1f, -64,
  11.         0.5f, 140,
  12.         1f, -40);
  13.  
  14.     UISprite bg = sp.gameObject.AddWidget<UISprite>(0);
  15.     bg.atlas = sp.atlas;
  16.     bg.spriteName = "Flat";
  17.     bg.type = UISprite.Type.Sliced;
  18.     bg.color = new Color(0.5f, 0.1f, 0.1f, 0.8f);
  19.     bg.pivot = UIWidget.Pivot.TopLeft;
  20.     bg.SetAnchor(0f, 0,
  21.         0f, 0,
  22.         1f, 0,
  23.         1f, 0);
  24.  
  25.     UILabel lbl = sp.gameObject.AddWidget<UILabel>(2);
  26.     lbl.name = "Name";
  27.     lbl.pivot = UIWidget.Pivot.Left;
  28.     lbl.bitmapFont = Resources.Load<UIFont>("UI/Font - Qlassik22");
  29.     lbl.fontSize = lbl.bitmapFont.defaultSize / 6 * 5;
  30.     lbl.effectStyle = UILabel.Effect.Shadow;
  31.     lbl.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f);
  32.     lbl.SetAnchor(0f, 6,
  33.         0f, 0,
  34.         1f, -6,
  35.         1f, 0);
  36.  
  37.     lbl = sp.gameObject.AddWidget<UILabel>(3);
  38.     lbl.name = "Percent";
  39.     lbl.pivot = UIWidget.Pivot.Right;
  40.     lbl.bitmapFont = Resources.Load<UIFont>("UI/Font - Qlassik22");
  41.     lbl.fontSize = lbl.bitmapFont.defaultSize / 6 * 5;
  42.     lbl.effectStyle = UILabel.Effect.Shadow;
  43.     lbl.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f);
  44.     lbl.SetAnchor(0f, 6,
  45.         0f, 0,
  46.         1f, -6,
  47.         1f, 0);
  48.  
  49.     UISlider slider = sp.gameObject.AddComponent<UISlider>();
  50.     slider.backgroundWidget = bg;
  51.     slider.foregroundWidget = sp;
  52. });
  53.  
  54. RuntimeBehaviour.Create("HP").onUpdate = delegate(RuntimeBehaviour rb)
  55. {
  56.     if (UILoadingScreen.isVisible) return;
  57.     UISlider slider = fg.GetComponent<UISlider>();
  58.  
  59.     for (int i = 0; i < GameShip.list.size; ++i)
  60.     {
  61.         GameShip ship = GameShip.list[i];
  62.  
  63.         if (ship != null && ship.isActive && ship.bossTier > 3 && ship.factionID == 0)
  64.         {
  65.             slider.value = ship.health;
  66.             Transform child = slider.transform.FindChild("Name");
  67.            
  68.             if (child != null)
  69.             {
  70.                 UILabel lbl = child.GetComponent<UILabel>();
  71.                 if (lbl != null) lbl.text = ship.name;
  72.             }
  73.            
  74.             child = slider.transform.FindChild("Percent");
  75.            
  76.             if (child != null)
  77.             {
  78.                 UILabel lbl = child.GetComponent<UILabel>();
  79.                 if (lbl != null) lbl.text = Mathf.RoundToInt(ship.health * 100f) + "%";
  80.             }
  81.             return;
  82.         }
  83.     }
  84.  
  85.     UnityEngine.Object.Destroy(fg.gameObject);
  86.     rb.onUpdate = null;
  87. };
Advertisement
Add Comment
Please, Sign In to add comment