コード例 #1
0
ファイル: NpcEditHelper.cs プロジェクト: dongpeng1988/xlj
    public void AddDoor(MapDoor node)
    {
        int id = 1;

        while (doorCollection.ContainsKey(id))
        {
            id++;
        }
        node.id = id;
        addMapDoor(node, OPERATE_ADD);
        Vector3 npcPos = new Vector3(0, 0, 0);

        GameObject obj = npcHelper.AddDoor(node, npcPos);

        if (obj == null)
        {
            return;
        }
        EditorTool.CenterObj(obj);
        if (EditorData.terrainMan != null)
        {
            Vector3 pos = obj.transform.localPosition;
            pos.y = EditorData.terrainMan.GetHeight(pos.x, pos.z);
            obj.transform.localPosition = pos;
            IntPoint pt = PathUtilEdit.Real2Logic(pos);
            node.x = pt.x;
            node.y = pt.y;

            //EditorTool.LookObj(obj);
        }
        node.target = obj;
    }
コード例 #2
0
    void Update()
    {
        if (!usrState)
        {
            transform.position = new Vector3(0, 0, -100);
            return;
        }

        MapDoor mapDoor = usrState.GetDoor();

        if (mapDoor)
        {
            if (usrState.currentDir.x == -1 && usrState.nearDoor == UsrState.LEFT_DIR ||
                usrState.currentDir.x == 1 && usrState.nearDoor == UsrState.RIGHT_DIR)
            {
                transform.position = (Vector2)mapDoor.transform.position
                                     + (mapDoor.dashDistance - mapDoor.boxCollider2D.size.x - usrState.startColliderSize.x)
                                     * usrState.currentDir;
            }
        }
        else
        {
            transform.position = new Vector3(0, 0, -100);
        }
    }
コード例 #3
0
    private void DashOnEnd()
    {
        MapDoor mapDoor = GetComponent <UsrControl>().dashTarget;

        if (mapDoor == null || Mathf.Abs(transform.position.y - mapDoor.transform.position.y) > state.doorDistance)//y轴再次确认
        {
            DashFail();
            return;
        }
        Vector2    colliderPos    = new Vector2(transform.position.x, transform.position.y) + state.boxCollider2D.offset;
        Vector2    endColliderPos = colliderPos + state.currentDir * mapDoor.dashDistance - new Vector2(0, -0.1f);
        Collider2D hit            = Physics2D.OverlapBox(endColliderPos, state.boxCollider2D.size, 0,
                                                         1 << LayerMask.NameToLayer("solid") | 1 << LayerMask.NameToLayer("wall") | 1 << LayerMask.NameToLayer("door"));

        if (hit == null || hit.GetComponent <PlatformEffector2D>())  //瞬移目标位置无碰撞
        {
            mapDoor.SetDash(state);

            Transform tempTarget = transform.Find("Camera Target");
            tempTarget.parent        = mapDoor.transform;
            tempTarget.localPosition = state.startCameraTargetLocalPos;
        }
        else
        {
            state.SafeRealseDoor(mapDoor);
            mapDoor.DisAppear();
            DashFail();
        }
        state.isOnMove = false;
    }
コード例 #4
0
        /*********
        ** Public methods
        *********/

        /// <summary>Construct an instance.</summary>
        /// <param name="position">The position the door is at.</param>
        /// <param name="property">Parsed door info.</param>
        /// <param name="map">The map the door will modify.</param>
        /// <param name="extras">Parsed door extras.</param>
        /// <param name="callbackTimer">Timer for animations.</param>
        public PendingDoor(Point position, MapDoor property, Map map, MapDoorExtras extras, CallbackTimer callbackTimer)
        {
            this.map           = map;
            this.Position      = position;
            this.Property      = property;
            this.extras        = extras;
            this.callbackTimer = callbackTimer;
        }
コード例 #5
0
 public void SafeRealseDoor(MapDoor md)
 {
     if (nearDoorL.Contains(md))
     {
         nearDoorL.Remove(md);
     }
     else if (nearDoorR.Contains(md))
     {
         nearDoorR.Remove(md);
     }
     nearDoor = 0;
 }
コード例 #6
0
ファイル: NpcEditHelper.cs プロジェクト: dongpeng1988/xlj
    private void initMapDoor()
    {
        foreach (KeyValuePair <int, MapDoor> kp in doorCollection)
        {
            MapDoor door = kp.Value;
            Vector2 pos  = PathUtilEdit.logicCenter2Real(door.x, door.y);


            float   h1     = EditorData.terrainMan.GetHeight(pos.x, pos.y);
            Vector3 npcPos = new Vector3(pos.x, h1, pos.y);
            npcHelper.AddDoor(door, npcPos);
        }
    }
