public void Init(Vector2Int size) { grid = transform.Find("grid").gameObject; this.size = size; PlaceableItem = new PlaceableItem(size); }
/** * If you are just doing boring serialization/deserialization like the following * remove the interface IACMFPlaceableItemCustomSerializationSystem and these following methods * and allow the system serialize/deserialize for you. * This is the default serialization/deseralization behaviour. */ public PlaceableItemSerializable SerializeItem(PlaceableItem placeableItem) { PlaceableItemSerializable placeableItemSerializable = new PlaceableItemSerializable(); placeableItemSerializable.SetObjectForSerializer(placeableItem); return(placeableItemSerializable); }
internal void Add(PlaceableItem placeableItem) { PlaceableItemSerializable placeableItemSerializable = new PlaceableItemSerializable(); placeableItemSerializable.SetObjectForSerializer(placeableItem); PlaceableItems.Add(placeableItemSerializable); }
public void InventoryRightClick(BaseItemSlot itemSlot) { if (itemSlot.Item is EquippableItem) { Equip((EquippableItem)itemSlot.Item); } else if (itemSlot.Item is UsableItem) { UsableItem usableItem = (UsableItem)itemSlot.Item; usableItem.Use(player); if (usableItem.isConsumable) { inventory.RemoveItem(usableItem); usableItem.Destroy(); } } else if (itemSlot.Item is PlaceableItem) { PlaceableItem placeable = (PlaceableItem)itemSlot.Item; placeable.Place(player); placeable.Destroy(); } }
internal static void Configure(ModComponent modComponent) { ModBedComponent modBedComponent = modComponent as ModBedComponent; if (modBedComponent == null) { return; } Bed bed = ModUtils.GetOrCreateComponent <Bed>(modBedComponent); bed.m_ConditionPercentGainPerHour = modBedComponent.ConditionGainPerHour; bed.m_UinterruptedRestPercentGainPerHour = modBedComponent.AdditionalConditionGainPerHour; bed.m_WarmthBonusCelsius = modBedComponent.WarmthBonusCelsius; bed.m_PercentChanceReduceBearAttackWhenSleeping = modBedComponent.BearAttackModifier; bed.m_PercentChanceReduceWolfAttackWhenSleeping = modBedComponent.WolfAttackModifier; bed.m_OpenAudio = ModUtils.DefaultIfEmpty(modBedComponent.OpenAudio, "PLAY_SNDGENSLEEPINGBAGCLOSE"); bed.m_CloseAudio = ModUtils.DefaultIfEmpty(modBedComponent.CloseAudio, "PLAY_SNDGENSLEEPINGBAGOPEN"); bed.m_BedRollMesh = modBedComponent.PackedMesh ?? modBedComponent.gameObject; bed.m_BedRollMesh.layer = vp_Layer.Gear; bed.m_BedRollPlacedMesh = modBedComponent.UsableMesh ?? modBedComponent.gameObject; bed.m_BedRollPlacedMesh.layer = vp_Layer.Gear; bed.SetState(BedRollState.Rolled); DegradeOnUse degradeOnUse = ModUtils.GetOrCreateComponent <DegradeOnUse>(modBedComponent); degradeOnUse.m_DegradeHP = Mathf.Max(degradeOnUse.m_DegradeHP, modBedComponent.DegradePerHour); PlaceableItem placeableItem = ModUtils.GetOrCreateComponent <PlaceableItem>(modBedComponent); placeableItem.m_Range = 4; }
public PlaceableItem CreateObject(PlaceableItem prefab, Vector3 position, float angle) { position = position.SnapToGrid(prefab.SnapGrideSize); var item = GameObject.Instantiate <PlaceableItem>(prefab, position, Quaternion.Euler(0, 0, angle)); _objects.Add(item); return(item); }
/** * Read the above comment for SerializeItem() */ public bool DeserializeItem(PlaceableItemSerializable placeableItemSerializable) { PlaceableItem component = Object.Instantiate(Prefab, placeableItemSerializable.position, placeableItemSerializable.rotation, FolderController.Instance.itemsFolder).GetComponent <PlaceableItem>(); component.SetObjectFromSerializer(placeableItemSerializable); component.ChangeToPlaced(false); return(true); }
private static void ConfigureCookingPot(ModComponent modComponent) { ModCookingPotComponent modCookingPotComponent = modComponent as ModCookingPotComponent; if (modCookingPotComponent == null) { return; } CookingPotItem cookingPotItem = ModUtils.GetOrCreateComponent <CookingPotItem>(modComponent); cookingPotItem.m_WaterCapacityLiters = modCookingPotComponent.Capacity; cookingPotItem.m_CanCookGrub = modCookingPotComponent.CanCookGrub; cookingPotItem.m_CanCookLiquid = modCookingPotComponent.CanCookLiquid; cookingPotItem.m_CanCookMeat = modCookingPotComponent.CanCookMeat; cookingPotItem.m_CanOnlyWarmUpFood = false; CookingPotItem template = ModUtils.GetItem <CookingPotItem>(modCookingPotComponent.Template, modComponent.name); cookingPotItem.m_BoilingTimeMultiplier = template.m_BoilingTimeMultiplier; cookingPotItem.m_BoilWaterPotMaterialsList = template.m_BoilWaterPotMaterialsList; cookingPotItem.m_BoilWaterReadyMaterialsList = template.m_BoilWaterReadyMaterialsList; cookingPotItem.m_ConditionPercentDamageFromBoilingDry = template.m_ConditionPercentDamageFromBoilingDry; cookingPotItem.m_ConditionPercentDamageFromBurningFood = template.m_ConditionPercentDamageFromBurningFood; cookingPotItem.m_CookedCalorieMultiplier = template.m_CookedCalorieMultiplier; cookingPotItem.m_CookingTimeMultiplier = template.m_CookingTimeMultiplier; cookingPotItem.m_GrubMeshType = template.m_GrubMeshType; cookingPotItem.m_LampOilMultiplier = template.m_LampOilMultiplier; cookingPotItem.m_MeltSnowMaterialsList = template.m_MeltSnowMaterialsList; cookingPotItem.m_NearFireWarmUpCookingTimeMultiplier = template.m_NearFireWarmUpCookingTimeMultiplier; cookingPotItem.m_NearFireWarmUpReadyTimeMultiplier = template.m_NearFireWarmUpReadyTimeMultiplier; cookingPotItem.m_ParticlesItemCooking = template.m_ParticlesItemCooking; cookingPotItem.m_ParticlesItemReady = template.m_ParticlesItemReady; cookingPotItem.m_ParticlesItemRuined = template.m_ParticlesItemRuined; cookingPotItem.m_ParticlesSnowMelting = template.m_ParticlesSnowMelting; cookingPotItem.m_ParticlesWaterBoiling = template.m_ParticlesWaterBoiling; cookingPotItem.m_ParticlesWaterReady = template.m_ParticlesWaterReady; cookingPotItem.m_ParticlesWaterRuined = template.m_ParticlesWaterRuined; cookingPotItem.m_ReadyTimeMultiplier = template.m_ReadyTimeMultiplier; cookingPotItem.m_RuinedFoodMaterialsList = template.m_RuinedFoodMaterialsList; cookingPotItem.m_SnowMesh = modCookingPotComponent.SnowMesh; cookingPotItem.m_WaterMesh = modCookingPotComponent.WaterMesh; GameObject grubMesh = UnityEngine.Object.Instantiate(template.m_GrubMeshFilter.gameObject, cookingPotItem.transform); cookingPotItem.m_GrubMeshFilter = grubMesh.GetComponent <MeshFilter>(); cookingPotItem.m_GrubMeshRenderer = grubMesh.GetComponent <MeshRenderer>(); PlaceableItem placeableItem = ModUtils.GetOrCreateComponent <PlaceableItem>(modComponent); placeableItem.m_Range = template.GetComponent <PlaceableItem>()?.m_Range ?? 3; }
public void Init(Vector2Int size, Direction dir) { // mesh = transform.Find("mesh/inner").gameObject; grid = transform.Find("grid").gameObject; innerMeshRenderer = transform.Find("mesh/inner").GetComponent <MeshRenderer>(); outterMeshRenderer = transform.Find("mesh/outter").GetComponent <MeshRenderer>(); // boxCollider = mesh.GetComponent<BoxCollider>(); this.size = size; this.dir = dir; PlaceableItem = new PlaceableItem(size); this.items = new List <ItemObject>(); }
// ---------------------------------------------------------------------------- private PrePlacementInstance FindPlacementAtPoint(Vector3 worldPosition) { var testPoint = new Vector2(worldPosition.x, worldPosition.y); PlaceableItem item = null; var collider = Physics2D.OverlapPoint(testPoint, 1 << LayerMask.NameToLayer("Placement")); if (collider) { item = collider.transform.FindUpHeirarchy <PlaceableItem>(); } return(GetFromPlaceholder(item)); }
private void OnSceneGUI() { if (!Application.isPlaying) { PlaceableItem pi = target as PlaceableItem; if (pi) { if (pi.transform.hasChanged) { pi.SnapToGrid(pi.transform.position, pi.transform.rotation); } } } }
//Items are not networked public GameObject GenerateItem(GameObject obj, int x, int y) { Vector3 pos = new Vector3((-totalWidth / 2.0f) + (tileSize / 2.0f) + x * tileSize, (totalHeight / 2.0f) - (tileSize / 2.0f) - tileSize * y, 1); //Debug.Log(pos); //GameObject newCreature = Instantiate(obj); GameObject newItem = Instantiate(obj); newItem.transform.SetParent(transform); newItem.transform.position = pos; PlaceableItem placeable = newItem.GetComponent <PlaceableItem>(); placeable.index = new Vector2Int(x, y); return(newItem); }
// ---------------------------------------------------------------------------- private PrePlacementInstance GetFromPlaceholder(PlaceableItem placeholder) { if (placeholder == null) { return(null); } PrePlacementInstance entry = null; if (_preplacementTable.TryGetValue(placeholder.GetInstanceID(), out entry)) { return(entry); } return(null); }
public override void _Ready() { if (CurrentItem == null) { try { var item = Database <Item> .Get(ItemID); try { CurrentItem = (PlaceableItem)item; } catch { throw new Exception("Given item is not a Placeable Item"); } } catch { throw new Exception("Invalid ItemID"); } } }
public static void SnapObjectToGrid(this Transform t, Vector3 worldPosition, PlaceableItem item) { if (t && item) { if (item.SnapPosition) { t.SnapToGrid(worldPosition, item.SnapGrideSize); } if (item.SnapRotation) { float rotIncrement = item.AngleInDeg; var rot = t.eulerAngles; rot.z = rotIncrement * (int)(rot.z / rotIncrement); t.eulerAngles = rot; } } }
// ---------------------------------------------------------------------------- private bool CanBePlaced(SpriteRenderer s, bool checkForSelectedItem = true) { ClearBuffer(_resultBuffer); int count = Physics2D.OverlapBoxNonAlloc(s.transform.position, 0.75f * s.size, 0, _resultBuffer); PlaceableItem obj = null; for (int i = 0; i < count; i++) { obj = _resultBuffer[i].transform.FindUpHeirarchy <PlaceableItem>(); if (checkForSelectedItem && obj && obj == _selection.Placeholder) { continue; } return(false); } return(true); }
/** * Used to configure the inventory slots * */ void Start() { inventory = FindObjectOfType <Inventory>(); placeableItemScript = FindObjectOfType <PlaceableItem>(); trackItemsScript = FindObjectOfType <SpawnAndTrackItems>(); backgroundSlots = inventory.backgroundSlots; inventorySlots = inventory.allInventorySlots; //canvas = FindObjectOfType<Canvas>(); Items = new Stack <Item>(); RectTransform slotRectTrans = GetComponent <RectTransform>(); RectTransform textRectTrans = stackText.GetComponent <RectTransform>(); int textScaleFactor = (int)(slotRectTrans.sizeDelta.x * scaleFactor); textRectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotRectTrans.sizeDelta.y); textRectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, slotRectTrans.sizeDelta.x); stackText.resizeTextMaxSize = textScaleFactor; stackText.resizeTextMinSize = textScaleFactor; }