Exemple #1
0
        //将特效节点打包回ModelEffect
        public ModelEffect Package()
        {
            ModelEffect modelEffect = null;

            if (m_curModelEffect == null)//这种方式,长度,级别基本都丢失了
            {
                if (m_effectNodes == null)
                {
                    return(null);
                }

                string     modfxName  = string.Format("{0}_modfx", gameObject.name);
                GameObject fxInstance = new GameObject(modfxName);

                modelEffect           = fxInstance.AddComponent <ModelEffect>();
                modelEffect.nodeInfos = new List <ModelEffect.NodeInfo>();

                foreach (var effectGo in m_effectNodes)
                {
                    if (effectGo != null)
                    {
                        var metadate = new ModelEffect.NodeInfo();

                        var nodePath = XGameObjectTools.GetPathByGameObject(effectGo, gameObject);
                        metadate.nodePath   = nodePath;
                        metadate.nodeEffect = effectGo;

                        modelEffect.nodeInfos.Add(metadate);

                        effectGo.transform.SetParent(fxInstance.transform, false);
                    }
                }

                m_effectNodes.Clear();
            }
            else
            {
                modelEffect = m_curModelEffect;
                if (modelEffect.nodeInfos != null)
                {
                    foreach (var nodePair in modelEffect.nodeInfos)
                    {
                        var nodeEffect = nodePair.nodeEffect;
                        if (nodeEffect != null)
                        {
                            nodeEffect.transform.SetParent(modelEffect.gameObject.transform, false);
                        }
                    }
                }
                m_curModelEffect = null;
            }

            return(modelEffect);
        }
