Browse Source

fixed Logic trough selection bug

Josh_Dev_branch
JoshuaReason 5 years ago
parent
commit
97dce6d999
8 changed files with 206 additions and 28 deletions
  1. +2
    -2
      Assets/Data/Inventory/BaseInventory.asset
  2. +136
    -7
      Assets/Scenes/Client Scenes/ClientScene.unity
  3. +33
    -5
      Assets/Scripts/Inventory.cs
  4. +1
    -1
      Assets/Scripts/Logic/BlockReader.cs
  5. +1
    -6
      Assets/Scripts/Logic/Blocks/LogicBlock.cs
  6. +2
    -2
      Assets/Scripts/Managers/GameManager.cs
  7. +12
    -2
      Assets/Scripts/UI/LogicTrayUI.cs
  8. +19
    -3
      Assets/Scripts/UI/NetworkedUIManager.cs

+ 2
- 2
Assets/Data/Inventory/BaseInventory.asset View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:c5679085887a5b78c9d233a70d5fd0ce061945cbe7f8cb80ddfaf9634f6aa58f
size 970
oid sha256:1d0672a6b3709593b57d6964e247a9ccf9ecc89b29d7cc88a1bbf5de996e3296
size 979

+ 136
- 7
Assets/Scenes/Client Scenes/ClientScene.unity View File

@ -314,7 +314,8 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 1593162621}
m_Father: {fileID: 5195354181466942484} m_Father: {fileID: 5195354181466942484}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -446,6 +447,134 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1363815576} m_GameObject: {fileID: 1363815576}
m_CullTransparentMesh: 0 m_CullTransparentMesh: 0
--- !u!1 &1593162620
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1593162621}
- component: {fileID: 1593162624}
- component: {fileID: 1593162623}
- component: {fileID: 1593162622}
m_Layer: 0
m_Name: Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1593162621
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593162620}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1363815577}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0.6498871}
m_SizeDelta: {x: 0, y: -0.49163055}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1593162622
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593162620}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1593162623}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 5195354181466942483}
m_MethodName: On_ClickPauseTime
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &1593162623
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593162620}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!222 &1593162624
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1593162620}
m_CullTransparentMesh: 0
--- !u!224 &1704581577 stripped --- !u!224 &1704581577 stripped
RectTransform: RectTransform:
m_CorrespondingSourceObject: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, m_CorrespondingSourceObject: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
@ -543,7 +672,7 @@ PrefabInstance:
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: -0.000015258307
value: -0.00009918213
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
@ -553,7 +682,7 @@ PrefabInstance:
- target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_AnchoredPosition.x propertyPath: m_AnchoredPosition.x
value: 0.000007958263
value: -0.000039558963
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354183134146528, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354183134146528, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
@ -689,12 +818,12 @@ PrefabInstance:
- target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_havePropertiesChanged propertyPath: m_havePropertiesChanged
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 5195354181796512270, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_isInputParsingRequired propertyPath: m_isInputParsingRequired
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2665231842396078511, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 2665231842396078511, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
@ -854,12 +983,12 @@ PrefabInstance:
- target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_havePropertiesChanged propertyPath: m_havePropertiesChanged
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}
propertyPath: m_isInputParsingRequired propertyPath: m_isInputParsingRequired
value: 1
value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - target: {fileID: 2665231841929910945, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f,
type: 3} type: 3}

+ 33
- 5
Assets/Scripts/Inventory.cs View File

