private void GenerateRandomBlock() { MapModel mapModel = MapModel.Inst; GComponent mapBlock = mapModel.GetCurrentBlockCom(); AddChildAt(mapBlock, 1); //要在TopFrame下面 //根据数据初始化不同的地图块 foreach (var child in mapBlock.GetChildren()) { MapNodeCom childNode = child as MapNodeCom; if (childNode == null) { continue; } string strIndex = childNode.name.Replace("node", ""); MapNodeBase nodeData = mapModel.GetCurrentLayerMapNodeData(strIndex); if (nodeData == null) { Debug.LogError("no node data:" + strIndex); continue; } childNode.SetNodeData(nodeData); childNode.onClick.Add(OnNodeClick); _dicNodeCom.Add(strIndex, childNode); } }
//更新可进入的节点 private void UpdateCanEnterNode() { MapNodeBase lastEnterNode = MapModel.Inst.enterNode; List <int> lstCanEnterIndex; if (lastEnterNode == null) //如果还没有进入过节点 { lstCanEnterIndex = new List <int>() { 1 } } ; else { lstCanEnterIndex = GetNextCanEnterIndexList(lastEnterNode.nodeIndex); } SetAllNodeNotEnter(); foreach (int canEnterIndex in lstCanEnterIndex) { MapNodeCom nodeCom = GetNodeCom(canEnterIndex); if (nodeCom == null) { Debug.LogError("can't find note:" + canEnterIndex); continue; } nodeCom.SetCanEnter(true); } }
//根据节点类型创建不同的显示对象 private IMapNode CreateNodeCom(MapNodeBase node) { if (node is NormalEnemyNode) { return(EnemyCom.CreateInstance()); } Debug.LogError("unhandle node:" + node.GetType()); return(null); }
//初始化地图列表 private void InitBlock() { //init model _lstBlockType = new List <Type> { typeof(MapBlock1), typeof(MapBlock2) }; _leftBoxNum = 6; _leftShopNum = 6; _leftElitNum = 12; lstOfLstBlockRoad.Clear(); //生成具体数据 _lstBlockCom = new List <GComponent>(); for (int i = 0; i < BLOCK_NUM; i++) { //生成block组件 int index = UnityEngine.Random.Range(0, _lstBlockType.Count); Type typeBlock = _lstBlockType[index]; var method = typeBlock.GetMethod("CreateInstance", BindingFlags.Public | BindingFlags.Static); GComponent mapBlock = method.Invoke(null, null) as GComponent; _lstBlockCom.Add(mapBlock); //生成可行走的节点的类型 string data = mapBlock.packageItem.componentData.GetAttribute("customData"); string[] lstRoad = data.Split('\r'); foreach (string strRoad in lstRoad) { string[] lstPointIndex = strRoad.Split(','); int roadCount = lstPointIndex.Length; List <int> lstBlockRoad = new List <int>(); for (int blockStep = 0; blockStep < roadCount; blockStep++) { string strPointIndex = lstPointIndex[blockStep]; string nodeKey = GetNodeKey(i, strPointIndex); if (_dicMapNode.ContainsKey(nodeKey)) { continue; } int step = i * STEP_PER_BLOCK + blockStep + 1; int nodeIndex; int.TryParse(strPointIndex, out nodeIndex); lstBlockRoad.Add(nodeIndex); MapNodeBase nodeBase = GetRandomNode(step, nodeIndex); _dicMapNode.Add(nodeKey, nodeBase); } lstOfLstBlockRoad.Add(lstBlockRoad); } } }
public void SetNode(MapNodeBase mapNode) { _enemyNode = mapNode as NormalEnemyNode; }
private bool _canEnter; //节点是否可以进入 internal void SetNodeData(MapNodeBase nodeData) { this.nodeData = nodeData; InitView(); }
/// <summary> /// 设置进入的节点 /// </summary> /// <param name="enterNode"></param> internal void SetEnterNode(MapNodeBase enterNode) { this.enterNode = enterNode; SendEvent(MapEvent.ENTER_NODE_UPDATE); }