Exemple #2
0
        //处理一个
        public static bool RidGameObjectByLv(GameObject newGO, int ridLv)
        {
            if (newGO)
            {
                if (ridLv > 0 && ridLv <= EffectLevelUtil.MAX_LEVEL)
                {
                    var levelCtrl = newGO.GetComponent <EffectLevelController>();
                    if (!levelCtrl)
                    {
                        levelCtrl = newGO.AddComponent <EffectLevelController>();
                    }
                    levelCtrl.level    = ridLv;
                    levelCtrl.nodeList = (levelCtrl.nodeList != null) ? levelCtrl.nodeList : new List <EffectLevelController.NodeInfo>();
                    levelCtrl.nodeList.Clear();

                    foreach (var node in newGO.GetComponentsInChildren <Transform>(true))
                    {
                        int nodeLv = EffectLevelUtil.GetEffectLevel(node.gameObject);
                        if (nodeLv != -1)
                        {
                            if (nodeLv > ridLv)
                            {
                                if (newGO == node.gameObject)
                                {
                                    continue;
                                }
                                Object.DestroyImmediate(node.gameObject);
                            }
                            else
                            {
                                var info = new EffectLevelController.NodeInfo();
                                info.node  = node.gameObject;
                                info.path  = XGameObjectTools.GetPathByGameObject(node.gameObject, newGO);
                                info.level = nodeLv;

                                levelCtrl.nodeList.Add(info);
                            }
                        }
                    }
                    levelCtrl.SortList();

                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
 public void SortList()
 {
     //保证顺序是从小到大,由浅到深
     if (nodeList != null)
     {
         nodeList.Sort(delegate(NodeInfo a, NodeInfo b)
         {
             if (a.node && b.node)
             {
                 if (a.level == b.level)
                 {
                     string aPath = XGameObjectTools.GetPathByGameObject(a.node, gameObject);
                     string bPath = XGameObjectTools.GetPathByGameObject(b.node, gameObject);
                     return(string.Compare(aPath, bPath));
                 }
             }
             return(a.level - b.level);
         });
     }
 }
Exemple #4
0
        public void RefreshInfo()
        {
            nodeList = nodeList ?? new List <NodeInfo>();
            nodeList.Clear();

            var levelNodes = GetComponentsInChildren <EffectLevelNode>(true);

            foreach (var lvNode in levelNodes)
            {
                var nodeGo     = lvNode.gameObject;
                var nodeGoPath = XGameObjectTools.GetPathByGameObject(nodeGo, gameObject);

                var nodeInfo = new NodeInfo();
                nodeInfo.level = lvNode.level;
                nodeInfo.node  = nodeGo;
                nodeInfo.path  = nodeGoPath;

                nodeList.Add(nodeInfo);
            }

            SortList();
        }
Exemple #5
0
        public void Upgrade(int lv, GameObject prefab)
        {
            lv = FixLevel(lv);

            if (lv == level)
            {
                return;
            }

            if (prefab == null)
            {
                return;
            }

            var ctrl = prefab.GetComponent <EffectLevelController>();

            if (ctrl == null)
            {
                return;
            }

            if (ctrl.nodeList == null)
            {
                return;
            }

            nodeList = (nodeList != null) ? nodeList : new List <NodeInfo>();
            foreach (var fxInfo in ctrl.nodeList)
            {
                var fxNode = fxInfo.node;
                if (fxNode == null)
                {
                    continue;
                }

                var fxNodePath = fxInfo.path;
                if (string.IsNullOrEmpty(fxNodePath))
                {
                    fxNodePath = XGameObjectTools.GetPathByGameObject(fxInfo.node, prefab);
                }

                var newNode = XGameObjectTools.GetGameObjectByPath(gameObject, fxNodePath);
                if (newNode != null)
                {
                    newNode.SetActive(true);
                }
                else
                {
                    string fxNodeParentPath = Path.GetDirectoryName(fxNodePath);
                    var    newNodeParent    = XGameObjectTools.GetGameObjectByPath(gameObject, fxNodePath);
                    if (newNodeParent != null)
                    {
                        var fxLevel = fxInfo.level;
                        newNode = Instantiate(fxNode, newNodeParent.transform, false);
                        var newInfo = new NodeInfo();
                        newInfo.node  = newNode;
                        newInfo.path  = Path.Combine(fxNodeParentPath, newNode.name);
                        newInfo.level = fxLevel;

                        nodeList.Add(newInfo);
                    }
                }
            }

            level = lv;
        }
Exemple #6
0
        public static void Make(GameObject modelWithEffect, GameObject modfxContainer)
        {
            if (modelWithEffect == null || modfxContainer == null)
            {
                return;
            }

            //搜集所有含NodeMark或名字是_modfx的节点

            Stack <GameObject> parentNodes = new Stack <GameObject>();

            parentNodes.Push(modelWithEffect);

            var nodeList = new List <GameObject>();

            while (parentNodes.Count > 0)
            {
                var curNode = parentNodes.Pop();
                for (int i = 0; i < curNode.transform.childCount; i++)
                {
                    var itNode = curNode.transform.GetChild(i).gameObject;
                    if (curNode == itNode)
                    {
                        continue;
                    }

                    var nodeMark = itNode.GetComponent <NodeMark>();
                    var nodeName = itNode.name;
                    if (nodeMark != null || nodeName.Contains(MODFX_NAME))
                    {
                        nodeList.Add(itNode);

                        continue;
                    }
                    parentNodes.Push(itNode);
                }
            }

            //
            Dictionary <GameObject, GameObject> nodeMap = new Dictionary <GameObject, GameObject>();
            var modfxComp = modfxContainer.GetComponent <ModelEffect>() ?? modfxContainer.AddComponent <ModelEffect>();

            modfxComp.nodeInfos = modfxComp.nodeInfos ?? new List <NodeInfo>();
            modfxComp.nodeInfos.Clear();

            foreach (var node in nodeList)
            {
                var nodeInfo = new NodeInfo();

                GameObject nodeEffect = Object.Instantiate(node, modfxContainer.transform, false);
                nodeMap[node] = nodeEffect; // 引用映射

                nodeEffect.name = nodeEffect.name.Replace("(Clone)", "");
                string nodePath = XGameObjectTools.GetPathByGameObject(node);

                nodeInfo.nodeEffect = nodeEffect;
                nodeInfo.nodePath   = nodePath;

                modfxComp.nodeInfos.Add(nodeInfo);
            }
            modfxContainer.name = modelWithEffect.name;

            //
            //尝试修复自定义节点的引用
            var particleSystems = modfxContainer.GetComponentsInChildren <ParticleSystem>();

            if (particleSystems != null && particleSystems.Length > 0)
            {
                foreach (var particleSystem in particleSystems)
                {
                    ParticleSystem.MainModule main = particleSystem.main;
                    if (main.simulationSpace == ParticleSystemSimulationSpace.Custom)
                    {
                        var        oldRefGo = main.customSimulationSpace;
                        GameObject newRefGo = null;
                        if (oldRefGo != null)
                        {
                            if (nodeMap.TryGetValue(oldRefGo.gameObject, out newRefGo))
                            {
                                if (newRefGo != null)
                                {
                                    var newTrans = newRefGo.transform;
                                    main.customSimulationSpace = newTrans;
                                }
                            }
                        }
                    }
                }
            }
        }