public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { if (audioSource != null) { audioSource.Play(); } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Ray screenRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(screenRay, out hit)) { waterIsOn = true; // target.position = hit.point; VFXEventAttribute eventAttributes = vf.CreateVFXEventAttribute(); eventAttributes.SetVector3("targetPosition", hit.point); vf.SendEvent("Start", eventAttributes); Vector3 difference = hit.point - transform.position; float rotationY = Mathf.Atan2(difference.x, difference.z) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0.0f, rotationY, 0.0f); } } else if (Input.GetMouseButtonUp(0) && !debug) { vf.SendEvent("Stop"); //waterIsOn = false; } }
private void CreateScanVFX(Vector3 targetPosition) { /* The event payload is a little weird. You can only set the value of * a couple built-in attributes (position and targetPosition are defaults). */ VFXEventAttribute payload = scanLineVFX.CreateVFXEventAttribute(); payload.SetVector3("position", transform.position); payload.SetVector3("targetPosition", targetPosition); scanLineVFX.SendEvent("SpawnScanLine", payload); }
public void Spawn(PlayerEnt player) { player.transform.position = spawnPosition.position; player.rb.velocity = Vector2.zero; VFXEventAttribute attribute = vfx.CreateVFXEventAttribute(); attribute.SetVector3("position", transform.InverseTransformPoint(spawnPosition.position)); vfx.SendEvent("PlayerSpawn", attribute); }
private void OnValidate() { if (target != null) { eventAttribute = target.CreateVFXEventAttribute(); } else { eventAttribute = null; } }
private void UpdateCacheEventAttribute() { if (target != null) { eventAttribute = target.CreateVFXEventAttribute(); } else { eventAttribute = null; } }
public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect) { var velocity = eventAttribute.GetVector3(k_Velocity); if (attributeSpace == Space.Local) { velocity = visualEffect.transform.localToWorldMatrix.MultiplyVector(velocity); } if (TryGetComponent <Rigidbody>(out m_RigidBody)) { m_RigidBody.WakeUp(); m_RigidBody.velocity = velocity; } }
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { if (cinemachineImpulseSource != null) { Vector3 pos = eventAttribute.GetVector3(k_Position); Vector3 vel = eventAttribute.GetVector3(k_Velocity); if (attributeSpace == Space.Local) { pos = transform.localToWorldMatrix.MultiplyPoint(pos); vel = transform.localToWorldMatrix.MultiplyVector(vel); } cinemachineImpulseSource.GenerateImpulseAt(pos, vel); } }
void Update() { if (Input.GetMouseButtonDown(0)) { var pos = Input.mousePosition; pos.z = _vfx.transform.position.z - _camera.transform.position.z; pos = _camera.ScreenToWorldPoint(pos); if (_attrib == null) { _attrib = _vfx.CreateVFXEventAttribute(); } _attrib.SetVector3("position", pos); _vfx.SendEvent("OnManualSpawn", _attrib); } }
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { if (rigidBodies == null || rigidBodies.Length == 0) { return; } var position = eventAttribute.GetVector3(k_Position); var size = eventAttribute.GetFloat(k_Size); var velocity = eventAttribute.GetVector3(k_Velocity); if (attributeSpace == Space.Local) { position = transform.localToWorldMatrix.MultiplyPoint(position); velocity = transform.localToWorldMatrix.MultiplyVector(velocity); // We assume that the size is bound to the X component of the transform scale // and that the transform is uniform. size = transform.localToWorldMatrix.MultiplyVector(Vector3.right * size).magnitude; } foreach (var rigidBody in rigidBodies) { if (rigidBody == null) { continue; } switch (eventType) { case RigidBodyEventType.Impulse: rigidBody.AddForce(velocity, ForceMode.Impulse); break; case RigidBodyEventType.Explosion: rigidBody.AddExplosionForce(velocity.magnitude, position, size, UpwardsModifier); break; case RigidBodyEventType.VelocityChange: rigidBody.AddForce(velocity, ForceMode.VelocityChange); break; default: break; } } }
public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect) { var color = eventAttribute.GetVector3(k_Color); var intensity = color.magnitude; var c = new Color(color.x, color.y, color.z) / intensity; intensity *= brightnessScale; #if VFX_OUTPUTEVENT_HDRP_10_0_0_OR_NEWER var hdlight = GetComponent <HDAdditionalLightData>(); hdlight.SetColor(c); hdlight.SetIntensity(intensity); #else var light = GetComponent <Light>(); light.color = c; light.intensity = intensity; #endif }
// Update is called once per frame void OnGUI() { if (GUI.Button(new Rect(50, 50, 100, 50), "play1")) { if (vfx1 == null) { var vfxGo1 = new UnityEngine.GameObject("VfxGo1"); vfx1 = vfxGo1.AddComponent <UnityEngine.Experimental.VFX.VisualEffect>(); var grenadeClient = GetComponent <GrenadeClient>(); vfx1.visualEffectAsset = grenadeClient.explodeEffect.effect; vfxEventAttribute1 = vfx1.CreateVFXEventAttribute(); vfxEventAttribute1.SetVector3(positionID, new Vector3(20.0f, 0.0f, 0.0f)); } vfx1.Play(vfxEventAttribute1); } #if false if (vfx1 != null && Time.frameCount % 30 == 0) { vfx1.Play(vfxEventAttribute1); } #endif if (GUI.Button(new Rect(50, 150, 100, 50), "play2")) { if (vfx2 == null) { var vfxGo2 = new UnityEngine.GameObject("VfxGo2"); vfx2 = vfxGo2.AddComponent <UnityEngine.Experimental.VFX.VisualEffect>(); var grenadePrefab = ReplicatedPrefabMgr.GetPrefab("assets__newnetwork_prefab_robot_grenade"); var grenadeClient = grenadePrefab.GetComponent <GrenadeClient>(); vfx2.visualEffectAsset = grenadeClient.explodeEffect.effect; vfxEventAttribute2 = vfx2.CreateVFXEventAttribute(); vfxEventAttribute2.SetVector3(positionID, new Vector3(20.0f, 0.0f, 0.0f)); } vfx2.Play(vfxEventAttribute2); } }
void Start() { var rand = new System.Random(158); for (uint i = 0; i < s_CircleCount; ++i) { var source = new SourceData(); source.time = (float)rand.NextDouble() * Mathf.PI * 2.0f; source.radius = Mathf.Lerp(0.2f, 0.9f, (float)rand.NextDouble()); source.speed = Mathf.Lerp(0.5f, 2.0f, (float)rand.NextDouble()); source.rate = Mathf.Lerp(8.0f, 32.0f, (float)rand.NextDouble()); var color = Color.HSVToRGB((float)rand.NextDouble(), 1.0f, 1.0f); source.color = new Vector3(color.r, color.g, color.b); source.spawnCount = 0.0f; m_Sources.Add(source); } m_VisualEffect = gameObject.GetComponent <VisualEffect>(); m_CacheEventAttribute = m_VisualEffect.CreateVFXEventAttribute(); }
public override void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect) { time = 0; }
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { onEvent?.Invoke(); }
/// <summary> /// This function is called when the specified event in outputEvent on the attached VisualEffect is triggered. /// The VFXEventAttribute passed as parameter is temporary and can be modified in a later process. /// </summary> /// <param name="eventAttribute">The VFXEventAttribute handling properties from the spawn event.</param> public abstract void OnVFXOutputEvent(VFXEventAttribute eventAttribute);
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { CheckAndRebuildInstances(); int freeIdx = -1; for (int i = 0; i < m_Instances.Length; i++) { if (!m_Instances[i].activeSelf) { freeIdx = i; break; } } if (freeIdx != -1) { var availableInstance = m_Instances[freeIdx]; availableInstance.SetActive(true); if (usePosition && eventAttribute.HasVector3(k_PositionID)) { if (m_ParentInstances) { availableInstance.transform.localPosition = eventAttribute.GetVector3(k_PositionID); } else { availableInstance.transform.position = eventAttribute.GetVector3(k_PositionID); } } if (useAngle && eventAttribute.HasVector3(k_AngleID)) { if (parentInstances) { availableInstance.transform.localEulerAngles = eventAttribute.GetVector3(k_AngleID); } else { availableInstance.transform.eulerAngles = eventAttribute.GetVector3(k_AngleID); } } if (useScale && eventAttribute.HasVector3(k_ScaleID)) { availableInstance.transform.localScale = eventAttribute.GetVector3(k_ScaleID); } if (useLifetime && eventAttribute.HasFloat(k_LifetimeID)) { m_TimesToLive[freeIdx] = eventAttribute.GetFloat(k_LifetimeID); } else { m_TimesToLive[freeIdx] = float.NegativeInfinity; } var handlers = availableInstance.GetComponentsInChildren <VFXOutputEventPrefabAttributeAbstractHandler>(); foreach (var handler in handlers) { handler.OnVFXEventAttribute(eventAttribute, m_VisualEffect); } } //Else, can't find an instance available, ignoring. }
public abstract void OnVFXEventAttribute(VFXEventAttribute eventAttribute, VisualEffect visualEffect);
private void Start() { _basicHitFx = GetComponent <VisualEffect>(); _eventAttribute = _basicHitFx.CreateVFXEventAttribute(); FindObjectOfType <ScoreManager>().onScoring += CreateHitParticle; }
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute) { Messager.Send(message, gameObject); }