Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="commandId"></param>
        /// <param name="bytes"></param>
        public void OnReceiveMessage(int commandId, byte[] bytes)
        {
            try
            {
                if (bytes == null)
                {
                    _onReceiveMessageCallback.Call(commandId, 0);
                }
                else
                {
                    ByteBuffer data = new ByteBuffer(bytes);

                    if (_onReceiveMessageCallback != null)
                    {
                        _onReceiveMessageCallback.Call(commandId, data.ReadBuffer());
                    }

                    data.Close();
                }
            }
            catch (Exception e)
            {
                DebugManager.LogError("Scoket OnReceiveMessage Error:" + commandId.ToString() + "," + e.Message);
            }
        }
Exemple #2
0
        public void LoadPrefab(string viewId, string abName, string assetName, LuaFunction func)
        {
            ResourceManager.Instance.LoadPrefabAsync(viewId, abName, delegate(AssetBundle assetBundle) {
                if (assetBundle == null)
                {
                    DebugManager.LogError("LoadPrefab Error result is null:" + abName + "," + assetName.ToString());
                    func.Dispose();
                    func = null;
                    return;
                }
                else
                {
                    if (func != null)
                    {
                        if (assetName.EndsWith("_sprite"))
                        {
                            string name = assetName.Substring(0, assetName.LastIndexOf("_sprite"));

                            func.Call(TextureToSprite(ResourceManager.Instance.GetTexture2DAsset(assetBundle, name)));
                        }
                        else
                        {
                            func.Call(ResourceManager.Instance.GetAsset(assetBundle, assetName));
                        }

                        func.Dispose();
                        func = null;
                    }
                }
            });
        }
Exemple #3
0
        /// <summary>
        /// 移除所有弹出窗口
        /// </summary>
        public void RemoveAllWindow()
        {
            if (this.CurrScene == null)
            {
                DebugManager.LogError("RemoveAllPopup Error:当前没有可用的场景!");

                return;
            }

            this.CurrScene.RemoveAllWindow();
        }
Exemple #4
0
        /// <summary>
        /// 获取当前弹出窗口
        /// </summary>
        /// <param name="id"></param>
        public BaseWindow GetWindow(string id)
        {
            if (this.CurrScene == null)
            {
                DebugManager.LogError("GetPopup Error:当前没有可用的场景!");

                return(null);
            }

            return(this.CurrScene.GetWindow(id));
        }
Exemple #5
0
        /// <summary>
        /// 移除弹出窗口
        /// </summary>
        /// <param name="id"></param>
        public void RemoveWindow(string id)
        {
            if (this.CurrScene == null)
            {
                DebugManager.LogError("RemovePopup Error:当前没有可用的场景!");

                return;
            }

            this.CurrScene.RemoveWindow(id);
            RemoveViewAllEvent(id);
        }
Exemple #6
0
        /// <summary>
        /// 实例化预制体
        /// </summary>
        /// <param name="name"></param>
        public Transform GetAsset(string abName, string name)
        {
            //ShowAbList();
            AssetBundle assetBundle;

            _bundleDic.TryGetValue(FormatPath(abName), out assetBundle);

            if (assetBundle == null)
            {
                DebugManager.LogError("GetAsset assetBundle is null     " + abName + "," + name);
                return(null);
            }
            return(GetAsset(assetBundle, name));
        }
Exemple #7
0
 /// <summary>
 /// 手动断开连接
 /// </summary>
 /// <param name="state"></param>
 public void OnDisconnect()
 {
     _clientSocket.Disconnect(false);
     try
     {
         if (_onDisconnectCallback != null)
         {
             _onDisconnectCallback.Call();
         }
     }
     catch (Exception e)
     {
         DebugManager.LogError("Scoket OnDisconnect Error:" + e.Message);
     }
 }
Exemple #8
0
        /// <summary>
        /// 实例化预制体
        /// </summary>
        /// <param name="name"></param>
        public Transform GetAsset(AssetBundle assetBundle, string name)
        {
            if (assetBundle == null)
            {
                DebugManager.LogError("GetAsset assetBundle is null     " + name);
                return(null);
            }

            GameObject go = Instantiate(assetBundle.LoadAsset <GameObject>(name));

            go.name = go.name.Replace("(Clone)", "");
            //GameObject go = assetBundle.LoadAsset<GameObject>(name);

            return(go.transform);
        }
Exemple #9
0
        /// <summary>
        /// 实例化预制体
        /// </summary>
        /// <param name="name"></param>
        public Texture2D GetTexture2DAsset(AssetBundle assetBundle, string name)
        {
            if (assetBundle == null)
            {
                DebugManager.LogError("GetAsset assetBundle is null     " + name);
                return(null);
            }

            foreach (Texture2D t in assetBundle.LoadAllAssets <Texture2D>())
            {
                if (t.name.Equals(name))
                {
                    return(assetBundle.LoadAsset <Texture2D>(name));
                }
            }

            return(null);
        }
