public EffectEntity CreateEffect(int id, bool attach, int unitUid, int posX, int posY) { MapField mapField = GameRoot.GetInstance().MapField; EffectData data = assetMng.GetEffectData(id); Vector3 pos; Entity entity; if (unitUid != -1) { entity = mapField.FindEntity(unitUid); if (entity == null) { Debug.Log("CreateEffect fail:entity is null"); } pos = entity.GetSocketPos(data.effectSocket); } else { float v_x, v_y; mapField.GetViewPos(posX, posY, out v_x, out v_y); pos = new Vector3(v_x, v_y, 0.05f); } GameObject obj = Instantiate(data.effectPrefab, pos, Quaternion.identity); if (attach == true) { entity = mapField.FindEntity(unitUid); obj.transform.SetParent(entity.gameObject.transform.Find(data.effectSocket).gameObject.transform); obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.Euler(0, 0, 0); obj.transform.localScale = Vector3.one * entity.radius / 4; } EffectEntity effectEntity = obj.AddComponent <EffectEntity>(); //clean effect if (data.isAutoClean) { ParticleSystem[] array = obj.GetComponentsInChildren <ParticleSystem>(); float time = 0; foreach (var par in array) { float temp = par.main.duration; if (temp > time) { time = temp; } } Destroy(obj, time); } effects.Add(effectEntity.gameObject); return(effectEntity); }
//flag:1,crit,2,miss,3,heal,4,warning public void PrintMessage(int uid, string text, int flag) { MapField mapField = GameRoot.GetInstance().MapField; Entity entity; entity = mapField.FindEntity(uid); if (entity == null) { Debug.Log("entity is null"); return; } Canvas canvas = GameRoot.GetInstance().battleTextUI.GetComponent <Canvas>(); CamaraManager camara = GameRoot.GetInstance().CameraMng; Vector2 screenPos = Camera.main.WorldToScreenPoint(entity.GetSocketPos("S_Center")); //Vector2 uiPos = Vector2.zero; //uiPos.x = screenPos.x - (Screen.width / 2); //uiPos.y = screenPos.y - (Screen.height / 2); //hpBar.GetComponent<RectTransform>().position = new Vector3(0, 0, 0); GameObject message = Instantiate(GameRoot.GetInstance().BattleField.assetManager.Message); message.GetComponent <RectTransform>().parent = GameRoot.GetInstance().battleTextUI.GetComponent <RectTransform>(); //hpBar.GetComponent<RectTransform>().sizeDelta = new Vector2(Mathf.Sqrt(radius) / 2 * 80, 22); message.SetActive(true); if (entity.side == 2) { switch (flag) { case 0: message.GetComponentInChildren <Text>().text = text; message.GetComponentInChildren <Text>().color = new Color(0.95f, 0.10f, 0.18f); message.transform.localScale = Vector3.one; break; case 1: message.GetComponentInChildren <Text>().text = text; message.GetComponentInChildren <Text>().color = new Color(0.9f, 0.1f, 0.7f); message.GetComponent <TipMessage>().SetLogo(int.Parse(text)); message.transform.DOScale(Vector3.one * 3.5f, 0.1f).onComplete += () => { message.transform.DOScale(Vector3.one * 2f, 0.15f).onComplete += () => { message.transform.DOScale(Vector3.one * 1.5f, 0.45f); }; }; break; case 4: message.GetComponentInChildren <Text>().text = StrUtil.GetText(text); message.GetComponentInChildren <Text>().color = new Color(0.87f, 0.82f, 0.34f); message.transform.localScale = new Vector3(1.2f, 1, 1); break; } } else { switch (flag) { case 0: case 1: message.GetComponentInChildren <Text>().text = text; message.GetComponentInChildren <Text>().color = new Color(0.7f, 0.6f, 1f); message.transform.localScale = Vector3.one * 0.7f; break; case 4: message.GetComponentInChildren <Text>().text = StrUtil.GetText(text); message.GetComponentInChildren <Text>().color = new Color(0.87f, 0.82f, 0.34f); message.transform.localScale = new Vector3(0.96f, 0.8f, 0.8f); break; } } message.transform.position = new Vector3(screenPos.x, screenPos.y, 0); Color t_color = message.GetComponentInChildren <Text>().color; message.GetComponentInChildren <Text>().DOColor(new Color(t_color.r, t_color.g, t_color.b, 1), 0.5f).onComplete += () => { message.GetComponentInChildren <Text>().DOColor(new Color(t_color.r, t_color.g, t_color.b, 0), 0.5f); }; Image logo = message.GetComponent <TipMessage>().CritLogo.GetComponentInChildren <Image>(); Color l_color = logo.color; if (logo != null && logo.gameObject.activeSelf == true) { logo.DOColor(new Color(l_color.r, l_color.g, l_color.b, 1), 0.3f).onComplete += () => { logo.DOColor(new Color(l_color.r, l_color.g, l_color.b, 0), 0.4f); } } ; //init message struct MessageEffect effect = new MessageEffect { effect = message, uid = uid, duration = 1.1f, pos = entity.GetSocketPos("S_Center"), canvas = BattleUICanvas.BattleText, }; messageCantainer.Add(effect); //float scale = camara.minSize / camara.size; //message.transform.localScale = Vector3.one; //message.transform.DOMoveY(message.transform.position.y + 20, 0.2f); //Destroy(message, 0.2f); }