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:
@@ -55,6 +55,17 @@ class EventType(str, Enum):
|
|||||||
# Random Events (Phase 17-C)
|
# Random Events (Phase 17-C)
|
||||||
RANDOM_EVENT = "random_event" # Random event occurred
|
RANDOM_EVENT = "random_event" # Random event occurred
|
||||||
|
|
||||||
|
# Economy (Phase 23)
|
||||||
|
GIVE_ITEM = "give_item" # Agent gives item to another
|
||||||
|
|
||||||
|
# Group Activities (Phase 24)
|
||||||
|
# Group Activities (Phase 24)
|
||||||
|
GROUP_ACTIVITY = "group_activity" # Storytelling, dancing, etc.
|
||||||
|
|
||||||
|
# VFX & Gifts (Phase 8)
|
||||||
|
VFX_EVENT = "vfx_event" # Visual effect trigger
|
||||||
|
GIFT_EFFECT = "gift_effect" # Twitch bits/sub effect
|
||||||
|
|
||||||
|
|
||||||
class GameEvent(BaseModel):
|
class GameEvent(BaseModel):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -353,6 +353,15 @@ namespace TheIsland.Models
|
|||||||
|
|
||||||
// Random Events (Phase 17-C)
|
// Random Events (Phase 17-C)
|
||||||
public const string RANDOM_EVENT = "random_event";
|
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>
|
/// <summary>
|
||||||
@@ -403,4 +412,41 @@ namespace TheIsland.Models
|
|||||||
public string message;
|
public string message;
|
||||||
public string agent_name; // Optional: affected agent
|
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<CraftEventData> OnCraft; // Phase 16: Crafting
|
||||||
public event Action<UseItemEventData> OnUseItem; // Phase 16: Using items
|
public event Action<UseItemEventData> OnUseItem; // Phase 16: Using items
|
||||||
public event Action<RandomEventData> OnRandomEvent; // Phase 17-C: Random Events
|
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
|
#endregion
|
||||||
|
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
@@ -377,6 +380,23 @@ namespace TheIsland.Network
|
|||||||
var randomEventData = JsonUtility.FromJson<RandomEventData>(dataJson);
|
var randomEventData = JsonUtility.FromJson<RandomEventData>(dataJson);
|
||||||
OnRandomEvent?.Invoke(randomEventData);
|
OnRandomEvent?.Invoke(randomEventData);
|
||||||
Debug.Log($"[Random Event] {randomEventData.event_type}: {randomEventData.message}");
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ namespace TheIsland.Visual
|
|||||||
[SerializeField] private int dustParticleCount = 8;
|
[SerializeField] private int dustParticleCount = 8;
|
||||||
[SerializeField] private float dustDuration = 0.5f;
|
[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")]
|
[Header("General Settings")]
|
||||||
[SerializeField] private float effectScale = 1f;
|
[SerializeField] private float effectScale = 1f;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -96,6 +101,17 @@ namespace TheIsland.Visual
|
|||||||
Destroy(ps.gameObject, dustDuration + 0.2f);
|
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>
|
/// <summary>
|
||||||
/// Play an effect by type name.
|
/// Play an effect by type name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -114,6 +130,10 @@ namespace TheIsland.Visual
|
|||||||
case "subscription":
|
case "subscription":
|
||||||
PlayHeartExplosion(position);
|
PlayHeartExplosion(position);
|
||||||
break;
|
break;
|
||||||
|
case "food":
|
||||||
|
case "feed":
|
||||||
|
PlayFoodPoof(position);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Default to gold rain
|
// Default to gold rain
|
||||||
PlayGoldRain(position);
|
PlayGoldRain(position);
|
||||||
@@ -130,9 +150,12 @@ namespace TheIsland.Visual
|
|||||||
{
|
{
|
||||||
GameObject go = new GameObject("GoldRain_VFX");
|
GameObject go = new GameObject("GoldRain_VFX");
|
||||||
go.transform.position = position + Vector3.up * 3f; // Start above
|
go.transform.position = position + Vector3.up * 3f; // Start above
|
||||||
|
|
||||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||||
|
// Stop immediately to prevent "duration while playing" warning
|
||||||
|
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||||
var main = ps.main;
|
var main = ps.main;
|
||||||
|
main.playOnAwake = false;
|
||||||
main.loop = false;
|
main.loop = false;
|
||||||
main.duration = goldDuration;
|
main.duration = goldDuration;
|
||||||
main.startLifetime = 1.5f;
|
main.startLifetime = 1.5f;
|
||||||
@@ -203,9 +226,12 @@ namespace TheIsland.Visual
|
|||||||
{
|
{
|
||||||
GameObject go = new GameObject("HeartExplosion_VFX");
|
GameObject go = new GameObject("HeartExplosion_VFX");
|
||||||
go.transform.position = position + Vector3.up * 1.5f;
|
go.transform.position = position + Vector3.up * 1.5f;
|
||||||
|
|
||||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||||
|
// Stop immediately to prevent "duration while playing" warning
|
||||||
|
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||||
var main = ps.main;
|
var main = ps.main;
|
||||||
|
main.playOnAwake = false;
|
||||||
main.loop = false;
|
main.loop = false;
|
||||||
main.duration = heartDuration;
|
main.duration = heartDuration;
|
||||||
main.startLifetime = 1.2f;
|
main.startLifetime = 1.2f;
|
||||||
@@ -280,7 +306,10 @@ namespace TheIsland.Visual
|
|||||||
go.transform.position = position;
|
go.transform.position = position;
|
||||||
|
|
||||||
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
ParticleSystem ps = go.AddComponent<ParticleSystem>();
|
||||||
|
// Stop immediately to prevent "duration while playing" warning
|
||||||
|
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
||||||
var main = ps.main;
|
var main = ps.main;
|
||||||
|
main.playOnAwake = false;
|
||||||
main.loop = false;
|
main.loop = false;
|
||||||
main.duration = dustDuration;
|
main.duration = dustDuration;
|
||||||
main.startLifetime = 0.4f;
|
main.startLifetime = 0.4f;
|
||||||
@@ -336,6 +365,61 @@ namespace TheIsland.Visual
|
|||||||
return ps;
|
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>
|
/// <summary>
|
||||||
/// Create a simple additive particle material.
|
/// Create a simple additive particle material.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user