MVC shop project for software architecture, in Unity.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
2.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This class defines the methods to be called by views to control a ShopModel. You can make concrete
/// controllers like a mouse controller, keyboard controller, gamepad controller, etc from this interface.
/// </summary>
public abstract class ShopController : MonoBehaviour
{
public ShopModel Model => model;//Public getter for the model
protected ShopModel model; //Ties this controller to a ShopModel
public abstract void HandleInput(); //Concrete controllers override this method and handle input in different ways.
//------------------------------------------------------------------------------------------------------------------------
// Initialize()
//------------------------------------------------------------------------------------------------------------------------
//Used as the equivalence of a constructor since we can't use new to create a MonoBehaviour, marked as virtual so that
//concrete controllers can add their own Initialize methods
public virtual ShopController Initialize(ShopModel pModel)
{
model = pModel;
return this;
}
//------------------------------------------------------------------------------------------------------------------------
// SelectItem()
//------------------------------------------------------------------------------------------------------------------------
//Called when a certain item is selected
public void SelectItem(Item item)
{
model.SelectItem(item);
}
//------------------------------------------------------------------------------------------------------------------------
// SelectItemByIndex()
//------------------------------------------------------------------------------------------------------------------------
//Select an item by its index
public void SelectItemByIndex(int index)
{
model.SelectItemByIndex(index);
}
//------------------------------------------------------------------------------------------------------------------------
// ConfirmSelectedItem()
//------------------------------------------------------------------------------------------------------------------------
//Tells the model to confirm the current selected item
public void ConfirmSelectedItem()
{
model.ConfirmSelectedItem();
}
}