/*
     * Loads an Object
     * 'i' is the number of the object we are loading.
     */
    private void LoadObject(int i, string file)
    {
        int    uniqueID   = ES2.Load <int>(file + "?tag=uniqueID" + i);
        string prefabName = ES2.Load <string>(file + "?tag=prefabName" + i);

        // Create or get an object based on our loaded id and prefabName
        GameObject loadObject;

        // If our prefab name is blank, we're loading a scene object.
        if (prefabName == "")
        {
            loadObject = UniqueID.FindTransform(uniqueID).gameObject;
        }
        else
        {
            loadObject = UniqueObjectManager.InstantiatePrefab(prefabName);
        }

        Transform t = loadObject.GetComponent <Transform>();

        if (t != null)
        {
            // Auto-assigning Load is the best way to load Components.
            ES2.Load <Transform>(file + "?tag=transform" + i, t);
            // Now we'll get the parent object, if any.
            int       parentuID = ES2.Load <int>(file + "?tag=parentID" + i);
            Transform parent    = UniqueID.FindTransform(parentuID);
            if (parent != null)
            {
                t.parent = parent;
            }
        }
    }
示例#2
0
 public void Awake()
 {
     // Allows us to get a static reference to this instance.
     // (Like a singleton)
     mgr = this;
     // Clear the createdObjects list incase we've entered from another scene.
     createdObjects.Clear();
 }
示例#3
0
    public IEnumerator DestroyOrCreateRoutine(float delaySeconds, float runEverySeconds)
    {
        yield return(new WaitForSeconds(delaySeconds));

        while (true)
        {
            // If we have more than 20 created objects, randomly destroy one ...
            if (UniqueObjectManager.CreatedObjects.Count > 9)
            {
                UniqueObjectManager.DestroyObject(UniqueObjectManager.CreatedObjects[Random.Range(0, UniqueObjectManager.CreatedObjects.Count)]);
            }
            // ... Else, randomly create one.
            else
            {
                UniqueObjectManager.InstantiatePrefab(UniqueObjectManager.Prefabs[Random.Range(0, UniqueObjectManager.Prefabs.Length)].name,
                                                      Random.insideUnitSphere * 10,
                                                      Random.rotation);
            }
            yield return(new WaitForSeconds(runEverySeconds));
        }
    }
示例#4
0
 public void Awake()
 {
     // Allows us to get a static reference to this instance.
     // (Like a singleton)
     mgr = this;
 }
	public void Awake()
	{		
		// Allows us to get a static reference to this instance.
		// (Like a singleton)
		mgr = this;
	}
示例#6
0
 private void Awake()
 {
     ObjectManager = gameObject.AddComponent <UniqueObjectManager>();
 }