Example #1
0
    private string GetKey(int id, string subfix = null)
    {
        string key;
        int    parentId;

        if (Application.isPlaying)
        {
            RedPointNode node = RedPointMgr.Inst.nodeDic[id];
            key      = node.key;
            parentId = node.parentId;
        }
        else
        {
            RedPointAssetCfg cfg = _nodeDic[id];
            key      = cfg.key;
            parentId = cfg.parentId;
        }
        if (string.IsNullOrEmpty(subfix))
        {
            subfix = key;
        }
        else
        {
            subfix = key + "." + subfix;
        }
        if (parentId == -1) //已经达到根节点了
        {
            return(subfix);
        }
        return(GetKey(parentId, subfix));
    }
Example #2
0
    private void OnEnable()
    {
        _index = 1;

        assetObj = (RedPointAsset)target;
        //根节点的id = 1, parentId = -1;
        assetObj.cfg.id       = 1;
        assetObj.cfg.parentId = -1;
        assetObj.cfg.key      = "Root";

        _nodeDic     = new Dictionary <int, RedPointAssetCfg>();
        _nodeViewDic = new Dictionary <int, RedPointAssetCfgViewItem>();
        _nodeDic.Add(1, assetObj.cfg);//添加根节点
        _nodeViewDic.Add(1, new RedPointAssetCfgViewItem(this, assetObj.cfg));
        for (int i = 0; i < assetObj.cfgList.Count; i++)
        {
            RedPointAssetCfg cfg = assetObj.cfgList[i];
            _nodeDic.Add(cfg.id, cfg);
            _nodeViewDic.Add(cfg.id, new RedPointAssetCfgViewItem(this, cfg));
            if (cfg.id > _index) //获取最大的索引值
            {
                _index = cfg.id;
            }
        }
    }
Example #3
0
    private void AddCfgItem(GenericMenu menu, RedPointAssetCfg cfg, string key)
    {
        string prefixKey    = key + "/";
        bool   addChildItem = false;

        for (int i = 0; i < cfg.childs.Count; i++)
        {
            RedPointAssetCfg childCfg = _nodeDic[cfg.childs[i]];
            menu.AddItem(new GUIContent(prefixKey + childCfg.key), false, OnSelectNode, childCfg.id);
            addChildItem = true;
        }
        //添加分割线
        if (addChildItem)
        {
            menu.AddSeparator(prefixKey);
        }
        //添加下一层
        for (int i = 0; i < cfg.childs.Count; i++)
        {
            RedPointAssetCfg childCfg = _nodeDic[cfg.childs[i]];
            if (childCfg.childs.Count > 0)
            {
                AddCfgItem(menu, childCfg, prefixKey + childCfg.key);
            }
        }
    }
Example #4
0
    private void AddNode()
    {
        RedPointAssetCfg newNode = _main.AddNodeCfg();

        newNode.parentId = _node.id; //记录父节点
        _node.childs.Add(newNode.id);
        _node.isShowChild = true;
    }
Example #5
0
    //删除节点
    public void RemoveNodeCfg(int id)
    {
        RedPointAssetCfg removeCfg = _nodeDic[id];

        _nodeDic.Remove(id);
        _nodeViewDic.Remove(id);
        for (int i = 0; i < removeCfg.childs.Count; i++)
        {
            RemoveNodeCfg(removeCfg.childs[i]);
        }
    }
Example #6
0
    //修改节点的父级
    private void ChangeNodeParent(int newParentId)
    {
        DelNodeFromParent();

        //直接修改ParentId
        _node.parentId = newParentId;
        //加入parentId所在node的child中
        RedPointAssetCfg cfg = _main.GetNodeCfg(newParentId);

        cfg.childs.Add(_node.id);
        cfg.isShowChild = true;
    }
Example #7
0
    private void DelNodeFromParent()
    {
        RedPointAssetCfg parentCfg = _main.GetNodeCfg(_node.parentId);

        for (int i = 0; i < parentCfg.childs.Count; i++)
        {
            int id = parentCfg.childs[i];
            if (_node.id == id)
            {
                parentCfg.childs.RemoveAt(i);
                break;
            }
        }
    }
Example #8
0
    //增加节点
    public RedPointAssetCfg AddNodeCfg()
    {
        _index++;
        RedPointAssetCfg cfg = new RedPointAssetCfg()
        {
            id  = _index,
            key = _index.ToString()
        };

        _nodeDic.Add(_index, cfg);
        _nodeViewDic.Add(_index, new RedPointAssetCfgViewItem(this, cfg));
        assetObj.cfgList.Add(cfg);
        return(cfg);
    }
