Invoke all registered callbacks (runtime and persistent).
void Start() { PlayerManager = PlayerManager.PM; UIManager = UIManager.UIM; OverworldCamera = GameObject.Find("Overworld Camera"); OverworldParent = GameObject.FindWithTag("OverworldParent"); initCharacters?.Invoke(); overworldLoaded?.Invoke(); }
IEnumerator SecondaryActionChecking(float delayInSeconds) { yield return(new WaitForSeconds(delayInSeconds)); if (secondaryCondition) { StartCoroutine(SecondaryActionValidation(validationDelay)); } else { onFailure.Invoke(); started = false; } }
IEnumerator SecondaryActionValidationAfterDelay(float delayInSeconds) { yield return(new WaitForSeconds(delayInSeconds)); if (secondaryCondition.Value == expectedValue) { onSuccess.Invoke(); } else { onFailure.Invoke(); } started = false; }
public virtual void GatherSuccess() { onGatherFinish?.Invoke(); GetComponent <Renderer>().enabled = false; GatherAble = false; if (GatheringInfo.ProductItems.Count > 0) { List <ItemInfo> lootItems = new List <ItemInfo>(); foreach (DropItemInfo di in GatheringInfo.ProductItems) { if (ZetanUtility.Probability(di.DropRate)) { if (!di.OnlyDropForQuest || (di.OnlyDropForQuest && QuestManager.Instance.HasOngoingQuestWithID(di.BindedQuest.ID))) { lootItems.Add(new ItemInfo(di.Item, Random.Range(1, di.Amount + 1))); } } } if (lootItems.Count > 0) { LootAgent la = ObjectPool.Get(GatheringInfo.LootPrefab).GetComponent <LootAgent>(); la.Init(lootItems, transform.position); } } StartCoroutine(UpdateTime()); }
public void OnHit(Vector3 hitPoint, Vector3 hitNormal) { var i = (int)limb; var w = (int)WeaponManager.CurrentWeapon; w = w < m_weaponMultipliers.Count && w >= 0 ? w : 0; float m = 1f, wm = 1f; if (LevelConditions.current) { if (LevelConditions.current.zombieAggression == LevelConditions.Difficulty.docile) { m = m_multipliers[i].x; wm = m_weaponMultipliers[w].x; } if (LevelConditions.current.zombieAggression == LevelConditions.Difficulty.agitated) { m = m_multipliers[i].y; wm = m_weaponMultipliers[w].y; } if (LevelConditions.current.zombieAggression == LevelConditions.Difficulty.crazed) { m = m_multipliers[i].z; wm = m_weaponMultipliers[w].z; } } var damageValue = wm * (m_values[i] * m); Instantiate(m_impactParticles, hitPoint, Quaternion.LookRotation(hitNormal, Vector3.up)); onHit?.Invoke((int)damageValue); }
private IEnumerator PluginsMessageRoutine(JsonObject jsonMsg) { // this is to avoid a deadlock for more info when trying to get data from two separate native plugins and handling them in Unity yield return(null); string msg = jsonMsg.GetString("msg"); if (msg.Equals(MSG_TEXT_CHANGE)) { string text = jsonMsg.GetString("text"); this.onTextChange(text); } else if (msg.Equals(MSG_TEXT_END_EDIT)) { string text = jsonMsg.GetString("text"); this.onTextEditEnd(text); } else if (msg.Equals(MSG_RETURN_PRESSED)) { if (returnPressed != null) { returnPressed(); } if (OnReturnPressed != null) { OnReturnPressed.Invoke(); } } }
public void OnHarvestSuccess() { onHarvestFinish?.Invoke(); HarvestAble = false; if (currentStage.ProductItems.Count > 0) { List <ItemInfo> lootItems = new List <ItemInfo>(); foreach (DropItemInfo di in currentStage.ProductItems) { if (ZetanUtility.Probability(di.DropRate)) { if (!di.OnlyDropForQuest || (di.OnlyDropForQuest && QuestManager.Instance.HasOngoingQuestWithID(di.BindedQuest.ID))) { lootItems.Add(new ItemInfo(di.Item, Random.Range(1, di.Amount + 1))); } } } if (lootItems.Count > 0) { LootAgent la = ObjectPool.Get(currentStage.LootPrefab).GetComponent <LootAgent>(); la.Init(lootItems, transform.position); } } HarvestDone(); }
void Update() { if (Input.GetKeyDown(KeyCode.E)) { myEvent.Invoke(); } if (Input.GetKeyDown(KeyCode.R)) { // エディタ上でイベントを登録した場合、ここで登録した引数は無視される。 myIntEvent.Invoke(123); } // スクリプトだけでイベントを加え、さらに、実行後自らを削除してみる例 // https://answers.unity.com/questions/1492047/unityactionunityevent-remove-listener-from-within.html if (Input.GetKeyDown(KeyCode.T)) { //SetEventFromCode(() => Debug.Log("Invoked Medthod whidh is added from code")); UnityAction myAction = null; myAction = new UnityAction(() => { Debug.Log("Invoked Medthod whidh is added from code"); myEvent.RemoveListener(myAction); }); SetEventFromCode(myAction); } }
/// Show a list of options, and wait for the player to make a /// selection. private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption) { ds.ClearOptions(); end = false; waitingForOptionSelection = true; currentOptionSelectionHandler = selectOption; foreach (var optionString in optionsCollection.Options) { string text = localisationProvider.GetLocalisedTextForLine(optionString.Line); ds.AddChoice(text, () => SelectOption(optionString.ID)); } onOptionsStart?.Invoke(); // Wait until the chooser has been used and then removed while (waitingForOptionSelection) { yield return(null); } onOptionsEnd?.Invoke(); }
public void Use() { if (action != null) { action.Invoke(); } }
private void Update() { if (Input.GetKeyDown(jumpCode)) { onPress?.Invoke(); } }
public void OnMilestoneAchieved(GameManager.Milestone milestone) { if (milestone == m_milestoneToAchieve) { m_onMilestoneAchievedEvent?.Invoke(); } }
protected virtual void HandlePluginMessage(JsonObject jsonMsg) { // By the time this is called the component might be destroyed if (this == null) { return; } string msg = jsonMsg.GetString("msg"); if (msg.Equals(MSG_TEXT_BEGIN_EDIT)) { if (this.OnBeginEditing != null) { this.OnBeginEditing.Invoke(); } } else if (msg.Equals(MSG_TEXT_CHANGE) || msg.Equals(MSG_TEXT_END_EDIT)) { this.InputField.text = jsonMsg.GetString("text"); } else if (msg.Equals(MSG_RETURN_PRESSED)) { if (returnPressed != null) { returnPressed(); } if (OnReturnPressed != null) { OnReturnPressed.Invoke(); } } }
private void OnFire(object sender, bool isFire) { if (isFire) { fireEvt?.Invoke(); } }
IEnumerator IntentionChecking() { yield return(new WaitForSeconds(intentionCheckingDelay)); // If, after some time, initial gesture is still being held then intention is validated if (primaryCondition.Value) { onIntentionValidated.Invoke(); // Secondary action validation switch (mode) { case SeqMode.CheckAfterDelay: StartCoroutine(SecondaryActionValidationAfterDelay(validationCheckingDelay)); break; case SeqMode.WaitUntilTimeout: StartCoroutine(SecondaryActionValidationUntilTimeout(validationTimeout, validationCheckingFreq)); break; } } else { // There was no intention onIntentionFailed.Invoke(); started = false; } }
private void Update() { if (Input.GetMouseButtonDown(0)) { onM1Clicked?.Invoke(); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { OnPlayerFinish?.Invoke(); } }
private void FilterAndInvoke(Collider2D collider, UnityEvent colliderEvent) { int mask = 1 << collider.gameObject.layer; if ((mask & filter.value) == 0) return; colliderEvent.Invoke(); }
private IEnumerator LerpToTargetSpot() { var startPosition = transform.position; var startRotation = transform.rotation; var startTime = Time.unscaledTime; var endTime = startTime + lerppingTime; while (true) { yield return(null); var t = Mathf.InverseLerp(startTime, endTime, Time.unscaledTime); transform.SetPositionAndRotation(Vector3.Lerp(startPosition, targetSpot.position, t), Quaternion.Lerp(startRotation, targetSpot.rotation, t)); if (Time.unscaledTime >= endTime) { lerpping = false; rb.isKinematic = true; inPosition = true; onPosition?.Invoke(); break; } } }
public void Trigger(Transform instigator) { if (!once || (once && !triggered)) { triggered = true; evt.Invoke(); } }
public void HealthDown(float damage) { health -= damage; if (health <= 0) { onHealthUnderZero?.Invoke(); } }
//Removes all listeners of an event, adds one listener, and then invokes the event depending on parameters public static void RemoveAllAndAddListener(UnityEvent e, UnityAction listenerToAdd, bool invoke) { e.RemoveAllListeners(); //Remove all listeners e.AddListener(listenerToAdd); //Add the listen if(invoke) //If the event should be invoked e.Invoke(); //Invoke all listeners }
public void SaveAndQuit(bool save) { saveChanges = save; saveOrDiscardMenu.SetActive(false); OnSaveAndQuit?.Invoke(); }
IEnumerator checkForKeyUp(KeyCode key, UnityEvent keyUpEvent) { while (alive) { if (Input.GetKeyUp(key) == true) { keyUpEvent.Invoke(); } yield return null; } }
public override void DialogueComplete() { onDialogueEnd?.Invoke(); // Hide the dialogue interface. // if (dialogueContainer != null) // dialogueContainer.SetActive(false); }
void Update() { lifeTime += Time.deltaTime; if (lifeTime > maxLifeTime) { onTimeUp?.Invoke(); } }
private void FixedUpdate() { if (timer > maxTime) { OnTimeUpEvent?.Invoke(); timer = 0; } timer += Time.deltaTime; }
/// EDITED FOR SAILING WITH THE GODS /// Designed for our dialog system to fill in a dialog object private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete) { onLineStart?.Invoke(); userRequestedNextLine = false; string text = localisationProvider.GetLocalisedTextForLine(line); if (text == null) { Debug.LogWarning($"Line {line.ID} doesn't have any localised text."); text = line.ID; } //Split one block of text into multiple sections string[] split = text.Split('^'); //If we need to end after the split, we have to save that for later //Otherwise, we'll end between the split, which isn't right bool eventualEnd = end; end = false; for (int i = 0; i < split.Length; i++) { if (split[i][0] == '&') { ds.AddImage(split[i].Remove(0, 1)); } else { ds.AddToDialogText(currentSpeakerName, split[i], textAlign); } //If this is the final part of the split text, remember if this is the end or not if (i == split.Length - 1) { end = eventualEnd; } // We're now waiting for the player to move on to the next line userRequestedNextLine = false; // Indicate to the rest of the game that the line has finished being delivered onLineFinishDisplaying?.Invoke(); while (userRequestedNextLine == false) { yield return(null); } } onLineEnd?.Invoke(); onComplete(); }
/// Show a line of dialogue, gradually private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete) { onLineStart?.Invoke(); userRequestedNextLine = false; // The final text we'll be showing for this line. string text = localisationProvider.GetLocalisedTextForLine(line); if (text == null) { Debug.LogWarning($"Line {line.ID} doesn't have any localised text."); text = line.ID; } string[] split = text.Split('^'); bool eventualEnd = end; end = false; for (int i = 0; i < split.Length; i++) { if (split[i][0] == '&') { ds.AddImage(split[i].Remove(0, 1)); } else { ds.AddToDialogText(currentSpeakerName, split[i], textAlign); } if (i == split.Length - 1) { end = eventualEnd; } // We're now waiting for the player to move on to the next line userRequestedNextLine = false; // Indicate to the rest of the game that the line has finished being delivered onLineFinishDisplaying?.Invoke(); while (userRequestedNextLine == false) { yield return(null); } } // Hide the text and prompt onLineEnd?.Invoke(); onComplete(); }
protected virtual void InteractableObjectUsed(object sender, InteractableObjectEventArgs e) { doorEvent.Invoke(); headsetCollision.GetComponent <VRTK_HeadsetCollisionFade>().blinkTransitionSpeed = 3.0f; headsetCollision.GetComponent <VRTK_HeadsetCollisionFade>().fadeColor = Color.white; isOpen = true; lightSource.SetActive(true); cameraFader.SetActive(true); doorKnobInteraction.enabled = false; }
public void LeaveScrap() { // recentScrap.transform.Find("onScrapPanel(Clone)").gameObject.GetComponentInChildren<TextMeshProUGUI>().text = // recentScrap.GetComponent<ScrapObject>().scrapName + "<size=60%><color=#798478> | <color=#FF752A>" + recentScrap.GetComponent<ScrapObject>().size.ToString("#,#") + " m<sup>3</sup></size>"; // Director.Dir.StartFadeCanvasGroup(recentScrap.transform.Find("onScrapPanel(Clone)").gameObject, "in", 0.1f); leftScrap?.Invoke(); Director.Dir.StartFadeCanvasGroup(readoutPanel, "out", 0.05f); AudioManager.AM.PlayMiscUIClip("dismiss"); DialogueManager.DM.RunNode("scrap-leave"); }
private void OnTriggerExit(Collider other) { Grabbable grabbable = other.GetComponent <Grabbable>(); if (grabbable != null && currentObjectOn == grabbable) { OnExit.Invoke(); currentObjectOn = null; } }
void OnMouseDown() { if (isToggle) { toggleState = !toggleState; RefreshToggle(); onMouseDown.Invoke(); } else { if (enabled) { time = lingerTime; rend.sprite = disabledSprite; rend.color = Color.Lerp(original, Color.black, lerpColorFactor); onMouseDown.Invoke(); } } }