Exemple #10
0
        public void CopyFiles(string sourcePath, string[] files, Action completeAction)
        {
            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)                    //如果是Android平台
            {
                foreach (string path in files)
                {
                    StartCoroutine(CopyFile_Android(sourcePath, path.Split('|')[0], completeAction));
                }
            }
            else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)          //如果是Windows平台
            {
                sourcePath = sourcePath.Replace("file://", "");
                foreach (string path in files)
                {
                    string _path = path.Split('|')[0];
                    if (path.Equals(""))
                    {
                        continue;
                    }
                    try
                    {
                        DebugManager.Log("Start CopyFile ======>" + sourcePath + _path + " to:" + FileUtil.Instance.GetWritePath(_path));

                        string toPath = FileUtil.Instance.GetWritePath(_path);
                        string toDir  = toPath.Substring(0, toPath.LastIndexOf("/"));

                        if (!Directory.Exists(toDir))
                        {
                            Directory.CreateDirectory(toDir);
                        }

                        File.Copy(sourcePath + _path, FileUtil.Instance.GetWritePath(_path), true);
                    }
                    catch (Exception e)
                    {
                        DebugManager.LogError("Copy file Error:" + path);
                        DebugManager.LogError(e.Message);
                    }
                    DebugManager.Log("CopyFile Success! ======> " + FileUtil.Instance.GetWritePath(_path));
                }
                completeAction();
            }
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="actionName"></param>
        /// <param name="isLoop"></param>
        /// <returns></returns>
        public void NewUISpineAni(string viewId, GameObject parent, string abName, string assetName, LuaFunction callback, string actionName = "", bool isLoop = true, bool hasButton = false, string name = null)
        {
            ResourceManager.Instance.LoadPrefabAsync(viewId, abName, delegate(AssetBundle assetBundle)
            {
                if (assetBundle == null)
                {
                    DebugManager.LogError("NewUISpineAni Error:下载资源失败!" + abName + "," + assetName);
                    return;
                }

                SkeletonDataAsset skeletonDataAsset = assetBundle.LoadAsset <SkeletonDataAsset>(assetName + "_SkeletonData");
                SkeletonGraphic graphic             = SkeletonGraphic.NewSkeletonGraphicGameObject(skeletonDataAsset, parent.transform);
                graphic.material = new Material(Shader.Find("Spine/SkeletonGraphic (Premultiply Alpha)"));

                if (actionName != "")
                {
                    graphic.AnimationState.SetAnimation(0, actionName, isLoop);
                }

                graphic.gameObject.transform.localPosition = new Vector3(0, 0, 0);

                if (name != null)
                {
                    graphic.gameObject.name = name;
                }
                else
                {
                    graphic.gameObject.name = "Spi_" + assetName;
                }

                if (hasButton == true)
                {
                    graphic.gameObject.AddComponent <UnityEngine.UI.Button>();
                }

                if (callback != null)
                {
                    callback.Call(graphic);
                    callback.Dispose();
                }
            });
        }
Exemple #12
0
        /// <summary>
        /// 添加一个场景窗口
        /// </summary>
        /// <param name="id"></param>
        /// <param name="preloadList"></param>
        /// <param name="luaWindowClass"></param>
        /// <param name="progressCallback"></param>
        /// <param name="isCahce"></param>
        public void AddWindow(string id, string abName, string assetName, string[] preloadList, bool isModal, LuaTable luaWindowClass,
                              LuaFunction progressCallback, bool isClickExit, bool isCache = false)
        {
            if (this.CurrScene == null)
            {
                DebugManager.LogError("AddPopup Error:当前没有可用的场景!");

                return;
            }

            this.CurrScene.AddWindow(id, abName, assetName, preloadList, isModal, isCache, isClickExit, delegate(BaseWindow window) {
                LuaComponent luaComponent = window.UiRoot.gameObject.AddComponent <LuaComponent>();
                luaComponent.New(luaWindowClass, window);

                if (progressCallback != null)
                {
                    progressCallback.Call();
                }
            }, delegate(int count, int total) {
            });
        }
