1193 lines
55 KiB
C#
1193 lines
55 KiB
C#
|
//********************************************************//
|
|||
|
// //
|
|||
|
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
|
|||
|
// //
|
|||
|
// REPRODUCTION FORBIDEN //
|
|||
|
// //
|
|||
|
//********************************************************//
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
using ItemsClassList;
|
|||
|
using ICWM.DragAndDrop;
|
|||
|
using ICWM.Enemy;
|
|||
|
using ICWM.IconSystem;
|
|||
|
using ICWM.ItemSystem;
|
|||
|
using ICWM.RenderSystem;
|
|||
|
using ICWM.SaveSystem;
|
|||
|
using ICWM.UISystem;
|
|||
|
using ICWM.WindowSystem;
|
|||
|
|
|||
|
namespace ICWM
|
|||
|
{
|
|||
|
namespace HelperSystem
|
|||
|
{
|
|||
|
public static class Helper
|
|||
|
{
|
|||
|
#region Render Helper
|
|||
|
|
|||
|
public static void AddItemToRenderList(GameObject itemSlot, ItemList cl) // in RenderWeaponScreenIcon
|
|||
|
{
|
|||
|
InventoryBase.instance.WeaponRenderScreen.GetComponent<RenderWeaponScreenIcon>().listMassiveRenderCL.Add(cl);
|
|||
|
InventoryBase.instance.WeaponRenderScreen.GetComponent<RenderWeaponScreenIcon>().listMassiveRenderGO.Add(itemSlot);
|
|||
|
InventoryBase.instance.WeaponRenderScreen.GetComponent<RenderWeaponScreenIcon>().isRenderTextures = true;
|
|||
|
}
|
|||
|
|
|||
|
public static Material CreateRenderMaterial(ItemList cl)
|
|||
|
{
|
|||
|
Material vspMatIcon;
|
|||
|
vspMatIcon = Material.Instantiate(InventoryBase.instance.WeaponRenderScreen.GetComponent<RenderWeaponScreenIcon>().MatIcon);
|
|||
|
vspMatIcon.name = "Mat_" + cl.id.ToString();
|
|||
|
|
|||
|
RenderTexture vspRTIcon;
|
|||
|
vspRTIcon = RenderTexture.Instantiate(InventoryBase.instance.WeaponRenderScreen.GetComponent<RenderWeaponScreenIcon>().RTIcon);
|
|||
|
vspRTIcon.name = "RT_" + vspMatIcon.name;
|
|||
|
if (cl.itWasRotated)
|
|||
|
{
|
|||
|
vspRTIcon.height = (int)(cl.indexPos60x60.x * BackpackBase.CELL_SIZE);
|
|||
|
vspRTIcon.width = (int)(cl.indexPos60x60.y * BackpackBase.CELL_SIZE);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vspRTIcon.height = (int)(cl.indexPos60x60.y * BackpackBase.CELL_SIZE);
|
|||
|
vspRTIcon.width = (int)(cl.indexPos60x60.x * BackpackBase.CELL_SIZE);
|
|||
|
}
|
|||
|
vspRTIcon.antiAliasing = 8;
|
|||
|
|
|||
|
vspMatIcon.mainTexture = vspRTIcon;
|
|||
|
return vspMatIcon;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Set Item Parameters
|
|||
|
|
|||
|
//
|
|||
|
// From ClassList to ClassList
|
|||
|
// Create a new item
|
|||
|
//
|
|||
|
public static ItemList SetParameters(ItemList clNew, ItemList clOrigin, bool isStoreItem = false)
|
|||
|
{
|
|||
|
clNew.id = InventoryBase.instance.idWeaponNames; //
|
|||
|
InventoryBase.instance.idWeaponNames++;
|
|||
|
|
|||
|
if (clOrigin.isStack)
|
|||
|
{
|
|||
|
clNew.isStack = clOrigin.isStack;
|
|||
|
clNew.stackID = clOrigin.stackID;
|
|||
|
}
|
|||
|
|
|||
|
clNew.amountStack = clOrigin.amountStack;
|
|||
|
if (clOrigin.isMoney)
|
|||
|
{
|
|||
|
clNew.isMoney = clOrigin.isMoney;
|
|||
|
clNew.moneyType = clOrigin.moneyType;
|
|||
|
clNew.isPurse = clOrigin.isPurse;
|
|||
|
if (clOrigin.isPurse)
|
|||
|
clNew.maxAmountStack = clOrigin.maxAmountStack;
|
|||
|
else
|
|||
|
clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack;
|
|||
|
}
|
|||
|
else
|
|||
|
clNew.maxAmountStack = clOrigin.maxAmountStack;
|
|||
|
|
|||
|
if (clOrigin.isCombine)
|
|||
|
{
|
|||
|
clNew.isCombine = clOrigin.isCombine;
|
|||
|
clNew.combineResultPrefab = clOrigin.combineResultPrefab;
|
|||
|
}
|
|||
|
|
|||
|
if (clOrigin.isResultCombine)
|
|||
|
{
|
|||
|
clNew.isResultCombine = clOrigin.isResultCombine;
|
|||
|
clNew.combineResultPrefab = clOrigin.combineResultPrefab;
|
|||
|
clNew.maxStackCombine = clOrigin.maxStackCombine;
|
|||
|
}
|
|||
|
|
|||
|
clNew.isEnemyItem = clOrigin.isEnemyItem;
|
|||
|
clNew.tagAttach = clOrigin.tagAttach;
|
|||
|
clNew.typeOfBullet = clOrigin.typeOfBullet;
|
|||
|
clNew.isLatchkey = clOrigin.isLatchkey;
|
|||
|
clNew.isBullet = clOrigin.isBullet;
|
|||
|
clNew.isMagazine = clOrigin.isMagazine;
|
|||
|
clNew.clipSize = clOrigin.clipSize;
|
|||
|
clNew.amountBullet = clOrigin.amountBullet;
|
|||
|
clNew.separatePrefab = clOrigin.separatePrefab;
|
|||
|
clNew.itHasMagazine = clOrigin.itHasMagazine;
|
|||
|
clNew.sortingType = clOrigin.sortingType;
|
|||
|
clNew.tagItem = clOrigin.tagItem;
|
|||
|
clNew.tagSize = clOrigin.tagSize;
|
|||
|
clNew.baseTagSize = clOrigin.baseTagSize;
|
|||
|
clNew.indexPos60x60 = clNew.GetIndexPos60x60();
|
|||
|
clNew.id_Weapon = clOrigin.id_Weapon;
|
|||
|
clNew.id_Attach = clOrigin.id_Attach;
|
|||
|
clNew.isLockRotate = clOrigin.isLockRotate;
|
|||
|
clNew.isBackpack = clOrigin.isBackpack;
|
|||
|
clNew.isTacticalRig = clOrigin.isTacticalRig;
|
|||
|
clNew.isPockets = clOrigin.isPockets;
|
|||
|
clNew.statisticList = clOrigin.statisticList;
|
|||
|
clNew.baseStatisticsList = clOrigin.statisticList;
|
|||
|
clNew.baseColliderSize = clOrigin.baseColliderSize;
|
|||
|
clNew.isPutOn = clOrigin.isPutOn;
|
|||
|
clNew.itemIcon = clOrigin.itemIcon;
|
|||
|
|
|||
|
clNew.startPositionInInventory = clOrigin.startPositionInInventory;
|
|||
|
|
|||
|
if (clNew.isPockets)
|
|||
|
{
|
|||
|
clNew.pocketSlots = clOrigin.pocketSlots;
|
|||
|
if (clNew.pocketSlots > 1)
|
|||
|
clNew.insertCL = new ItemList[clNew.pocketSlots];
|
|||
|
else
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS];
|
|||
|
}
|
|||
|
else if (clNew.isTacticalRig)
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS];
|
|||
|
clNew.typeTRStyle = clOrigin.typeTRStyle;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[1];
|
|||
|
}
|
|||
|
|
|||
|
if (clOrigin.itemModding)
|
|||
|
{
|
|||
|
if (!isStoreItem)
|
|||
|
clNew.itemModding = GameObject.Instantiate(clOrigin.itemModding);
|
|||
|
else
|
|||
|
clNew.itemModding = clOrigin.itemModding;
|
|||
|
}
|
|||
|
else if (clOrigin.vspItemModdingPrefab)
|
|||
|
clNew.itemModding = GameObject.Instantiate(clOrigin.vspItemModdingPrefab);
|
|||
|
clNew.vspItemModdingPrefab = clOrigin.vspItemModdingPrefab;
|
|||
|
|
|||
|
if (clOrigin.weaponPlayerRig)
|
|||
|
clNew.weaponPlayerRig = clOrigin.weaponPlayerRig;
|
|||
|
|
|||
|
if (clOrigin.spriteTextureItemInventory)
|
|||
|
clNew.spriteTextureItemInventory = clOrigin.spriteTextureItemInventory;
|
|||
|
|
|||
|
if (clOrigin.spriteTextureItemModding)
|
|||
|
clNew.spriteTextureItemModding = clOrigin.spriteTextureItemModding;
|
|||
|
|
|||
|
clNew.isDefaultRenderParams = clOrigin.isDefaultRenderParams;
|
|||
|
clNew.modelRenderPosition = clOrigin.modelRenderPosition;
|
|||
|
clNew.modelRenderRotation = clOrigin.modelRenderRotation;
|
|||
|
clNew.modelRenderScale = clOrigin.modelRenderScale;
|
|||
|
|
|||
|
return clNew;
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
// From ItemDrop to ClassList
|
|||
|
// Create a new item
|
|||
|
//
|
|||
|
public static ItemList SetParameters(ItemList clNew, GameObject idOrigin, bool isCreateItemModding = false, bool isCreateNewId = true, GameObject DestroyObj = null, bool IsNotEnemyItem = false)
|
|||
|
{
|
|||
|
if (isCreateNewId)
|
|||
|
{
|
|||
|
clNew.id = InventoryBase.instance.idWeaponNames; //
|
|||
|
InventoryBase.instance.idWeaponNames++;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
clNew.id = idOrigin.GetComponent<ItemsDrop>().id;
|
|||
|
}
|
|||
|
|
|||
|
if (DestroyObj != null)
|
|||
|
clNew.destroyItemDrop = DestroyObj;
|
|||
|
else
|
|||
|
clNew.destroyItemDrop = idOrigin.GetComponent<ItemsDrop>().gameObject;
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().IsStack)
|
|||
|
{
|
|||
|
clNew.isStack = idOrigin.GetComponent<ItemsDrop>().IsStack;
|
|||
|
clNew.stackID = idOrigin.GetComponent<ItemsDrop>().StackID;
|
|||
|
}
|
|||
|
|
|||
|
clNew.amountStack = idOrigin.GetComponent<ItemsDrop>().AmountStack;
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().IsMoney)
|
|||
|
{
|
|||
|
clNew.isMoney = idOrigin.GetComponent<ItemsDrop>().IsMoney;
|
|||
|
clNew.moneyType = idOrigin.GetComponent<ItemsDrop>().MoneyType;
|
|||
|
clNew.isPurse = idOrigin.GetComponent<ItemsDrop>().IsPurse;
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().IsPurse)
|
|||
|
clNew.maxAmountStack = idOrigin.GetComponent<ItemsDrop>().MaxAmountStack;
|
|||
|
else
|
|||
|
clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack;
|
|||
|
}
|
|||
|
else
|
|||
|
clNew.maxAmountStack = idOrigin.GetComponent<ItemsDrop>().MaxAmountStack;
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().IsCombine)
|
|||
|
{
|
|||
|
clNew.isCombine = idOrigin.GetComponent<ItemsDrop>().IsCombine;
|
|||
|
clNew.combineResultPrefab = idOrigin.GetComponent<ItemsDrop>().CombineResultPrefab;
|
|||
|
}
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().IsResultCombine)
|
|||
|
{
|
|||
|
clNew.isResultCombine = idOrigin.GetComponent<ItemsDrop>().IsResultCombine;
|
|||
|
clNew.combineResultPrefab = idOrigin.GetComponent<ItemsDrop>().CombineResultPrefab;
|
|||
|
clNew.maxStackCombine = idOrigin.GetComponent<ItemsDrop>().MaxStackCombine;
|
|||
|
}
|
|||
|
|
|||
|
clNew.tagAttach = idOrigin.GetComponent<ItemsDrop>().AttachTag;
|
|||
|
clNew.typeOfBullet = idOrigin.GetComponent<ItemsDrop>().TypeOfBullet;
|
|||
|
clNew.isLatchkey = idOrigin.GetComponent<ItemsDrop>().IsLatchkey;
|
|||
|
clNew.isBullet = idOrigin.GetComponent<ItemsDrop>().IsBullet;
|
|||
|
clNew.isMagazine = idOrigin.GetComponent<ItemsDrop>().IsMagazine;
|
|||
|
clNew.clipSize = idOrigin.GetComponent<ItemsDrop>().ClipSize;
|
|||
|
clNew.amountBullet = idOrigin.GetComponent<ItemsDrop>().AmountBullet;
|
|||
|
clNew.separatePrefab = idOrigin.GetComponent<ItemsDrop>().SeparatePrefab;
|
|||
|
clNew.itHasMagazine = idOrigin.GetComponent<ItemsDrop>().ItHasMagazine;
|
|||
|
clNew.sortingType = idOrigin.GetComponent<ItemsDrop>().SortingType;
|
|||
|
clNew.tagItem = idOrigin.GetComponent<ItemsDrop>().ItemTag;
|
|||
|
clNew.tagSize = idOrigin.GetComponent<ItemsDrop>().SizeTag;
|
|||
|
clNew.baseTagSize = clNew.tagSize;
|
|||
|
clNew.indexPos60x60 = clNew.GetIndexPos60x60();
|
|||
|
clNew.id_Weapon = idOrigin.GetComponent<ItemsDrop>().ID_Weapon;
|
|||
|
clNew.id_Attach = idOrigin.GetComponent<ItemsDrop>().ID_Attachments;
|
|||
|
clNew.isLockRotate = idOrigin.GetComponent<ItemsDrop>().IsLockRotate;
|
|||
|
clNew.isBackpack = idOrigin.GetComponent<ItemsDrop>().IsBackpack;
|
|||
|
clNew.isTacticalRig = idOrigin.GetComponent<ItemsDrop>().IsTacticalRig;
|
|||
|
clNew.isPockets = idOrigin.GetComponent<ItemsDrop>().IsPockets;
|
|||
|
clNew.statisticList = idOrigin.GetComponent<ItemsDrop>().StatList;
|
|||
|
clNew.baseStatisticsList = idOrigin.GetComponent<ItemsDrop>().StatList;
|
|||
|
clNew.baseColliderSize = idOrigin.GetComponent<BoxCollider>().size;
|
|||
|
|
|||
|
//
|
|||
|
clNew.startPositionInInventory = idOrigin.GetComponent<ItemsDrop>().StartPositionInInventory;
|
|||
|
|
|||
|
if (IsNotEnemyItem == false)
|
|||
|
{
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().CL.insertCL != null && idOrigin.GetComponent<ItemsDrop>().CL.insertCL.Length != 0)
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[idOrigin.GetComponent<ItemsDrop>().CL.insertCL.Length];
|
|||
|
clNew.startPositionInBackpack = new Vector2[idOrigin.GetComponent<ItemsDrop>().CL.insertCL.Length];
|
|||
|
|
|||
|
for (int i = 0; i < idOrigin.GetComponent<ItemsDrop>().CL.insertCL.Length; i++)
|
|||
|
{
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().CL.insertCL[i] == null)
|
|||
|
break;
|
|||
|
|
|||
|
clNew.startPositionInBackpack[i] = idOrigin.GetComponent<ItemsDrop>().CL.insertCL[i].startPositionInInventory;
|
|||
|
clNew.insertCL[i] = idOrigin.GetComponent<ItemsDrop>().CL.insertCL[i];
|
|||
|
clNew.insertCL[i] = SetParameters(clNew.insertCL[i], idOrigin.GetComponent<ItemsDrop>().CL.insertCL[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
clNew.isPutOn = idOrigin.GetComponent<ItemsDrop>().IsPutOn;
|
|||
|
|
|||
|
if (clNew.isPockets)
|
|||
|
{
|
|||
|
clNew.pocketSlots = idOrigin.GetComponent<ItemsDrop>().PocketSlots;
|
|||
|
if (clNew.pocketSlots > 1)
|
|||
|
clNew.insertCL = new ItemList[clNew.pocketSlots];
|
|||
|
else
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS];
|
|||
|
}
|
|||
|
else if (clNew.isTacticalRig)
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS];
|
|||
|
clNew.typeTRStyle = idOrigin.GetComponent<ItemsDrop>().TypeTRStyle;
|
|||
|
}
|
|||
|
else if (clNew.isBackpack)
|
|||
|
{
|
|||
|
clNew.tagSizeBackpack = idOrigin.GetComponent<ItemsDrop>().SizeBackpack;
|
|||
|
clNew.insertCL = new ItemList[clNew.GetMasSizeBackpack()];
|
|||
|
clNew.startPositionInBackpack = new Vector2[clNew.GetMasSizeBackpack()];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[1];
|
|||
|
}
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().itemModding)
|
|||
|
{
|
|||
|
clNew.vspItemModdingPrefab = idOrigin.GetComponent<ItemsDrop>().itemModding;
|
|||
|
clNew.SetItemModdingParameters(true, null);
|
|||
|
}
|
|||
|
else
|
|||
|
Debug.Log("id_Original.GetComponent<ItemsDrop>().itemModding == null");
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().WeaponPlayerRig)
|
|||
|
clNew.weaponPlayerRig = idOrigin.GetComponent<ItemsDrop>().WeaponPlayerRig;
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().SpriteTextureItemInventory)
|
|||
|
clNew.spriteTextureItemInventory = idOrigin.GetComponent<ItemsDrop>().SpriteTextureItemInventory;
|
|||
|
|
|||
|
if (idOrigin.GetComponent<ItemsDrop>().SpriteTextureItemModding)
|
|||
|
clNew.spriteTextureItemModding = idOrigin.GetComponent<ItemsDrop>().SpriteTextureItemModding;
|
|||
|
|
|||
|
clNew.isDefaultRenderParams = idOrigin.GetComponent<ItemsDrop>().ByDefaultRenderParams;
|
|||
|
clNew.modelRenderPosition = idOrigin.GetComponent<ItemsDrop>().WeaponPosition;
|
|||
|
clNew.modelRenderRotation = idOrigin.GetComponent<ItemsDrop>().WeaponRotation;
|
|||
|
clNew.modelRenderScale = idOrigin.GetComponent<ItemsDrop>().WeaponScale;
|
|||
|
|
|||
|
return clNew;
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
// From ClassList to ItemDrop
|
|||
|
// We do not create a new item
|
|||
|
//
|
|||
|
public static void SetParameters(GameObject idNew, ItemList idOrigin)
|
|||
|
{
|
|||
|
idNew.GetComponent<ItemsDrop>().id = idOrigin.id;
|
|||
|
|
|||
|
if (idOrigin.isStack)
|
|||
|
{
|
|||
|
idNew.GetComponent<ItemsDrop>().IsStack = idOrigin.isStack;
|
|||
|
idNew.GetComponent<ItemsDrop>().StackID = idOrigin.stackID;
|
|||
|
}
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().AmountStack = idOrigin.amountStack;
|
|||
|
|
|||
|
if (idOrigin.isMoney)
|
|||
|
{
|
|||
|
idNew.GetComponent<ItemsDrop>().IsMoney = idOrigin.isMoney;
|
|||
|
idNew.GetComponent<ItemsDrop>().MoneyType = idOrigin.moneyType;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsPurse = idOrigin.isPurse;
|
|||
|
if (idNew.GetComponent<ItemsDrop>().IsPurse)
|
|||
|
idNew.GetComponent<ItemsDrop>().MaxAmountStack = idOrigin.maxAmountStack;
|
|||
|
else
|
|||
|
InventoryBase.instance.PlayerStatistics.MaxMoneyStack = idOrigin.maxAmountStack;
|
|||
|
}
|
|||
|
else
|
|||
|
idNew.GetComponent<ItemsDrop>().MaxAmountStack = idOrigin.maxAmountStack;
|
|||
|
|
|||
|
if (idOrigin.isCombine)
|
|||
|
{
|
|||
|
idNew.GetComponent<ItemsDrop>().IsCombine = idOrigin.isCombine;
|
|||
|
idNew.GetComponent<ItemsDrop>().CombineResultPrefab = idOrigin.combineResultPrefab;
|
|||
|
}
|
|||
|
|
|||
|
if (idOrigin.isResultCombine)
|
|||
|
{
|
|||
|
idNew.GetComponent<ItemsDrop>().IsResultCombine = idOrigin.isResultCombine;
|
|||
|
idNew.GetComponent<ItemsDrop>().CombineResultPrefab = idOrigin.combineResultPrefab;
|
|||
|
idNew.GetComponent<ItemsDrop>().MaxStackCombine = idOrigin.maxStackCombine;
|
|||
|
}
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().AttachTag = idOrigin.tagAttach;
|
|||
|
idNew.GetComponent<ItemsDrop>().TypeOfBullet = idOrigin.typeOfBullet;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsLatchkey = idOrigin.isLatchkey;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsBullet = idOrigin.isBullet;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsMagazine = idOrigin.isMagazine;
|
|||
|
idNew.GetComponent<ItemsDrop>().ClipSize = idOrigin.clipSize;
|
|||
|
idNew.GetComponent<ItemsDrop>().AmountBullet = idOrigin.amountBullet;
|
|||
|
idNew.GetComponent<ItemsDrop>().SeparatePrefab = idOrigin.separatePrefab;
|
|||
|
idNew.GetComponent<ItemsDrop>().ItHasMagazine = idOrigin.itHasMagazine;
|
|||
|
idNew.GetComponent<ItemsDrop>().SortingType = idOrigin.sortingType;
|
|||
|
idNew.GetComponent<ItemsDrop>().ItemTag = idOrigin.tagItem;
|
|||
|
idNew.GetComponent<ItemsDrop>().SizeTag = idOrigin.baseTagSize;
|
|||
|
idNew.GetComponent<ItemsDrop>().ID_Weapon = idOrigin.id_Weapon;
|
|||
|
idNew.GetComponent<ItemsDrop>().ID_Attachments = idOrigin.id_Attach;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsLockRotate = idOrigin.isLockRotate;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsBackpack = idOrigin.isBackpack;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsTacticalRig = idOrigin.isTacticalRig;
|
|||
|
idNew.GetComponent<ItemsDrop>().IsPockets = idOrigin.isPockets;
|
|||
|
|
|||
|
//
|
|||
|
idNew.GetComponent<ItemsDrop>().StartPositionInInventory = idOrigin.startPositionInInventory;
|
|||
|
|
|||
|
if (idOrigin.insertCL != null && idOrigin.insertCL != null && idOrigin.insertCL.Length != 0)
|
|||
|
{
|
|||
|
if (idNew.GetComponent<ItemsDrop>().CL == null)
|
|||
|
idNew.GetComponent<ItemsDrop>().CL = new ItemList();
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().CL.insertCL = new ItemList[idOrigin.insertCL.Length];
|
|||
|
|
|||
|
for (int i = 0; i < idOrigin.insertCL.Length; i++)
|
|||
|
{
|
|||
|
if (idOrigin.insertCL[i] == null)
|
|||
|
break;
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().CL.insertCL[i] = idOrigin.insertCL[i];
|
|||
|
idNew.GetComponent<ItemsDrop>().CL.insertCL[i] = SetParameters(idNew.GetComponent<ItemsDrop>().CL.insertCL[i], idOrigin.insertCL[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().IsPutOn = idOrigin.isPutOn;
|
|||
|
|
|||
|
// ?
|
|||
|
idNew.GetComponent<ItemsDrop>().StatList = idOrigin.statisticList;
|
|||
|
idNew.GetComponent<ItemsDrop>().StatList = idOrigin.baseStatisticsList;
|
|||
|
|
|||
|
idNew.GetComponent<BoxCollider>().size = idOrigin.baseColliderSize;
|
|||
|
|
|||
|
if (idNew.GetComponent<ItemsDrop>().IsBackpack)
|
|||
|
idNew.GetComponent<ItemsDrop>().SizeBackpack = idOrigin.tagSizeBackpack;
|
|||
|
|
|||
|
if (idOrigin.vspItemModdingPrefab)
|
|||
|
idNew.GetComponent<ItemsDrop>().itemModding = idOrigin.vspItemModdingPrefab;
|
|||
|
else if (idOrigin.itemModding)
|
|||
|
idNew.GetComponent<ItemsDrop>().itemModding = idOrigin.itemModding;
|
|||
|
|
|||
|
if (idOrigin.weaponPlayerRig)
|
|||
|
idNew.GetComponent<ItemsDrop>().WeaponPlayerRig = idOrigin.weaponPlayerRig;
|
|||
|
|
|||
|
if (idOrigin.spriteTextureItemInventory)
|
|||
|
idNew.GetComponent<ItemsDrop>().SpriteTextureItemInventory = idOrigin.spriteTextureItemInventory;
|
|||
|
|
|||
|
if (idOrigin.spriteTextureItemModding)
|
|||
|
idNew.GetComponent<ItemsDrop>().SpriteTextureItemModding = idOrigin.spriteTextureItemModding;
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().CL = idOrigin;
|
|||
|
|
|||
|
idNew.GetComponent<ItemsDrop>().ByDefaultRenderParams = idOrigin.isDefaultRenderParams;
|
|||
|
idNew.GetComponent<ItemsDrop>().WeaponPosition = idOrigin.modelRenderPosition;
|
|||
|
idNew.GetComponent<ItemsDrop>().WeaponRotation = idOrigin.modelRenderRotation;
|
|||
|
idNew.GetComponent<ItemsDrop>().WeaponScale = idOrigin.modelRenderScale;
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
// From ItemDrop to ClassList
|
|||
|
//
|
|||
|
public static ItemList SetParameters(ItemList clNew, ItemsDrop idOrigin, int lootID)
|
|||
|
{
|
|||
|
clNew.id = InventoryBase.instance.idWeaponNames;
|
|||
|
InventoryBase.instance.idWeaponNames++;
|
|||
|
|
|||
|
clNew.lootID = lootID;
|
|||
|
|
|||
|
if (idOrigin.IsStack)
|
|||
|
{
|
|||
|
clNew.isStack = idOrigin.IsStack;
|
|||
|
clNew.stackID = idOrigin.StackID;
|
|||
|
}
|
|||
|
clNew.amountStack = idOrigin.AmountStack;
|
|||
|
|
|||
|
if (idOrigin.IsMoney)
|
|||
|
{
|
|||
|
clNew.isMoney = idOrigin.IsMoney;
|
|||
|
clNew.isPurse = idOrigin.IsPurse;
|
|||
|
clNew.moneyType = idOrigin.MoneyType;
|
|||
|
if (idOrigin.IsPurse)
|
|||
|
clNew.maxAmountStack = idOrigin.MaxAmountStack;
|
|||
|
else
|
|||
|
clNew.maxAmountStack = InventoryBase.instance.PlayerStatistics.MaxMoneyStack;
|
|||
|
}
|
|||
|
else
|
|||
|
clNew.maxAmountStack = idOrigin.MaxAmountStack;
|
|||
|
|
|||
|
if (idOrigin.IsCombine)
|
|||
|
{
|
|||
|
clNew.isCombine = idOrigin.IsCombine;
|
|||
|
clNew.combineResultPrefab = idOrigin.CombineResultPrefab;
|
|||
|
}
|
|||
|
|
|||
|
if (idOrigin.IsResultCombine)
|
|||
|
{
|
|||
|
clNew.isResultCombine = idOrigin.IsResultCombine;
|
|||
|
clNew.combineResultPrefab = idOrigin.CombineResultPrefab;
|
|||
|
clNew.maxStackCombine = idOrigin.MaxStackCombine;
|
|||
|
}
|
|||
|
|
|||
|
clNew.tagAttach = idOrigin.AttachTag;
|
|||
|
clNew.typeOfBullet = idOrigin.TypeOfBullet;
|
|||
|
clNew.isBullet = idOrigin.IsBullet;
|
|||
|
clNew.isMagazine = idOrigin.IsMagazine;
|
|||
|
clNew.clipSize = idOrigin.ClipSize;
|
|||
|
clNew.amountBullet = idOrigin.AmountBullet;
|
|||
|
clNew.separatePrefab = idOrigin.SeparatePrefab;
|
|||
|
clNew.sortingType = idOrigin.SortingType;
|
|||
|
clNew.isLatchkey = idOrigin.IsLatchkey;
|
|||
|
clNew.tagItem = idOrigin.ItemTag;
|
|||
|
clNew.tagSize = idOrigin.SizeTag;
|
|||
|
clNew.id_Weapon = idOrigin.ID_Weapon;
|
|||
|
clNew.id_Attach = idOrigin.ID_Attachments;
|
|||
|
clNew.isLockRotate = idOrigin.IsLockRotate;
|
|||
|
clNew.isBackpack = idOrigin.IsBackpack;
|
|||
|
clNew.isTacticalRig = idOrigin.IsTacticalRig;
|
|||
|
clNew.isPockets = idOrigin.IsPockets;
|
|||
|
clNew.statisticList = idOrigin.StatList;
|
|||
|
clNew.baseStatisticsList = idOrigin.StatList;
|
|||
|
clNew.indexPos60x60 = clNew.GetIndexPos60x60();
|
|||
|
clNew.baseTagSize = idOrigin.SizeTag;
|
|||
|
clNew.baseColliderSize = idOrigin.GetComponent<BoxCollider>().size;
|
|||
|
|
|||
|
if (clNew.isBackpack)
|
|||
|
{
|
|||
|
clNew.tagSizeBackpack = idOrigin.SizeBackpack;
|
|||
|
clNew.insertCL = new ItemList[clNew.GetMasSizeBackpack()];
|
|||
|
clNew.startPositionInBackpack = new Vector2[clNew.GetMasSizeBackpack()];
|
|||
|
}
|
|||
|
else if (clNew.isTacticalRig)
|
|||
|
{
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_TACTICAL_RIG_CELLS];
|
|||
|
}
|
|||
|
else if (clNew.isPockets)
|
|||
|
{
|
|||
|
clNew.pocketSlots = idOrigin.PocketSlots;
|
|||
|
if (clNew.pocketSlots > 1)
|
|||
|
clNew.insertCL = new ItemList[clNew.pocketSlots];
|
|||
|
else
|
|||
|
clNew.insertCL = new ItemList[BackpackBase.MAX_POCKETS_CELLS];
|
|||
|
}
|
|||
|
|
|||
|
if (idOrigin.WeaponPlayerRig)
|
|||
|
clNew.weaponPlayerRig = idOrigin.WeaponPlayerRig;
|
|||
|
|
|||
|
if (idOrigin.itemModding)
|
|||
|
{
|
|||
|
clNew.vspItemModdingPrefab = idOrigin.itemModding;
|
|||
|
clNew.itemModding = GameObject.Instantiate(clNew.vspItemModdingPrefab);
|
|||
|
}
|
|||
|
else
|
|||
|
Debug.Log("id_Original.GetComponent<ItemsDrop>().itemModding == null");
|
|||
|
|
|||
|
if (idOrigin.SpriteTextureItemInventory)
|
|||
|
clNew.spriteTextureItemInventory = idOrigin.SpriteTextureItemInventory;
|
|||
|
if (idOrigin.SpriteTextureItemModding)
|
|||
|
clNew.spriteTextureItemModding = idOrigin.SpriteTextureItemModding;
|
|||
|
|
|||
|
clNew.isDefaultRenderParams = idOrigin.ByDefaultRenderParams;
|
|||
|
clNew.modelRenderPosition = idOrigin.WeaponPosition;
|
|||
|
clNew.modelRenderRotation = idOrigin.WeaponRotation;
|
|||
|
clNew.modelRenderScale = idOrigin.WeaponScale;
|
|||
|
|
|||
|
return clNew;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Set, Get, Reset
|
|||
|
|
|||
|
public static void ResetTransform(Transform itemTransform)
|
|||
|
{
|
|||
|
itemTransform.localScale = Vector3.one;
|
|||
|
itemTransform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
itemTransform.localPosition = Vector3.zero;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Inventory Slots
|
|||
|
|
|||
|
public static bool IsHaveFreeSlotInInventory(ItemList cl)
|
|||
|
{
|
|||
|
if (cl == null)
|
|||
|
return false;
|
|||
|
|
|||
|
bool isFoundFreeSlot = false;
|
|||
|
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack)
|
|||
|
isFoundFreeSlot = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(cl.indexPos60x60);
|
|||
|
|
|||
|
if (!isFoundFreeSlot)
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize) != -1)
|
|||
|
isFoundFreeSlot = true;
|
|||
|
|
|||
|
if (StashSystem.instance && InventoryBase.instance.hideStash)
|
|||
|
isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(cl.indexPos60x60);
|
|||
|
}
|
|||
|
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return true;
|
|||
|
else
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
// Return:
|
|||
|
// -1 - No place
|
|||
|
// 0 - Backpack / Backpack Window
|
|||
|
// 1 - TacticalRig / TacticalRig Window
|
|||
|
// 2 - Pockets / Pockets Window
|
|||
|
// 3 - Stash
|
|||
|
// IsEnemyBackpack - значит будем искать в инвентаре Енеми
|
|||
|
public static int GetFreeSlotIndexPlayerInventoryForSeparateAction(ItemList cl, bool storeMode = false, bool isEnemyBackpack = false, bool stashMode = false, bool isFromBackpackWindow = false, bool isFromTacticalRigPocketsWindow = false)
|
|||
|
{
|
|||
|
Vector2 indexPos60x60 = cl.indexPos60x60;
|
|||
|
if (cl.IsProbablyDifferentSeparateItem() && cl.separatePrefab != null)
|
|||
|
indexPos60x60 = cl.GetIndexPos60x60ByTag(cl.separatePrefab.GetComponent<ItemsDrop>().SizeTag);
|
|||
|
|
|||
|
bool isFoundFreeSlot = false;
|
|||
|
if (!isEnemyBackpack) // Player inventory
|
|||
|
{
|
|||
|
if (stashMode)
|
|||
|
{
|
|||
|
isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60);
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return 3;
|
|||
|
else
|
|||
|
return -1;
|
|||
|
}
|
|||
|
else if (isFromBackpackWindow)
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.m_vspBackpackWindow)
|
|||
|
{
|
|||
|
int vsp = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl);
|
|||
|
|
|||
|
if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (isFromTacticalRigPocketsWindow)
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.m_vspBackpackWindow)
|
|||
|
{
|
|||
|
int IndexFreePlace = -1;
|
|||
|
|
|||
|
if (cl.separatePrefab)
|
|||
|
IndexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().GetFreeSlotTacticRigPockets(cl.separatePrefab.GetComponent<ItemsDrop>().SizeTag);
|
|||
|
else
|
|||
|
IndexFreePlace = BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().GetBackpackInfo().GetFreeSlotTacticRigPockets(cl.tagSize); // Itself
|
|||
|
|
|||
|
if (IndexFreePlace != -1)
|
|||
|
return IndexFreePlace;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot
|
|||
|
{
|
|||
|
int vsp = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl);
|
|||
|
|
|||
|
if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
else
|
|||
|
isFoundFreeSlot = false;
|
|||
|
}
|
|||
|
|
|||
|
if (!isFoundFreeSlot)
|
|||
|
{
|
|||
|
int IndexFreePlace = 0;
|
|||
|
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets)
|
|||
|
{
|
|||
|
if (cl.separatePrefab)
|
|||
|
IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.separatePrefab.GetComponent<ItemsDrop>().SizeTag);
|
|||
|
else
|
|||
|
IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize); // Itself
|
|||
|
|
|||
|
if (IndexFreePlace != -1)
|
|||
|
return IndexFreePlace;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else // Enemy inventory
|
|||
|
{
|
|||
|
if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot
|
|||
|
{
|
|||
|
int vsp = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, 2, cl);
|
|||
|
|
|||
|
if (vsp == 2 && cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
else if (vsp != 0 && !cl.isResultCombine) // 2 - так как делим предмет на 2 части
|
|||
|
return 0;
|
|||
|
else
|
|||
|
isFoundFreeSlot = false;
|
|||
|
}
|
|||
|
|
|||
|
if (!isFoundFreeSlot)
|
|||
|
{
|
|||
|
int IndexFreePlace = 0;
|
|||
|
|
|||
|
if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveTacticalRig || BackpackEnemyBase.instance.GetBackpackInfo().isActivePockets)
|
|||
|
{
|
|||
|
if (cl.separatePrefab)
|
|||
|
IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.separatePrefab.GetComponent<ItemsDrop>().SizeTag);
|
|||
|
else
|
|||
|
IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(cl.tagSize); // Itself
|
|||
|
|
|||
|
if (IndexFreePlace != -1)
|
|||
|
return IndexFreePlace;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
public static int GetFreeSlotIndexPlayerInventory(Vector2 indexPos60x60, ItemList.SizeIconInventory tagSize, bool storeMode = false, bool isEnemyBackpack = false, bool isLootWindow = false)
|
|||
|
{
|
|||
|
bool isFoundFreeSlot = false;
|
|||
|
|
|||
|
if (!isEnemyBackpack)
|
|||
|
{
|
|||
|
if (isLootWindow) // For loot window only one iteration
|
|||
|
{
|
|||
|
isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60);
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return 3;
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot
|
|||
|
{
|
|||
|
isFoundFreeSlot = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60);
|
|||
|
}
|
|||
|
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return 0;
|
|||
|
else
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets)
|
|||
|
{
|
|||
|
int IndexFreePlace = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(tagSize);
|
|||
|
if (IndexFreePlace != -1)
|
|||
|
return IndexFreePlace;
|
|||
|
}
|
|||
|
else if (StashSystem.instance && InventoryBase.instance.hideStash && !storeMode)
|
|||
|
{
|
|||
|
isFoundFreeSlot = StashSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60);
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return 3;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot
|
|||
|
{
|
|||
|
isFoundFreeSlot = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotBackpack(indexPos60x60);
|
|||
|
}
|
|||
|
|
|||
|
if (isFoundFreeSlot)
|
|||
|
return 0;
|
|||
|
else
|
|||
|
{
|
|||
|
if (BackpackEnemyBase.instance.GetBackpackInfo().isActiveTacticalRig || BackpackEnemyBase.instance.GetBackpackInfo().isActivePockets)
|
|||
|
{
|
|||
|
int IndexFreePlace = BackpackEnemyBase.instance.GetBackpackInfo().IsHaveFreeSlotInTacticalRigOrPockets(tagSize);
|
|||
|
if (IndexFreePlace != -1)
|
|||
|
return IndexFreePlace;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
// Not used
|
|||
|
public static bool IsFreeSlotIndexForMoney(Vector2 indexPos60x60, ItemList.SizeIconInventory tagSize, int amountItems, bool storeMode = false)
|
|||
|
{
|
|||
|
int countFreeCells = 0;
|
|||
|
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveBackpack) // If there is a slot in the slot
|
|||
|
countFreeCells = BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotBackpackMassive(indexPos60x60, amountItems, null);
|
|||
|
|
|||
|
if (countFreeCells == amountItems)
|
|||
|
return true;
|
|||
|
else
|
|||
|
{
|
|||
|
if (BackpackSystem.instance.GetBackpackInfo().isActiveTacticalRig || BackpackSystem.instance.GetBackpackInfo().isActivePockets)
|
|||
|
{
|
|||
|
countFreeCells += BackpackSystem.instance.GetBackpackInfo().IsHaveFreeSlotTacticRigPocketsMassive(tagSize, amountItems);
|
|||
|
if (countFreeCells == amountItems)
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Save
|
|||
|
|
|||
|
public static void SaveWeapon(ItemList itemCL)
|
|||
|
{
|
|||
|
string filename = itemCL.id.ToString();
|
|||
|
InventoryBase.instance.RenderRoot.GetComponentInChildren<SaveWeaponModdingButton>().SaveButtonParameters(filename);
|
|||
|
itemCL.itemModding.GetComponentInChildren<SaveWeaponModding>().SaveParameters(filename, true);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Helper script
|
|||
|
|
|||
|
public static bool AddAttachmentsToItem(GameObject[] weaponAttachments, ItemList weaponCL, Transform spawnPoint)
|
|||
|
{
|
|||
|
if (weaponAttachments != null && weaponAttachments.Length != 0)
|
|||
|
{
|
|||
|
// Для начала создадим в корне эти аттачи (чтобы не иметь дело с префабами)
|
|||
|
GameObject[] vspWeaponAttachments = new GameObject[weaponAttachments.Length];
|
|||
|
weaponCL.insertCL = new ItemList[weaponAttachments.Length];
|
|||
|
|
|||
|
int i = 0;
|
|||
|
for (; i < weaponAttachments.Length; i++)
|
|||
|
{
|
|||
|
vspWeaponAttachments[i] = GameObject.Instantiate(weaponAttachments[i], spawnPoint);
|
|||
|
vspWeaponAttachments[i].SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
//
|
|||
|
//
|
|||
|
//
|
|||
|
int count = 0;
|
|||
|
do
|
|||
|
{
|
|||
|
List<GameObject> attachments = new List<GameObject>();
|
|||
|
i = 0;
|
|||
|
foreach (GameObject n in vspWeaponAttachments)
|
|||
|
{
|
|||
|
ItemList cl = new ItemList();
|
|||
|
cl = SetParameters(cl, n, true);
|
|||
|
|
|||
|
cl.itemModding.GetComponent<AttachIdentity>().CL = cl;
|
|||
|
weaponCL.insertCL[i] = cl;
|
|||
|
|
|||
|
if (AttachAttachmentToItemHelper(cl, weaponCL, true))
|
|||
|
GameObject.Destroy(n);
|
|||
|
else
|
|||
|
{
|
|||
|
attachments.Add(n); // добавляем в список аттач, которому якобы не нашлось место
|
|||
|
if (cl.itemModding)
|
|||
|
GameObject.Destroy(cl.itemModding);
|
|||
|
}
|
|||
|
|
|||
|
i++;
|
|||
|
}
|
|||
|
|
|||
|
if (attachments.Count == 0)
|
|||
|
break;
|
|||
|
else
|
|||
|
{
|
|||
|
vspWeaponAttachments = null;
|
|||
|
vspWeaponAttachments = new GameObject[attachments.Count];
|
|||
|
|
|||
|
for (int j = 0; j < vspWeaponAttachments.Length; j++)
|
|||
|
vspWeaponAttachments[j] = attachments[j];
|
|||
|
}
|
|||
|
|
|||
|
count++;
|
|||
|
} while (count < 5);
|
|||
|
|
|||
|
FindMagazineInTheWeapon(weaponCL);
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public static bool AttachAttachmentToItemHelper(ItemList attachmentCL, ItemList itemCL, bool setActiveAttachment)
|
|||
|
{
|
|||
|
Component[] p = itemCL.itemModding.GetComponentsInChildren(typeof(Helpers), true);
|
|||
|
if (p != null)
|
|||
|
{
|
|||
|
foreach (Helpers n in p)
|
|||
|
{
|
|||
|
if (n.TagAttach == attachmentCL.tagAttach)
|
|||
|
{
|
|||
|
attachmentCL.SetItemModdingParameters(setActiveAttachment, n.transform);
|
|||
|
n.AddParametersToHelper(attachmentCL, n.GetOriginalAttachmentID());
|
|||
|
n.openHelper = 1;
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public static void FindMagazineInTheWeapon(ItemList weaponCL)
|
|||
|
{
|
|||
|
Component[] p = weaponCL.itemModding.GetComponentsInChildren(typeof(AttachIdentity), true);
|
|||
|
if (p != null)
|
|||
|
{
|
|||
|
// turn flag
|
|||
|
weaponCL.isMagazineAttached = false;
|
|||
|
|
|||
|
// Seraching the magazine
|
|||
|
foreach (AttachIdentity n in p)
|
|||
|
{
|
|||
|
// found
|
|||
|
if (n.CL.tagAttach == ItemList.TagAttchments.ATTACH_MAGAZINE)
|
|||
|
{
|
|||
|
weaponCL.isMagazineAttached = true;
|
|||
|
if (weaponCL.insertCL == null)
|
|||
|
weaponCL.insertCL = new ItemList[1];
|
|||
|
weaponCL.insertCL[0] = n.CL; // Remember the data magazine (to have access to them)
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Icon item
|
|||
|
|
|||
|
public static void SetItemComponentsParameters(GameObject item, ItemList cl)
|
|||
|
{
|
|||
|
item.GetComponent<Slot>().TagItem = cl.tagItem;
|
|||
|
item.GetComponent<Slot>().TagSize[0] = cl.tagSize;
|
|||
|
item.GetComponentInChildren<ButtonOptions>().CL = cl;
|
|||
|
item.GetComponentInChildren<ButtonOptions>().SetTextParameters(cl);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Image/Text Alpha
|
|||
|
|
|||
|
public static void SetImageAlpha(Image icon, float alpha)
|
|||
|
{
|
|||
|
Color _a = icon.color;
|
|||
|
_a.a = alpha;
|
|||
|
icon.color = _a;
|
|||
|
}
|
|||
|
|
|||
|
public static void SetTextAlpha(Text text, float alpha)
|
|||
|
{
|
|||
|
Color _a = text.color;
|
|||
|
_a.a = alpha;
|
|||
|
text.color = _a;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get new Icon
|
|||
|
|
|||
|
public static IEnumerator CreateNewIconInInventoryNextFrame(int returnIndex, ItemList returnCL, GameObject destroyOriginal, bool isEnemyBackpack, bool isCreateInBackpackWindow)
|
|||
|
{
|
|||
|
int index = returnIndex;
|
|||
|
ItemList cl = returnCL;
|
|||
|
GameObject originalItem = destroyOriginal;
|
|||
|
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
|
|||
|
if (isEnemyBackpack)
|
|||
|
{
|
|||
|
if (index == 0)
|
|||
|
{
|
|||
|
//BackpackEnemyBase.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, originalItem.GetComponent<Slot>().transform.localPosition);
|
|||
|
BackpackEnemyBase.instance.CreateItemInBackpack(cl, BackpackEnemyBase.instance.rootBackpackIconsSpawn.transform);
|
|||
|
}
|
|||
|
else if (index == 1 || index == 2)
|
|||
|
{
|
|||
|
//BackpackEnemyBase.instance.OpenIndicesTacticalRigPockets(originalItem.GetComponentInChildren<ButtonOptions>().CL);
|
|||
|
BackpackEnemyBase.instance.CreateItemInTacticalRigOrPockets(cl);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (index == 0)
|
|||
|
{
|
|||
|
if (isCreateInBackpackWindow)
|
|||
|
{
|
|||
|
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, originalItem.GetComponent<Slot>().transform.localPosition);
|
|||
|
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CreateItemInBackpack(cl, BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().rootIconsSpawn.transform);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//BackpackSystem.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, originalItem.GetComponent<Slot>().transform.localPosition);
|
|||
|
BackpackSystem.instance.CreateItemInBackpack(cl, BackpackSystem.instance.rootIconItemsBackpackSpawn.transform);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (index == 1 || index == 2)
|
|||
|
{
|
|||
|
if (isCreateInBackpackWindow)
|
|||
|
{
|
|||
|
//BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, originalItem.GetComponent<Slot>().transform.localPosition);
|
|||
|
BackpackSystem.instance.m_vspBackpackWindow.GetComponentInChildren<BackpackWindow>().CreateItemInTacticalRigOrPockets(cl);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//BackpackSystem.instance.OpenIndicesTacticalRigPockets(originalItem.GetComponentInChildren<ButtonOptions>().CL);
|
|||
|
BackpackSystem.instance.CreateItemInTacticalRigOrPockets(cl);
|
|||
|
}
|
|||
|
}
|
|||
|
else if (index == 3)
|
|||
|
{
|
|||
|
//StashSystem.instance.OpenIndicesBackpackByIconPosition(originalItem.GetComponentInChildren<ButtonOptions>().CL.indexPos60x60, originalItem.GetComponent<Slot>().transform.localPosition);
|
|||
|
StashSystem.instance.CreateItemInStashNextFrame(cl);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
GameObject.Destroy(originalItem.GetComponentInChildren<ButtonOptions>().CL.itemModding);
|
|||
|
GameObject.Destroy(originalItem);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Calculation
|
|||
|
|
|||
|
// Возвращает коэффциент масштаба экрана в зависимости от области, в котороый мы работаем (инвентарь или юи)
|
|||
|
public static Vector2 CalculateScreenCoefficient()
|
|||
|
{
|
|||
|
Vector2 coeff;
|
|||
|
// First, we calculate the difference between the sizes of the canvas and the screen window
|
|||
|
if (InventoryBase.instance.isActive)
|
|||
|
{
|
|||
|
coeff.x = InventoryBase.instance.CanvasRoot.GetComponent<RectTransform>().rect.width - Screen.width;
|
|||
|
coeff.y = InventoryBase.instance.CanvasRoot.GetComponent<RectTransform>().rect.height - Screen.height;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
coeff.x = UI.instance.GetComponent<RectTransform>().rect.width - Screen.width;
|
|||
|
coeff.y = UI.instance.GetComponent<RectTransform>().rect.height - Screen.height;
|
|||
|
}
|
|||
|
|
|||
|
// Then we find what percentage is the screen window relative to the canvas
|
|||
|
coeff.x /= Screen.width;
|
|||
|
coeff.y /= Screen.height;
|
|||
|
|
|||
|
return coeff;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Clamp
|
|||
|
|
|||
|
public static void ClampWindowRE4Position(Vector2 windowPosition, Vector2 windowRoot)
|
|||
|
{
|
|||
|
// Top
|
|||
|
if (windowPosition.y >= InventoryBase.instance.CanvasRoot.GetComponent<RectTransform>().rect.height - 10.0f)
|
|||
|
{
|
|||
|
BackpackSystem.instance.SetAmountCreatedWindows(0);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// Down
|
|||
|
if (windowPosition.y - windowRoot.y <= 0.0f)
|
|||
|
{
|
|||
|
BackpackSystem.instance.SetAmountCreatedWindows(0);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// Left
|
|||
|
if (windowPosition.x - windowRoot.x / 2.0f <= 0.0f)
|
|||
|
{
|
|||
|
BackpackSystem.instance.SetAmountCreatedWindows(0);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//Right
|
|||
|
if (windowPosition.x + windowRoot.x / 2.0f >= InventoryBase.instance.CanvasRoot.GetComponent<RectTransform>().rect.width)
|
|||
|
{
|
|||
|
BackpackSystem.instance.SetAmountCreatedWindows(0);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static Quaternion ClampRotationAroundAxis(Quaternion q, Vector2 limitRotation, int axisIndex)
|
|||
|
{
|
|||
|
q.x /= q.w;
|
|||
|
q.y /= q.w;
|
|||
|
q.z /= q.w;
|
|||
|
q.w = 1.0f;
|
|||
|
|
|||
|
float angle = 0f;
|
|||
|
|
|||
|
if (axisIndex == 0) // X
|
|||
|
{
|
|||
|
angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
|
|||
|
angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y);
|
|||
|
q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle);
|
|||
|
}
|
|||
|
else if (axisIndex == 1) // Y
|
|||
|
{
|
|||
|
angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.y);
|
|||
|
angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y);
|
|||
|
q.y = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle);
|
|||
|
}
|
|||
|
else if (axisIndex == 2) // Z
|
|||
|
{
|
|||
|
angle = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.z);
|
|||
|
angle = Mathf.Clamp(angle, limitRotation.x, limitRotation.y);
|
|||
|
q.z = Mathf.Tan(0.5f * Mathf.Deg2Rad * angle);
|
|||
|
}
|
|||
|
|
|||
|
return q;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Random
|
|||
|
|
|||
|
public static float GetRandomIndex(Vector2 vector)
|
|||
|
{
|
|||
|
return Random.Range((int)vector.x, (int)vector.y);
|
|||
|
}
|
|||
|
|
|||
|
public static int GetRandomIndex(int maxAmount)
|
|||
|
{
|
|||
|
return Random.Range(0, maxAmount);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Layer
|
|||
|
|
|||
|
public static void SetItemLayerGroup(GameObject item, string layerGroupName)
|
|||
|
{
|
|||
|
Component[] p = item.GetComponentsInChildren(typeof(Transform), true);
|
|||
|
if (p != null)
|
|||
|
{
|
|||
|
foreach (Transform g in p)
|
|||
|
g.gameObject.layer = LayerMask.NameToLayer(layerGroupName);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
public class Scavenger
|
|||
|
{
|
|||
|
List<GameObject> vspDestroyObjects = new List<GameObject>(); // Сюда сохраняются все объекты, которые после закрытия инвентаря будут удалены
|
|||
|
GameObject[] vspInspectWindow;
|
|||
|
|
|||
|
public Scavenger(int limitOfWindows)
|
|||
|
{
|
|||
|
vspInspectWindow = new GameObject[limitOfWindows];
|
|||
|
}
|
|||
|
|
|||
|
public void AddNewComponentToDestroyList(GameObject obj)
|
|||
|
{
|
|||
|
if (!vspDestroyObjects.Contains(obj))
|
|||
|
vspDestroyObjects.Add(obj);
|
|||
|
}
|
|||
|
|
|||
|
public void AddNewInspectWindowToDestroyList(int index, GameObject window)
|
|||
|
{
|
|||
|
vspInspectWindow[index] = window;
|
|||
|
}
|
|||
|
|
|||
|
public GameObject GetInspectWindowByIndex(int index)
|
|||
|
{
|
|||
|
return vspInspectWindow[index];
|
|||
|
}
|
|||
|
|
|||
|
public void FreeObjects()
|
|||
|
{
|
|||
|
if (vspDestroyObjects != null)
|
|||
|
{
|
|||
|
for (int i = 0; i < vspDestroyObjects.Count; i++)
|
|||
|
{
|
|||
|
if (vspDestroyObjects[i])
|
|||
|
{
|
|||
|
if (vspDestroyObjects[i].GetComponentInChildren<BackpackWindow>())
|
|||
|
vspDestroyObjects[i].GetComponentInChildren<BackpackWindow>().CloseWindow(true);
|
|||
|
GameObject.Destroy(vspDestroyObjects[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
vspDestroyObjects.Clear();
|
|||
|
|
|||
|
for (int i = 0; i < vspInspectWindow.Length; i++)
|
|||
|
{
|
|||
|
if (vspInspectWindow[i] && vspInspectWindow[i].GetComponentInChildren<InspectWindow>())
|
|||
|
vspInspectWindow[i].GetComponentInChildren<InspectWindow>().CloseWindow(true);
|
|||
|
vspInspectWindow[i] = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|