public static bool sendEvent(EventConst eventID, object obj = null) { //if (!DebugEx.IsMainThread()) //{ // return false; //} List <EventWatcher> list = null; lock (lockEventMap) { if (!mapEventObject.ContainsKey(eventID)) { Log.i("EventCenter", "post event = " + eventID + ", no watcher."); return(false); } EventObject obj2 = mapEventObject[eventID]; list = new List <EventWatcher>(obj2.listEventWatcher); } BaseEventArgs evtArgs = new BaseEventArgs(eventID, obj); foreach (EventWatcher watcher in list) { watcher.doInvoke(evtArgs); } return(true); }
private void CalculateAimPosition() { float x_axis = input.GetAxis(RewiredConsts.Action.CameraHorizontal); float y_axis = input.GetAxis(RewiredConsts.Action.CameraVertical); pointerPosition += new Vector2( x_axis * mouseSensitivity, y_axis * mouseSensitivity); pointerPosition.x = Mathf.Clamp(pointerPosition.x, -Screen.width / 2, Screen.width / 2); pointerPosition.y = Mathf.Clamp(pointerPosition.y, -Screen.height / 2, Screen.height / 2); Transform cameraTr = Camera.main.transform; Vector3 forwardPosition = transform.position + cameraTr.forward * aimAheadDistance; Vector3 xyPosition = cameraTr.up * pointerPosition.y * offset + cameraTr.right * pointerPosition.x * offset; Vector3 worldPosition = forwardPosition + xyPosition; Vector2 uiPosition = Camera.main.WorldToScreenPoint(worldPosition); EventManager.Invoke <Vector3>(EventConst.GetUpdateWorldPosAim(player.ID), worldPosition); EventManager.Invoke <Vector2>(EventConst.GetUpdateUIPosAim(player.ID), uiPosition); if (debugAim != null) { debugAim.position = worldPosition; } }
void UpdateAimPosition() { LayerMask ignoreCollision = player.hitScanner.IgnoreCollisionLayerMask; Collider[] hit = Physics.OverlapSphere(transform.position, radius, ignoreCollision); currentTarget = null; for (int i = 0; i < hit.Length; i++) { if (hit[i] != collider) { currentTarget = hit[i]; break; } } Vector3 aimDesiredPosition; if (currentTarget == null) { aimDesiredPosition = transform.forward * radius; } else { aimDesiredPosition = currentTarget.transform.position; } currentAimPosition = Vector3.Lerp(currentAimPosition, aimDesiredPosition, reflexSpeed * Time.deltaTime); EventManager.Invoke <Vector3>(EventConst.GetUpdateWorldPosAim(player.ID), currentAimPosition); }
public static bool postEvent(EventConst eventID, object param1 = null, object param2 = null) { lock (lockEventMap) { if (!mapEventObject.ContainsKey(eventID)) { return(false); } EventObject obj2 = mapEventObject[eventID]; return(obj2.beginInvoke(new BaseEventArgs(eventID, param1, param2))); } }
public static void printfInfo() { lock (lockEventMap) { foreach (KeyValuePair <EventConst, EventObject> pair in mapEventObject) { EventConst key = pair.Key; EventObject obj2 = pair.Value; if (obj2 != null) { obj2.printInfo(); } } } }
private void InvokeEventIfNewTargetInSight() { if (scanHit.collider != null) { if (previousScanHit.collider == null) { EventManager.Invoke <bool>(EventConst.GetUpdateAimTargetInSight(player.ID), true); } } else { if (previousScanHit.collider != null) { EventManager.Invoke <bool>(EventConst.GetUpdateAimTargetInSight(player.ID), false); } } }
void Start() { rigidBody = GetComponent <Rigidbody>(); Player = GetComponent <Player>(); mousePos = new Vector2(0, 0); playerAim = GetComponent <PlayerAim>(); roll = 0; //Setting this equal to 0 here as a failsafe in case the roll axis is not set up. EventManager.Subscribe <Vector2>(EventConst.GetUpdateUIPosAim(Player.ID), (mPos) => UpdateCursorPosition(mPos)); if (Player.Type == PlayerType.HUMAN) { AkSoundEngine.PostEvent("Start", gameObject); } }
public static bool removeEventHandler(EventConst eventID, EventHandlerDelegate eventHandler) { lock (lockEventMap) { if ((eventHandler == null) || !mapEventObject.ContainsKey(eventID)) { Log.e("EventCenter", "remove event handler failed, eventid= " + eventID); return(false); } EventObject obj2 = mapEventObject[eventID]; bool flag = obj2.removeWatcher(eventHandler); if (obj2.getCount() == 0) { mapEventObject.Remove(eventID); } return(flag); } }
public static bool removeEventWatcher(EventConst eventID, string watchName) { lock (lockEventMap) { if (!mapEventObject.ContainsKey(eventID)) { Log.e("EventCenter", "remove event handler failed, eventid= " + eventID); return(false); } EventObject obj2 = mapEventObject[eventID]; bool flag = obj2.removeWatcher(watchName); if (obj2.getCount() == 0) { mapEventObject.Remove(eventID); } return(flag); } }
public static bool postCombineEvent(EventConst eventID, object obj) { lock (lockEventMap) { if (!mapEventObject.ContainsKey(eventID)) { return(false); } EventObject obj2 = mapEventObject[eventID]; if (obj2.args == null) { obj2.args = new BaseEventArgs(eventID, new List <object>()); //Deployment.get_Current().get_Dispatcher().BeginInvoke(new DispatcherEventDelegate(EventCenter.onDispatchEvent), new object[] { obj2 }); DispatcherEventDelegate dde = new DispatcherEventDelegate(EventCenter.onDispatchEvent); dde.BeginInvoke(obj2, null, null); } ((List <object>)obj2.args.mObject).Add(obj); return(true); } }
public static bool registerEventWatcher(EventConst eventID, EventWatcher eventWatcher) { if ((eventWatcher == null) || (eventWatcher.mHandler == null)) { Log.e("EventCenter", "register event id without watcher, ignored. eventid = " + eventID); return(false); } lock (lockEventMap) { EventObject obj2; if (mapEventObject.ContainsKey(eventID)) { obj2 = mapEventObject[eventID]; } else { obj2 = new EventObject(eventID); mapEventObject.Add(eventID, obj2); } return(obj2.addWatcher(eventWatcher)); } }
void SubscribeToEvents() { EventManager.Subscribe <GameFSMStates>(GameFSM.EVT_ON_CHANGE_GAME_STATE, (CurrentState) => { ToggleInGameUI(CurrentState == GameFSMStates.MAINMENU); }); EventManager.Subscribe <GameFSMStates>(GameFSM.EVT_ON_CHANGE_GAME_STATE, (CurrentState) => { ToggleInGameUI(CurrentState == GameFSMStates.GAMEOVER); }); EventManager.Subscribe <GameFSMStates>(GameFSM.EVT_ON_CHANGE_GAME_STATE, (CurrentState) => { ToggleInGameUI(CurrentState != GameFSMStates.MAINMENU || CurrentState != GameFSMStates.GAMEOVER); }); //0 for player ID EventManager.Subscribe <ObjectStats>(EventConst.GetUpdatePlayerStats(0), (currentStats) => ShowStats(currentStats)); EventManager.Subscribe <float>(EventConst.GetUpdatePlayerHealth(0), (health) => healthBar.UpdateFill(health)); EventManager.Subscribe <float>(EventConst.GetUpdatePlayerFuel(0), (fuel) => fuelBar.UpdateFill(fuel)); EventManager.Subscribe <Vector2>(EventConst.GetUpdateUIPosAim(0), (mPos) => UpdateCursorPosition(mPos)); EventManager.Subscribe <bool>(EventConst.GetUpdateAimTargetInSight(0), (isInSight) => UpdateTargetInSight(isInSight)); }
public EventObject(EventConst id) { this.mID = id; }
void InvokeFuelEvent() { EventManager.Invoke <float>(EventConst.GetUpdatePlayerFuel(player.ID), CurrentFuel / maxFuel); }
protected void Start() { IgnoreCollisionLayerMask = (1 << LayerMask.NameToLayer(layerMaskName)); EventManager.Subscribe <Vector3>(EventConst.GetUpdateWorldPosAim(player.ID), (aimPosition) => UpdateAimDirection(aimPosition)); }
public static bool registerEventHandler(EventConst eventID, EventHandlerDelegate eventHandler) { EventWatcher eventWatcher = new EventWatcher(null, null, eventHandler); return(registerEventWatcher(eventID, eventWatcher)); }
//void DestroyStickingObject(StickingObject stickingObject) //{ // if(this.stickingObject == stickingObject) // { // Debug.Log("I DIE OH NON"); // EventManager.Invoke<Player>(EVT_ON_PLAYER_DEATH,this); // gameObject.SetActive(false); // } //} public void OnDamage(float healthRatio) { Debug.Log(healthRatio); EventManager.Invoke <float>(EventConst.GetUpdatePlayerHealth(ID), healthRatio); }
void CalculatePlayerStats() { playerStats.Reset(); // stickingObject.RecrusiveCalculateStats(playerStats); EventManager.Invoke <ObjectStats>(EventConst.GetUpdatePlayerStats(ID), playerStats); }
public BaseEventArgs(EventConst id, object obj, object obj1) { this.mEventID = id; this.mObject = obj; this.mObject1 = obj1; }
public static bool registerEventWatcher(EventConst eventID, string watchName, EventHandlerDelegate eventHandler) { EventWatcher eventWatcher = new EventWatcher(watchName, eventHandler); return(registerEventWatcher(eventID, eventWatcher)); }