Example #9
0
    public void ShowList()
    {
        //显示列表
        GenericMenu menu = new GenericMenu();

        menu.allowDuplicateNames = true;
        RedPointAssetCfg cfg = _assetObj.cfg;

        menu.AddItem(new GUIContent("Dynamic"), false, OnSelectNode, 0);
        menu.AddItem(new GUIContent(cfg.key), false, OnSelectNode, cfg.id);
        menu.AddSeparator("");
        AddCfgItem(menu, cfg, cfg.key);
        menu.ShowAsContext();
    }
Example #10
0
    public void ShowParentList(int expectId, GenericMenu.MenuFunction2 callBack)
    {
        //显示列表
        GenericMenu menu = new GenericMenu();

        menu.allowDuplicateNames = true;
        RedPointAssetCfg cfg = GetRootNodeCfg();

        //排除的节点的直接父节点也不显示
        if (GetNodeCfg(expectId).parentId != cfg.id)
        {
            menu.AddItem(new GUIContent(cfg.key), false, callBack, cfg.id);
            menu.AddSeparator("");
        }
        AddCfgItem(expectId, menu, cfg, cfg.key, callBack);
        menu.ShowAsContext();
    }
Example #11
0
    private void OnEnable()
    {
        _idProperty   = serializedObject.FindProperty("id");
        _typeProperty = serializedObject.FindProperty("type");
        _goProperty   = serializedObject.FindProperty("viewGo");
        _numProperty  = serializedObject.FindProperty("numTxt");

        if (!Application.isPlaying)
        {
            string path = "Assets/Data/RedPointCfg.asset";
            if (File.Exists(path))
            {
                _assetObj = AssetDatabase.LoadAssetAtPath <RedPointAsset>(path);
                _nodeDic  = new Dictionary <int, RedPointAssetCfg>();
                _nodeDic.Add(1, _assetObj.cfg);//添加根节点
                for (int i = 0; i < _assetObj.cfgList.Count; i++)
                {
                    RedPointAssetCfg cfg = _assetObj.cfgList[i];
                    _nodeDic.Add(cfg.id, cfg);
                }
                if (!_nodeDic.ContainsKey(_idProperty.intValue))
                {
                    _idProperty.intValue = 0;
                    _idProperty.serializedObject.ApplyModifiedProperties();
                    _key = "Dynamic";
                }
                else
                {
                    _key = GetKey(_idProperty.intValue);
                }
            }
            else
            {
                _assetObj            = null;
                _nodeDic             = null;
                _idProperty.intValue = 0;
                _idProperty.serializedObject.ApplyModifiedProperties();
                _key = "Dynamic";
            }
        }
        else //运行时,从RedPointMgr中获取数据
        {
            _key = GetKey(_idProperty.intValue);
        }
    }
Example #12
0
    private void AddCfgItem(int expectId, GenericMenu menu, RedPointAssetCfg cfg, string key, GenericMenu.MenuFunction2 callBack)
    {
        if (cfg.id == expectId)
        {
            return;                     //排除掉不显示的
        }
        RedPointAssetCfg expectCfg    = GetNodeCfg(expectId);
        string           prefixKey    = key + "/";
        bool             addChildItem = false;

        for (int i = 0; i < cfg.childs.Count; i++)
        {
            RedPointAssetCfg childCfg = GetNodeCfg(cfg.childs[i]);
            if (childCfg.id == expectId)
            {
                continue;                          //排除掉不显示的
            }
            if (expectCfg.parentId == childCfg.id)
            {
                continue;
            }
            menu.AddItem(new GUIContent(prefixKey + childCfg.key), false, callBack, childCfg.id);
            addChildItem = true;
        }
        //添加分割线
        if (addChildItem)
        {
            menu.AddSeparator(prefixKey);
        }
        //添加下一层
        for (int i = 0; i < cfg.childs.Count; i++)
        {
            RedPointAssetCfg childCfg = GetNodeCfg(cfg.childs[i]);
            if (childCfg.childs.Count > 0)
            {
                AddCfgItem(expectId, menu, childCfg, prefixKey + childCfg.key, callBack);
            }
        }
    }
Example #13
0
 public RedPointAssetCfgViewItem(RedPointAssetInspector main, RedPointAssetCfg node)
 {
     _main = main;
     _node = node;
 }
Example #14
0
    private void AddNode(RedPointAssetCfg cfg)
    {
        RedPointNode node = new RedPointNode(cfg);

        nodeDic.Add(cfg.id, node);
    }
Example #15
0
 public RedPointNode(RedPointAssetCfg cfg) : this(cfg.id, cfg.key, cfg.parentId)
 {
     this.childs.AddRange(cfg.childs);
 }