IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
FireSource.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: This object can be set on fire
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  public class FireSource : MonoBehaviour
14  {
15  public GameObject fireParticlePrefab;
16  public bool startActive;
17  private GameObject fireObject;
18 
19  public ParticleSystem customParticles;
20 
21  public bool isBurning;
22 
23  public float burnTime;
24  public float ignitionDelay = 0;
25  private float ignitionTime;
26 
27  private Hand hand;
28 
29  public AudioSource ignitionSound;
30 
31  public bool canSpreadFromThisSource = true;
32 
33  //-------------------------------------------------
34  void Start()
35  {
36  if ( startActive )
37  {
38  StartBurning();
39  }
40  }
41 
42 
43  //-------------------------------------------------
44  void Update()
45  {
46  if ( ( burnTime != 0 ) && ( Time.time > ( ignitionTime + burnTime ) ) && isBurning )
47  {
48  isBurning = false;
49  if ( customParticles != null )
50  {
51  customParticles.Stop();
52  }
53  else
54  {
55  Destroy( fireObject );
56  }
57  }
58  }
59 
60 
61  //-------------------------------------------------
62  void OnTriggerEnter( Collider other )
63  {
64  if ( isBurning && canSpreadFromThisSource )
65  {
66  other.SendMessageUpwards( "FireExposure", SendMessageOptions.DontRequireReceiver );
67  }
68  }
69 
70 
71  //-------------------------------------------------
72  private void FireExposure()
73  {
74  if ( fireObject == null )
75  {
76  Invoke( "StartBurning", ignitionDelay );
77  }
78 
79  if ( hand = GetComponentInParent<Hand>() )
80  {
81  hand.controller.TriggerHapticPulse( 1000 );
82  }
83  }
84 
85 
86  //-------------------------------------------------
87  private void StartBurning()
88  {
89  isBurning = true;
90  ignitionTime = Time.time;
91 
92  // Play the fire ignition sound if there is one
93  if ( ignitionSound != null )
94  {
95  ignitionSound.Play();
96  }
97 
98  if ( customParticles != null )
99  {
100  customParticles.Play();
101  }
102  else
103  {
104  if ( fireParticlePrefab != null )
105  {
106  fireObject = Instantiate( fireParticlePrefab, transform.position, transform.rotation ) as GameObject;
107  fireObject.transform.parent = transform;
108  }
109  }
110  }
111  }
112 }