예제 #1
0
    public static GameObject CreateAndRegisterCompostableFromPrefab(GameObject original)
    {
        if ((Object)original.GetComponent <Compostable>() != (Object)null)
        {
            return(null);
        }
        Compostable compostable = original.AddComponent <Compostable>();

        compostable.isMarkedForCompost = false;
        KPrefabID  component  = original.GetComponent <KPrefabID>();
        GameObject gameObject = Object.Instantiate(original);

        Object.DontDestroyOnLoad(gameObject);
        string tag_string = "Compost" + component.PrefabTag.Name;
        string text       = MISC.TAGS.COMPOST_FORMAT.Replace("{Item}", component.PrefabTag.ProperName());

        gameObject.GetComponent <KPrefabID>().PrefabTag = TagManager.Create(tag_string, text);
        gameObject.GetComponent <KPrefabID>().AddTag(GameTags.Compostable, false);
        gameObject.name = text;
        gameObject.GetComponent <Compostable>().isMarkedForCompost = true;
        gameObject.GetComponent <KSelectable>().SetName(text);
        gameObject.GetComponent <Compostable>().originalPrefab = original;
        gameObject.GetComponent <Compostable>().compostPrefab  = gameObject;
        original.GetComponent <Compostable>().originalPrefab   = original;
        original.GetComponent <Compostable>().compostPrefab    = gameObject;
        Assets.AddPrefab(gameObject.GetComponent <KPrefabID>());
        return(gameObject);
    }
예제 #2
0
        /// <summary>
        /// A version of Compostable.OnToggleCompost that does not crash if the select tool
        /// is not in use.
        /// </summary>
        /// <param name="comp">The item to toggle compost.</param>
        private static void DoToggleCompost(Compostable comp)
        {
            var obj        = comp.gameObject;
            var pickupable = obj.GetComponent <Pickupable>();

            if (comp.isMarkedForCompost)
            {
                EntitySplitter.Split(pickupable, pickupable.TotalAmount, comp.originalPrefab);
            }
            else
            {
                pickupable.storage?.Drop(obj, true);
                EntitySplitter.Split(pickupable, pickupable.TotalAmount, comp.compostPrefab);
            }
        }