@ -7,6 +7,8 @@ using UnityEngine;
public class Inventory : ScriptableObject public class Inventory : ScriptableObject
{ {
public string test;
public List<Data> BagItems { get { if (_bagItems == null) _bagItems = new List<Data>(); return _bagItems; } } public List<Data> BagItems { get { if (_bagItems == null) _bagItems = new List<Data>(); return _bagItems; } }
[SerializeField] [SerializeField]
@ -28,9 +30,9 @@ public class Inventory : ScriptableObject
public void Add(Data data) public void Add(Data data)
{ {
if (_bagItems.Contains(data))
if (_bagItems.Exists(p => p.element.isSameType(data.element)))
{ {
Data bagData = BagItems.Find(p => p.Equals(data));
Data bagData = BagItems.Find(p => p.element.isSameType(data.element));
bagData.Count += data.Count; bagData.Count += data.Count;
bagData.isInfinit = (data.isInfinit || bagData.isInfinit); bagData.isInfinit = (data.isInfinit || bagData.isInfinit);
@ -43,14 +45,24 @@ public class Inventory : ScriptableObject
public void Remove(LogicBlock element) { public void Remove(LogicBlock element) {
if (!_bagItems.Exists(p => p.element == element))
if (!_bagItems.Exists(p => p.element.isSameType(element)))
{
return; return;
}
Data data = _bagItems.First(p => p.element == element);
Data data = _bagItems.First(p => p.element.isSameType(element));
if (!data.isInfinit) if (!data.isInfinit)
{
data.Count--; data.Count--;
if (data.Count <= 0)
_bagItems.Remove(data);
}
OnItemsUpdated?.Invoke(); OnItemsUpdated?.Invoke();
} }
@ -69,7 +81,13 @@ public class Inventory : ScriptableObject
public static Inventory Clone(Inventory copy) public static Inventory Clone(Inventory copy)
{ {
Inventory retVal = ScriptableObject.CreateInstance<Inventory>(); Inventory retVal = ScriptableObject.CreateInstance<Inventory>();
retVal._bagItems = new List<Data>(copy._bagItems);
retVal._bagItems = new List<Data>();
foreach (Data data in copy.BagItems)
{
Data dataCopy = new Data(data.element,data.Count,data.isInfinit);
retVal._bagItems.Add(dataCopy);
}
return retVal; return retVal;
} }
@ -81,5 +99,15 @@ public class Inventory : ScriptableObject
public LogicBlock element; public LogicBlock element;
public int Count; public int Count;
public bool isInfinit = false; public bool isInfinit = false;
public Data() { }
public Data(LogicBlock element, int Count, bool isInfinit)
{
this.element = element;
this.Count = Count;
this.isInfinit = isInfinit;
}
} }
} }

+ 1
- 1
Assets/Scripts/Logic/BlockReader.cs View File

@ -29,7 +29,7 @@ public class BlockReader
/// <summary> /// <summary>
/// Gets the current block in the logic chain /// Gets the current block in the logic chain
/// </summary> /// </summary>
public LogicBlock CurrentBlock { get { return LogicChain[currentBlockIndex]; } }
public LogicBlock CurrentBlock { get { return ((currentBlockIndex < LogicChain.Count) ? LogicChain[currentBlockIndex] : null); } }
#endregion Read-only Variables #endregion Read-only Variables

+ 1
- 6
Assets/Scripts/Logic/Blocks/LogicBlock.cs View File

@ -137,7 +137,7 @@ public abstract class LogicBlock : ScriptableObject
#endregion Serialisation Functions #endregion Serialisation Functions
public override bool Equals(object other)
public bool isSameType(object other)
{ {
if (Object.ReferenceEquals(null, other)) if (Object.ReferenceEquals(null, other))
return false; return false;
@ -150,11 +150,6 @@ public abstract class LogicBlock : ScriptableObject
&& string.Equals(name, otherLogic.name); && string.Equals(name, otherLogic.name);
} }
public override int GetHashCode()
{
return name.GetHashCode();
}
public virtual void OnDoubleClick() public virtual void OnDoubleClick()
{ {

+ 2
- 2
Assets/Scripts/Managers/GameManager.cs View File

@ -46,7 +46,6 @@ public class GameManager : MonoBehaviour
gamemode = CurrentGameMode.Value; gamemode = CurrentGameMode.Value;
RegisterHandlers(); RegisterHandlers();
SpawnCharacters(); SpawnCharacters();
gamemode.GameStart(playerArray.ToArray());
ClientList.ForEach(p => p.ChangeScene("ClientScene")); ClientList.ForEach(p => p.ChangeScene("ClientScene"));
} }
@ -99,8 +98,9 @@ public class GameManager : MonoBehaviour
{ {
if (!player.waiting) if (!player.waiting)
{ {
if (!player.blockReader.CurrentBlock.hasBeenRemoved)
if (player.blockReader.CurrentBlock != null && !player.blockReader.CurrentBlock.hasBeenRemoved)
{ {
Debug.Log("used Block: " + player.blockReader.CurrentBlock.name);
player.client.Inventory.Remove(player.blockReader.CurrentBlock); player.client.Inventory.Remove(player.blockReader.CurrentBlock);
player.blockReader.CurrentBlock.hasBeenRemoved = true; player.blockReader.CurrentBlock.hasBeenRemoved = true;
} }

+ 12
- 2
Assets/Scripts/UI/LogicTrayUI.cs View File

@ -91,7 +91,11 @@ public class LogicTrayUI : LogicElementHolder
/// <param name="element">Element which is being dragged</param> /// <param name="element">Element which is being dragged</param>
public override void OnRemove(LogicElementUI element) public override void OnRemove(LogicElementUI element)
{ {
reader.Remove(element.logicElement);
Vector2 offset = new Vector2(element.rectTransform.rect.width/2, 0);
int index = GetInsertIndex(element.rectTransform,offset);
if (index >= reader.LogicChain.Count)
index = reader.LogicChain.Count - 1;
reader.LogicChain.RemoveAt(index);
} }
/// <summary> /// <summary>
@ -151,9 +155,10 @@ public class LogicTrayUI : LogicElementHolder
#region Helper Functions #region Helper Functions
public int GetInsertIndex(RectTransform rt)
public int GetInsertIndex(RectTransform rt, Vector2 offset)
{ {
Rect rect = rt.GlobalRect(); Rect rect = rt.GlobalRect();
rect.center += offset;
foreach (Transform child in content) foreach (Transform child in content)
{ {
@ -165,6 +170,11 @@ public class LogicTrayUI : LogicElementHolder
return reader.LogicChain.Count; return reader.LogicChain.Count;
} }
public int GetInsertIndex(RectTransform rt)
{
return GetInsertIndex(rt, Vector2.zero);
}
#endregion Helper Functions #endregion Helper Functions

+ 19
- 3
Assets/Scripts/UI/NetworkedUIManager.cs View File

@ -17,6 +17,9 @@ public class NetworkedUIManager : PlayerUIManager
[SerializeField] [SerializeField]
private float TotalTime; private float TotalTime;
[Header("Debug")]
[SerializeField]
private bool isTimePaused;
private float StartTime; private float StartTime;
@ -29,14 +32,18 @@ public class NetworkedUIManager : PlayerUIManager
TrayUI.SetBlockReader(reader); TrayUI.SetBlockReader(reader);
StartTime = Time.time; StartTime = Time.time;
ShowPosition.y -= Title.rect.height; ShowPosition.y -= Title.rect.height;
OnClick_Show();
} }
private void Update() private void Update()
{ {
TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString();
if (!isTimePaused)
{
TimeText.text = ((int)(TotalTime - (Time.time - StartTime))).ToString();
if (Time.time - StartTime > TotalTime)
OnClick_Play();
if (Time.time - StartTime > TotalTime)
OnClick_Play();
}
} }
public override void OnClick_Play() public override void OnClick_Play()
@ -49,5 +56,14 @@ public class NetworkedUIManager : PlayerUIManager
UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene"); UnityEngine.SceneManagement.SceneManager.LoadScene("WaitScene");
} }
public void On_ClickPauseTime()
{
isTimePaused = !isTimePaused;
if (isTimePaused)
TimeText.color = Color.grey;
else
TimeText.color = Color.black;
}
} }

Loading…
Cancel
Save