コード例 #7
0
ファイル: MapNpcHelper.cs プロジェクト: dongpeng1988/xlj
    public GameObject AddDoor(MapDoor door, Vector3 pos)
    {
        Object prefab = EditorTool.LoadAssetBundle("model/sence_chuansong.unity3d");

        if (prefab == null)
        {
            Debug.LogError("阻挡门 资源找不到:model/sence_chuansong.unity3d");

            return(null);
        }

        string    subpath     = "door";
        Transform parentTrans = getRoot().FindChild(subpath);

        if (parentTrans == null)
        {
            GameObject subroot = new GameObject(subpath);
            subroot.transform.SetParent(getRoot());
            parentTrans = subroot.transform;
        }
        string nodeName = "door_" + door.id;



        GameObject npcObj = (GameObject)GameObject.Instantiate(prefab);

        npcObj.name = nodeName;


        npcObj.transform.SetParent(parentTrans);
        npcObj.transform.localPosition = pos;
        if (door.eulerangles != null)
        {
            string[] arr = door.eulerangles.Split(',');
            if (arr.Length == 3)
            {
                //npcObj.transform.Rotate(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2]));
                npcObj.transform.localRotation = Quaternion.Euler(float.Parse(arr[0]), float.Parse(arr[1]), float.Parse(arr[2]));
            }
        }

        MapDoorView view = npcObj.AddComponent <MapDoorView>();

        view.data = door;
        foreach (ParticleSystem ps in npcObj.GetComponentsInChildren <ParticleSystem>())
        {
            ps.Play(true);
        }
        door.target = npcObj;
        return(npcObj);
    }
コード例 #8
0
    public void ClimbingDash()
    {
        if (!state.currentAni.IsName("climbing"))
        {
            return;
        }

        if (state.nearWall == UsrState.LEFT_DIR)
        {
            state.currentDir = new Vector2(1, 0);
        }
        if (state.nearWall == UsrState.RIGHT_DIR)
        {
            state.currentDir = new Vector2(-1, 0);
        }

        if (!Create())
        {
            if (state.nearWall == UsrState.LEFT_DIR)
            {
                state.currentDir = new Vector2(-1, 0);
            }
            if (state.nearWall == UsrState.RIGHT_DIR)
            {
                state.currentDir = new Vector2(1, 0);
            }
            return;
        }

        dashTarget = myCreate;
        if (Mathf.Abs(transform.position.y - dashTarget.transform.position.y) <= state.doorDistance)
        {
            myCreate.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static;
            ChangeControlMode(ControlMode.COMMON);
            state.animator.SetBool("isDash", true);
            state.rigidbody2D.bodyType = RigidbodyType2D.Static;
        }
        else
        {
            if (state.nearWall == UsrState.LEFT_DIR)
            {
                state.currentDir = new Vector2(-1, 0);
            }
            if (state.nearWall == UsrState.RIGHT_DIR)
            {
                state.currentDir = new Vector2(1, 0);
            }
        }
    }
コード例 #9
0
ファイル: NpcEditHelper.cs プロジェクト: dongpeng1988/xlj
 public void addMapDoor(MapDoor door, int addOrDelete = OPERATE_ADD)
 {
     if (doorCollection.ContainsKey(door.id) && addOrDelete == OPERATE_ADD)
     {
         Debug.Log("这个阻挡门已经被添加过了");
     }
     else if (doorCollection.ContainsKey(door.id) && addOrDelete == OPERATE_DELETE)
     {
         doorCollection.Remove(door.id);
     }
     else if (!doorCollection.ContainsKey(door.id) && addOrDelete == OPERATE_ADD)
     {
         doorCollection[door.id] = door;
     }
 }
コード例 #10
0
    private void Start()
    {
        parent      = gameObject.GetComponentInParent <Keypad>();
        originalMat = gameObject.GetComponent <MeshRenderer>().material;

        if (doorRelation != null)
        {
            likedDoor    = doorRelation.GetComponent <MapDoor>();
            doorAnimator = doorRelation.GetComponent <Animator>();
        }

        if (!validate)
        {
            support = transform.GetChild(0).gameObject;
        }
    }
コード例 #11
0
    public void Dash()
    {
        if (!state.animator.GetBool("isDash") && state.nearDoor != 0 && state.isOnMove &&
            (state.currentAni.IsName("run") || state.currentAni.IsName("rise") || state.currentAni.IsName("fall")))
        {
            //
            dashTarget = state.GetDoor();
            if (dashTarget == null || !dashTarget.IsEnable())
            {
                return;
            }

            if (Mathf.Abs(transform.position.y - dashTarget.transform.position.y) <= state.doorDistance)  //y轴对齐
            {
                state.animator.SetBool("isDash", true);
                state.rigidbody2D.bodyType = RigidbodyType2D.Static;
            }
        }
    }
