Exemple #1
0
        public void Attach(GameObject targetObj, bool isUseFullPath = true, bool isSetLayer = false)
        {
            if (targetObj == this)
            {
                return;
            }

            if (m_targetObj != null)
            {
                Deattach();
            }

            if (nodeInfos != null)
            {
                foreach (var nodeInfo in nodeInfos)
                {
                    var nodeEffect = nodeInfo.nodeEffect;
                    if (nodeEffect != null)
                    {
                        string nodeParentPath = Path.GetDirectoryName(nodeInfo.nodePath);
                        nodeParentPath = isUseFullPath ? nodeParentPath : Path.GetFileName(nodeParentPath);

                        Transform targetParentTrans = targetObj.transform.Find(nodeParentPath);
                        if (targetParentTrans != null)
                        {
                            m_trgetEffects = m_trgetEffects ?? new List <GameObject>();
                            nodeEffect.transform.SetParent(targetParentTrans, false);
                            nodeEffect.SetActive(true);

                            m_trgetEffects.Add(nodeEffect);

                            if (isSetLayer)
                            {
                                XGameObjectTools.SetLayer(nodeEffect, gameObject);
                            }
                        }
                        else
                        {
                            nodeEffect.SetActive(false);
                        }
                    }
                }
                m_targetObj = targetObj;
            }
        }
Exemple #2
0
        //解包
        public bool Unpackage(ModelEffect modelEffect, bool isUseFullPath = true, bool isSetLayer = false)
        {
            if (modelEffect == null)
            {
                return(false);
            }

            Unsetup();
            foreach (var nodeInfo in modelEffect.nodeInfos)
            {
                var newEffectGO = nodeInfo.nodeEffect;
                if (newEffectGO != null)
                {
                    string nodeParentPath = Path.GetDirectoryName(nodeInfo.nodePath);
                    nodeParentPath = isUseFullPath ? nodeParentPath : Path.GetFileName(nodeParentPath);

                    var parentNode = gameObject.transform.Find(nodeParentPath);
                    if (parentNode != null)
                    {
                        newEffectGO.transform.SetParent(parentNode.transform, false);
                        newEffectGO.name = newEffectGO.name.Replace("(Clone)", "");
                        newEffectGO.SetActive(true);

                        m_effectNodes = m_effectNodes ?? new List <GameObject>();
                        m_effectNodes.Add(newEffectGO);

                        if (isSetLayer)
                        {
                            XGameObjectTools.SetLayer(newEffectGO, gameObject);
                        }
                    }
                    else
                    {
                        newEffectGO.SetActive(false);
                    }
                }
            }

            modelEffect.transform.SetParent(transform.parent, false);
            m_curModelEffect = modelEffect;

            return(true);
        }
Exemple #3
0
        public bool Setup(ModelEffect modfx, bool isUseFullPath = true, bool isSetLayer = true)
        {
            if (modfx == null)
            {
                return(false);
            }

            if (modfx.nodeInfos == null)
            {
                return(false);
            }

            Unsetup();
            foreach (var nodeInfo in modfx.nodeInfos)
            {
                string nodeParentPath = Path.GetDirectoryName(nodeInfo.nodePath);
                nodeParentPath = isUseFullPath ? nodeParentPath : Path.GetFileName(nodeParentPath);

                Transform targetParentTrans = gameObject.transform.Find(nodeParentPath);
                if (targetParentTrans != null)
                {
                    var nodeEffect = Object.Instantiate(nodeInfo.nodeEffect, targetParentTrans, false);
                    nodeEffect.name = nodeEffect.name.Replace("(Clone)", "");

                    m_effectNodes = m_effectNodes ?? new List <GameObject>();
                    m_effectNodes.Add(nodeEffect);

                    if (isSetLayer)
                    {
                        XGameObjectTools.SetLayer(nodeEffect, gameObject);
                    }
                }
            }
            key         = modfx.name;
            m_isSetuped = true;
            return(true);
        }