6 changed files with 2158 additions and 1189 deletions
File diff suppressed because it is too large
@ -0,0 +1,7 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 2217ade0fb51b46daa2e279fbf1589d7 |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
File diff suppressed because it is too large
@ -0,0 +1,82 @@ |
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Security.Permissions; |
|||
using UnityEngine; |
|||
using UnityEngine.Assertions; |
|||
using UnityEngine.UI; |
|||
|
|||
/// <summary>
|
|||
/// This view is meant to be used in conjunction with a list. Realistically, it is mostly similar to the grid view,
|
|||
/// as both operate with prototypes!
|
|||
/// </summary>
|
|||
public class ShopViewList : ShopView |
|||
{ |
|||
private VerticalLayoutGroup _listLayoutGroup; // This is essentially just a reference to ShopView's layout group but with the correct type
|
|||
|
|||
//protected ViewConfig viewConfig; //To set up the grid view, we need to know how many columns the grid view has, in the current setup,
|
|||
//this information can be found in a ViewConfig scriptable object, which serves as a configuration file for
|
|||
//views.
|
|||
|
|||
// Start is called before the first frame update
|
|||
protected override void Awake() |
|||
{ |
|||
//iewConfig = Resources.Load<ViewConfig>("ViewConfig");//Load the ViewConfig scriptable object from the Resources folder
|
|||
//Debug.Assert(viewConfig != null);
|
|||
Debug.Assert(_listLayoutGroup != null); |
|||
base.Awake(); |
|||
print("ShopView Grid Initialised"); |
|||
} |
|||
|
|||
protected override void SetupItemIconView() |
|||
{ |
|||
//_listLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;//Set the constraint mode of the GridLayoutGroup
|
|||
//_listLayoutGroup.constraintCount = viewConfig.gridViewColumnCount; //Set the column count according to the ViewConfig object
|
|||
// Do we set up anything at all here?
|
|||
} |
|||
|
|||
protected override void ClearIconView() |
|||
{ |
|||
Transform[] allIcons = layoutGroup.transform.GetComponentsInChildren<Transform>(); |
|||
foreach (Transform child in allIcons) { |
|||
if (child != layoutGroup.transform) { |
|||
Destroy(child.gameObject); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override void AddItemToView(Item item) |
|||
{ |
|||
GameObject newItemIcon = GameObject.Instantiate(itemPrefab, layoutGroup.transform, true); |
|||
newItemIcon.transform.localScale = Vector3.one;//The scale would automatically change in Unity so we set it back to Vector3.one.
|
|||
|
|||
ViewItemContainer itemContainer = newItemIcon.GetComponent<ViewItemContainer>(); |
|||
Debug.Assert(itemContainer != null); |
|||
//bool isSelected = (item == model.GetSelectedItem());
|
|||
var unsub = model.RegisterObserver(itemContainer); |
|||
itemContainer.Initialize(item,unsub); |
|||
print("Attempt to add item " + item.name + " to view"); |
|||
} |
|||
|
|||
protected override void RemoveItemFromView(Item item) |
|||
{ |
|||
var items = layoutGroup.transform.GetComponentsInChildren<ViewItemContainer>(); |
|||
foreach (var itemView in items) |
|||
{ |
|||
if (itemView.Item == item) |
|||
{ |
|||
model.RemoveObserver(itemView); |
|||
Destroy(itemView.gameObject); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void OnValidate() |
|||
{ |
|||
_listLayoutGroup = (VerticalLayoutGroup) layoutGroup; |
|||
bool correctLayout = _listLayoutGroup != null; |
|||
if(!correctLayout) Debug.LogError("Layout group is not of type Vertical!",this); |
|||
//else Debug.Log("Grid shop view validated",this);
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 9a7a26539e5861144890978c82020e75 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Loading…
Reference in new issue