コード例 #12
0
    public bool Create()
    {
        if (myCreate != null)  //回收
        {
            state.SafeRealseDoor(myCreate);
            myCreate.DisAppear();
            return(false);
        }

        if (state.goldenKeyTime <= 0 && state.greenKey <= 0)  //钥匙不足
        {
            GetComponent <UsrAniCallBack>().ErrorSound();
            return(false);
        }

        Vector2    colliderPos    = new Vector2(transform.position.x, transform.position.y) + state.boxCollider2D.offset;
        Vector2    endColliderPos = colliderPos + state.currentDir * state.createDistance - new Vector2(0, -0.1f);
        Collider2D hit            = Physics2D.OverlapBox(endColliderPos, state.boxCollider2D.size, 0,
                                                         1 << LayerMask.NameToLayer("solid") | 1 << LayerMask.NameToLayer("wall") | 1 << LayerMask.NameToLayer("door"));

        if (hit != null && !hit.GetComponent <PlatformEffector2D>())
        {
            GetComponent <UsrAniCallBack>().ErrorSound();
            return(false);
        }
        GameObject temp = Instantiate(pbDoor, (Vector2)transform.position + state.currentDir * state.createDistance, Quaternion.identity);

        temp.transform.parent = GameObject.Find("MapManager").transform;
        myCreate = temp.GetComponent <MapDoor>();
        myCreate.SetColorA(0);
        if (state.goldenKeyTime > 0)
        {
            myCreate.reCollectable = false;
        }
        else
        {
            myCreate.reCollectable = true;
            state.UseGreenKey();
        }
        return(true);
    }
コード例 #13
0
        /// <summary>Finds every door in a map.</summary>
        /// <param name="map">The map to look in.</param>
        /// <param name="pendingDoors">The doors that were found.</param>
        /// <returns>Whether any doors were found.</returns>
        public bool FindDoorsInLocation(Map map, out IList <PendingDoor> pendingDoors)
        {
            pendingDoors = new List <PendingDoor>();

            Layer backLayer = map?.GetLayer("Back");

            if (backLayer == null)
            {
                return(false);
            }

            // Search for doors in the provided location.
            bool foundDoors = false;

            for (int x = 0; x < backLayer.LayerWidth; x++)
            {
                for (int y = 0; y < backLayer.LayerHeight; y++)
                {
                    Tile tile = backLayer.Tiles[x, y];

                    if (tile == null)
                    {
                        continue;
                    }

                    // If there's no version property log an error if other properties are present.
                    if (!tile.Properties.TryGetValue(MapDoorVersion.PropertyKey, out PropertyValue doorVersionValue))
                    {
                        if (tile.Properties.ContainsKey(MapDoor.PropertyKey) || tile.Properties.ContainsKey(MapDoorExtras.PropertyKey))
                        {
                            this.errorQueue.AddError($"The door at ({x},{y}) is malformed. Info: Missing a {MapDoorVersion.PropertyKey} property.");
                        }

                        continue;
                    }

                    // Log an error if the version is invalid.
                    if (!MapDoorVersion.TryParseString(doorVersionValue.ToString(), out string error, out MapDoorVersion version))
                    {
                        this.errorQueue.AddError($"The {MapDoorVersion.PropertyKey} property at ({x},{y}) is malformed. Info: {error}.");
                        continue;
                    }

                    if (version.PropertyVersion.IsNewerThan(this.modVersion))
                    {
                        this.errorQueue.AddError($"The door at ({x},{y}) is too new to be loaded ({version.PropertyVersion}). Please update Better Doors! ");
                        continue;
                    }

                    // Log an error if the door property is missing.
                    if (!tile.Properties.TryGetValue(MapDoor.PropertyKey, out PropertyValue doorValue))
                    {
                        this.errorQueue.AddError($"The door at ({x},{y}) is malformed. Info: No {MapDoor.PropertyKey} property was found.");
                        continue;
                    }

                    // Log an error if the door property is invalid.
                    if (!MapDoor.TryParseString(doorValue.ToString(), version.PropertyVersion, out error, out MapDoor property))
                    {
                        this.errorQueue.AddError($"The {MapDoor.PropertyKey} property at ({x},{y}) is malformed. Info: {error}.");
                        continue;
                    }

                    // Log an error if the door extras property is present but invalid.
                    MapDoorExtras extras = new MapDoorExtras();
                    if (tile.Properties.TryGetValue(MapDoorExtras.PropertyKey, out PropertyValue doorExtraValue) && !MapDoorExtras.TryParseString(doorExtraValue.ToString(), version.PropertyVersion, out error, out extras))
                    {
                        this.errorQueue.AddError($"The {MapDoorExtras.PropertyKey} property at ({x},{y}) is malformed. Info: {error}.");
                        continue;
                    }

                    // Log an error for invalid door and extras property combinations.
                    if (property.Orientation == Orientation.Horizontal && extras.IsDoubleDoor)
                    {
                        this.errorQueue.AddError($"The door at ({x},{y}) is invalid. Info: Horizontal doors can't be double doors.");
                        continue;
                    }

                    foundDoors = true;

                    // Record sprite request.
                    this.doorTileInfoManager.RegisterDoorRequest(property.ModId, property.DoorName, property.Orientation, property.OpeningDirection);

                    // Mark door as pending.
                    pendingDoors.Add(new PendingDoor(new Point(x, y), property, map, extras, this.timer));
                }
            }

            this.errorQueue.PrintErrors("Found some errors when parsing doors from maps:");

            return(foundDoors);
        }
