fix: prevent ParticleSystem "duration while playing" warnings
- Stop ParticleSystem immediately after AddComponent to prevent auto-play - Set playOnAwake=false on all procedural particle systems - Also add missing EventType definitions for Phase 23/24 features 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -353,6 +353,15 @@ namespace TheIsland.Models
|
||||
|
||||
// Random Events (Phase 17-C)
|
||||
public const string RANDOM_EVENT = "random_event";
|
||||
|
||||
// Economy (Phase 23)
|
||||
public const string GIVE_ITEM = "give_item";
|
||||
|
||||
// Group Activities (Phase 24)
|
||||
public const string GROUP_ACTIVITY = "group_activity";
|
||||
|
||||
// Phase 8: VFX
|
||||
public const string VFX_EVENT = "vfx_event";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -403,4 +412,41 @@ namespace TheIsland.Models
|
||||
public string message;
|
||||
public string agent_name; // Optional: affected agent
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Give item event data (Phase 23).
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class GiveItemEventData
|
||||
{
|
||||
public int from_id;
|
||||
public int to_id;
|
||||
public string item_type; // "herb", "food", "medicine"
|
||||
public string message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Group Activity event data (Phase 24).
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class GroupActivityEventData
|
||||
{
|
||||
public string activity_type; // "storytelling"
|
||||
public int storyteller_id;
|
||||
public string storyteller_name;
|
||||
public List<int> listener_ids;
|
||||
public string content; // The story text
|
||||
public string topic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// VFX event data (Phase 8).
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class VFXEventData
|
||||
{
|
||||
public string effect; // "gold_rain", "heart", "food"
|
||||
public int target_id; // Optional: if -1 or 0, might mean global or specific position logic
|
||||
public string message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace TheIsland.Network
|
||||
public event Action<CraftEventData> OnCraft; // Phase 16: Crafting
|
||||
public event Action<UseItemEventData> OnUseItem; // Phase 16: Using items
|
||||
public event Action<RandomEventData> OnRandomEvent; // Phase 17-C: Random Events
|
||||
public event Action<GiveItemEventData> OnGiveItem; // Phase 23: Item Exchange
|
||||
public event Action<GroupActivityEventData> OnGroupActivity; // Phase 24: Group Activities
|
||||
public event Action<VFXEventData> OnVFXEvent; // Phase 8: VFX
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
@@ -377,6 +380,23 @@ namespace TheIsland.Network
|
||||
var randomEventData = JsonUtility.FromJson<RandomEventData>(dataJson);
|
||||
OnRandomEvent?.Invoke(randomEventData);
|
||||
Debug.Log($"[Random Event] {randomEventData.event_type}: {randomEventData.message}");
|
||||
OnRandomEvent?.Invoke(randomEventData);
|
||||
Debug.Log($"[Random Event] {randomEventData.event_type}: {randomEventData.message}");
|
||||
break;
|
||||
|
||||
case EventTypes.GIVE_ITEM:
|
||||
var giveData = JsonUtility.FromJson<GiveItemEventData>(dataJson);
|
||||
OnGiveItem?.Invoke(giveData);
|
||||
break;
|
||||
|
||||
case EventTypes.GROUP_ACTIVITY:
|
||||
var groupData = JsonUtility.FromJson<GroupActivityEventData>(dataJson);
|
||||
OnGroupActivity?.Invoke(groupData);
|
||||
break;
|
||||
|
||||
case EventTypes.VFX_EVENT:
|
||||
var vfxData = JsonUtility.FromJson<VFXEventData>(dataJson);
|
||||
OnVFXEvent?.Invoke(vfxData);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -44,6 +44,11 @@ namespace TheIsland.Visual
|
||||
[SerializeField] private int dustParticleCount = 8;
|
||||
[SerializeField] private float dustDuration = 0.5f;
|
||||
|
||||
[Header("Food Poof Settings")]
|
||||
[SerializeField] private Color foodColor = new Color(1f, 1f, 1f, 0.7f); // White smoke
|
||||
[SerializeField] private int foodParticleCount = 15;
|
||||
[SerializeField] private float foodDuration = 1.0f;
|
||||
|
||||
[Header("General Settings")]
|
||||
[SerializeField] private float effectScale = 1f;
|
||||
#endregion
|
||||
@@ -96,6 +101,17 @@ namespace TheIsland.Visual
|
||||
Destroy(ps.gameObject, dustDuration + 0.2f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play food poof effect (white smoke).
|
||||
/// Used for feeding.
|
||||
/// </summary>
|
||||
public void PlayFoodPoof(Vector3 position)
|
||||
{
|
||||
var ps = CreateFoodPoofSystem(position);
|
||||
ps.Play();
|
||||
Destroy(ps.gameObject, foodDuration + 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play an effect by type name.
|
||||
/// </summary>
|
||||
@@ -114,6 +130,10 @@ namespace TheIsland.Visual
|
||||
case "subscription":
|
||||
PlayHeartExplosion(position);
|
||||
break;
|
||||
case "food":
|
||||
case "feed":
|
||||
PlayFoodPoof(position);
|
||||
break;
|
||||
default:
|
||||
// Default to gold rain
|
||||
PlayGoldRain(position);
|
||||
@@ -130,9 +150,12 @@ namespace TheIsland.Visual
|
||||
{
|
||||
GameObject go = new GameObject("GoldRain_VFX");
|
||||
go.transform.position = position + Vector3.up * 3f; // Start above
|
||||
|
||||
|
||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||
// Stop immediately to prevent "duration while playing" warning
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.playOnAwake = false;
|
||||
main.loop = false;
|
||||
main.duration = goldDuration;
|
||||
main.startLifetime = 1.5f;
|
||||
@@ -203,9 +226,12 @@ namespace TheIsland.Visual
|
||||
{
|
||||
GameObject go = new GameObject("HeartExplosion_VFX");
|
||||
go.transform.position = position + Vector3.up * 1.5f;
|
||||
|
||||
|
||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||
// Stop immediately to prevent "duration while playing" warning
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.playOnAwake = false;
|
||||
main.loop = false;
|
||||
main.duration = heartDuration;
|
||||
main.startLifetime = 1.2f;
|
||||
@@ -280,7 +306,10 @@ namespace TheIsland.Visual
|
||||
go.transform.position = position;
|
||||
|
||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||
// Stop immediately to prevent "duration while playing" warning
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.playOnAwake = false;
|
||||
main.loop = false;
|
||||
main.duration = dustDuration;
|
||||
main.startLifetime = 0.4f;
|
||||
@@ -336,6 +365,61 @@ namespace TheIsland.Visual
|
||||
return ps;
|
||||
}
|
||||
|
||||
private ParticleSystem CreateFoodPoofSystem(Vector3 position)
|
||||
{
|
||||
GameObject go = new GameObject("FoodPoof_VFX");
|
||||
go.transform.position = position + Vector3.up * 1.5f;
|
||||
|
||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||
// Stop immediately to prevent "duration while playing" warning
|
||||
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||
var main = ps.main;
|
||||
main.playOnAwake = false;
|
||||
main.loop = false;
|
||||
main.duration = foodDuration;
|
||||
main.startLifetime = 0.8f;
|
||||
main.startSpeed = new ParticleSystem.MinMaxCurve(0.5f, 2f);
|
||||
main.startSize = new ParticleSystem.MinMaxCurve(0.3f * effectScale, 0.6f * effectScale);
|
||||
main.startColor = foodColor;
|
||||
main.gravityModifier = -0.05f; // Slight float
|
||||
main.maxParticles = foodParticleCount;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
|
||||
var emission = ps.emission;
|
||||
emission.enabled = true;
|
||||
emission.rateOverTime = 0;
|
||||
// Burst
|
||||
emission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0f, (short)foodParticleCount) });
|
||||
|
||||
var shape = ps.shape;
|
||||
shape.enabled = true;
|
||||
shape.shapeType = ParticleSystemShapeType.Sphere;
|
||||
shape.radius = 0.4f * effectScale;
|
||||
|
||||
var sizeOverLifetime = ps.sizeOverLifetime;
|
||||
sizeOverLifetime.enabled = true;
|
||||
AnimationCurve sizeCurve = new AnimationCurve();
|
||||
sizeCurve.AddKey(0f, 0.2f);
|
||||
sizeCurve.AddKey(0.5f, 1f);
|
||||
sizeCurve.AddKey(1f, 0f);
|
||||
sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1f, sizeCurve);
|
||||
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
colorOverLifetime.enabled = true;
|
||||
Gradient gradient = new Gradient();
|
||||
gradient.SetKeys(
|
||||
new GradientColorKey[] { new GradientColorKey(foodColor, 0f), new GradientColorKey(foodColor, 1f) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey(0.8f, 0f), new GradientAlphaKey(1f, 0.2f), new GradientAlphaKey(0f, 1f) }
|
||||
);
|
||||
colorOverLifetime.color = gradient;
|
||||
|
||||
var renderer = go.GetComponent<ParticleSystemRenderer>();
|
||||
renderer.renderMode = ParticleSystemRenderMode.Billboard;
|
||||
renderer.material = CreateParticleMaterial(foodColor);
|
||||
|
||||
return ps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a simple additive particle material.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user