static void Main(string[] args) { // Instantiate the delegate for an int return and a string parameter. // Point to a method, AMethod, that matches that signature. MyAction<int, string> act = new MyAction<int, string>(Program.AMethod); // Invoke the delegate with an argument of the appropriate type. int result = act("antidisestablishmentarianism"); Console.WriteLine("Length of word is {0}", result); // Instantiate the delegate for a Student return and a string parameter. // Point to a method, Method2, with that signature (note the alternative // way to specify the method (in boldface) - much more convenient). MyAction<Student, string> act2 = Program.Method2; // Invoke the delegate. Student aStudent = act2("Marco"); Console.WriteLine("Student's name is {0}", aStudent.Name); // Invoke the delegate using an anonymous method. MyAction<int, int> act3 = delegate(int param) { return param; }; Console.WriteLine("Result is {0}", act3(4)); // Call a method that takes a MyAction<string, int> delegate. // Pass a lambda expression (Chapter 16) for the delegate. string name = GetNumberName(4, (n) => "four" ); Console.WriteLine("Number name for number 4 = {0}", name); // Wait for user to acknowledge results. Console.WriteLine("Press Enter to terminate..."); Console.Read(); }
public void Query(Vector3 pos, float range, MyAction<float, KdTreeObject> visitor) { if (null != m_KdTree && m_ObjectNum > 0 && m_KdTree.Length > 0) { float rangeSq = Sqr(range); QueryImpl(pos, range, rangeSq, (float distSqr, KdTreeObject obj) => { visitor(distSqr, obj); return true; }); } }
//Ray ray; //RaycastHit hit ; // Use this for initialization void Action(MyAction action) { if (StartTag == action.Tag) { print("ChangeGameState"); GameState.ChangeGameState(NextStateTransform); } }
// Update is called once per frame void Update() { if(!IsStart){ return; } if(Vector3.SqrMagnitude(MainCameraTransform.position - CameraPosition.position) > 0.01f){ MainCameraTransform.position = Vector3.MoveTowards(MainCameraTransform.position,CameraPosition.position,MoveIndex * Time.deltaTime); if(RotateIndex != 0.0f){ MainCameraTransform.rotation = Quaternion.RotateTowards(MainCameraTransform.rotation,CameraPosition.rotation,RotateIndex * Time.deltaTime); } }else{ MainCameraTransform.position = CameraPosition.position; MainCameraTransform.rotation = CameraPosition.rotation; if(EndActionTag >= 0){ MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; transform.root.BroadcastMessage(MyAction.ActionString,tempaction); } } if(LookAtTransform){ MainCameraTransform.LookAt(LookAtTransform); } }
// Update is called once per frame void Update() { // if(!IsInit){ // IsInit = true; // ToAngle = Quaternion.Euler(MyRotateAngle); // RotateIndex = Quaternion.Angle(RotateTransform.rotation,ToAngle) / MyRotateTime; // if(RotateIndex == 0.0f){ // return; // } // //print ("Quaternion.Angle(RotateTransform.rotation,ToAngle) = " + Quaternion.Angle(RotateTransform.rotation,ToAngle)); // //print ("RotateIndex = " + RotateIndex); // } if(!IsRotateOK){ RotateTransform.rotation = Quaternion.RotateTowards(RotateTransform.rotation,ToAngle,Time.deltaTime * RotateIndex); //print("RotateTransform.rotation = " + RotateTransform.rotation); if(Quaternion.Angle(RotateTransform.rotation,ToAngle) < 0.1f){ IsRotateOK = true; if(EndActionTag >= 0){ MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; BroadcastMessage(MyAction.ActionString,tempaction); } } } }
void Action(MyAction action) { if (StartActionTag == action.Tag) { MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; BroadcastMessage(MyAction.ActionString,tempaction); } }
void OnEnable() { if(ActionStart == ActionEvent.WhenOn){ MyAction tempaction = new MyAction(); tempaction.Tag = StartActionTag; Action(tempaction); } }
void OnEnable() { if (MyEvent == ActionEvent.WhenOn) { // BroadcastMessage (SetEnable, true); MyAction tempaction = new MyAction(); tempaction.Tag = StartActionTag; Action(tempaction); } }
void OnEnable() { IsRotateOK = true; if(MyActionEvent == ActionEvent.WhenOn){ MyAction tempaction = new MyAction(); tempaction.Tag = StartActionTag; Action(tempaction); } }
void Action(MyAction action) { if(StartActionTag == action.Tag){ IsRotateOK = false; OriginalQuaternion = RotateTransform.rotation; ToAngle = Quaternion.Euler(MyRotateAngle); RotateIndex = Quaternion.Angle(RotateTransform.rotation,ToAngle) / MyRotateTime; } }
void Action(MyAction action) { if (StartActionTag == action.Tag) { MainCamera = Camera.main; MainCameraTransform = MainCamera.transform; MoveIndex = Vector3.Magnitude(MainCameraTransform.position - CameraPosition.position) / AnimationTime; RotateIndex = Quaternion.Angle(MainCameraTransform.rotation,CameraPosition.rotation) / AnimationTime; IsStart = true; } }
void Action(MyAction action) { if (StartActionTag == action.Tag) { print("DisableCollider"); if(EndActionTag >= 0){ MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; BroadcastMessage (MyAction.ActionString, tempaction); } } }
void Action(MyAction action) { if (action.Tag == StartActionTag) { print("SetCollider = " + MyCollider.name); MyCollider.GetComponent<Collider> ().enabled = isEnableCollider; if(EndActionTag >= 0){ MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; BroadcastMessage (MyAction.ActionString, tempaction); } } }
public static void RunWithTempFiles (MyAction<string,string> action) { var file1 = Path.GetTempFileName (); var file2 = Path.GetTempFileName (); try { File.Delete (file1); File.Delete (file2); action (file1, file2); } finally { if (File.Exists (file1)) File.Delete (file1); if (File.Exists (file2)) File.Delete (file2); } }
// Update is called once per frame void Update() { #if UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { print ("HitTransform = " + HitTransform.name); ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast (ray, out hit,Mathf.Infinity,IngnoreLayerShift) && hit.transform == HitTransform) { MyAction tempaction = new MyAction(); tempaction.Tag = EndActionTag; //if there is switch function if(IsSwitch){ NowSwitch = !NowSwitch; if(NowSwitch){ // BroadcastMessage(ClickedOn,SendMessageOptions.DontRequireReceiver); tempaction.Message = "on"; }else{ tempaction.Message = "off"; // BroadcastMessage(ClickedOff,SendMessageOptions.DontRequireReceiver); } }else{ tempaction.Message = "on"; // BroadcastMessage(ClickedOn,SendMessageOptions.DontRequireReceiver); } BroadcastMessage(MyAction.ActionString,tempaction); } } #else foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { ray = Camera.main.ScreenPointToRay(touch.position); if (Physics.Raycast (ray, out hit) && hit.transform == HitTransform) { // GameState.ChangeGameState(NextStateTransform); } } } #endif }
internal void ActiveRoom(int roomid, int sceneId, MyAction<bool> callbackOnFinish) { LogSys.Log(LOG_TYPE.INFO, "[0] active room {0} scene {1} thread {2}", roomid, sceneId, cur_thread_id_); Room rm = room_pool_.NewRoom(); if (null == rm) { //���ڲ���ԭ���п���lobby�����̻߳���һЩ���伤� //����ͨ��Ԥ��һ�������ķ����������������η����ĸ��ʡ� Interlocked.Decrement(ref preactive_room_count_); if (null != callbackOnFinish) { callbackOnFinish(false); } LogSys.Log(LOG_TYPE.ERROR, "Failed active room {0} in thread {1}, preactive room count {2}", roomid, cur_thread_id_, preactive_room_count_); return; } LogSys.Log(LOG_TYPE.INFO, "[1] active room {0} scene {1} thread {2}", roomid, sceneId, cur_thread_id_); rm.ScenePool = scene_pool_; rm.Init(roomid, sceneId, user_pool_, connector_); LogSys.Log(LOG_TYPE.INFO, "[2] active room {0} scene {1} thread {2}", roomid, sceneId, cur_thread_id_); /* //��ʱ��Ӳ��Թ۲��� for (int obIx = 0; obIx < 5; ++obIx) { uint key = 0xf0000000 + (uint)((roomid << 4) + obIx); string observerName = "Observer_" + key; if (rm.AddObserver(key, observerName, key)) { LogSys.Log(LOG_TYPE.DEBUG, "Add room observer successed, guid:{0} name:{1} key:{2}", key, observerName, key); } else { LogSys.Log(LOG_TYPE.DEBUG, "Add room observer failed, guid:{0} name:{1} key:{2}", key, observerName, key); } } */ //����ȫ����ɺ��ټӵ�������б����ʼtick active_room_.Add(rm); Interlocked.Decrement(ref preactive_room_count_); if (null != callbackOnFinish) { callbackOnFinish(true); } LogSys.Log(LOG_TYPE.DEBUG, "active room {0} in thread {1}, preactive room count {2}", roomid, cur_thread_id_, preactive_room_count_); }
public void QueueAction <T1, T2, T3, T4, T5, T6, T7, T8, T9>(MyAction <T1, T2, T3, T4, T5, T6, T7, T8, T9> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { m_ActionQueue.QueueAction(action, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
void QueueAction(MyAction action, bool unique) { bool start; lock (lockObj) { if (unique) { for (int i = 0; i < actions.Count; i++) { if (actions[i].GetType() == action.GetType()) { actions.RemoveAt(i); break; } } } actions.Add(action); start = actions.Count == 1; } if (start) dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(EmptyQueue)); }
public void QueueAction(MyAction action) { m_Actions.Enqueue(action); }
public void Query(EntityInfo obj, float range, MyAction<float, KdTreeObject> visitor) { Query(obj.GetMovementStateInfo().GetPosition3D(), range, visitor); }
private void txTotal_TextChanged(object sender, EventArgs e) { slbTotal.Text = MyAction.FormatMoney(txTotal.Text); }
public void VisitObjectInShape(Vector3 pos, float direction, Shape area, MyAction <float, ISpaceObject> visitor) { area.Transform(pos, (float)Math.Cos(direction), (float)Math.Sin(direction)); VisitObjectInArea(area, visitor); }
public void VisitTree(MyAction<float, float, float, float, int, int, KdTreeObject[]> visitor) { VisitTree((float minx, float minz, float maxx, float maxz, int begin, int end, KdTreeObject[] objs) => { visitor(minx, minz, maxx, maxz, begin, end, objs); return true; }); }
void Action(MyAction action) { if (StartActionTag == action.Tag) { SoundTransform.BroadcastMessage(SoundOn); } }
/// <summary> /// 当所有内容加载完以后的回调,告诉外部,全部加载完了 /// </summary> /// <param name="action"></param> public void doComplate(MyAction action) { LoadFactory.loadAllComplate = action; }
// GetNumberName - Given a number and a delegate, carries out the delegate // action on the number and returns the result as a string. static string GetNumberName(int number, MyAction<string, int> act) { return act(number); }
internal void RemoveUser(ulong guid, int roomId, bool free, MyAction<bool, int, User> callbackOnFinish) { RemoveUser(new ulong[] { guid }, roomId, free, (bool ret, int sceneId, IList<User> users) => { if(users.Count>0) callbackOnFinish(ret, sceneId, users[0]); else callbackOnFinish(ret, sceneId, null); }); }
internal void RemoveUser(IList<ulong> guids, int roomId, bool free, MyAction<bool, int, IList<User>> callbackOnFinish) { Room room = GetRoomByID(roomId); if (null != room) { List<User> users = new List<User>(); for (int i = 0; i < guids.Count; ++i) { User user = room.GetUserByGuid(guids[i]); if (null != user) { room.RemoveUserFromRoomThread(user, free); users.Add(user); } } if (null != callbackOnFinish) { int sceneId = 0; Scene scene = room.ActiveScene; if (null != scene) { sceneId = scene.SceneResId; } callbackOnFinish(true, sceneId, users); return; } } if (null != callbackOnFinish) { callbackOnFinish(false, -1, null); } }
internal void ChangeRoomScene(int roomid, int sceneId, MyAction<bool> callbackOnFinish) { Room room = GetRoomByID(roomid); if (null != room) { room.ChangeScene(sceneId); if (null != callbackOnFinish) { callbackOnFinish(true); return; } } if (null != callbackOnFinish) { callbackOnFinish(false); } }
public void VisitCellsCrossByPolygon(IList <Vector3> pts, MyAction <int, int> visitor) { cell_manager_.VisitCellsCrossByPolygon(pts, visitor); }
//逻辑层与unity3d脚本交互函数 public static void QueueGfxAction(MyAction action) { s_Instance.m_GfxInvoker.QueueAction(action); }
public DelegateCommand(MyPredecate canExec, MyAction exec) { this.canExecute = canExec; this.execute = exec; }
public void Query(float x, float y, float z, float range, MyAction<float, KdTreeObject> visitor) { Query(new Vector3(x, y, z), range, visitor); }
public void TestDelegate() { MyAction <BaseClass> b = DelegateFunc01; }
internal void AddUser(IList<User> users, int roomId, MyAction<bool, int, IList<User>> callbackOnFinish) { Room room = GetRoomByID(roomId); if (null != room) { List<User> successUsers = new List<User>(); for (int i = 0; i < users.Count; ++i) { if (room.AddNewUser(users[i])) { successUsers.Add(users[i]); } } if (null != callbackOnFinish) { int sceneId = 0; Scene scene = room.ActiveScene; if (null != scene) { sceneId = scene.SceneResId; } callbackOnFinish(true, sceneId, successUsers); return; } } if (null != callbackOnFinish) { callbackOnFinish(false, -1, null); } }
public void QueueAction <T1>(MyAction <T1> action, T1 t1) { m_ActionQueue.QueueAction(action, t1); }
public void Init(MyAction action) { m_OnCommand = action; }
public void QueueAction <T1, T2, T3>(MyAction <T1, T2, T3> action, T1 t1, T2 t2, T3 t3) { m_ActionQueue.QueueAction(action, t1, t2, t3); }
public void OnAddedToShootStateInfo(MyAction <WeaponInfo> cb) { mStatusCB = cb; }
public void QueueAction <T1, T2, T3, T4, T5>(MyAction <T1, T2, T3, T4, T5> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { m_ActionQueue.QueueAction(action, t1, t2, t3, t4, t5); }
public void QueueAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(MyAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16) { bool needUseLambda = true; ObjectPool <PoolAllocatedAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> > pool; m_ActionPools.GetOrNewData(out pool); if (null != pool) { PoolAllocatedAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> helper = pool.Alloc(); if (null != helper) { helper.SetPoolRecycleLock(m_LockForAsyncActionRun); helper.Init(action, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16); m_Actions.Enqueue(helper.Run); needUseLambda = false; } } if (needUseLambda) { m_Actions.Enqueue(() => { action(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16); }); LogSystem.Warn("QueueAction {0}({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16}) use lambda expression, maybe out of memory.", action.Method.ToString(), t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16); } }
//-------------------------------------------------------------------------------------------------------------------------- //供外部直接调用的方法,需要保证多线程安全。 //-------------------------------------------------------------------------------------------------------------------------- internal void VisitUsers(MyAction<UserInfo> visitor) { foreach (KeyValuePair<ulong,UserInfo> pair in m_UserInfos) { UserInfo userInfo = pair.Value; visitor(userInfo); } }
public void SetAction(MyAction action) { clickAction = action; }
public void SetDispatcher(System.Windows.Threading.Dispatcher dispatcher) { this.BeginInvoke = action => dispatcher.BeginInvoke(action); }
public void VisitCellsCrossByLine(Vector3 start, Vector3 end, MyAction <int, int> visitor) { cell_manager_.VisitCellsCrossByLine(start, end, visitor); }
void Action(MyAction action) { if (StartActionTag == action.Tag) { transform.root.BroadcastMessage("ChangeState",toInState); } }
public void VisitCellsCrossByCircle(Vector3 center, float radius, MyAction <int, int> visitor) { cell_manager_.VisitCellsCrossByCircle(center, radius, visitor); }
internal void QueueAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(MyAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) { QueueActionWithDelegation(action, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11); }
new = RoutedUICommand(nameof(MyAction), nameof(MyAction), typeof(MyCustomCommands));
internal void QueueAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(MyAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16) { QueueActionWithDelegation(action, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16); }
public void QueueAction(MyAction action) { m_ActionQueue.QueueAction(action); }
//事件注册,事件处理会通过IActionQueue在游戏逻辑线程处理(仅在初始化时调用【第一次tick前】) public static void ListenKeyboardEvent(Keyboard.Code c, MyAction <int, int> handler) { s_Instance.ListenKeyboardEventImpl(c, handler); }
public void QueueAction <T1, T2>(MyAction <T1, T2> action, T1 t1, T2 t2) { m_ActionQueue.QueueAction(action, t1, t2); }
public static void ListenMouseEvent(Mouse.Code c, MyAction <int, int> handler) { s_Instance.ListenMouseEventImpl(c, handler); }
public void QueueAction <T1, T2, T3, T4>(MyAction <T1, T2, T3, T4> action, T1 t1, T2 t2, T3 t3, T4 t4) { m_ActionQueue.QueueAction(action, t1, t2, t3, t4); }
public static void ListenTouchEvent(TouchEvent c, MyAction <int, GestureArgs> handler) { s_Instance.ListenTouchEventImpl(c, handler); }
public void QueueAction <T1, T2, T3, T4, T5, T6, T7>(MyAction <T1, T2, T3, T4, T5, T6, T7> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { m_ActionQueue.QueueAction(action, t1, t2, t3, t4, t5, t6, t7); }
//供逻辑线程调用的异步命令 public static void LoadScene(string sceneName, MyAction onFinish) { s_Instance.m_GfxInvoker.QueueAction(s_Instance.LoadSceneImpl, sceneName, onFinish); }
public void QueueAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(MyAction <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> action, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) { m_ActionQueue.QueueAction(action, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12); }
public static void SetLogicLogCallback(MyAction <string, object[]> callback) { s_Instance.SetLogicLogCallbackImpl(callback); }