public static ItemPrefabRegister GetInstance()                      // for singleton
 {
     if (instance == null)
     {
         return(instance = new ItemPrefabRegister());
     }
     return(instance);
 }     // end : GetInstance
示例#2
0
    }     // end : Add to Inventory

    /* DumpItem()
     *  Removes the fetched item from the inventory or stack
     *  and places a copy of the assigned prefab on the
     *  player position.
     *  If no item with id is left, nothing happens.
     */
    public void DumpItem(int id)
    {
        GameObject objItem;
        Item       dataItem;

        if (RemoveFromInventory(id, out dataItem))
        {
            // copy the prefab to player's location
            objItem = ItemPrefabRegister.GetInstance().GetClone(dataItem.Prefab);
            objItem.transform.position = player.transform.position;
        }
    }     // end : DumpItem
示例#3
0
    void Awake()
    {
        bool   success;
        string filename = Application.dataPath + ITEM_FILE;

        database = InvokeDatabase(filename);

        // load every prefab data to the database
        foreach (Item item in database.Values)
        {
            ItemPrefabRegister.GetInstance().AddPrefab(item.Prefab);
            ItemIconRegister.GetInstance().AddIcon(item.Handle);
        }
        success  = ItemPrefabRegister.GetInstance().LoadPrefabs();
        success &= ItemIconRegister.GetInstance().LoadIcons();
        if (!success)
        {
            Debug.Log("Some item prefabs could not be loaded. See Error Log!");
        }
    }     // end : Awake