コード例 #1
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);
        }
コード例 #2
0
        public static void ChangEffectLevel(int level)
        {
            if (Selection.transforms.Length > 0)
            {
                Transform[] GOs = Selection.transforms;
                foreach (var GO in GOs)
                {
                    //需要递归往上做检查
                    Transform targetNode;
                    int       minLv = level;

                    Transform father = GO.transform.parent;
                    while (father != null)
                    {
                        int fatherLv = EffectLevelUtil.GetEffectLevel(father.gameObject);
                        fatherLv   = fatherLv == -1 ? 1 : fatherLv;
                        targetNode = father;
                        if (fatherLv <= minLv)
                        {
                            minLv = fatherLv;
                        }
                        else
                        {
                            EditorGUIUtility.PingObject(targetNode); //跳转定位
                            EditorUtility.DisplayDialog("警告", string.Format("父节点({0})存在级别较小的,所以这里只能大于{1}级别", targetNode.name, fatherLv), "好的");
                            return;
                        }
                        father = father.parent;
                    }

                    //往下查找-必须让子节点最小的那个大于要设置的
                    targetNode = null;
                    minLv      = level;
                    foreach (var child in GO.GetComponentsInChildren <Transform>(true))
                    {
                        if (child == GO)
                        {
                            continue;
                        }
                        int childLv = EffectLevelUtil.GetEffectLevel(child.gameObject);
                        childLv = childLv == -1 ? level : childLv;

                        if (childLv <= minLv)
                        {
                            minLv      = childLv;
                            targetNode = child;
                        }
                    }
                    if (level > minLv)
                    {
                        EditorGUIUtility.PingObject(targetNode); //跳转定位
                        EditorUtility.DisplayDialog("警告", string.Format("子节点({0})存在级别较大的,所以这里只能小于或等于{1}级别", targetNode.name, minLv), "好的");
                        return;
                    }

                    EffectLevelUtil.SetEffectLevel(GO.gameObject, level);
                    EditorUtility.SetDirty(GO);
                    AssetDatabase.SaveAssets();
                }
            }
            else
            {
                Debug.LogWarning("请选择一个节点");
            }
        }