Replace highlighted platform with lever-activated sign
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
- Заменена уменьшенная платформа TriggeringPlatform_2 на сцене 1-1 на табличку со стрелкой влево (Signs_Arrow_Left). - Создан C# скрипт ShowObjectWithVFX.cs для активации скрытых объектов со спецэффектами частиц (sparks). - Добавлен вспомогательный редакторский скрипт ReplacePlatformWithSign.cs для автоматической перестройки сцены. - Рычаг на уровне 1-1 привязан к активации таблички: табличка изначально скрыта, при переключении рычага появляется с эффектом искр.
This commit is contained in:
parent
77f7f9ef39
commit
a0211d50fc
174
Assets/Editor/ReplacePlatformWithSign.cs
Normal file
174
Assets/Editor/ReplacePlatformWithSign.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Events;
|
||||
using RR.Game2D.Entities;
|
||||
|
||||
public static class ReplacePlatformWithSign
|
||||
{
|
||||
[MenuItem("Tools/Replace Platform with Sign")]
|
||||
public static string Run()
|
||||
{
|
||||
GameObject platformObj = GameObject.Find("Level/Props/Platforms/TriggeringPlatform_2");
|
||||
if (platformObj == null)
|
||||
{
|
||||
platformObj = GameObject.Find("TriggeringPlatform_2");
|
||||
}
|
||||
if (platformObj == null)
|
||||
{
|
||||
Debug.LogError("Error: TriggeringPlatform_2 not found in scene!");
|
||||
return "Error: TriggeringPlatform_2 not found in scene!";
|
||||
}
|
||||
|
||||
GameObject leverObj = GameObject.Find("Level/Props/Lever");
|
||||
if (leverObj == null)
|
||||
{
|
||||
leverObj = GameObject.Find("Lever");
|
||||
}
|
||||
if (leverObj == null)
|
||||
{
|
||||
Debug.LogError("Error: Lever not found in scene!");
|
||||
return "Error: Lever not found in scene!";
|
||||
}
|
||||
|
||||
Transform parentTransform = platformObj.transform.parent;
|
||||
Vector3 position = platformObj.transform.position;
|
||||
|
||||
Sprite signSprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Resources/Sprites/Props/Signs/Signs_Arrow_Left.png");
|
||||
if (signSprite == null)
|
||||
{
|
||||
// Try fallback OLD folder
|
||||
signSprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Resources/Sprites/Props/Signs/OLD/Signs_Arrow_Left.png");
|
||||
}
|
||||
|
||||
if (signSprite == null)
|
||||
{
|
||||
Debug.LogError("Error: Signs_Arrow_Left.png not found in Assets!");
|
||||
return "Error: Signs_Arrow_Left.png not found in Assets!";
|
||||
}
|
||||
|
||||
// Create sign GameObject
|
||||
GameObject signObj = new GameObject("SignLeft");
|
||||
Undo.RegisterCreatedObjectUndo(signObj, "Create SignLeft");
|
||||
signObj.transform.parent = parentTransform;
|
||||
signObj.transform.position = position;
|
||||
signObj.transform.localScale = Vector3.one;
|
||||
|
||||
// Add SpriteRenderer
|
||||
SpriteRenderer sr = signObj.AddComponent<SpriteRenderer>();
|
||||
sr.sprite = signSprite;
|
||||
|
||||
// Copy sorting layer and order from sibling or default
|
||||
SpriteRenderer[] allRenderers = parentTransform.parent.GetComponentsInChildren<SpriteRenderer>(true);
|
||||
if (allRenderers != null && allRenderers.Length > 0)
|
||||
{
|
||||
sr.sortingLayerID = allRenderers[0].sortingLayerID;
|
||||
sr.sortingLayerName = allRenderers[0].sortingLayerName;
|
||||
sr.sortingOrder = allRenderers[0].sortingOrder;
|
||||
}
|
||||
else
|
||||
{
|
||||
sr.sortingLayerName = "Foreground";
|
||||
sr.sortingOrder = 0;
|
||||
}
|
||||
|
||||
// Add ShowObjectWithVFX component
|
||||
ShowObjectWithVFX triggerScript = signObj.AddComponent<ShowObjectWithVFX>();
|
||||
|
||||
// Use reflection to set private serialized fields
|
||||
var targetField = typeof(ShowObjectWithVFX).GetField("targetObject", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (targetField != null)
|
||||
{
|
||||
targetField.SetValue(triggerScript, signObj);
|
||||
}
|
||||
|
||||
// Create Sparks ParticleSystem
|
||||
GameObject sparksObj = new GameObject("Sparks");
|
||||
sparksObj.transform.parent = signObj.transform;
|
||||
sparksObj.transform.localPosition = Vector3.zero;
|
||||
|
||||
ParticleSystem ps = sparksObj.AddComponent<ParticleSystem>();
|
||||
|
||||
// Configure particles to look like sparks
|
||||
var main = ps.main;
|
||||
main.duration = 1.0f;
|
||||
main.loop = false;
|
||||
main.startLifetime = new ParticleSystem.MinMaxCurve(0.4f, 0.8f);
|
||||
main.startSpeed = new ParticleSystem.MinMaxCurve(3.0f, 6.0f);
|
||||
main.startSize = new ParticleSystem.MinMaxCurve(0.1f, 0.25f);
|
||||
main.gravityModifier = 0.9f;
|
||||
main.playOnAwake = false;
|
||||
|
||||
var emission = ps.emission;
|
||||
emission.enabled = true;
|
||||
emission.rateOverTime = 0;
|
||||
var burst = new ParticleSystem.Burst(0.0f, 40);
|
||||
emission.SetBursts(new ParticleSystem.Burst[] { burst });
|
||||
|
||||
var shape = ps.shape;
|
||||
shape.enabled = true;
|
||||
shape.shapeType = ParticleSystemShapeType.Cone;
|
||||
shape.angle = 60f;
|
||||
shape.radius = 0.3f;
|
||||
|
||||
var colorOverLifetime = ps.colorOverLifetime;
|
||||
colorOverLifetime.enabled = true;
|
||||
Gradient gradient = new Gradient();
|
||||
gradient.SetKeys(
|
||||
new GradientColorKey[] { new GradientColorKey(new Color(1f, 0.9f, 0.3f), 0.0f), new GradientColorKey(new Color(1f, 0.3f, 0.0f), 1.0f) },
|
||||
new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }
|
||||
);
|
||||
colorOverLifetime.color = gradient;
|
||||
|
||||
var psr = sparksObj.GetComponent<ParticleSystemRenderer>();
|
||||
if (psr != null)
|
||||
{
|
||||
psr.material = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Particle.mat");
|
||||
}
|
||||
|
||||
// Assign particle system to triggerScript
|
||||
var psField = typeof(ShowObjectWithVFX).GetField("particleSystemComponent", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
||||
if (psField != null)
|
||||
{
|
||||
psField.SetValue(triggerScript, ps);
|
||||
}
|
||||
|
||||
// Set up Lever activation
|
||||
Lever lever = leverObj.GetComponent<Lever>();
|
||||
if (lever != null)
|
||||
{
|
||||
var onActivateField = typeof(Lever).GetField("onActivate", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
|
||||
if (onActivateField != null)
|
||||
{
|
||||
UnityEngine.Events.UnityEvent onActivate = (UnityEngine.Events.UnityEvent)onActivateField.GetValue(lever);
|
||||
if (onActivate != null)
|
||||
{
|
||||
// Clear any old triggers pointing to platform
|
||||
int persistentEventCount = onActivate.GetPersistentEventCount();
|
||||
for (int i = persistentEventCount - 1; i >= 0; i--)
|
||||
{
|
||||
Object target = onActivate.GetPersistentTarget(i);
|
||||
if (target == platformObj || (target is Component comp && comp.gameObject == platformObj))
|
||||
{
|
||||
UnityEventTools.RemovePersistentListener(onActivate, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Bind new activation
|
||||
UnityEventTools.AddPersistentListener(onActivate, triggerScript.Activate);
|
||||
EditorUtility.SetDirty(lever);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy old platform object
|
||||
Undo.DestroyObjectImmediate(platformObj);
|
||||
|
||||
// Mark scene dirty and save
|
||||
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(signObj.scene);
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(signObj.scene);
|
||||
|
||||
Debug.Log("Success! TriggeringPlatform_2 replaced with SignLeft, particle system configured, and Lever.onActivate event updated.");
|
||||
return "Success!";
|
||||
}
|
||||
}
|
||||
2
Assets/Editor/ReplacePlatformWithSign.cs.meta
Normal file
2
Assets/Editor/ReplacePlatformWithSign.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 664333a25198dc74bb19121701092ce5
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
67
Assets/Scripts/Entities/Props/ShowObjectWithVFX.cs
Normal file
67
Assets/Scripts/Entities/Props/ShowObjectWithVFX.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
|
||||
namespace RR.Game2D.Entities
|
||||
{
|
||||
public class ShowObjectWithVFX : MonoBehaviour
|
||||
{
|
||||
[Header("Target Settings")]
|
||||
[SerializeField] private GameObject targetObject;
|
||||
[SerializeField] private bool hideOnStart = true;
|
||||
|
||||
[Header("VFX Settings")]
|
||||
[SerializeField] private VisualEffect visualEffect;
|
||||
[SerializeField] private ParticleSystem particleSystemComponent;
|
||||
[SerializeField] private GameObject vfxPrefab;
|
||||
[SerializeField] private float vfxDestroyDelay = 3f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (hideOnStart && targetObject != null)
|
||||
{
|
||||
targetObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (visualEffect != null)
|
||||
{
|
||||
visualEffect.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (particleSystemComponent != null)
|
||||
{
|
||||
var emission = particleSystemComponent.emission;
|
||||
emission.enabled = false;
|
||||
particleSystemComponent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Activate")]
|
||||
public void Activate()
|
||||
{
|
||||
if (targetObject != null)
|
||||
{
|
||||
targetObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (visualEffect != null)
|
||||
{
|
||||
visualEffect.gameObject.SetActive(true);
|
||||
visualEffect.Play();
|
||||
}
|
||||
|
||||
if (particleSystemComponent != null)
|
||||
{
|
||||
particleSystemComponent.gameObject.SetActive(true);
|
||||
var emission = particleSystemComponent.emission;
|
||||
emission.enabled = true;
|
||||
particleSystemComponent.Play();
|
||||
}
|
||||
|
||||
if (vfxPrefab != null)
|
||||
{
|
||||
GameObject vfxInstance = Instantiate(vfxPrefab, transform.position, transform.rotation);
|
||||
Destroy(vfxInstance, vfxDestroyDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Entities/Props/ShowObjectWithVFX.cs.meta
Normal file
2
Assets/Scripts/Entities/Props/ShowObjectWithVFX.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49989a9e1bab58c42bf27b3f7eca8d5b
|
||||
Loading…
x
Reference in New Issue
Block a user