/// <summary> /// Resets the power up with the given responses. /// </summary> /// <param name="resetResponses">Which set of reset actions to run.</param> virtual public void ResetPowerUp(PowerUpResponse resetResponse) { if (activePowerUps.Contains(resetResponse.type)) { activePowerUps.Remove(resetResponse.type); } foreach (PowerUpResponse r in responses) { if (resetResponse.powerUpReset == r.type) { for (int i = 0; i < r.actions.Length; i++) { DoAction(r.actions[i], null); } } } // Remove any associated event listeners if (resetResponse.damageResetListener != null) { CharacterHealth health = character.GetComponentInChildren <CharacterHealth>(); if (health != null) { health.Damaged -= resetResponse.damageResetListener; resetResponse.damageResetListener = null; } } }
/// <summary> /// Does the listed power up reset after the given time. /// </summary> /// <param name="time">The powers up lifetime.</param> /// <param name="resetResponses">Which set of reset actions to run when the timer expires.</param> virtual protected IEnumerator DoResetAfterTime(int time, PowerUpResponse resetResponse) { yield return(new WaitForSeconds(time)); ResetPowerUp(resetResponse); }
/// <summary> /// Sets the power up timer. /// </summary> /// <param name="time">Time.</param> /// <param name="resetResponses">Which set of reset actions to run when the timer expires.</param> virtual protected void SetTimer(int time, PowerUpResponse resetResponse) { StopAllCoroutines(); StartCoroutine(DoResetAfterTime(time, resetResponse)); }
virtual protected void RenderResponse(PowerUpResponse response) { responseVisibility[response] = EditorGUILayout.Foldout(responseVisibility[response], response.type); if (responseVisibility[response]) { GUILayout.BeginVertical(EditorStyles.textArea); GUILayout.Space(5); string type = EditorGUILayout.TextField(new GUIContent("PowerUp Type", "Type of the PowerUp."), response.type); if (type != response.type) { response.type = type; responseNames = new List <string>(); responseNames.Add(" - NONE - "); foreach (PowerUpResponse r in myTarget.responses) { responseNames.Add(r.type); } } bool isReset = EditorGUILayout.Toggle(new GUIContent("Is Reset", "Is this a reset for another power up?"), response.isReset); if (isReset != response.isReset) { response.isReset = isReset; } if (!response.isReset) { bool resetOnDamage = EditorGUILayout.Toggle(new GUIContent("Reset on Damage", "Should the power up be removed if the character is damaged."), response.resetOnDamage); if (resetOnDamage != response.resetOnDamage) { response.resetOnDamage = resetOnDamage; } int timer = EditorGUILayout.IntField(new GUIContent("PowerUp Timer", "Time the PowerUp is active for (use 0 for unlimited)."), response.time); if (timer < 0) { timer = 0; } if (timer != response.time) { response.time = timer; } // Show resets if timer > 0 if (timer > 0.0f || resetOnDamage) { int originalResetIndex = 0; if (response.powerUpReset != null) { originalResetIndex = responseNames.IndexOf(response.powerUpReset); } int selectedResetIndex = originalResetIndex; GUILayout.BeginHorizontal(); selectedResetIndex = EditorGUILayout.Popup("Reset Response", originalResetIndex, responseNames.ToArray()); if (originalResetIndex != selectedResetIndex) { response.powerUpReset = responseNames[selectedResetIndex]; } if (selectedResetIndex <= 0 && GUILayout.Button("Create Reset")) { selectedResetIndex = 0; PowerUpResponse resetResponse = new PowerUpResponse(); resetResponse.type = "Reset " + response.type; resetResponse.isReset = true; myTarget.responses.Add(resetResponse); response.powerUpReset = resetResponse.type; } GUILayout.EndHorizontal(); if (selectedResetIndex <= 0) { selectedResetIndex = 0; EditorGUILayout.HelpBox("Power up is set as resetabble but no reset is provided (this could be valid in some cases).", MessageType.Info); } if (response.powerUpReset == response.type) { EditorGUILayout.HelpBox("Power-up is set to reset itself. This is probably not desired.", MessageType.Warning); } } } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Add new actions if (GUILayout.Button("Add Action")) { if (response.actions == null) { response.actions = new EventResponse[1]; } else { // Copy and grow array EventResponse[] tmpActions = response.actions; response.actions = new EventResponse[tmpActions.Length + 1]; System.Array.Copy(tmpActions, response.actions, tmpActions.Length); } } if (GUILayout.Button("Remove PowerUp Type")) { myTarget.responses.Remove(response); } EditorGUILayout.EndHorizontal(); if (response.actions != null) { for (int i = 0; i < response.actions.Length; i++) { EditorGUILayout.BeginVertical("HelpBox"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (i == 0) { GUI.enabled = false; } if (GUILayout.Button("Move Up", EditorStyles.miniButtonLeft)) { EventResponse tmp = response.actions[i - 1]; response.actions[i - 1] = response.actions[i]; response.actions[i] = tmp; break; } GUI.enabled = true; if (i == response.actions.Length - 1) { GUI.enabled = false; } if (GUILayout.Button("Move Down", EditorStyles.miniButtonRight)) { EventResponse tmp = response.actions[i + 1]; response.actions[i + 1] = response.actions[i]; response.actions[i] = tmp; break; } GUI.enabled = true; // Remove GUILayout.Space(4); bool removed = false; if (GUILayout.Button("Remove", EditorStyles.miniButton)) { response.actions = response.actions.Where(a => a != response.actions[i]).ToArray(); removed = true; } GUILayout.EndHorizontal(); if (!removed) { EventResponderInspector.RenderAction(target, response, response.actions[i]); } EditorGUILayout.EndVertical(); } } GUILayout.EndVertical(); } }
virtual protected void RenderResponse(PowerUpResponse response) { responseVisibility[response] = EditorGUILayout.Foldout(responseVisibility[response], response.type); if (responseVisibility[response]) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Box("", GUILayout.Width(1), GUILayout.ExpandHeight(true)); EditorGUILayout.BeginVertical(); string type = EditorGUILayout.TextField(new GUIContent("PowerUp Type", "Type of the PowerUp."), response.type); if (type != response.type) { response.type = type; EditorUtility.SetDirty(target); responseNames = null; } bool resetOnDamage = EditorGUILayout.Toggle(new GUIContent("Reset on Damage", "Should the power up be removed if the character is damaged)."), response.resetOnDamage); if (resetOnDamage != response.resetOnDamage) { response.resetOnDamage = resetOnDamage; EditorUtility.SetDirty(target); } int timer = EditorGUILayout.IntField(new GUIContent("PowerUp Timer", "Time the PowerUp is active for (use 0 for unlimited)."), response.time); if (timer < 0) { timer = 0; } if (timer != response.time) { response.time = timer; EditorUtility.SetDirty(target); } // Show resets if timer > 0 if (timer > 0.0f) { int originalResetIndex = responseNames.IndexOf(response.powerUpReset); int selectedResetIndex = originalResetIndex; selectedResetIndex = EditorGUILayout.Popup("Reset Response", originalResetIndex, responseNames.ToArray()); if (originalResetIndex != selectedResetIndex) { response.powerUpReset = responseNames[selectedResetIndex]; } } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Add new actions if (GUILayout.Button("Add Action")) { if (response.actions == null) { response.actions = new EventResponse[1]; } else { // Copy and grow array EventResponse[] tmpActions = response.actions; response.actions = new EventResponse[tmpActions.Length + 1]; System.Array.Copy(tmpActions, response.actions, tmpActions.Length); } EditorUtility.SetDirty(target); } if (GUILayout.Button("Remove PowerUp Type")) { myTarget.responses.Remove(response); EditorUtility.SetDirty(target); } EditorGUILayout.EndHorizontal(); if (response.actions != null) { for (int i = 0; i < response.actions.Length; i++) { EditorGUILayout.BeginVertical("HelpBox"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (i == 0) { GUI.enabled = false; } if (GUILayout.Button("Move Up", EditorStyles.miniButtonLeft)) { EventResponse tmp = response.actions[i - 1]; response.actions[i - 1] = response.actions[i]; response.actions[i] = tmp; EditorUtility.SetDirty(target); break; } GUI.enabled = true; if (i == response.actions.Length - 1) { GUI.enabled = false; } if (GUILayout.Button("Move Down", EditorStyles.miniButtonRight)) { EventResponse tmp = response.actions[i + 1]; response.actions[i + 1] = response.actions[i]; response.actions[i] = tmp; EditorUtility.SetDirty(target); break; } GUI.enabled = true; // Remove GUILayout.Space(4); bool removed = false; if (GUILayout.Button("Remove", EditorStyles.miniButton)) { response.actions = response.actions.Where(a => a != response.actions[i]).ToArray(); EditorUtility.SetDirty(target); removed = true; } GUILayout.EndHorizontal(); if (!removed) { EventResponderInspector.RenderAction(target, response, response.actions[i]); } EditorGUILayout.EndVertical(); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } }
protected virtual void RenderResponse(PowerUpResponse response) { responseVisibility[response] = EditorGUILayout.Foldout(responseVisibility[response], response.type); if(responseVisibility[response]) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Box("", GUILayout.Width(1), GUILayout.ExpandHeight(true)); EditorGUILayout.BeginVertical(); string type = EditorGUILayout.TextField(new GUIContent("PowerUp Type", "Type of the PowerUp."), response.type); if (type != response.type) { response.type = type; EditorUtility.SetDirty(target); responseNames = null; } bool resetOnDamage = EditorGUILayout.Toggle(new GUIContent("Reset on Damage", "Should the power up be removed if the character is damaged)."), response.resetOnDamage); if (resetOnDamage != response.resetOnDamage) { response.resetOnDamage = resetOnDamage; EditorUtility.SetDirty(target); } int timer = EditorGUILayout.IntField(new GUIContent("PowerUp Timer", "Time the PowerUp is active for (use 0 for unlimited)."), response.time); if (timer < 0) timer = 0; if (timer != response.time) { response.time = timer; EditorUtility.SetDirty(target); } // Show resets if timer > 0 if (timer > 0.0f) { int originalResetIndex = responseNames.IndexOf(response.powerUpReset); int selectedResetIndex = originalResetIndex; selectedResetIndex = EditorGUILayout.Popup("Reset Response", originalResetIndex, responseNames.ToArray()); if (originalResetIndex != selectedResetIndex) { response.powerUpReset = responseNames[selectedResetIndex]; } } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Add new actions if (GUILayout.Button("Add Action")) { if (response.actions == null) { response.actions = new EventResponse[1]; } else { // Copy and grow array EventResponse[] tmpActions = response.actions; response.actions = new EventResponse[tmpActions.Length + 1]; System.Array.Copy(tmpActions, response.actions, tmpActions.Length); } EditorUtility.SetDirty(target); } if (GUILayout.Button("Remove PowerUp Type")) { myTarget.responses.Remove (response); EditorUtility.SetDirty(target); } EditorGUILayout.EndHorizontal(); if (response.actions != null) { for (int i = 0; i < response.actions.Length; i++) { EventResponderInspector.RenderAction(target, response, response.actions[i]); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } }