private void setupDamageViewInfo(DamageViewInfo damage_view_info) { damage_view_info.m_InstanceObject = Instantiate(m_DamageNumberPrefab); Transform text_anim_trans = damage_view_info.m_InstanceObject.transform.Find("TextAnim"); if (text_anim_trans != null) { damage_view_info.m_TextAnimation = text_anim_trans.GetComponent <Animation>(); } Transform text_trans = damage_view_info.m_InstanceObject.transform.Find("TextAnim/TextObject"); if (text_trans != null) { damage_view_info.m_TextMesh = text_trans.GetComponent <TextMeshPro>(); } Transform sprite_anim_trans = damage_view_info.m_InstanceObject.transform.Find("SpriteAnim"); if (sprite_anim_trans != null) { damage_view_info.m_SpriteAnimation = sprite_anim_trans.GetComponent <Animation>(); } Transform weak_sprite_trans = damage_view_info.m_InstanceObject.transform.Find("SpriteAnim/WeakSprite"); if (weak_sprite_trans != null) { damage_view_info.m_WeakSprite = weak_sprite_trans.GetComponent <SpriteRenderer>(); } damage_view_info.m_InstanceObject.transform.SetParent(transform, false); damage_view_info.m_InstanceObject.SetActive(false); }
//---------------------------------------------------------------------------- /*! * @brief Unity固有処理:更新処理 ※定期処理 */ //---------------------------------------------------------------------------- void Update() { m_IsShowing = false; for (int idx = 0; idx < m_DamageViewInfots.Length; idx++) { DamageViewInfo damage_view_info = m_DamageViewInfots[idx]; if (damage_view_info != null && damage_view_info.m_ShowTimer > 0.0f) { GameObject instance_object = damage_view_info.m_InstanceObject; if (instance_object != null) { damage_view_info.m_ShowTimer -= Time.deltaTime; if (damage_view_info.m_ShowTimer <= 0.0f) { instance_object.SetActive(false); instance_object.transform.SetParent(transform, false); instance_object.transform.localPosition = m_InitPrefabPosition; instance_object.transform.localRotation = m_InitPrefabRotation; instance_object.transform.localScale = m_InitPrefabScale; } else { m_IsShowing = true; } } else { damage_view_info.m_ShowTimer = 0.0f; } } } }
//---------------------------------------------------------------------------- /*! * @brief Unity固有処理:初期化処理 ※初回のUpdateを呼び出す直前に呼出し */ //---------------------------------------------------------------------------- protected override void Start() { base.Start(); m_InitPrefabPosition = m_DamageNumberPrefab.transform.localPosition; m_InitPrefabRotation = m_DamageNumberPrefab.transform.localRotation; m_InitPrefabScale = m_DamageNumberPrefab.transform.localScale; for (int idx = 0; idx < m_DamageViewInfots.Length; idx++) { DamageViewInfo damage_view_info = new DamageViewInfo(); setupDamageViewInfo(damage_view_info); m_DamageViewInfots[idx] = damage_view_info; } }
private void _showDamage(Transform parent, int damage_value, EDAMAGE_TYPE damage_type, float scale, float offset_y, float type_scale) { DamageViewInfo damage_view_info = m_DamageViewInfots[m_CurrentIndex]; if (damage_view_info.m_InstanceObject == null) { // 表示中にライド先の削除に巻き込まれて消える場合があるので.その場合インスタンスを作り直し. setupDamageViewInfo(damage_view_info); } damage_view_info.m_ShowTimer = 1.0f; damage_view_info.m_InstanceObject.transform.SetParent(parent, false); if (damage_view_info.m_TextMesh != null) { string anim_name = null; Sprite weak_sprite = null; Color moji_color = MOJI_COLORS[(int)damage_type]; Color moji_shadow_color = MOJI_SHADOW_COLORS[(int)damage_type]; float moji_scale = MOJI_SCALES[(int)damage_type]; switch (damage_type) { case EDAMAGE_TYPE.eDAMAGE_TYPE_NORMAL: default: { anim_name = TEXT_ANIM_NAME_DAMAGE; weak_sprite = null; } break; case EDAMAGE_TYPE.eDAMAGE_TYPE_WEEK: { anim_name = TEXT_ANIM_NAME_DAMAGE; weak_sprite = m_WeakSprite; } break; case EDAMAGE_TYPE.eDAMAGE_TYPE_GUARD: { anim_name = TEXT_ANIM_NAME_DAMAGE_GUARD; weak_sprite = m_GuardSprite; } break; case EDAMAGE_TYPE.eDAMAGE_TYPE_HEAL: { anim_name = TEXT_ANIM_NAME_DAMAGE_GUARD; weak_sprite = null; } break; case EDAMAGE_TYPE.eDAMAGE_TYPE_CRITICAL: { anim_name = TEXT_ANIM_NAME_DAMAGE; weak_sprite = m_CriticalSprite; } break; } damage_view_info.m_InstanceObject.transform.localPosition = new Vector3(0.0f, offset_y, 0.0f); damage_view_info.m_TextMesh.text = damage_value.ToString(); damage_view_info.m_TextMesh.color = moji_color; if (damage_view_info.m_TextMesh != null) { damage_view_info.m_TextMesh.fontMaterial.SetColor("_UnderlayColor", moji_shadow_color); } damage_view_info.m_TextMesh.gameObject.GetComponent <RectTransform>().localScale = Vector3.one * (moji_scale * 0.05f * scale); const float WEAK_SPRITE_BASE_SCALE = 0.5f; damage_view_info.m_WeakSprite.transform.localScale = new Vector3(type_scale * WEAK_SPRITE_BASE_SCALE, type_scale * WEAK_SPRITE_BASE_SCALE, type_scale * WEAK_SPRITE_BASE_SCALE); damage_view_info.m_WeakSprite.sprite = weak_sprite; damage_view_info.m_InstanceObject.SetActive(true); damage_view_info.m_TextAnimation.Stop(); damage_view_info.m_TextAnimation.Play(anim_name); if (weak_sprite != null) { damage_view_info.m_SpriteAnimation.Stop(); if (weak_sprite == m_CriticalSprite) { damage_view_info.m_SpriteAnimation.Play(SPRITE_ANIM_NAME_CRITICAL); } else { damage_view_info.m_SpriteAnimation.Play(SPRITE_ANIM_NAME); } } } m_CurrentIndex = (m_CurrentIndex + 1) % m_DamageViewInfots.Length; m_IsShowing = true; }