Exemple #13
0
        /// <summary>
        /// 添加打入Lua代码的AssetBundle
        /// </summary>
        /// <param name="bundle"></param>
        public void AddBundle(string path, string bundleName)
        {
            AssetBundle bundle = null;

            if (Application.platform == RuntimePlatform.Android)
            {
                if (path.StartsWith("file://"))
                {
                    path = path.Replace("file://", string.Empty);
                }

                bundle = AssetBundle.LoadFromFile(path);
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                if (path.StartsWith("file://"))
                {
                    path = path.Replace("file://", string.Empty);
                }

                bundle = AssetBundle.LoadFromFile(path);
            }
            else
            {
                if (File.Exists(path) == true)
                {
                    bundle = AssetBundle.LoadFromMemory(File.ReadAllBytes(path));
                }
            }

            if (bundle != null)
            {
                base.AddSearchBundle(bundleName.ToLower(), bundle);
            }
            else
            {
                DebugManager.LogError("AddSearchBundle Error:" + path + "," + bundleName);
            }
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="parent"></param>
        /// <param name="abName"></param>
        /// <param name="assetName"></param>
        /// <param name="callback"></param>
        public void NewSpineAni(string viewId, GameObject parent, string abName, string assetName, LuaFunction callback, string actionName = "", bool isLoop = true)
        {
            ResourceManager.Instance.LoadPrefabAsync(viewId, abName, delegate(AssetBundle assetBundle)
            {
                if (assetBundle == null)
                {
                    DebugManager.LogError("NewSpineAni Error:下载资源失败!" + abName + "," + assetName);
                    return;
                }

                //foreach (UnityEngine.Object obj in assetBundle.LoadAllAssets()) {
                //    DebugManager.Log(obj.name);
                //}

                SkeletonAnimation animation = createSpineAni(parent, assetBundle, assetName, actionName, isLoop);

                if (callback != null)
                {
                    callback.Call(animation);
                    callback.Dispose();
                }
            });
        }
Exemple #15
0
        IEnumerator DoRegisterPB(LuaFunction processCallback, LuaFunction completeCallback)
        {
            string configFilePath = "";
            string pbDir          = "";

            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                pbDir = FileUtil.Instance.GetWritePath("protobuf/");
            }
            else
            {
                pbDir = FileUtil.Instance.GetAssetsPath("GameApp/Protobuf/").Replace("file://", "");
            }

            configFilePath = pbDir + "proto.config";

            Debugger.Log(configFilePath);

            string configFileStr = "";

            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                WWW www = new WWW(configFilePath);

                yield return(www);

                if (www.isDone)
                {
                    configFileStr = www.text;

                    yield return(0);
                }
                else
                {
                    DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath);
                }

                www.Dispose();
            }
            else
            {
                if (File.Exists(configFilePath) == true)
                {
                    try
                    {
                        configFileStr = File.ReadAllText(configFilePath);
                    }
                    catch (Exception e)
                    {
                        DebugManager.LogError("DoRegisterPB Error:读取配置文件错误!" + e.Message);

                        yield break;
                    }
                }
                else
                {
                    DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + configFilePath);
                }
            }

            DebugManager.Log("configFileStr:" + configFileStr);

            string[] pClassCommandList = configFileStr.Split(',');

            string fpath = pbDir + "message.pb";

            DebugManager.Log("读取注册PB文件:" + fpath);

            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                WWW www = new WWW(fpath);

                yield return(www);

                if (www.isDone)
                {
                    ByteBuffer data = new ByteBuffer(www.bytes);

                    processCallback.Call(data);
                    data.Close();

                    yield return(0);
                }
                else
                {
                    DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath);
                }

                www.Dispose();
            }
            else
            {
                try
                {
                    ByteBuffer data = new ByteBuffer(File.ReadAllBytes(fpath));
                    processCallback.Call(data);
                    data.Close();
                }
                catch (Exception e)
                {
                    DebugManager.LogError("DoRegisterPB Error:读取文件错误!" + fpath + "\n error:\n" + e.Message);
                }
            }

            completeCallback.Call(pClassCommandList);
            completeCallback.Dispose();

            processCallback.Dispose();
        }
