示例#1
0
    // Property -------------------------------------------------------------------------
    public static void Create(GameObject parentObj, GameObject linkObject)
    {
        NcDetachObject_B deObj = parentObj.AddComponent <NcDetachObject_B>();

        deObj.m_LinkGameObject = linkObject;
    }
示例#2
0
    // 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);
        }
    }