// Use this for initialization public void initialize() { elapsedTime = 0.0f; opacity = 0.0f; targetOpacity = 0.0f; status = UIInventoryItemStatus.appearing; //go = new GameObject (); theImage = this.gameObject.AddComponent <Image> (); theImage.sprite = theSprite; this.transform.parent = parent.transform; theImage.transform.parent = this.transform; imageRect = theImage.GetComponent <RectTransform> (); float op; op = maxOpacity * opacity; if (op > maxOpacity) { op = maxOpacity; } theImage.color = new Vector4(1.0f, 1.0f, 1.0f, op); EventTrigger evt = this.gameObject.AddComponent <EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback = new EventTrigger.TriggerEvent(); entry.callback.AddListener((eventData) => UIItemClickedOn()); evt.triggers.Add(entry); running = false; }
public void show() { elapsedTime = 0.0f; status = UIInventoryItemStatus.appearing; targetOpacity = 1.0f; running = true; }
// Use this for initialization public void initialize() { elapsedTime = 0.0f; opacity = 0.0f; targetOpacity = 0.0f; status = UIInventoryItemStatus.appearing; //go = new GameObject (); theText = this.gameObject.AddComponent <Text> (); theText.text = theString; theText.fontStyle = FontStyle.Bold; theText.font = font; //Resources.Load<Font>("Fonts/Arial"); this.transform.parent = parent.transform; theText.transform.parent = this.transform; theText.raycastTarget = false; imageRect = theText.GetComponent <RectTransform> (); theText.color = new Vector4(0.0f, 0.0f, 0.0f, opacity); running = false; }
// Update is called once per frame void Update() { if (status == UIInventoryItemStatus.appearing) { if (running && (elapsedTime < delay)) { elapsedTime += Time.deltaTime; if (elapsedTime > delay) { show(); status = UIInventoryItemStatus.idle; } return; } } if (opacity > targetOpacity) { opacity -= opacitySpeed * Time.deltaTime; if (opacity < targetOpacity) { opacity = targetOpacity; } float op; op = maxOpacity * opacity; if (op > maxOpacity) { op = maxOpacity; } theImage.color = new Vector4(1.0f, 1.0f, 1.0f, op); } if (opacity < targetOpacity) { opacity += opacitySpeed * Time.deltaTime; if (opacity > targetOpacity) { opacity = targetOpacity; } float op; op = maxOpacity * opacity; if (op > maxOpacity) { op = maxOpacity; } theImage.color = new Vector4(1.0f, 1.0f, 1.0f, op); } }
// Update is called once per frame void Update() { if (status == UIInventoryItemStatus.appearing) { if (running && (elapsedTime < delay)) { elapsedTime += Time.deltaTime; if (elapsedTime > delay) { show(); status = UIInventoryItemStatus.idle; } return; } } if (opacity > targetOpacity) { opacity -= opacitySpeed * Time.deltaTime; if (opacity < targetOpacity) { opacity = targetOpacity; } theText.color = new Vector4(0.0f, 0.0f, 0.0f, opacity); } if (opacity < targetOpacity) { opacity += opacitySpeed * Time.deltaTime; if (opacity > targetOpacity) { opacity = targetOpacity; } theText.color = new Vector4(0.0f, 0.0f, 0.0f, opacity); } }