Exemple #16
0
        /// <summary>
        /// 添加控件事件
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="eventId"></param>
        /// <param name="target"></param>
        /// <param name="callback"></param>
        public void AddEvent(string viewId, int eventId, Transform target, LuaFunction callback, string fullEventId = null)
        {
            if (target == null || callback == null)
            {
                DebugManager.LogError("AddEvent Error:target or callback is null!" + viewId + "," + eventId);

                return;
            }

            Dictionary <string, EventData> viewEventList = null;

            this._eventList.TryGetValue(viewId, out viewEventList);

            if (viewEventList == null)
            {
                viewEventList = new Dictionary <string, EventData>();
                this._eventList.Add(viewId, viewEventList);
            }

            if (fullEventId == null)
            {
                fullEventId = viewId + "_" + target.name + "_" + eventId.ToString();
            }

            EventData eventData = new EventData();

            eventData.obj     = target.gameObject;
            eventData.luaFunc = callback;

            if (viewEventList.ContainsKey(fullEventId) == true)
            {
                DebugManager.LogError("AddEvent Error:重复的事件ID注册!" + fullEventId);

                return;
            }

            viewEventList.Add(fullEventId, eventData);

            switch (eventId)
            {
            case 1:
                //click事件
                Button btn = target.GetComponent <Button>();

                if (btn == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加Button组件!" + target.name);
                    return;
                }

                btn.onClick.AddListener(
                    delegate()
                {
                    callback.Call(target);
                });
                break;

            case 2:
                //Scroll OnValueChanged
                ScrollRect scrollRect = target.GetComponent <ScrollRect>();

                if (scrollRect == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加ScrollRect组件!" + target.name);
                    return;
                }

                scrollRect.onValueChanged.AddListener(
                    delegate(Vector2 v)
                {
                    callback.Call(target, v);
                });

                break;

            case 3:

                Toggle toggle = target.GetComponent <Toggle>();

                if (toggle == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加Toggle组件!" + target.name);
                    return;
                }

                toggle.onValueChanged.AddListener(
                    delegate(bool check)
                {
                    callback.Call(target, check);
                }
                    );

                break;

            case 4:

                Slider slider = target.GetComponent <Slider>();

                if (slider == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加Slider组件!" + target.name);
                    return;
                }

                slider.onValueChanged.AddListener(
                    delegate(float v)
                {
                    callback.Call(target, v);
                }
                    );

                break;

            case 5:

                //SkeletonGraphic skeleton = target.GetComponent<SkeletonGraphic>();

                //if (skeleton == null)
                //{
                //    DebugManager.Instance.LogError("AddEvent Error:对象没有添加SkeletonGraphic组件!"+ target.name);

                //    return;
                //}

                //skeleton.AnimationState.Event += delegate (Spine.TrackEntry trackEntry, Spine.Event e)
                //{
                //    callback.Call(target, e.Data.Name);
                //};

                //skeleton.AnimationState.Complete += delegate (Spine.TrackEntry trackEntry)
                //{
                //    callback.Call(target, "End");
                //};

                break;

            case 6:
                break;

            case 7:

                InputField field = target.GetComponent <InputField>();

                if (field == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加InputField组件!" + target.name);

                    return;
                }

                field.onEndEdit.AddListener(delegate(string txt) {
                    callback.Call(target, txt);
                });

                break;

            case 8:

                InputField field1 = target.GetComponent <InputField>();

                if (field1 == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加InputField组件!" + target.name);

                    return;
                }

                field1.onValueChanged.AddListener(delegate(string txt) {
                    callback.Call(target, txt);
                });

                break;

            case 9:

                Dropdown dropdown = target.GetComponent <Dropdown>();

                if (dropdown == null)
                {
                    DebugManager.LogError("AddEvent Error:对象没有添加Dropdown组件!" + target.name);

                    return;
                }

                dropdown.onValueChanged.AddListener(delegate(int v) {
                    callback.Call(target, v);
                });

                break;
            }
        }
Exemple #17
0
        /// <summary>
        /// 移除控件事件
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="eventId"></param>
        /// <param name="target"></param>
        public void RemoveEvent(string viewId, int eventId, Transform target, string fullEventId = null)
        {
            if (target == null)
            {
                DebugManager.LogError("RemoveEvent Error:target is null!");

                return;
            }

            Dictionary <string, EventData> viewEventList = null;

            this._eventList.TryGetValue(viewId, out viewEventList);

            if (fullEventId == null)
            {
                fullEventId = viewId + "_" + target.name + "_" + eventId.ToString();
            }

            if (viewEventList != null && viewEventList.ContainsKey(fullEventId) == true)
            {
                switch (eventId)
                {
                case 1:
                    //click事件
                    target.GetComponent <Button>().onClick.RemoveAllListeners();
                    break;

                case 2:
                    //Scroll OnValueChanged
                    target.GetComponent <ScrollRect>().onValueChanged.RemoveAllListeners();
                    break;

                case 3:

                    target.GetComponent <Toggle>().onValueChanged.RemoveAllListeners();
                    break;

                case 4:

                    target.GetComponent <Slider>().onValueChanged.RemoveAllListeners();
                    break;

                case 5:
                    break;

                case 6:
                    break;

                case 7:

                    target.GetComponent <InputField>().onEndEdit.RemoveAllListeners();
                    break;

                case 8:

                    target.GetComponent <InputField>().onValueChanged.RemoveAllListeners();
                    break;

                case 9:

                    target.GetComponent <Dropdown>().onValueChanged.RemoveAllListeners();
                    break;
                }

                EventData eventData = viewEventList[fullEventId];
                eventData.obj = null;

                if (eventData.luaFunc != null)
                {
                    //eventData.luaFunc.Dispose();
                    eventData.luaFunc = null;
                }

                viewEventList.Remove(fullEventId);
            }
        }