protected void ChangeParent(Transform newParent, Transform child, bool bKeepingLocalTransform, Transform addTransform) { // Keeping transform NcTransformTool_B trans = null; if (bKeepingLocalTransform) { trans = new NcTransformTool_B(child.transform); if (addTransform != null) { trans.AddTransform(addTransform); } } child.parent = newParent; if (bKeepingLocalTransform) { trans.CopyToLocalTransform(child.transform); } // Update component if (bKeepingLocalTransform) { // NcEffectBehaviour[] coms = gameObject.GetComponentsInChildren<NcEffectBehaviour>(); // foreach (NcEffectBehaviour com in coms) // com.SendMessage("Update", SendMessageOptions.DontRequireReceiver); NcBillboard_B[] ncBills = gameObject.GetComponentsInChildren <NcBillboard_B>(); foreach (NcBillboard_B ncb in ncBills) { ncb.UpdateBillboard(); } } }
// Loop Function -------------------------------------------------------------------- void Update() { if (m_bStartDetach == false) { m_bStartDetach = true; if (transform.parent != null) { m_ParentGameObject = transform.parent.gameObject; NcDetachObject_B.Create(m_ParentGameObject, transform.gameObject); } // Detach Parent GameObject parentObj = GetRootInstanceEffect(); if (m_bFollowParentTransform) { m_OriginalPos.SetLocalTransform(transform); ChangeParent(parentObj.transform, transform, false, null); m_OriginalPos.CopyToLocalTransform(transform); } else { ChangeParent(parentObj.transform, transform, false, null); } if (m_bParentHideToStartDestroy == false) { StartDestroy(); } } // Live time if (0 < m_fStartDestroyTime) { if (0 < m_fSmoothDestroyTime) { if (m_bSmoothHide) { float fRate = 1 - ((GetEngineTime() - m_fStartDestroyTime) / m_fSmoothDestroyTime); if (fRate < 0) { fRate = 0; } // Recursively Renderer[] rens = transform.GetComponentsInChildren <Renderer>(true); for (int n = 0; n < rens.Length; n++) { Renderer ren = rens[n]; string colName = GetMaterialColorName(ren.material); if (colName != null) { Color col = ren.material.GetColor(colName); col.a = Mathf.Min(fRate, col.a); ren.material.SetColor(colName, col); } } } if (m_fStartDestroyTime + m_fSmoothDestroyTime < GetEngineTime()) { Object.Destroy(gameObject); } } } else { if (m_bParentHideToStartDestroy) { if (m_ParentGameObject == null || IsActive(m_ParentGameObject) == false) { StartDestroy(); } } } // follow parent transform if (m_bFollowParentTransform && m_ParentGameObject != null && m_ParentGameObject.transform != null) { NcTransformTool_B tmp = new NcTransformTool_B(); tmp.SetTransform(m_OriginalPos); tmp.AddTransform(m_ParentGameObject.transform); tmp.CopyToLocalTransform(transform); } }