示例#1
0
    public GameObject Get_Object()
    {
        GameObject spawned_object;

        //check if an inactive object exists
        if (inactive_objects.Count > 0)
        {
            spawned_object = inactive_objects.Pop();
        }
        // otherwise create a new object
        else
        {
            spawned_object = (GameObject)GameObject.Instantiate(prefab);

            // add to the prefab
            SignInDirectoryObject directory_object = spawned_object.AddComponent <SignInDirectoryObject>();
            directory_object.files = this;
        }

        spawned_object.transform.SetParent(null);
        spawned_object.SetActive(true);

        // return the object
        return(spawned_object);
    }
示例#2
0
    public void ReturnObject(GameObject return_object)
    {
        SignInDirectoryObject directory_object = return_object.GetComponent <SignInDirectoryObject>();

        // check if the instance is from this directory
        if (directory_object != null && directory_object.files == this)
        {
            // disable this instance
            return_object.transform.SetParent(transform);
            return_object.SetActive(false);

            // add as an inactive instance
            inactive_objects.Push(return_object);
        }

        // otherwise delete the object
        else
        {
            Debug.LogWarning(return_object.name + " was returned to the directory it isn't from.");
            Destroy(return_object);
        }
    }