コード例 #1
0
ファイル: WorldManager.cs プロジェクト: lykyyy/HalfWorld
        //根据城市总数,随机城市
        private void CreateCities()
        {
            GameObject cityNode = GameObject.FindGameObjectWithTag(EGameConstL.TAG_CITY_NODE);

            if (!cityNode || !m_cityModel)
            {
                EUtilityHelperL.LogError("None city node or model!");
                return;
            }

            //生成预定数量的城市
            for (int i = 0; i < m_citiesCount; ++i)
            {
                City clone = Instantiate <City>(m_cityModel);
                clone.name     = string.Format("City_{0}", i);
                clone.UnitName = clone.name;

                clone.transform.SetParent(cityNode.transform);
                clone.transform.localPosition = GetCityPos();
                clone.transform.localScale    = Vector3.one;
                clone.transform.localRotation = Quaternion.identity;
                clone.transform.gameObject.SetActive(true);

                //初始化城市
                clone.Init();
            }
        }
コード例 #2
0
        //准备加载战场
        private void PrepareBattleMap()
        {
            if (currentData == null)
            {
                EUtilityHelperL.LogError("Prepare battle map failed. No battle data.");
                return;
            }
            gridUnits = new GridUnit[currentData.mapWidth, currentData.mapHeight];

            for (int row = 0; row < currentData.mapHeight; ++row)
            {
                for (int column = 0; column < currentData.mapWidth; ++column)
                {
                    GridUnitData gud = currentData.mapGrids[column, row];
                    if (gud != null)
                    {
                        //创建一个用于显示的格子对象
                        GridUnit gu = CreateGrid();
                        if (gu != null)
                        {
                            gridUnits[column, row]     = gu;
                            gu.transform.localPosition = gud.localPosition;
                            gu.name     = string.Format("Grid_{0}_{1}", row, column);
                            gu.gridData = gud;
                            gu.Refresh();
                            gu.gameObject.SetActive(true);
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: BattleField.cs プロジェクト: yxpandjay/HalfSLG
        //准备加载战场
        private void PrepareBattleMap()
        {
            if (currentData == null)
            {
                EUtilityHelperL.LogError("Prepare battle map failed. No battle data.");
                return;
            }
            gridUnits = new GridUnit[currentData.mapData.mapWidth, currentData.mapData.mapHeight];

            for (int r = 0; r < currentData.mapData.mapHeight; ++r)
            {
                for (int c = 0; c < currentData.mapData.mapWidth; ++c)
                {
                    GridUnitData gud = currentData.mapData.mapGrids[c, r];
                    if (gud != null)
                    {
                        //创建一个用于显示的格子对象
                        GridUnit gridUnit = CreateGrid();
                        if (gridUnit != null)
                        {
                            gridUnits[c, r] = gridUnit;
                            gridUnit.transform.localPosition = gud.localPosition;
                            gridUnit.name     = string.Format("Grid_{0}_{1}", r, c);
                            gridUnit.gridData = gud;
                            gridUnit.RefreshColor();
                            gridUnit.gameObject.SetActive(true);
                        }
                    }
                }
            }
        }
コード例 #4
0
        //拷贝文件夹
        public static void CopyFolder(string _from, string _to)
        {
            // EUtilityHelperL.Log(string.Format("拷贝文件:从{0}到{1}", _from, _to));
            if (Directory.Exists(_from) == false)
            {
                EUtilityHelperL.LogError("拷贝文件失败:文件不存在(" + _from + ")");
                return;
            }

            if (Directory.Exists(_to) == false)
            {
                // EUtilityHelperL.Log(_to + "文件不存在,新建");
                Directory.CreateDirectory(_to);
            }

            //TODO:先这么写吧,能用就行,有机会再完善
            //拷贝.txt, .lua, .json
            string[] paths = Directory.GetFiles(_from, "*.*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < paths.Length; ++i)
            {
                paths[i] = paths[i].Replace('\\', '/');
                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
                File.Copy(paths[i], _to + "/" + fileName, true);
            }
            //            paths = Directory.GetFiles(_from, "*.json", SearchOption.TopDirectoryOnly);
            //            for(int i = 0; i < paths.Length; ++i)
            //            {
            //                paths[i] = paths[i].Replace('\\','/');
            //                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
            //                File.Copy(paths[i], _to + "/" + fileName, true);
            //            }
            //            paths = Directory.GetFiles(_from, "*.txt", SearchOption.TopDirectoryOnly);
            //            for(int i = 0; i < paths.Length; ++i)
            //            {
            //                paths[i] = paths[i].Replace('\\','/');
            //                string fileName = paths[i].Remove(0, paths[i].LastIndexOf("/") + 1);
            //                File.Copy(paths[i], _to + "/" + fileName, true);
            //            }

            //拷贝文件夹
            string[] folderPaths = Directory.GetDirectories(_from, "*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < folderPaths.Length; ++i)
            {
                folderPaths[i] = folderPaths[i].Replace('\\', '/');
                string folderName = folderPaths[i].Remove(0, folderPaths[i].LastIndexOf("/") + 1);
                //递归拷贝
                CopyFolder(folderPaths[i], _to + "/" + folderName);
            }
        }
コード例 #5
0
        //获取文件名字
        public static string GetFileName(string _path, bool hideBack = true)
        {
            int start = _path.LastIndexOf('/');

            if (start >= 0)
            {
                string _temp = _path.Remove(0, start + 1);
                int    end   = _temp.IndexOf('.');
                if (end >= 0 && hideBack)
                {
                    return(_temp.Remove(end));
                }
            }
            EUtilityHelperL.LogError("获取文件名称失败");
            return("");
        }
コード例 #6
0
ファイル: BattleMapManager.cs プロジェクト: yxpandjay/HalfSLG
        public BattleMapData CreateMap(int width, int height, int obstacleCount, int obstacleGap)
        {
            BattleMapData battleMapData = null;
            int           mapID         = 0;

            base.Create(out battleMapData, out mapID);
            if (battleMapData != null)
            {
                battleMapData.mapID = mapID;
                battleMapData.Generate(width, height, obstacleCount, obstacleGap);
            }
            else
            {
                EUtilityHelperL.LogError(string.Format("Create map failed->width:{0},height:{1}",
                                                       width, height));
            }
            return(battleMapData);
        }
コード例 #7
0
ファイル: City.cs プロジェクト: lykyyy/HalfWorld
        public override void Init(params object[] args)
        {
            if (m_inited)
            {
                return;
            }

            if (!m_fieldModel)
            {
                EUtilityHelperL.LogError("City unit error: none file model");
                return;
            }

            //向世界管理器注册
            WorldManager.Instance.OperateCity(this, true);

            m_inited = true;
        }
コード例 #8
0
ファイル: City.cs プロジェクト: lykyyy/HalfWorld
        /// <summary>
        /// 创建野外
        /// </summary>
        /// <param name="count">创建数量</param>
        /// <param name="density">密度系数</param>
        /// <param name="minRadius">最小半径</param>
        /// <param name="maxRadius">最大半径</param>
        public void CreateFields(int count, float density, float minRadius, float maxRadius)
        {
            GameObject fieldNode = GameObject.FindGameObjectWithTag(EGameConstL.TAG_FIELD_NODE);

            if (!fieldNode || !m_fieldModel)
            {
                EUtilityHelperL.LogError("None filed node or model!");
                return;
            }

            int created = 0;

            //生成预定数量的野外
            for (int i = 0; i < count; ++i)
            {
                Field clone = Instantiate <Field>(m_fieldModel);
                clone.transform.SetParent(fieldNode.transform);

                //设置名字
                clone.name     = string.Format("Field_{0}_{1}", m_roundFields.Count, UnitName);
                clone.UnitName = clone.name;

                //设置所属城市
                clone.CityUnit = this;

                //必须要做的转换
                clone.transform.position      = transform.TransformPoint(GetFieldPos(density, minRadius, maxRadius));
                clone.transform.localScale    = Vector3.one;
                clone.transform.localRotation = Quaternion.identity;
                clone.gameObject.SetActive(true);
                m_roundFields.Add(clone);

                clone.Init();

                ++created;
            }
        }
コード例 #9
0
        //计算探索速度
        public float CalculateExploreTimeMultiple(HeroData heroData, FieldData fieldData)
        {
            float strNeed = Mathf.Infinity;

            if (fieldDiff.ContainsKey(fieldData.difficulty))
            {
                strNeed = fieldDiff[fieldData.difficulty].value;
            }
            else
            {
                EUtilityHelperL.LogError("错误的野外难度等级");
            }
            //计算力量差距
            int gap = Mathf.FloorToInt((heroData.strength - strNeed) / strNeed * 100f);

            for (int i = 0; i < ladderTime.Length; ++i)
            {
                if (gap <= ladderTime[i].key)
                {
                    return(ladderTime[i].value);
                }
            }
            return(ladderTime[ladderTime.Length - 1].value);
        }