Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
hWebPool.cs
1 #region Copyright Notice & License Information
2 //
3 // hWebPool.cs
4 //
5 // Author:
6 // Matthew Davey <matthew.davey@dotbunny.com>
7 //
8 // Copyright (c) 2013 dotBunny Inc. (http://www.dotbunny.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 #endregion
28 
29 using UnityEngine;
30 
31 /// <summary>
32 /// A drop in implementation of the Hydrogen.Core.WebPool. This simply makes the class an accessible singleton
33 /// with some very simple additional functionality.
34 /// </summary>
35 [AddComponentMenu ("Hydrogen/Singletons/Web Pool")]
36 public sealed class hWebPool : Hydrogen.Core.WebPool
37 {
38  /// <summary>
39  /// Should this web pool survive scene switches?
40  /// </summary>
41  public bool Persistent = true;
42  /// <summary>
43  /// Internal fail safe to maintain instance across threads.
44  /// </summary>
45  /// <remarks>
46  /// Multithreaded Safe Singleton Pattern.
47  /// </remarks>
48  /// <description>
49  /// http://msdn.microsoft.com/en-us/library/ms998558.aspx
50  /// </description>
51  static readonly System.Object _syncRoot = new System.Object ();
52  /// <summary>
53  /// Internal reference to the static instance of the web pool.
54  /// </summary>
55  static volatile hWebPool _staticInstance;
56 
57  /// <summary>
58  /// Gets the web pool instance, creating one if none is found.
59  /// </summary>
60  /// <value>
61  /// The Web Pool.
62  /// </value>
63  public static hWebPool Instance {
64  get {
65  if (_staticInstance == null) {
66  lock (_syncRoot) {
67  _staticInstance = FindObjectOfType (typeof(hWebPool)) as hWebPool;
68 
69  // If we don't have it, lets make it!
70  if (_staticInstance == null) {
71  var go = GameObject.Find (Hydrogen.Components.DefaultSingletonName) ??
72  new GameObject (Hydrogen.Components.DefaultSingletonName);
73 
74  // Add our WebPool
75  go.AddComponent<hWebPool> ();
76  _staticInstance = go.GetComponent<hWebPool> ();
77  }
78  }
79  }
80  return _staticInstance;
81  }
82  }
83 
84  /// <summary>
85  /// Does a Web Pool already exist?
86  /// </summary>
87  public static bool Exists ()
88  {
89  return _staticInstance != null;
90  }
91 
92  /// <summary>
93  /// Unity's Awake Event
94  /// </summary>
95  protected override void Awake ()
96  {
97  // Make sure to do the object pools normal initialization
98  base.Awake ();
99 
100  // Should this gameObject be kept around :) I think so.
101  if (Persistent)
102  DontDestroyOnLoad (gameObject);
103  }
104 }
A drop in implementation of the Hydrogen.Core.WebPool. This simply makes the class an accessible sing...
Definition: hWebPool.cs:36
override void Awake()
Unity&#39;s Awake Event
Definition: hWebPool.cs:95
bool Persistent
Should this web pool survive scene switches?
Definition: hWebPool.cs:41
static hWebPool Instance
Gets the web pool instance, creating one if none is found.
Definition: hWebPool.cs:63
static bool Exists()
Does a Web Pool already exist?
Definition: hWebPool.cs:87