Beispiel #1
0
    IEnumerator LoadAndCopyImage(string path, string saveName, Action <UnityEngine.Object> callback)
    {
        UnityWebRequest        request     = UnityWebRequest.Get("file:///" + path);
        DownloadHandlerTexture downTexture = new DownloadHandlerTexture(true);

        request.downloadHandler = downTexture;
        yield return(request.SendWebRequest());

        if (request.result == UnityWebRequest.Result.Success && request != null)
        {
            //获取Texture
            Texture2D texture = downTexture.texture;
            //直接将选择图保存为png格式,拷贝到指定目录
            byte[] bytes = texture.EncodeToPNG();
            File.WriteAllBytes(PathMgr.GetInstance().ImagePath + saveName + ".png", bytes);
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            if (!m_dicCachSprite.ContainsKey(saveName))
            {
                m_dicCachSprite.Add(saveName, sprite);
            }
            callback(sprite);
        }
        else
        {
            LogMgr.GetInstance().Log(LogEnum.Error, "加载图片失败:" + path);
        }
    }
Beispiel #2
0
 /// <summary>
 /// 保存json数据到本地
 /// </summary>
 /// <param name="data"></param>
 public static bool SaveJsonDataToLocal(JsonData data, string saveName)
 {
     if (data == null)
     {
         return(false);
     }
     try
     {
         string saveData = JsonMapper.ToJson(data);
         //转译中文
         Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
         saveData = reg.Replace(saveData, delegate(Match m) { return(((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString()); });
         StreamWriter streamWriter;
         if (!PathMgr.GetInstance().CheckFile(PathMgr.GetInstance().StreamPath + "/" + saveName + ".json"))
         {
             streamWriter = File.CreateText(PathMgr.GetInstance().StreamPath + "/" + saveName + ".json");
         }
         else
         {
             streamWriter = new StreamWriter(PathMgr.GetInstance().StreamPath + "/" + saveName + ".json");
         }
         streamWriter.Write(saveData);
         streamWriter.Dispose();
         streamWriter.Close();
         return(true);
     }
     catch (Exception e)
     {
         LogMgr.GetInstance().Log(LogEnum.Error, "保存" + saveName + ".json失败" + e.Message);
         return(false);
     }
 }
Beispiel #3
0
    //创建jsonfile
    public static void BuildlerJsonFile(DirectoryInfo di, string pingString, string filename, string suffix)
    {
        //Debug.Log("选择文件截取" + substr);
        string ProfilePath = PathMgr.GetTextFilePath();

        //Debug.Log("资源文件路径" + ProfilePath);
        ////创建资源文件
        if (!Directory.Exists(ProfilePath))
        {
            Debug.Log("资源文件不存在" + ProfilePath);
            Directory.CreateDirectory(ProfilePath);
        }

        FileStream   fs         = CreateFile(ProfilePath, filename);
        string       jsonString = FileListToJsonStr(di, pingString + PathHua, suffix);
        StreamWriter sw         = new StreamWriter(fs, Encoding.UTF8);

        try
        {
            sw.Write(jsonString);
            sw.Flush();
        }
        catch (IOException e)
        {
            Debug.Log(e.ToString());
            Debug.Log("创建失败");
        }
        finally
        {
            sw.Close();
            fs.Close();
        }
        Debug.Log("创建成功");
    }
Beispiel #4
0
    public static void BuildlerEmunFile(DirectoryInfo di, string filename, string suffix)
    {
        string     enumPath = PathMgr.getAssetPath() + "/Script/u3d_scripts/Define";
        FileStream enumf    = CreateFile(enumPath, filename, ".cs");
        string     enumStr  = FileListEnumstr(di, filename, suffix);

        StreamWriter sw2 = new StreamWriter(enumf, Encoding.UTF8);

        try
        {
            sw2.Write(enumStr);
            sw2.Flush();
        }
        catch (IOException e)
        {
            Debug.Log(e.ToString());
            Debug.Log("创建失败");
        }
        finally
        {
            enumf.Close();
            sw2.Close();
        }
        Debug.Log("创建成功");
    }
    private void InitComponent(EnemyData data, EnemyType type, Sprite sprite, ITrajectoryData trajectoryData)
    {
        //更新飞机图片
        Renderer = gameObject.AddOrGet <RenderComponent>();
        Renderer.Init();
        Renderer.SetSprite(sprite);
        //路径初始化
        _path = new PathMgr();
        _path.Init(transform, data, trajectoryData);

        gameObject.AddOrGet <CameraMove>().enabled = _path.NeedMoveWithCamera();
        gameObject.AddOrGet <AutoDespawnComponent>();
        gameObject.AddOrGet <EnemyTypeComponent>().Init(type);
        var lifeC = gameObject.AddOrGet <LifeComponent>();

        lifeC.Init(data.life);
        gameObject.AddOrGet <EnemyBehaviour>().Init(data);
        _moveComponent = gameObject.AddOrGet <MoveComponent>();
        _moveComponent.Init((float)data.speed);
        gameObject.AddOrGet <ColliderComponent>();
        gameObject.AddOrGet <PlaneCollideMsgComponent>();
        var bulletMgr = transform.Find("BulletRoot").AddOrGet <EnemyBulletMgr>();

        bulletMgr.Init(data);

        if (_lifeView == null)
        {
            var lifeGo = LoadMgr.Single.LoadPrefabAndInstantiate(Paths.PREFAB_ENEMY_LIFE, transform);
            _lifeView = lifeGo.AddComponent <EnemyLifeView>();
        }

        _lifeView.Init();
    }
Beispiel #6
0
 void Awake()
 {
     Instance   = this;
     canUsePath = new List <int>();
     for (int i = 0; i < transform.childCount; i++)
     {
         canUsePath.Add(i);
     }
 }
Beispiel #7
0
 void Start()
 {
     FrameMgr.GetInstance();
     TimerMgr.GetInstance();
     PathMgr.GetInstance();
     ConfigMgr.GetInstance();
     AssetMgr.GetInstance();
     UIMgr.GetInstance();
     SoundMgr.GetInstance();
     LoadSceneMgr.LoadSence("test");
 }
Beispiel #8
0
    //-------------------------------------------------------------------------
    void Start()
    {
        // 初始化系统参数
        {
            Application.runInBackground = true;
            Time.fixedDeltaTime         = 0.03f;
            Application.targetFrameRate = 60;
            Screen.sleepTimeout         = SleepTimeout.NeverSleep;
        }

        // 初始化日志
        {
            EbLog.NoteCallback    = Debug.Log;
            EbLog.WarningCallback = Debug.LogWarning;
            EbLog.ErrorCallback   = Debug.LogError;
        }

        EbLog.Note("MbMain.Start()");

        // 初始化PathMgr
        if (mPathMgr == null)
        {
            mPathMgr = new PathMgr();
        }

        if (mClientConfig == null)
        {
            mClientConfig = new ClientConfig();
        }

        if (mAsyncLoadAssetMgr == null)
        {
            mAsyncLoadAssetMgr = new AsyncLoadAssetMgr();
            mAsyncLoadAssetMgr.init();
        }

        if (mEngine == null)
        {
            EcEngineSettings settings;
            settings.ProjectName         = "Fishing";
            settings.RootEntityType      = "EtRoot";
            settings.EnableCoSuperSocket = true;
            mEngine = new EcEngine(ref settings, new EcEngineListener());
        }

        UiMgr = new UiMgr();
        UiMgr.create(EntityMgr.Instance);

        mSoundMgr = new CSoundMgr();

        // 创建EtClientApp
        EntityMgr.Instance.createEntity <EtApp>(null, EcEngine.Instance.EtNode);
    }
Beispiel #9
0
    public void DeleteImage(string name)
    {
        string path = PathMgr.GetInstance().ImagePath + name;

        if (m_dicCachSprite.ContainsKey(name))
        {
            m_dicCachSprite.Remove(name);
            File.Delete(path);
        }
        else
        {
            LogMgr.GetInstance().Log(LogEnum.Warming, "没有缓存的图片,怎么删除呢:" + path);
        }
    }
Beispiel #10
0
    public static void TestReadFile(string ProFileName)
    {
        string       filePath = PathMgr.GetTextFilePath() + PathMgr.PathHua + ProFileName + ".json";
        StreamReader sr       = new StreamReader(filePath);
        string       json     = sr.ReadToEnd();

        Debug.Log(json);

        JsonData jd = JsonMapper.ToObject(json);

        foreach (JsonData item in jd)
        {
            Debug.Log(item["Type"] + "-" + item["PathName"]);
        }
    }
Beispiel #11
0
    IEnumerator LoadSpriteAsync(string name, Action <UnityEngine.Object> callback)
    {
        string                 path        = PathMgr.GetInstance().ImagePath + name + ".png";
        UnityWebRequest        request     = UnityWebRequest.Get("file:///" + path);
        DownloadHandlerTexture downTexture = new DownloadHandlerTexture(true);

        request.downloadHandler = downTexture;
        yield return(request.SendWebRequest());

        if (request.result == UnityWebRequest.Result.Success && request != null)
        {
            Texture2D texture = downTexture.texture;
            Sprite    sprite  = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            callback(sprite);
        }
    }
Beispiel #12
0
 private static void Init()
 {
     if (DicLocalization.Count == 0)
     {
         AssetMgr.GetInstance().LoadAsset(PathMgr.GetInstance().GetPath(Define.DataType.Localization), false, false, () => {
             string[] loc = AssetMgr.GetInstance().GetAsset().ToString().Split(new[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
             for (int i = 0; i < loc.Length; i++)
             {
                 loc[i] = loc[i].Replace("\r", "");
             }
             LanguageList = loc[0].Split(',');
             for (int i = 1; i < loc.Length; i++)
             {
                 string[] data = loc[i].Split(',');
                 DicLocalization.Add(data[0], data);
             }
         });
     }
 }
Beispiel #13
0
    /// <summary>
    /// 解析json数据
    /// </summary>
    /// <param name="jsonName">json名字</param>
    /// <returns>Objec类型的JsonData</returns>
    public static JsonData ParseToJsonData(string jsonName)
    {
        string path = PathMgr.GetInstance().StreamPath + "/" + jsonName + ".json";

        if (PathMgr.GetInstance().CheckFile(path))
        {
            try
            {
                StreamReader r    = new StreamReader(path);
                string       json = r.ReadToEnd();
                r.Close();
                JsonData data = JsonMapper.ToObject(json);
                return(data);
            }
            catch (Exception e)
            {
                LogMgr.GetInstance().Log(LogEnum.Error, "解析Json出错:" + e.Message);
                return(null);
            }
        }
        return(null);
    }
Beispiel #14
0
    public void Init()
    {
        //缓存保存的图片资源
        if (Directory.Exists(PathMgr.GetInstance().ImagePath))
        {
            DirectoryInfo dir   = new DirectoryInfo(PathMgr.GetInstance().ImagePath);
            FileInfo[]    files = dir.GetFiles("*", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name.EndsWith(".meta"))
                {
                    continue;
                }
                int    index = files[i].Name.LastIndexOf('.');
                string key   = files[i].Name.Remove(index);
                //没有缓存过的才请求加载
                if (!m_dicCachSprite.ContainsKey(key))
                {
                    StartCoroutine(LoadSpriteAsync(key, (obj) =>
                    {
                        Sprite sp = obj as Sprite;
                        if (sp == null)
                        {
                            return;
                        }
                        m_dicCachSprite.Add(key, sp);
                    }));
                }
            }
            ConfigMgr.GetInstance().V_MaxImageIndex = m_dicCachSprite.Count;
        }
        else
        {
            Directory.CreateDirectory(PathMgr.GetInstance().ImagePath);
        }
    }
 // Start is called before the first frame update
 void Awake()
 {
     Instance = this;
 }
Beispiel #16
0
    //-------------------------------------------------------------------------
    void Start()
    {
        // 初始化系统参数
        {
            Application.runInBackground = true;
            Time.fixedDeltaTime = 0.03f;
            Application.targetFrameRate = 60;
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        // 初始化日志
        {
            EbLog.NoteCallback = Debug.Log;
            EbLog.WarningCallback = Debug.LogWarning;
            EbLog.ErrorCallback = Debug.LogError;
        }

        EbLog.Note("MbMain.Start()");

        // 初始化PathMgr
        if (mPathMgr == null)
        {
            mPathMgr = new PathMgr();
        }

        if (mClientConfig == null)
        {
            mClientConfig = new ClientConfig();
        }

        if (mAsyncLoadAssetMgr == null)
        {
            mAsyncLoadAssetMgr = new AsyncLoadAssetMgr();
            mAsyncLoadAssetMgr.init();
        }

        if (mEngine == null)
        {
            EcEngineSettings settings;
            settings.ProjectName = "Fishing";
            settings.RootEntityType = "EtRoot";
            mEngine = new EcEngine(ref settings, new EcEngineListener());
        }

        UiMgr = new UiMgr();
        UiMgr.create(EntityMgr.Instance);

        mSoundMgr = new CSoundMgr();

        // 创建EtClientApp
        EntityMgr.Instance.createEntity<EtApp>(null, EcEngine.Instance.EtNode);
    }
Beispiel #17
0
 protected override void OnEnable()
 {
     _pathMgr = (PathMgr)target;
 }