コード例 #14
0
ファイル: NpcEditHelper.cs プロジェクト: dongpeng1988/xlj
    public void saveMapXML()
    {
        XmlDocument    xmlDocs = new XmlDocument();
        string         xmlPath = EditorConfig.ExcelDataDir + "../地图数据文件/xianwang/map/" + mapXmlId + ".xml";
        XmlDeclaration dec     = xmlDocs.CreateXmlDeclaration("1.0", "UTF-8", null);
        XmlElement     root    = xmlDocs.CreateElement("HLMapConfig");

        xmlDocs.AppendChild(root);
        root.SetAttribute("resourceid", EditorData.mapTileId);
        root.SetAttribute("mapid", EditorData.mapId);
        Dictionary <int, string> row_region = new Dictionary <int, string>();

        foreach (KeyValuePair <string, MapNpc> kp_npc in npcCollection)
        {
            MapNpc npcNode = kp_npc.Value;
            if (npcNode.target == null)
            {
                continue;
            }
            XmlElement ele_npc = xmlDocs.CreateElement("npc");
            ele_npc.SetAttribute("id", npcNode.id.ToString());
            ele_npc.SetAttribute("type", npcNode.type.ToString());
            ele_npc.SetAttribute("x", npcNode.x.ToString());
            ele_npc.SetAttribute("y", npcNode.y.ToString());
            ele_npc.SetAttribute("direction", npcNode.direction.ToString());
            ele_npc.SetAttribute("level", npcNode.level.ToString());
            ele_npc.SetAttribute("scope", npcNode.scope.ToString());
            ele_npc.SetAttribute("ai", npcNode.ai.ToString());
            ele_npc.SetAttribute("modelId", npcNode.modelId);
            ele_npc.SetAttribute("name", npcNode.npcName.ToString());
            ele_npc.SetAttribute("enemyType", npcNode.enemyType.ToString());
            ele_npc.SetAttribute("num", npcNode.num.ToString());
            ele_npc.SetAttribute("interval", npcNode.interval.ToString());
            ele_npc.SetAttribute("height", npcNode.height.ToString());
            ele_npc.SetAttribute("width", npcNode.width.ToString());
            ele_npc.SetAttribute("chase", npcNode.chase.ToString());
            ele_npc.SetAttribute("uniqueId", npcNode.uniqueId.ToString());
            root.AppendChild(ele_npc);
        }

        foreach (KeyValuePair <int, MapZone> kp_zone in zoneCollection)
        {
            MapZone zoneNode = kp_zone.Value;
            if (zoneNode.target == null)
            {
                continue;
            }
            XmlElement ele_zone = xmlDocs.CreateElement("zonedef");
            ele_zone.SetAttribute("id", zoneNode.id.ToString());
            ele_zone.SetAttribute("type", zoneNode.type.ToString());
            ele_zone.SetAttribute("regiontype", zoneNode.regiontype.ToString());
            ele_zone.SetAttribute("contryflag", zoneNode.countryflag.ToString());
            ele_zone.SetAttribute("x", zoneNode.x.ToString());
            ele_zone.SetAttribute("y", zoneNode.y.ToString());
            ele_zone.SetAttribute("width", zoneNode.width.ToString());
            ele_zone.SetAttribute("height", zoneNode.height.ToString());
            ele_zone.SetAttribute("zoneindex", zoneNode.zoneindex.ToString());
            ele_zone.SetAttribute("eulerangles", zoneNode.eulerangles);
            root.AppendChild(ele_zone);

            row_region.Clear();
            //fill nodes to dict by row num
            foreach (KeyValuePair <MapNode, int> kp_node in kp_zone.Value.nodeDict)
            {
                if (row_region.ContainsKey(kp_node.Key.y))
                {
                    row_region[kp_node.Key.y] += kp_node.Key.x + ",";
                }
                else
                {
                    row_region[kp_node.Key.y] = kp_node.Key.x + ",";
                }
            }
            //append each row
            foreach (KeyValuePair <int, string> kp_region in row_region)
            {
                XmlElement ele_region = xmlDocs.CreateElement("region");
                ele_region.SetAttribute("row", kp_region.Key.ToString());
                ele_region.SetAttribute("points", kp_region.Value.Substring(0, kp_region.Value.Length - 1));
                ele_zone.AppendChild(ele_region);
            }
        }

        foreach (KeyValuePair <int, MapWarp> kp_warp in warpCollection)
        {
            MapWarp warpNode = kp_warp.Value;
            if (warpNode.target == null)
            {
                continue;
            }

            XmlElement ele_warp = xmlDocs.CreateElement("waypoint");
            ele_warp.SetAttribute("id", warpNode.id.ToString());
            ele_warp.SetAttribute("type", warpNode.type.ToString());
            ele_warp.SetAttribute("x", warpNode.warpX.ToString());
            ele_warp.SetAttribute("y", warpNode.warpY.ToString());
            ele_warp.SetAttribute("state", warpNode.state.ToString());
            ele_warp.SetAttribute("name", warpNode.warpName);
            ele_warp.SetAttribute("openCondition", warpNode.openCondition.ToString());


            ele_warp.SetAttribute("destMapId1", warpNode.destMapId.ToString());
            ele_warp.SetAttribute("destPosX1", warpNode.destMapX.ToString());
            ele_warp.SetAttribute("destPosY1", warpNode.destMapY.ToString());
            ele_warp.SetAttribute("destMapId2", warpNode.destMapId.ToString());
            ele_warp.SetAttribute("destPosX2", warpNode.destMapX.ToString());
            ele_warp.SetAttribute("destPosY2", warpNode.destMapY.ToString());
            ele_warp.SetAttribute("destMapId3", warpNode.destMapId.ToString());
            ele_warp.SetAttribute("destPosX3", warpNode.destMapX.ToString());
            ele_warp.SetAttribute("destPosY3", warpNode.destMapY.ToString());
            ele_warp.SetAttribute("warpType", warpNode.warpType.ToString());
            root.AppendChild(ele_warp);
        }

        foreach (KeyValuePair <int, MapDoor> kp_door in doorCollection)
        {
            MapDoor doorNode = kp_door.Value;
            if (doorNode.target == null)
            {
                continue;
            }

            XmlElement ele_door = xmlDocs.CreateElement("mapDoor");
            ele_door.SetAttribute("id", doorNode.id.ToString());
            ele_door.SetAttribute("type", doorNode.type.ToString());
            ele_door.SetAttribute("x", doorNode.x.ToString());
            ele_door.SetAttribute("y", doorNode.y.ToString());
            ele_door.SetAttribute("width", doorNode.width.ToString());
            ele_door.SetAttribute("height", doorNode.height.ToString());

            ele_door.SetAttribute("state", doorNode.state.ToString());
            ele_door.SetAttribute("res", doorNode.res);
            ele_door.SetAttribute("eulerangles", doorNode.eulerangles.ToString());
            root.AppendChild(ele_door);
        }

        foreach (KeyValuePair <int, MapTrigger> kp_trigger in triggerCollection)
        {
            MapTrigger triggerNode = kp_trigger.Value;
            if (triggerNode.target == null)
            {
                continue;
            }

            XmlElement ele_trigger = xmlDocs.CreateElement("mapTrigger");
            ele_trigger.SetAttribute("id", triggerNode.id.ToString());
            ele_trigger.SetAttribute("type", triggerNode.type.ToString());
            ele_trigger.SetAttribute("x", triggerNode.x.ToString());
            ele_trigger.SetAttribute("y", triggerNode.y.ToString());
            ele_trigger.SetAttribute("width", triggerNode.width.ToString());
            ele_trigger.SetAttribute("height", triggerNode.height.ToString());

            ele_trigger.SetAttribute("triggerType", triggerNode.triggerType.ToString());
            try { ele_trigger.SetAttribute("triggerParam", triggerNode.triggerParam.ToString()); }
            catch { ele_trigger.SetAttribute("triggerParam", ""); }
            ele_trigger.SetAttribute("targetType", triggerNode.targetType.ToString());
            ele_trigger.SetAttribute("targetParam", triggerNode.targetParam.ToString());
            ele_trigger.SetAttribute("eulerangles", triggerNode.eulerangles.ToString());
            root.AppendChild(ele_trigger);
        }

        foreach (KeyValuePair <int, MapEffectPoint> kp_effectpoint in effectPointCollection)
        {
            MapEffectPoint effectpointNode = kp_effectpoint.Value;
            if (effectpointNode.target == null)
            {
                continue;
            }

            XmlElement ele_effectpoint = xmlDocs.CreateElement("mapEffectPoint");
            ele_effectpoint.SetAttribute("id", effectpointNode.id.ToString());
            ele_effectpoint.SetAttribute("type", effectpointNode.type.ToString());
            ele_effectpoint.SetAttribute("x", effectpointNode.x.ToString());
            ele_effectpoint.SetAttribute("y", effectpointNode.y.ToString());
            ele_effectpoint.SetAttribute("width", effectpointNode.width.ToString());
            ele_effectpoint.SetAttribute("height", effectpointNode.height.ToString());
            ele_effectpoint.SetAttribute("res", effectpointNode.res);

            ele_effectpoint.SetAttribute("eulerangles", effectpointNode.eulerangles.ToString());
            root.AppendChild(ele_effectpoint);
        }

        foreach (KeyValuePair <int, MapLine> kp_line in lineCollection)
        {
            MapLine lineNode = kp_line.Value;
            if (lineNode.target == null)
            {
                continue;
            }

            XmlElement ele_line = xmlDocs.CreateElement("linedef");
            ele_line.SetAttribute("id", lineNode.id.ToString());
            ele_line.SetAttribute("type", lineNode.type.ToString());
            ele_line.SetAttribute("x", lineNode.x.ToString());
            ele_line.SetAttribute("y", lineNode.y.ToString());
            ele_line.SetAttribute("startobjid", lineNode.starobjid.ToString());

            string ptStr = "";
            for (int j = 0; j < lineNode.linepts.Count; j++)
            {
                ptStr += lineNode.linepts[j].x.ToString() + " " + lineNode.linepts[j].y.ToString() + ";";
            }
            ptStr = ptStr.Substring(0, ptStr.Length - 1);
            ele_line.SetAttribute("points", ptStr);

            root.AppendChild(ele_line);
        }

        xmlDocs.Save(xmlPath);
        Debug.Log("保存成功:" + xmlPath);
    }
