/// <summary> /// Applies the properties from the given Laser to the VolumeLineRenderer. /// </summary> /// <param name="renderer">The VolumeLineRenderer to configure.</param> /// <param name="laser">The Laser beam to use as template.</param> /// <param name="prop">The LaserProperties describing the Laser beam.</param> /// <returns>The configured LineRenderer.</returns> public static VolumeLineRenderer ApplyProperties(VolumeLineRenderer renderer, LaserBeam laser, LaserProperties prop) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (laser == null) { throw new ArgumentNullException("laser"); } if (prop == null) { throw new ArgumentNullException("prop"); } renderer.UseWorldSpace = true; renderer.LineMaterial = laser.Emitter.LineRenderer.LineMaterial; renderer.ReceiveShadows = false; renderer.CastShadows = false; prop.RGBStrengths = laser.Emitter.Properties.RGBStrengths; return(renderer); }
/// <summary> /// Creates a new LaserEmitter that emits the same type of Laser beam /// as the provided one. /// <para> /// The LaserEmitter is created as a separate game object and /// added as a child of this game object. /// </para> /// <para> /// To save resources, it is recommended to call <see cref="MultiEmitter.GetEmitter"/> /// instead, which re-uses existing LaserEmitters. However, this method can be called /// to create LaserEmitters beforehand. /// </para> /// </summary> /// <param name="laser">The original Laser beam.</param> /// <returns>The created LaserEmitter.</returns> public LaserEmitter CreateEmitter(LaserBeam laser) { GameObject emitterObject = new GameObject("Emitter"); emitterObject.transform.parent = this.gameObject.transform; VolumeLineRenderer renderer = emitterObject.AddComponent <VolumeLineRenderer>(); LaserEmitter emitter = emitterObject.AddComponent <LaserEmitter>(); LaserProperties prop = emitterObject.AddComponent <LaserProperties>(); ApplyProperties(renderer, laser, prop); return(emitter); }
/// <summary> /// Starts the LaserEmitter and initializes the LineRenderer. /// </summary> public void Start() { if (this.LineRenderer == null) { this.LineRenderer = this.GetComponent <VolumeLineRenderer>(); } if (this.gameObject.GetComponent <LaserProperties>() == null) { Debug.LogError("No LaserProperties object detected."); } this.Enabled = true; }