public static singleton getInstance() { if (instance == null) { instance = new singleton(); } return(instance); }
private static void Main(string[] args) { Mysingleton Object = Mysingleton.sravs; Object.check(); singleton obj1 = singleton.sravs; obj1.worked(); Console.ReadKey(); }
// Start is called before the first frame update void Start() { GameObject g = GameObject.FindGameObjectWithTag("MainCamera"); infoWorld = g.GetComponent <singleton>(); audio = GetComponent <AudioSource>(); pop_transform = infoWorld.canvas.GetComponent <AudioSource>(); }
// Use this for initialization void Awake() { if (singleton.instance != null) { Destroy(gameObject); } else { instance = this; } }
private void Awake() { if (instance == null) { DontDestroyOnLoad(this.gameObject); instance = this; } else { Destroy(this.gameObject); } }
public static void Main() { for (int i = 0; i < 7; i++) { singleton a = singleton.Create(); a.VAL = i; } for (int i = 0; i < 7; i++) { singleton a = singleton.Create(); Console.WriteLine(a.VAL); } }
void Awake() { singleton data = singleton.getInstance(); int cellCount = data.cellCount; float size = prefub.GetComponent <MeshFilter>().sharedMesh.bounds.size.x *prefub.transform.localScale.x; Vector3 start = new Vector3(cellCount * size / 2.0f - size / 2, 0.1f, cellCount * size / 2.0f - size / 2); arr = new CellBehaviour[cellCount, cellCount]; for (int i = 0; i < cellCount; i++) { for (int j = 0; j < cellCount; j++) { GameObject obj = Instantiate(prefub.gameObject); arr[i, j] = obj.GetComponent <CellBehaviour>(); obj.transform.SetParent(world.transform); obj.transform.localPosition = start; data.navigate.SetPoint(i, j, obj.transform); start.x -= size; } start.z -= size; start.x = cellCount * size / 2 - size / 2; } data.navigate.CreateNavMesh(); for (int i = 0; i < cellCount; i++) { for (int j = 0; j < cellCount; j++) { arr[i, j].SetNode(data.navigate.GetNode(i, j)); } } for (int i = 0; i < data.enemyCount; i++) { Vector3 position = data.navigate.GetNode(Random.Range(0, cellCount - 1), Random.Range(0, cellCount - 1)).position; EnemyBehaviour agent = Instantiate(walker.gameObject, position, Quaternion.identity).GetComponent <EnemyBehaviour>(); data.enemys.Add(agent); } info.text = string.Format("world side {0}\nenemy count {1}", data.cellCount, data.enemyCount); }
public static singleton Create() { if (!full) { singleton nowy = new singleton(); Tab[cur] = nowy; if (cur>=MAX-1) full=true; return nowy; } else { cur++; if(cur>=MAX) cur=0; return Tab[cur]; } }
// Create as a static method so this can be called using // just the class name (no object instance is required). // It simplifies other code because it will always return // the single instance of this class, either newly created // or from the session public static singleton GetCurrentSingleton() { singleton oSingleton; if (null == System.Web.HttpContext.Current.Session[SESSION_SINGLETON]) { //No current session object exists, use private constructor to // create an instance, place it into the session oSingleton = new singleton(); System.Web.HttpContext.Current.Session[SESSION_SINGLETON] = oSingleton; } else { //Retrieve the already instance that was already created oSingleton = (singleton)System.Web.HttpContext.Current.Session[SESSION_SINGLETON]; } //Return the single instance of this class that was stored in the session return(oSingleton); }
static public singleton Create() { if (!full) { singleton nowy = new singleton(); Tab[cur] = nowy; if (cur >= MAX - 1) { full = true; } return(nowy); } else { cur++; if (cur >= MAX) { cur = 0; } return(Tab[cur]); } }
private void Awake() { sg = this; }