コード例 #15
0
ファイル: NpcEditHelper.cs プロジェクト: dongpeng1988/xlj
    public void readMapXML(string param_mapXmlId)
    {
        npcHelper.Reset();
        mapXmlId = param_mapXmlId;
        XmlDocument xmlDocs = new XmlDocument();
        string      xmlPath = EditorConfig.ExcelDataDir + "../地图数据文件/xianwang/map/" + param_mapXmlId + ".xml";

        if (File.Exists(xmlPath))
        {
            XmlReaderSettings set = new XmlReaderSettings();
            set.IgnoreComments = true;
            XmlReader reader = XmlReader.Create(xmlPath, set);

            xmlDocs.Load(reader);
            reader.Close();
            XmlElement root = (XmlElement)xmlDocs.GetElementsByTagName("HLMapConfig")[0];

            XmlNodeList npcXmlNodes = xmlDocs.GetElementsByTagName("npc");
            for (int i = 0; i < npcXmlNodes.Count; i++)
            {
                XmlElement npcXml   = (XmlElement)npcXmlNodes[i];
                MapNpc     npc_node = new MapNpc(int.Parse(npcXml.GetAttribute("id")));
                npc_node.ai = int.Parse(npcXml.GetAttribute("ai"));
                if (npcXml.HasAttribute("chase"))
                {
                    int.TryParse(npcXml.GetAttribute("chase"), out npc_node.chase);
                }

                npc_node.direction = int.Parse(npcXml.GetAttribute("direction"));
                npc_node.enemyType = int.Parse(npcXml.GetAttribute("enemyType"));
                npc_node.height    = readIntAttribute(npcXml, "height");
                npc_node.interval  = readIntAttribute(npcXml, "interval");
                npc_node.level     = readIntAttribute(npcXml, "level");
                npc_node.nkind     = readIntAttribute(npcXml, "nkind");
                npc_node.npcName   = npcXml.GetAttribute("name").ToString();
                npc_node.modelId   = npcXml.GetAttribute("modelId");
                npc_node.ntype     = readIntAttribute(npcXml, "ntype");
                npc_node.num       = readIntAttribute(npcXml, "num");
                npc_node.speed     = readIntAttribute(npcXml, "speed");
                npc_node.scope     = readIntAttribute(npcXml, "scope");
                npc_node.type      = readIntAttribute(npcXml, "type");
                npc_node.walklen   = readIntAttribute(npcXml, "walklen");
                npc_node.width     = readIntAttribute(npcXml, "width");
                npc_node.x         = readIntAttribute(npcXml, "x");
                npc_node.y         = readIntAttribute(npcXml, "y");

                npc_node.uniqueId = npcXml.GetAttribute("uniqueId");



                editMapNpc(npc_node, OPERATE_ADD);
            }

            XmlNodeList zoneXmlNodes = xmlDocs.GetElementsByTagName("zonedef");
            for (int i = 0; i < zoneXmlNodes.Count; i++)
            {
                XmlElement zoneXml   = (XmlElement)zoneXmlNodes[i];
                MapZone    zone_node = new MapZone();
                zone_node.id = int.Parse(zoneXml.GetAttribute("id"));
                try { zone_node.regiontype = int.Parse(zoneXml.GetAttribute("regiontype")); }
                catch { zone_node.type = 0; }
                zone_node.height = int.Parse(zoneXml.GetAttribute("height"));
                zone_node.type   = int.Parse(zoneXml.GetAttribute("type"));
                zone_node.width  = int.Parse(zoneXml.GetAttribute("width"));
                zone_node.x      = int.Parse(zoneXml.GetAttribute("x"));
                zone_node.y      = int.Parse(zoneXml.GetAttribute("y"));
                try { zone_node.countryflag = int.Parse(zoneXml.GetAttribute("contryflag")); }
                catch { zone_node.countryflag = 7; }
                try { zone_node.zoneindex = int.Parse(zoneXml.GetAttribute("zoneindex")); }
                catch { zone_node.zoneindex = 1; }
                try { zone_node.eulerangles = zoneXml.GetAttribute("eulerangles"); }
                catch { zone_node.eulerangles = ""; }
                foreach (XmlElement region_item in zoneXml.ChildNodes)
                {
                    string[] col_list = region_item.GetAttribute("points").Split(',');
                    for (int j = 0; j < col_list.Length; j++)
                    {
                        //id ,x ,y ,add
                        MapNode region_node = new MapNode(zone_node.id, int.Parse(col_list[j]), int.Parse(region_item.GetAttribute("row")), OPERATE_ADD);
                        zone_node.nodeDict[region_node] = 1;
                    }
                }
                editWholeZone(zone_node, OPERATE_ADD);
            }

            XmlNodeList warpXmlNodes = xmlDocs.GetElementsByTagName("waypoint");
            for (int i = 0; i < warpXmlNodes.Count; i++)
            {
                XmlElement warpXml   = (XmlElement)warpXmlNodes[i];
                MapWarp    warp_node = new MapWarp();
                warp_node.warpX = int.Parse(warpXml.GetAttribute("x"));
                warp_node.warpY = int.Parse(warpXml.GetAttribute("y"));
                //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); }
                //catch { warp_node.type = 0; }
                warp_node.warpName  = warpXml.GetAttribute("name");
                warp_node.type      = int.Parse(warpXml.GetAttribute("type"));
                warp_node.state     = int.Parse(warpXml.GetAttribute("state"));
                warp_node.destMapId = int.Parse(warpXml.GetAttribute("destMapId1"));
                warp_node.destMapX  = int.Parse(warpXml.GetAttribute("destPosX1"));
                warp_node.destMapY  = int.Parse(warpXml.GetAttribute("destPosY1"));
                warp_node.id        = readIntAttribute(warpXml, "id");
                warp_node.warpType  = readIntAttribute(warpXml, "warpType");
                try { warp_node.openCondition = int.Parse(warpXml.GetAttribute("openCondition")); }
                catch { warp_node.openCondition = 0; }
                addMapWarp(warp_node, OPERATE_ADD);
            }

            XmlNodeList doorXmlNodes = xmlDocs.GetElementsByTagName("mapDoor");
            for (int i = 0; i < doorXmlNodes.Count; i++)
            {
                XmlElement doorXml   = (XmlElement)doorXmlNodes[i];
                MapDoor    door_node = new MapDoor();
                door_node.id   = readIntAttribute(doorXml, "id");
                door_node.type = int.Parse(doorXml.GetAttribute("type"));
                door_node.x    = int.Parse(doorXml.GetAttribute("x"));
                door_node.y    = int.Parse(doorXml.GetAttribute("y"));
                //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); }
                //catch { warp_node.type = 0; }
                door_node.width       = int.Parse(doorXml.GetAttribute("width"));
                door_node.height      = int.Parse(doorXml.GetAttribute("height"));
                door_node.state       = int.Parse(doorXml.GetAttribute("state"));
                door_node.res         = doorXml.GetAttribute("res");
                door_node.eulerangles = doorXml.GetAttribute("eulerangles");


                addMapDoor(door_node, OPERATE_ADD);
            }

            XmlNodeList triggerXmlNodes = xmlDocs.GetElementsByTagName("mapTrigger");
            for (int i = 0; i < triggerXmlNodes.Count; i++)
            {
                XmlElement triggerXml   = (XmlElement)triggerXmlNodes[i];
                MapTrigger trigger_node = new MapTrigger();
                trigger_node.id     = readIntAttribute(triggerXml, "id");
                trigger_node.type   = int.Parse(triggerXml.GetAttribute("type"));
                trigger_node.x      = int.Parse(triggerXml.GetAttribute("x"));
                trigger_node.y      = int.Parse(triggerXml.GetAttribute("y"));
                trigger_node.width  = int.Parse(triggerXml.GetAttribute("width"));
                trigger_node.height = int.Parse(triggerXml.GetAttribute("height"));
                //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); }
                //catch { warp_node.type = 0; }
                try { trigger_node.triggerType = int.Parse(triggerXml.GetAttribute("triggerType")); }
                catch { trigger_node.triggerType = 0; }
                try { trigger_node.triggerParam = triggerXml.GetAttribute("triggerParam"); }
                catch { trigger_node.triggerParam = ""; }
                trigger_node.targetType  = int.Parse(triggerXml.GetAttribute("targetType"));
                trigger_node.targetParam = triggerXml.GetAttribute("targetParam");
                trigger_node.eulerangles = triggerXml.GetAttribute("eulerangles");

                addMapTrigger(trigger_node, OPERATE_ADD);
            }

            XmlNodeList effectPointXmlNodes = xmlDocs.GetElementsByTagName("mapEffectPoint");
            for (int i = 0; i < effectPointXmlNodes.Count; i++)
            {
                XmlElement     effectPointXml   = (XmlElement)effectPointXmlNodes[i];
                MapEffectPoint effectpoint_node = new MapEffectPoint();
                effectpoint_node.id          = int.Parse(effectPointXml.GetAttribute("id"));
                effectpoint_node.type        = int.Parse(effectPointXml.GetAttribute("type"));
                effectpoint_node.x           = int.Parse(effectPointXml.GetAttribute("x"));
                effectpoint_node.y           = int.Parse(effectPointXml.GetAttribute("y"));
                effectpoint_node.width       = int.Parse(effectPointXml.GetAttribute("width"));
                effectpoint_node.height      = int.Parse(effectPointXml.GetAttribute("height"));
                effectpoint_node.res         = effectPointXml.GetAttribute("res");
                effectpoint_node.eulerangles = effectPointXml.GetAttribute("eulerangles");

                addMapEffectPoint(effectpoint_node, OPERATE_ADD);
            }

            XmlNodeList lineXmlNodes = xmlDocs.GetElementsByTagName("linedef");
            for (int i = 0; i < lineXmlNodes.Count; i++)
            {
                XmlElement lineXML   = (XmlElement)lineXmlNodes[i];
                MapLine    line_node = new MapLine(int.Parse(lineXML.GetAttribute("startobjid")));
                line_node.x = int.Parse(lineXML.GetAttribute("x"));
                line_node.y = int.Parse(lineXML.GetAttribute("y"));
                //try { warp_node.regiontype = int.Parse(warpXml.GetAttribute("regiontype")); }
                //catch { warp_node.type = 0; }
                line_node.id = int.Parse(lineXML.GetAttribute("id"));
                string ptStr = lineXML.GetAttribute("points");
                line_node.type = int.Parse(lineXML.GetAttribute("type"));
                //line_node.pointsStr = ptStr;
                line_node.linepts = new List <MapLinePoint>();
                string[] ptArr = ptStr.Split(';');
                for (int j = 0; j < ptArr.Length; j++)
                {
                    line_node.linepts.Add(new MapLinePoint(int.Parse(ptArr[j].Split(' ')[0]), int.Parse(ptArr[j].Split(' ')[1])));
                }

                addMapLine(line_node, OPERATE_ADD);
            }
        }
        else
        {
            //XmlDeclaration dec = xmlDocs.CreateXmlDeclaration("1.0", "UTF-8", null);
            //xmlDocs.AppendChild(dec);
            //XmlElement root = xmlDocs.CreateElement("Hoolai");
            //xmlDocs.AppendChild(root);
            //xmlDocs.Save(xmlPath);
        }

        initMapNpc();
        initMapWarp();
        initZone();
        initLine();
        initMapDoor();
        initMapTrigger();
        initMapEffectPoint();
    }
