Skip to content
Snippets Groups Projects
Commit fb5529a1 authored by Alexander Gatland's avatar Alexander Gatland
Browse files

Merge branch 'alexander' into 'main'

Alexander

See merge request !45
parents 8bb5ff3a b835a540
No related branches found
No related tags found
2 merge requests!52Updating master,!45Alexander
Showing
with 509 additions and 270 deletions
fileFormatVersion: 2
guid: 56c2d0cf94959324d9338760068472da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -19,6 +19,18 @@ namespace BigSock {
public int Speed { get; set; }
public int Luck { get; set; }
public int Concentration { get; set; }
public Skills Clone() {
return new Skills{
HP = HP,
SP = SP,
MP = MP,
Damage = Damage,
Speed = Speed,
Luck = Luck,
Concentration = Concentration,
};
}
}
......@@ -39,7 +51,7 @@ namespace BigSock {
Holds extension methods for skills objects.
*/
public static class SkillsExtension {
/*
Increases one skill object by the amount of the other.
*/
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Chest : MonoBehaviour, IInteractable
{
[SerializeField] private string _prompt;
[SerializeField] private Animator animator;
[SerializeField] private string goldenChestOpen = "OpeningGoldChest";
[SerializeField] private string idleGoldChest = "Idle";
using BigSock.UI;
using BigSock.Service;
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
namespace BigSock.Interact {
public class Chest : MonoBehaviour, IInteractable
{
[SerializeField] private string _prompt;
[SerializeField] private Animator animator;
[SerializeField] private string goldenChestOpen = "OpeningGoldChest";
[SerializeField] private string idleGoldChest = "Idle";
void Start() {
animator = gameObject.GetComponent<Animator>();
}
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
void Start() {
animator = gameObject.GetComponent<Animator>();
}
public string InteractionPrompt => _prompt;
public string InteractionPrompt => _prompt;
public bool Interact(Interactor interactor) {
Debug.Log("Opening chest!");
GetComponent<Animator>().Play(goldenChestOpen);
spriteRenderer.sprite = newSprite;
//animator.Play(idleGoldChest, -1, 0.0f);
return true;
public bool Interact(Interactor interactor) {
var chestContents = PrefabService.SINGLETON.Instance("UI/ChestContents", GameObject.FindWithTag("MainCamera").transform.position+new Vector3(1000,600,0));
chestContents.transform.SetParent(GameObject.Find("Canvas").transform);
GetComponent<Animator>().Play(goldenChestOpen);
spriteRenderer.sprite = newSprite;
return true;
}
}
}
......@@ -3,11 +3,12 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour, IInteractable
{
[SerializeField] private string _prompt;
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
namespace BigSock.Interact {
public class Door : MonoBehaviour, IInteractable
{
[SerializeField] private string _prompt;
public SpriteRenderer spriteRenderer;
public Sprite newSprite;
private GameObject player;
private GameObject cameraPlayer;
......
......@@ -2,11 +2,13 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface IInteractable
{
public string InteractionPrompt { get; }
public bool Interact(Interactor interactor) {
throw new System.NotImplementedException();
}
namespace BigSock.Interact {
public interface IInteractable
{
public string InteractionPrompt { get; }
public bool Interact(Interactor interactor) {
throw new System.NotImplementedException();
}
}
}
......@@ -3,31 +3,33 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Interactor : MonoBehaviour
{
[SerializeField] private Transform _interactionPoint;
[SerializeField] private float _interactionpointRadius = 0.5f;
[SerializeField] private LayerMask _interactableMask;
namespace BigSock.Interact {
public class Interactor : MonoBehaviour
{
[SerializeField] private Transform _interactionPoint;
[SerializeField] private float _interactionpointRadius = 0.5f;
[SerializeField] private LayerMask _interactableMask;
private readonly Collider2D[] _colliders = new Collider2D[3];
[SerializeField] private int _numFound;
private readonly Collider2D[] _colliders = new Collider2D[3];
[SerializeField] private int _numFound;
private void Update() {
_numFound = Physics2D.OverlapCircleNonAlloc(_interactionPoint.position, _interactionpointRadius, _colliders, _interactableMask);
private void Update() {
_numFound = Physics2D.OverlapCircleNonAlloc(_interactionPoint.position, _interactionpointRadius, _colliders, _interactableMask);
if (_numFound > 0)
{
var interactable = _colliders[0].GetComponent<IInteractable>();
if (interactable != null && Keyboard.current.eKey.wasPressedThisFrame)
if (_numFound > 0)
{
interactable.Interact(this);
var interactable = _colliders[0].GetComponent<IInteractable>();
if (interactable != null && Keyboard.current.eKey.wasPressedThisFrame)
{
interactable.Interact(this);
}
}
}
}
private void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(_interactionPoint.position, _interactionpointRadius);
private void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(_interactionPoint.position, _interactionpointRadius);
}
}
}
}
\ No newline at end of file
......@@ -26,5 +26,11 @@ namespace BigSock.Item {
*/
ulong Id { get; }
/*
The icon of the item.
*/
Sprite Icon { get; }
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using BigSock.Service;
namespace BigSock.Item {
......@@ -26,5 +28,24 @@ namespace BigSock.Item {
*/
public abstract ulong Id { get; }
/*
The icon of the item.
*/
public Sprite Icon => SpriteService.SINGLETON.Get(IconName);
/*
The name of the icon this item uses.
Override this to change what icon the item uses.
*/
public virtual string IconName { get; } = "item/tilesetnice";
public ItemBase() {
//Icon = SpriteService.SINGLETON.Get(IconName);
}
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ namespace BigSock.Item {
public override ulong Id => 201;
public override string Name => "Four Eyes";
public override string Description => "30% chance to deal double dammage. Has a 2 second cooldown.";
public override string IconName => "item/chest";
public static readonly double CHANCE = 0.3;
public static readonly TimeSpan COOLDOWN = new TimeSpan(0, 0, 0, 2, 0);
......
......@@ -14,6 +14,8 @@ namespace BigSock.Item {
public override ulong Id => 101;
public override string Name => "Running Shoes";
public override string Description => "Increases movement speed by 50%";
public override string IconName => "item/breadwithjamx16";
public ItemRunningShoes() {
Modifier = new CharacterStats{
......
......@@ -16,33 +16,33 @@ namespace BigSock {
public partial class PlayerController : Character
{
public UtilBar utilBar;
public UtilBar utilBar;
public float collisionOffset = 0.05f;
public ContactFilter2D movementFilter;
public GameObject attack;
public float collisionOffset = 0.05f;
public ContactFilter2D movementFilter;
public GameObject attack;
Vector2 movementInput;
SpriteRenderer spriteRenderer;
//Rigidbody2D rb;
Animator animator;
List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
Vector2 movementInput;
SpriteRenderer spriteRenderer;
//Rigidbody2D rb;
Animator animator;
List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
bool canMove = true;
bool canMove = true;
protected IAttack _testAttack;
protected IAttack _testAttack2;
protected IAbility _dodge;
protected IAttack _testAttack;
protected IAttack _testAttack2;
protected IAbility _dodge;
public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now;
public DateTime NextTimeCanAttack { get; private set; } = DateTime.Now;
public PlayerController()
{
{
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
......@@ -51,69 +51,70 @@ namespace BigSock {
// Start is called before the first frame update
protected override void Start()
{
base.Start();
{
base.Start();
utilBar?.WithXP((int)xp, (int)maxXp)
?.WithHealth(Convert.ToInt32(HP), Convert.ToInt32(MaxHP));
utilBar?.WithXP((int)xp, (int)maxXp)
?.WithHealth(Convert.ToInt32(HP), Convert.ToInt32(MaxHP));
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
//!! DEBUG: Add item to player at start to test if it works.
/*
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
TryPickUpItem(ItemService.SINGLETON.Get(101));
*/
//var tmp = PrefabService.SINGLETON;
//!! DEBUG: Add item to player at start to test if it works.
/*
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(201));
TryPickUpItem(ItemService.SINGLETON.Get(202));
TryPickUpItem(ItemService.SINGLETON.Get(101));
*/
//var tmp = PrefabService.SINGLETON;
//var tmp = SpriteService.SINGLETON;
_testAttack = (IAttack) AbilityService.SINGLETON.Get(101);
_testAttack2 = (IAttack) AbilityService.SINGLETON.Get(102);
_dodge = AbilityService.SINGLETON.Get(201);
}
_testAttack = (IAttack) AbilityService.SINGLETON.Get(101);
_testAttack2 = (IAttack) AbilityService.SINGLETON.Get(102);
_dodge = AbilityService.SINGLETON.Get(201);
}
private void FixedUpdate() {
if(canMove) {
// If movement input is not 0, try to move
if(movementInput != Vector2.zero){
bool success = TryMove(movementInput);
if(!success) {
success = TryMove(new Vector2(movementInput.x, 0));
}
if(!success) {
success = TryMove(new Vector2(0, movementInput.y));
}
animator.SetBool("isMoving", success);
} else {
animator.SetBool("isMoving", false);
}
// Set direction of sprite to movement direction
var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var pos = transform.position;
var temp = (mouse - pos);
//temp.z = 0;
//direction = temp.normalized;
if(temp.x < 0) {
spriteRenderer.flipX = true;
} else if (temp.x > 0) {
spriteRenderer.flipX = false;
}
}
if(canMove) {
// If movement input is not 0, try to move
if(movementInput != Vector2.zero){
bool success = TryMove(movementInput);
if(!success) {
success = TryMove(new Vector2(movementInput.x, 0));
}
if(!success) {
success = TryMove(new Vector2(0, movementInput.y));
}
animator.SetBool("isMoving", success);
} else {
animator.SetBool("isMoving", false);
}
// Set direction of sprite to movement direction
var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var pos = transform.position;
var temp = (mouse - pos);
//temp.z = 0;
//direction = temp.normalized;
if(temp.x < 0) {
spriteRenderer.flipX = true;
} else if (temp.x > 0) {
spriteRenderer.flipX = false;
}
}
}
......
......@@ -70,9 +70,9 @@ namespace BigSock.Service {
_abilities = _abilityList
.ToDictionary(t => t.Id);
foreach(var a in _abilityList) {
Debug.Log($"[AbilityService._loadItems()] {a.Id}");
}
//foreach(var a in _abilityList) {
// Debug.Log($"[AbilityService._loadItems()] {a.Id}");
//}
}
/*
......
......@@ -37,6 +37,18 @@ namespace BigSock.Service {
return _new(_itemList[num]);
}
public List<IItem> Get3Random() {
List<IItem> tempItemList = _itemList;
List<IItem> returnList = new List<IItem>();
var num = 0;
for(int i = 0; i < 3; i++) {
num = _rnd.Next(tempItemList.Count);
returnList.Add(tempItemList[num]);
tempItemList.Remove(tempItemList[num]);
}
return returnList;
}
}
public partial class ItemService {
......
......@@ -80,7 +80,7 @@ namespace BigSock.Service {
var name = _sanitize(path.Replace(".prefab", "").Replace("Assets/Prefabs/", ""));
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>( path );
Debug.Log($"[PrefabService._loadItems()] {name}");
//Debug.Log($"[PrefabService._loadItems()] {name}");
dict[name] = go;
}
......
using System.Collections;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEditor;
using BigSock.Item;
namespace BigSock.Service {
/*
Service for handling sprites.
*/
public partial class SpriteService {
/*
The instance to use.
*/
public static readonly SpriteService SINGLETON = new SpriteService();
/*
Get a prefab of a name.
*/
public Sprite Get(string name) {
if(_sprites.TryGetValue(_sanitize(name), out var res)) return res;
return null;
}
}
public partial class SpriteService {
private Dictionary<string, Sprite> _sprites = new Dictionary<string, Sprite>();
private System.Random _rnd = new System.Random();
private SpriteService() {
_loadItems();
}
/*
Load the items into the dictionary.
Based on: https://stackoverflow.com/a/67670629
*/
private void _loadItems() {
string[] guids = AssetDatabase.FindAssets( "t:Sprite", new string[] {"Assets/Sprites"} );
var dict = new Dictionary<string, Sprite>();
foreach(var guid in guids) {
var path = AssetDatabase.GUIDToAssetPath( guid );
var name = _sanitize(path.Replace(".png", "").Replace(".jpg", "").Replace("Assets/Sprites/", ""));
Sprite go = AssetDatabase.LoadAssetAtPath<Sprite>( path );
//Debug.Log($"[SpriteService._loadItems()] {name}");
dict[name] = go;
}
_sprites = dict;
}
private string _sanitize(string name)
=> name.Replace(" ", "").Replace("_", "").ToLower();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 884f816930ab2e045b11aaeb06ef8bce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using BigSock.Service;
using BigSock.UI;
using BigSock.Item;
using BigSock.Interact;
using UnityEditor;
namespace BigSock.UI {
public class ChestDisplay : MonoBehaviour
{
public Button item1Button, item2Button, item3Button;
public IItem item1, item2, item3;
public GameObject other;
// Update is called once per frame
void Start() {
var itemButtonLocation = transform.Find("ItemBox").Find("ItemBoxBackground");
item1Button = itemButtonLocation.transform.Find("ButtonItem1").GetComponent<Button>();
item1Button.onClick.AddListener(ItemPicked1);
item2Button = itemButtonLocation.transform.Find("ButtonItem2").GetComponent<Button>();
item2Button.onClick.AddListener(ItemPicked2);
item3Button = itemButtonLocation.transform.Find("ButtonItem3").GetComponent<Button>();
item3Button.onClick.AddListener(ItemPicked3);
List<IItem> items = ItemService.SINGLETON.Get3Random();
item1 = items[0];
item2 = items[1];
item3 = items[2];
item1Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item1.Id).Icon;
item1Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item1.Id).Name;
item2Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item2.Id).Icon;
item2Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item2.Id).Name;
item3Button.gameObject.transform.Find("Item").GetComponent<Image>().sprite = ItemService.SINGLETON.Get(item3.Id).Icon;
item3Button.gameObject.transform.Find("ItemName").GetComponent<TMPro.TMP_Text>().text = ItemService.SINGLETON.Get(item3.Id).Name;
}
void ItemPicked1() {
ItemPicked(1);
}
void ItemPicked2() {
ItemPicked(2);
}
void ItemPicked3() {
ItemPicked(3);
}
void ItemPicked(int number) {
this.other = GameObject.FindWithTag("Player");
var player = other.GetComponent<PlayerController>();
if (number == 1) {player.TryPickUpItem(ItemService.SINGLETON.Get(item1.Id));}
else if (number == 2) {player.TryPickUpItem(ItemService.SINGLETON.Get(item2.Id));}
else if (number == 3) {player.TryPickUpItem(ItemService.SINGLETON.Get(item3.Id));}
Destroy(this.gameObject);
}
}
}
fileFormatVersion: 2
guid: 31ea0fadbcb4be94f95d44c8cf8bcf20
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -7,107 +7,99 @@ using UnityEngine.UI;
namespace BigSock.UI
{
public class InventoryPanel : MonoBehaviour
{
public PlayerController player;
public const string INVSLOT = "UI/Inventoryslot";
public const string ITEM = "UI/Item";
public class InventoryPanel : MonoBehaviour
{
public PlayerController player;
public const string INVSLOT = "UI/Inventoryslot";
public const string ITEM = "UI/Item";
public GridLayoutGroup gridBackPack;
public GridLayoutGroup gridTools;
public GridLayoutGroup gridAccessory;
public GridLayoutGroup gridEquipment;
public GridLayoutGroup gridBackPack;
public GridLayoutGroup gridTools;
public GridLayoutGroup gridAccessory;
public GridLayoutGroup gridEquipment;
//var bullet = PrefabService.SINGLETON.Instance(PROJECTILE_NAME, actor.transform.position);
//var bulletScript = bullet.GetComponent<AttackMovement>();
public void Start() {
GenerateInv();
}
public void Start()
{
GenerateInv();
}
public void GenerateInv()
{
var inventory = player.Inventory;
for (int i = 0; i < inventory.Backpack.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridBackPack.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Backpack;
invScript.position = i;
var item = inventory.Backpack[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
for (int i = 0; i < inventory.Tools.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridTools.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Tool;
invScript.position = i;
var item = inventory.Tools[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
public void GenerateInv()
{
var inventory = player.Inventory;
for (int i = 0; i < inventory.Backpack.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridBackPack.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Backpack;
invScript.position = i;
var item = inventory.Backpack[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
for (int i = 0; i < inventory.Tools.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridTools.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Tool;
invScript.position = i;
var item = inventory.Tools[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
for (int i = 0; i < inventory.Equipment.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridEquipment.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Equipment;
invScript.position = i;
var item = inventory.Equipment[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
for (int i = 0; i < inventory.Accessories.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridAccessory.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Accessory;
invScript.position = i;
var item = inventory.Accessories[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
}
}
for (int i = 0; i < inventory.Equipment.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridEquipment.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Equipment;
invScript.position = i;
var item = inventory.Equipment[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
for (int i = 0; i < inventory.Accessories.Count; ++i)
{
var invSlot = PrefabService.SINGLETON.Instance(INVSLOT, gridAccessory.transform);
var invScript = invSlot.GetComponent<ItemSlot>();
invScript.inventory = inventory;
invScript.inventoryType = InventoryType.Accessory;
invScript.position = i;
var item = inventory.Accessories[i];
if (item != null)
{
var itemPref = PrefabService.SINGLETON.Instance(ITEM, transform);
var itemScript = itemPref.GetComponent<ItemPref>();
itemScript.item = item;
itemScript.itemSlot = invScript;
invScript.item = itemScript;
itemScript.transform.position = invScript.transform.position;
}
}
}
}
}
}
}
......@@ -7,52 +7,60 @@ using BigSock.Item;
namespace BigSock.UI
{
public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler
{
public IItem item;
public ItemSlot itemSlot;
private RectTransform rectTransform;
private CanvasGroup canvasGroup;
public Vector2? position;
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
canvasGroup = GetComponent<CanvasGroup>();
}
public void OnBeginDrag(PointerEventData eventData)
{
position = transform.position;
canvasGroup.alpha = .6f;
canvasGroup.blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
rectTransform.anchoredPosition += eventData.delta;
}
public void OnEndDrag(PointerEventData eventData)
{
if (position != null)
{
transform.position = position.Value;
}
canvasGroup.alpha = 1f;
canvasGroup.blocksRaycasts = true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
}
public class ItemPref : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler
{
public IItem item;
public ItemSlot itemSlot;
private RectTransform rectTransform;
private CanvasGroup canvasGroup;
public Vector2? position;
void Start()
{
// Change the sprite if the item has one.
var sprite = item?.Icon;
if(sprite != null)
GetComponent<UnityEngine.UI.Image>().overrideSprite = sprite;
}
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
canvasGroup = GetComponent<CanvasGroup>();
}
public void OnBeginDrag(PointerEventData eventData)
{
position = transform.position;
canvasGroup.alpha = .6f;
canvasGroup.blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
rectTransform.anchoredPosition += eventData.delta;
}
public void OnEndDrag(PointerEventData eventData)
{
if (position != null)
{
transform.position = position.Value;
}
canvasGroup.alpha = 1f;
canvasGroup.blocksRaycasts = true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment