Skip to content
Snippets Groups Projects
Commit 6f4db616 authored by Benjamin Bösl's avatar Benjamin Bösl
Browse files

adapted inventory stuff, to use global fact-management-system (fms)

parent fe9328a8
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 295 deletions
......@@ -16,6 +16,7 @@ public class LineFact : Fact
{
//Id's of the 2 Point-Facts that are connected
public int Pid1, Pid2;
}
public class AngleFact : Fact
{
......
......@@ -3,10 +3,11 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
public class DisplayFacts : MonoBehaviour
{
public Inventory inventory;
public HashSet<int> displayedFacts = new HashSet<int>();
public GameObject prefab_Point;
public GameObject prefab_Distance;
......@@ -27,33 +28,67 @@ void Start()
// Update is called once per frame
void Update()
{
UpdateDisplay();
UpdateDisplay2();
}
public void UpdateDisplay()
{
for( int i = 0; i< inventory.Facts.Count; i++){
if(! inventory.Facts[i].isDisplayed){
var item = inventory.Facts[i].item;
var obj = item.CreateDisplay(transform, getPrefab( item));
obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
inventory.Facts[i].isDisplayed = true;
public void UpdateDisplay2()
{
List<Fact>.Enumerator enumerator = CommunicationEvents.Facts.GetEnumerator();
while (enumerator.MoveNext())
{
int fid = enumerator.Current.Id;
if (displayedFacts.Contains(fid))
{
continue;
}
var obj = CreateDisplay(transform, enumerator.Current);
obj.GetComponent<RectTransform>().localPosition = GetPosition(fid);
displayedFacts.Add(fid);
}
}
public Vector3 GetPosition(int i)
private GameObject CreateDisplay(Transform transform, Fact fact)
{
return new Vector3(x_Start+ (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
}
switch (fact)
{
case LineFact f:
{
var obj = Instantiate(prefab_Distance, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid1].Id;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id;
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
case AngleFact f:
{
var obj = Instantiate(prefab_Angle, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid1].Id;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid2].Id;
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = "" + CommunicationEvents.Facts[f.Pid3].Id;
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
public GameObject getPrefab(ItemObject item){
switch( item.type){
case ItemObject.ItemType.LengthFact:return prefab_Distance;
case ItemObject.ItemType.AngleFact: return prefab_Angle;
case ItemObject.ItemType.Point: return prefab_Point;
default: return prefab_Default;
case PointFact f:
{
var obj = Instantiate(prefab_Point, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = "" + f.Id;
obj.GetComponent<FactWrapper>().fact = f;
return obj;
}
default:
{
var obj = Instantiate(prefab_Default, Vector3.zero, Quaternion.identity, transform);
return obj;
}
}
}
public Vector3 GetPosition(int i)
{
return new Vector3(x_Start + (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
}
}
......@@ -5,7 +5,7 @@
public class DisplayScrolls : MonoBehaviour
{
public Inventory inventory;
//public Inventory inventory;
public int x_Start;
......@@ -22,12 +22,12 @@ void Start()
// Update is called once per frame
void Update()
{
UpdateDisplay();
// UpdateDisplay();
}
public void UpdateDisplay()
{
for( int i = 0; i< inventory.Scrolls.Count; i++){
/* for( int i = 0; i< inventory.Scrolls.Count; i++){
if(! inventory.Scrolls[i].isDisplayed){
var item = inventory.Scrolls[i].item;
var obj = Instantiate(item.IconPrefab, Vector3.zero, Quaternion.identity, transform);
......@@ -36,6 +36,7 @@ public void UpdateDisplay()
}
}
*/
}
public Vector3 GetPosition(int i)
......
......@@ -14,7 +14,7 @@ public void OnDrop(PointerEventData eventData){
GameObject scrollShow = gameObject.transform.parent.gameObject;
PythagorasScript pythagorasScript = scrollShow.GetComponent<PythagorasScript>();
var fact = ((FactWrapper)current.GetComponent<FactWrapper>()).fact;
pythagorasScript.putItem(gameObject.name, fact);
pythagorasScript.putFact(gameObject.name, fact);
}
}
......@@ -4,5 +4,5 @@
public class FactWrapper : MonoBehaviour
{
public ItemObject fact;
public Fact fact;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Inventory", menuName= "Inventory System/Inventory" )]
public class Inventory : ScriptableObject
{
public List<InventorySlotFact> Facts = new List<InventorySlotFact>();
public List<InventorySlotScroll> Scrolls = new List<InventorySlotScroll>();
public void AddFact(ItemObject fact){
Facts.Add(new InventorySlotFact(fact));
}
public void AddScroll(DefaultScroll scroll){
Scrolls.Add(new InventorySlotScroll(scroll));
}
}
[System.Serializable]
public class InventorySlotFact{
public ItemObject item;
public bool isDisplayed;
public InventorySlotFact(ItemObject _item){
item = _item;
isDisplayed = false;
}
}
[System.Serializable]
public class InventorySlotScroll{
public DefaultScroll item;
public bool isDisplayed;
public InventorySlotScroll( DefaultScroll _item){
item = _item;
isDisplayed = false;
}
}
fileFormatVersion: 2
guid: 14aa6bfc325535540999d9ee4927d556
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 14aa6bfc325535540999d9ee4927d556, type: 3}
m_Name: THE_INVENTORY
m_EditorClassIdentifier:
Facts: []
Scrolls:
- item: {fileID: 11400000, guid: b8e04ce999b77dc48a7f225e635bc2ce, type: 2}
isDisplayed: 0
fileFormatVersion: 2
guid: f3a619d9c65f61d4b9c7c86923b1ad95
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[CreateAssetMenu(fileName = "new DefaultObject", menuName = "Inventory System/Items/Angle")]
public class AngleObject : ItemObject
{
public string pointA;
public string pointB;
public string pointC;
public double angle;
public void Awake()
{
type = ItemType.AngleFact;
}
//prefab should be "AngleDisplay"
public override GameObject CreateDisplay(Transform transform, GameObject prefab){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = pointA;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = pointB;
obj.transform.GetChild(2).gameObject.GetComponent<TextMeshProUGUI>().text = pointC;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
}
fileFormatVersion: 2
guid: 53c362d013ad14747b779900f8c8242e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "new DefaultObject", menuName = "Inventory System/Items/Default")]
public class DefaultObject : ItemObject
{
public void Awake()
{
type = ItemType.Default;
}
//prefab should be "DefaultObjectDisplay"
public override GameObject CreateDisplay(Transform transform, GameObject prefab){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
return obj;
}
}
fileFormatVersion: 2
guid: 8fbc458136995e149baa33442083c952
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "new DefaultScroll", menuName = "Inventory System/Items/DefaultScroll")]
public class DefaultScroll : ItemObject
{
public GameObject IconPrefab;
public GameObject UsagePrefab;
public void Awake()
{
type = ItemType.DefaultScroll;
}
//prefab should be "DefaultScrollDisplay"
public override GameObject CreateDisplay(Transform transform, GameObject prefab){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
return obj;
}
}
fileFormatVersion: 2
guid: 4863e36a3d5b58b47a13400c96dce2fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class ItemObject : ScriptableObject
{
public enum ItemType{
LengthFact,
AngleFact,
DefaultScroll,
Point,
Default
};
public ItemType type;
[TextArea(15,20)]
public string Description;
public abstract GameObject CreateDisplay(Transform transform, GameObject prefab);
}
fileFormatVersion: 2
guid: 6fce2c2f8f4464e418f67820fc788f26
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[CreateAssetMenu(fileName = "new DefaultObject", menuName = "Inventory System/Items/Length")]
public class LengthObject : ItemObject
{
public string pointA;
public string pointB;
public double Lenght;
public void Awake()
{
type = ItemType.LengthFact;
}
//prefab should be "LengthDisplay"
public override GameObject CreateDisplay(Transform transform, GameObject prefab){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = pointA;
obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = pointB;
obj.GetComponent<FactWrapper>().fact = this;
return obj;
}
}
fileFormatVersion: 2
guid: bc65288d8a9b7f343a6e221e4bdba74c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- prefab: {fileID: 4221381813544557775, guid: 8106c748f1aeb084d87fdc71dd009b67,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[CreateAssetMenu(fileName = "new PointObject", menuName = "Inventory System/Items/Point")]
public class PointObject : ItemObject
{
public string point;
public void Awake()
{
type = ItemType.Point;
}
//prefab should be "LengthDisplay"
public override GameObject CreateDisplay(Transform transform, GameObject prefab){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = point;
obj.GetComponent<FactWrapper>(). fact = this;
return obj;
}
}
\ No newline at end of file
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