Ejemplo n.º 1
0
 /// <summary>
 /// 增加Web请求任务(可等待)
 /// </summary>
 public static Task <byte[]> AwaitAddWebRequest(this WebRequestComponent webRequestComponent, string webRequestUri, byte[] postData = null)
 {
     m_WebRequestTcs      = new TaskCompletionSource <byte[]>();
     m_WebRequestSerialId = webRequestComponent.AddWebRequest(webRequestUri, postData);
     GameEntry.Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
     GameEntry.Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
     return(m_WebRequestTcs.Task);
 }
Ejemplo n.º 2
0
    public void OnNet2Click()
    {
        // 开了代理会失败!
        WebRequestComponent WebRequest = GameEntry.GetComponent <WebRequestComponent>();
        string   url  = "http://localhost:18810/";
        JsonData data = new JsonData();

        data["UserName"] = "******";
        byte[]  postBytes = System.Text.Encoding.UTF8.GetBytes(data.ToJson());
        WWWForm Form      = new WWWForm();

        WebRequest.AddWebRequest(url, postBytes, Form, 1, this);
    }
Ejemplo n.º 3
0
        public static void InitializationExtension(this WebRequestComponent webRequestComponent)
        {
            EventComponent eventComponent = GameEntry.GetComponent <EventComponent>();

            if (eventComponent == null)
            {
                Log.Fatal("Event component is invalid.");
                return;
            }

            eventComponent.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
            eventComponent.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
            eventComponent.Subscribe(WebRequestStartEventArgs.EventId, OnWebRequestStart);
        }
Ejemplo n.º 4
0
    protected void Get()
    {
        EventComponent      EventComment = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent>();
        WebRequestComponent webRequest   = UnityGameFramework.Runtime.GameEntry.GetComponent <WebRequestComponent>();

        EventComment.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess); //成功返回数据
        EventComment.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestFailure); //失败返回数据

        WWWForm wwwForm = new WWWForm();

        wwwForm.AddField("username", _NameInp.text);
        wwwForm.AddField("password", _PasswordInp.text);
        string uri = "http://117.78.60.124:8081/security/login";//请求数据地址

        webRequest.AddWebRequest(uri, wwwForm);
    }
Ejemplo n.º 5
0
    protected internal override void OnEnter(IFsm <IProcedureManager> procedureOwner)
    {
        base.OnEnter(procedureOwner);

        // 获取框架事件组件
        EventComponent Event
            = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent>();

        Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
        Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
        // 获取框架网络组件
        WebRequestComponent WebRequest
            = UnityGameFramework.Runtime.GameEntry.GetComponent <WebRequestComponent>();
        string url = "http://gameframework.cn/starforce/version.txt";

        WebRequest.AddWebRequest(url, this);
    }
Ejemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            WebRequestComponent t = target as WebRequestComponent;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                EditorGUILayout.PropertyField(m_InstanceRoot);
                m_WebRequestAgentHelperInfo.Draw();
                m_WebRequestAgentHelperCount.intValue = EditorGUILayout.IntSlider("Web Request Agent Helper Count", m_WebRequestAgentHelperCount.intValue, 1, 16);
            }
            EditorGUI.EndDisabledGroup();

            //超时时间
            float timeout = EditorGUILayout.Slider("Timeout", m_Timeout.floatValue, 0f, 120f);

            if (timeout != m_Timeout.floatValue)
            {
                if (EditorApplication.isPlaying)
                {
                    t.Timeout = timeout;
                }
                else
                {
                    m_Timeout.floatValue = timeout;
                }
            }

            //运行时显示一些信息
            if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
            {
                EditorGUILayout.LabelField("Total Agent Count", t.TotalAgentCount.ToString());
                EditorGUILayout.LabelField("Free Agent Count", t.FreeAgentCount.ToString());
                EditorGUILayout.LabelField("Working Agent Count", t.WorkingAgentCount.ToString());
                EditorGUILayout.LabelField("Waiting Agent Count", t.WaitingTaskCount.ToString());
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
 private static void InitBuiltinComponents()
 {
     Base         = UnityGameFramework.Runtime.GameEntry.GetComponent <BaseComponent>();
     DataNode     = UnityGameFramework.Runtime.GameEntry.GetComponent <DataNodeComponent>();
     DataTable    = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>();
     Debugger     = UnityGameFramework.Runtime.GameEntry.GetComponent <DebuggerComponent>();
     Download     = UnityGameFramework.Runtime.GameEntry.GetComponent <DownloadComponent>();
     Entity       = UnityGameFramework.Runtime.GameEntry.GetComponent <EntityComponent>();
     Event        = UnityGameFramework.Runtime.GameEntry.GetComponent <EventComponent>();
     Fsm          = UnityGameFramework.Runtime.GameEntry.GetComponent <FsmComponent>();
     Localization = UnityGameFramework.Runtime.GameEntry.GetComponent <LocalizationComponent>();
     Network      = UnityGameFramework.Runtime.GameEntry.GetComponent <NetworkComponent>();
     ObjectPool   = UnityGameFramework.Runtime.GameEntry.GetComponent <ObjectPoolComponent>();
     Procedure    = UnityGameFramework.Runtime.GameEntry.GetComponent <ProcedureComponent>();
     Resource     = UnityGameFramework.Runtime.GameEntry.GetComponent <ResourceComponent>();
     Scene        = UnityGameFramework.Runtime.GameEntry.GetComponent <SceneComponent>();
     Setting      = UnityGameFramework.Runtime.GameEntry.GetComponent <SettingComponent>();
     Sound        = UnityGameFramework.Runtime.GameEntry.GetComponent <SoundComponent>();
     UI           = UnityGameFramework.Runtime.GameEntry.GetComponent <UIComponent>();
     WebRequest   = UnityGameFramework.Runtime.GameEntry.GetComponent <WebRequestComponent>();
 }
Ejemplo n.º 8
0
 void InitBuildComponents()
 {
     Base         = GameEntry.GetComponent <BaseComponent>();
     Config       = GameEntry.GetComponent <ConfigComponent>();
     DataNode     = GameEntry.GetComponent <DataNodeComponent>();
     DataTable    = GameEntry.GetComponent <DataTableComponent>();
     Debugger     = GameEntry.GetComponent <DebuggerComponent>();
     Download     = GameEntry.GetComponent <DownloadComponent>();
     Entity       = GameEntry.GetComponent <EntityComponent>();
     Event        = GameEntry.GetComponent <EventComponent>();
     Fsm          = GameEntry.GetComponent <FsmComponent>();
     Localization = GameEntry.GetComponent <LocalizationComponent>();
     Network      = GameEntry.GetComponent <NetworkComponent>();
     ObjectPool   = GameEntry.GetComponent <ObjectPoolComponent>();
     Procedure    = GameEntry.GetComponent <ProcedureComponent>();
     Resource     = GameEntry.GetComponent <ResourceComponent>();
     Scene        = GameEntry.GetComponent <SceneComponent>();
     Setting      = GameEntry.GetComponent <SettingComponent>();
     Sound        = GameEntry.GetComponent <SoundComponent>();
     UI           = GameEntry.GetComponent <UIComponent>();
     WebRequest   = GameEntry.GetComponent <WebRequestComponent>();
 }
Ejemplo n.º 9
0
        protected override void Awake()
        {
            base.Awake();
            m_WebRequestMethods = CentorPivot.This.GetComponent <WebRequestComponent>();
            if (m_WebRequestMethods == null)
            {
                Log.Fatal("Web request manager is invalid.");
                return;
            }

            m_WebRequestMethods.Timeout = m_Timeout;

            if (EventComponent.This == null)
            {
                Log.Fatal("Event component is invalid.");
                return;
            }

            for (int i = 0; i < m_WebRequestAgentHelperCount; i++)
            {
                AddWebRequestAgentHelper();
            }
        }
Ejemplo n.º 10
0
 public static int Post(this WebRequestComponent web, string url, byte[] datas, object userData)
 {
     return(web.AddWebRequest(url, datas, userData));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 增加Web请求任务(可等待)
 /// </summary>
 public static Task <byte[]> AwaitAddWebRequest(this WebRequestComponent self, string webRequestUri, byte[] postData = null)
 {
     s_WebRequestTcs      = new TaskCompletionSource <byte[]>();
     s_WebRequestSerialId = self.AddWebRequest(webRequestUri, postData);
     return(s_WebRequestTcs.Task);
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            WebRequestComponent t = (WebRequestComponent)target;

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
            {
                EditorGUILayout.PropertyField(m_InstanceRoot);

                m_WebRequestAgentHelperInfo.Draw();

                m_WebRequestAgentHelperCount.intValue = EditorGUILayout.IntSlider("Web Request Agent Helper Count", m_WebRequestAgentHelperCount.intValue, 1, 16);
            }
            EditorGUI.EndDisabledGroup();

            float timeout = EditorGUILayout.Slider("Timeout", m_Timeout.floatValue, 0f, 120f);

            if (timeout != m_Timeout.floatValue)
            {
                if (EditorApplication.isPlaying)
                {
                    t.Timeout = timeout;
                }
                else
                {
                    m_Timeout.floatValue = timeout;
                }
            }

            if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
            {
                EditorGUILayout.LabelField("Total Agent Count", t.TotalAgentCount.ToString());
                EditorGUILayout.LabelField("Free Agent Count", t.FreeAgentCount.ToString());
                EditorGUILayout.LabelField("Working Agent Count", t.WorkingAgentCount.ToString());
                EditorGUILayout.LabelField("Waiting Agent Count", t.WaitingTaskCount.ToString());
                EditorGUILayout.BeginVertical("box");
                {
                    TaskInfo[] webRequestInfos = t.GetAllWebRequestInfos();
                    if (webRequestInfos.Length > 0)
                    {
                        foreach (TaskInfo webRequestInfo in webRequestInfos)
                        {
                            DrawWebRequestInfo(webRequestInfo);
                        }

                        if (GUILayout.Button("Export CSV Data"))
                        {
                            string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, "WebRequest Task Data.csv", string.Empty);
                            if (!string.IsNullOrEmpty(exportFileName))
                            {
                                try
                                {
                                    int      index = 0;
                                    string[] data  = new string[webRequestInfos.Length + 1];
                                    data[index++] = "WebRequest Uri,Serial Id,Tag,Priority,Status";
                                    foreach (TaskInfo webRequestInfo in webRequestInfos)
                                    {
                                        data[index++] = Utility.Text.Format("{0},{1},{2},{3},{4}", webRequestInfo.Description, webRequestInfo.SerialId, webRequestInfo.Tag ?? string.Empty, webRequestInfo.Priority, webRequestInfo.Status);
                                    }

                                    File.WriteAllLines(exportFileName, data, Encoding.UTF8);
                                    Debug.Log(Utility.Text.Format("Export web request task CSV data to '{0}' success.", exportFileName));
                                }
                                catch (Exception exception)
                                {
                                    Debug.LogError(Utility.Text.Format("Export web request task CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception));
                                }
                            }
                        }
                    }
                    else
                    {
                        GUILayout.Label("WebRequset Task is Empty ...");
                    }
                }
                EditorGUILayout.EndVertical();
            }

            serializedObject.ApplyModifiedProperties();

            Repaint();
        }
Ejemplo n.º 13
0
 public static int Get(this WebRequestComponent web, string url, object userData)
 {
     return(web.AddWebRequest(url, userData));
 }
Ejemplo n.º 14
0
 public static int Post(this WebRequestComponent web, string url, WWWForm form)
 {
     return(web.AddWebRequest(url, form));
 }
Ejemplo n.º 15
0
 public static int Get(this WebRequestComponent web, string url)
 {
     return(web.AddWebRequest(url));
 }
Ejemplo n.º 16
0
 public static int Post(this WebRequestComponent web, string url, WWWForm form, object userData)
 {
     return(web.AddWebRequest(url, form, userData));
 }
Ejemplo n.º 17
0
 public static int Post(this WebRequestComponent web, string url, byte[] datas)
 {
     return(web.AddWebRequest(url, datas));
 }