コード例 #16
0
ファイル: LoadMapWindow.cs プロジェクト: dongpeng1988/xlj
    void showNpcTool()
    {
        if (!npcLoaded)
        {
            if (GUILayout.Button("加载"))
            {
                loadNpc();
            }
        }
        else
        {
            if (showAdd = EditorGUILayout.Foldout(showAdd, "添加npc"))
            {
                selAddNpc = GUILayout.Toolbar(selAddNpc, new string[] { "添加Npc", "添加怪物" });
                if (selAddNpc == 0)
                {
                    showNpcAdd(2);
                }
                else
                {
                    showNpcAdd(1);
                }
            }
            EditorGUILayout.Separator();
            if (showAddZone = EditorGUILayout.Foldout(showAddZone, "添加区域"))
            {
                EditorGUILayout.BeginVertical();
                zone_id = EditorGUILayout.IntField("输入区域ID:", zone_id);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("区域类型:");
                selReginType = EditorGUILayout.Popup(selReginType, regionType);
                if (GUILayout.Button("添加"))
                {
                    MapZone node = new MapZone();
                    node.regiontype = selReginType;
                    node.width      = 4;
                    node.height     = 4;
                    node.id         = zone_id;
                    npcHelper.AddZone(node);
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }

            if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加传送门"))
            {
                if (GUILayout.Button("添加传送门"))
                {
                    MapWarp node = new MapWarp();

                    npcHelper.AddWarp(node);
                }
            }
            if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加阻挡门"))
            {
                if (GUILayout.Button("添加阻挡门"))
                {
                    MapDoor node = new MapDoor();

                    npcHelper.AddDoor(node);
                }
            }
            if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加触发器"))
            {
                if (GUILayout.Button("添加触发器"))
                {
                    MapTrigger node = new MapTrigger();

                    npcHelper.AddTrigger(node);
                }
            }
            if (showAddWarp = EditorGUILayout.Foldout(showAddWarp, "添加地图特效"))
            {
                if (GUILayout.Button("添加地图特效"))
                {
                    MapEffectPoint node = new MapEffectPoint();

                    npcHelper.AddEffectPoint(node);
                }
            }
            if (showAddLine = EditorGUILayout.Foldout(showAddLine, "添加挂机路线"))
            {
                EditorGUILayout.BeginVertical();
                zone_id = EditorGUILayout.IntField("添加挂机路线:", line_starobjid);
                if (GUILayout.Button("添加挂机路线"))
                {
                    MapLine node = new MapLine(line_starobjid);

                    npcHelper.addLine(node);
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            if (GUILayout.Button("保存"))
            {
                try
                {
                    npcHelper.saveMapXML();
                    //  EditorGUILayout.HelpBox("保存成功 地图文件:" + mapFileName + ",通过性:" + curTile, MessageType.Info);
                }
                catch (Exception ex)
                {
                    showError("保存失败");
                }
            }
            GUILayout.Space(50);
            if (GUILayout.Button("重新加载npc表"))
            {
                EditorTool.LoadNpcConfig();
                showAdd = false;
            }
        }
    }