mirror of
https://github.com/DerTyp7/industrialize-unity.git
synced 2025-10-30 12:57:11 +01:00
a
This commit is contained in:
13
Assets/Items/testItem/StackSizeText.cs
Normal file
13
Assets/Items/testItem/StackSizeText.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
//! DEBUG TEXT
|
||||||
|
public class StackSizeText : MonoBehaviour
|
||||||
|
{
|
||||||
|
public ItemObject itemObject;
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
gameObject.GetComponent<TMPro.TextMeshPro>().text = itemObject.stackSize.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Items/testItem/StackSizeText.cs.meta
Normal file
11
Assets/Items/testItem/StackSizeText.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 113a94b344e135249a6f9928d9617df2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,5 +1,200 @@
|
|||||||
%YAML 1.1
|
%YAML 1.1
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &7598110288018339969
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 7235504030812167489}
|
||||||
|
- component: {fileID: 8792484635333935822}
|
||||||
|
- component: {fileID: 776590918211704844}
|
||||||
|
- component: {fileID: 2839967651599440056}
|
||||||
|
- component: {fileID: 7272902474709330505}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: stackSizeText
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &7235504030812167489
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7598110288018339969}
|
||||||
|
m_LocalRotation: {x: 0.000017120734, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 1}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 8936059402275091559}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0.002, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||||
|
m_AnchoredPosition: {x: 0.51, y: 1.26}
|
||||||
|
m_SizeDelta: {x: 0.8314, y: 0.8685}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &8792484635333935822
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7598110288018339969}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 113a94b344e135249a6f9928d9617df2, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
itemObject: {fileID: 8936059402275091553}
|
||||||
|
--- !u!222 &776590918211704844
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7598110288018339969}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!23 &2839967651599440056
|
||||||
|
MeshRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7598110288018339969}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_StaticShadowCaster: 0
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 2
|
||||||
|
m_RayTraceProcedural: 0
|
||||||
|
m_RenderingLayerMask: 4294967295
|
||||||
|
m_RendererPriority: 0
|
||||||
|
m_Materials:
|
||||||
|
- {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_StaticBatchInfo:
|
||||||
|
firstSubMesh: 0
|
||||||
|
subMeshCount: 0
|
||||||
|
m_StaticBatchRoot: {fileID: 0}
|
||||||
|
m_ProbeAnchor: {fileID: 0}
|
||||||
|
m_LightProbeVolumeOverride: {fileID: 0}
|
||||||
|
m_ScaleInLightmap: 1
|
||||||
|
m_ReceiveGI: 1
|
||||||
|
m_PreserveUVs: 0
|
||||||
|
m_IgnoreNormalsForChartDetection: 0
|
||||||
|
m_ImportantGI: 0
|
||||||
|
m_StitchLightmapSeams: 1
|
||||||
|
m_SelectedEditorRenderState: 3
|
||||||
|
m_MinimumChartSize: 4
|
||||||
|
m_AutoUVMaxDistance: 0.5
|
||||||
|
m_AutoUVMaxAngle: 89
|
||||||
|
m_LightmapParameters: {fileID: 0}
|
||||||
|
m_SortingLayerID: 0
|
||||||
|
m_SortingLayer: 0
|
||||||
|
m_SortingOrder: 0
|
||||||
|
m_AdditionalVertexStreams: {fileID: 0}
|
||||||
|
--- !u!114 &7272902474709330505
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7598110288018339969}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_text: 1
|
||||||
|
m_isRightToLeft: 0
|
||||||
|
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||||
|
m_fontSharedMaterials: []
|
||||||
|
m_fontMaterial: {fileID: 0}
|
||||||
|
m_fontMaterials: []
|
||||||
|
m_fontColor32:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4294967295
|
||||||
|
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_enableVertexGradient: 0
|
||||||
|
m_colorMode: 3
|
||||||
|
m_fontColorGradient:
|
||||||
|
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_fontColorGradientPreset: {fileID: 0}
|
||||||
|
m_spriteAsset: {fileID: 0}
|
||||||
|
m_tintAllSprites: 0
|
||||||
|
m_StyleSheet: {fileID: 0}
|
||||||
|
m_TextStyleHashCode: -1183493901
|
||||||
|
m_overrideHtmlColors: 0
|
||||||
|
m_faceColor:
|
||||||
|
serializedVersion: 2
|
||||||
|
rgba: 4294967295
|
||||||
|
m_fontSize: 5.1
|
||||||
|
m_fontSizeBase: 5.1
|
||||||
|
m_fontWeight: 400
|
||||||
|
m_enableAutoSizing: 0
|
||||||
|
m_fontSizeMin: 18
|
||||||
|
m_fontSizeMax: 72
|
||||||
|
m_fontStyle: 1
|
||||||
|
m_HorizontalAlignment: 2
|
||||||
|
m_VerticalAlignment: 512
|
||||||
|
m_textAlignment: 65535
|
||||||
|
m_characterSpacing: 0
|
||||||
|
m_wordSpacing: 0
|
||||||
|
m_lineSpacing: 0
|
||||||
|
m_lineSpacingMax: 0
|
||||||
|
m_paragraphSpacing: 0
|
||||||
|
m_charWidthMaxAdj: 0
|
||||||
|
m_enableWordWrapping: 1
|
||||||
|
m_wordWrappingRatios: 0.4
|
||||||
|
m_overflowMode: 0
|
||||||
|
m_linkedTextComponent: {fileID: 0}
|
||||||
|
parentLinkedComponent: {fileID: 0}
|
||||||
|
m_enableKerning: 1
|
||||||
|
m_enableExtraPadding: 0
|
||||||
|
checkPaddingRequired: 0
|
||||||
|
m_isRichText: 1
|
||||||
|
m_parseCtrlCharacters: 1
|
||||||
|
m_isOrthographic: 0
|
||||||
|
m_isCullingEnabled: 0
|
||||||
|
m_horizontalMapping: 0
|
||||||
|
m_verticalMapping: 0
|
||||||
|
m_uvLineOffset: 0
|
||||||
|
m_geometrySortingOrder: 0
|
||||||
|
m_IsTextObjectScaleStatic: 0
|
||||||
|
m_VertexBufferAutoSizeReduction: 0
|
||||||
|
m_useMaxVisibleDescender: 1
|
||||||
|
m_pageToDisplay: 1
|
||||||
|
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_isUsingLegacyAnimationComponent: 0
|
||||||
|
m_isVolumetricText: 0
|
||||||
|
_SortingLayer: 0
|
||||||
|
_SortingLayerID: 0
|
||||||
|
_SortingOrder: 0
|
||||||
|
m_hasFontAssetChanged: 0
|
||||||
|
m_renderer: {fileID: 2839967651599440056}
|
||||||
|
m_maskType: 0
|
||||||
--- !u!1 &8936059402275091554
|
--- !u!1 &8936059402275091554
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -31,7 +226,8 @@ Transform:
|
|||||||
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_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children:
|
||||||
|
- {fileID: 7235504030812167489}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@@ -75,7 +271,7 @@ SpriteRenderer:
|
|||||||
m_LightmapParameters: {fileID: 0}
|
m_LightmapParameters: {fileID: 0}
|
||||||
m_SortingLayerID: 0
|
m_SortingLayerID: 0
|
||||||
m_SortingLayer: 0
|
m_SortingLayer: 0
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 1
|
||||||
m_Sprite: {fileID: 21300000, guid: f703c137a9648eb4bbffb1f6b1aed05e, type: 3}
|
m_Sprite: {fileID: 21300000, guid: f703c137a9648eb4bbffb1f6b1aed05e, type: 3}
|
||||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
m_FlipX: 0
|
m_FlipX: 0
|
||||||
@@ -103,7 +299,9 @@ MonoBehaviour:
|
|||||||
stackSize: 1
|
stackSize: 1
|
||||||
itemSO: {fileID: 0}
|
itemSO: {fileID: 0}
|
||||||
timeAlive: 0
|
timeAlive: 0
|
||||||
maxTimeAlive: 60
|
maxTimeAlive: 600
|
||||||
|
maxTimeWithoutConveyor: 10
|
||||||
|
timeWithoutConveyor: 0
|
||||||
--- !u!61 &3180622400512972912
|
--- !u!61 &3180622400512972912
|
||||||
BoxCollider2D:
|
BoxCollider2D:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ MonoBehaviour:
|
|||||||
placedObjectTypeSO: {fileID: 11400000, guid: fbec66c9ae95b954d994cc26105f0302, type: 2}
|
placedObjectTypeSO: {fileID: 11400000, guid: fbec66c9ae95b954d994cc26105f0302, type: 2}
|
||||||
origin: {x: 0, y: 0}
|
origin: {x: 0, y: 0}
|
||||||
isBlueprint: 1
|
isBlueprint: 1
|
||||||
speed: 0.3
|
speed: 1
|
||||||
previousConveyor: {fileID: 0}
|
previousConveyor: {fileID: 0}
|
||||||
nextConveyor: {fileID: 0}
|
nextConveyor: {fileID: 0}
|
||||||
sprites:
|
sprites:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class ConveyorPO : PlacedObject
|
public class ConveyorPO : PlacedObject
|
||||||
{
|
{
|
||||||
public float speed = 0.3f;
|
[SerializeField] private float speed = 0.3f;
|
||||||
|
|
||||||
public ConveyorPO previousConveyor;
|
public ConveyorPO previousConveyor;
|
||||||
public ConveyorPO nextConveyor;
|
public ConveyorPO nextConveyor;
|
||||||
@@ -11,6 +11,17 @@ public class ConveyorPO : PlacedObject
|
|||||||
public List<Sprite> sprites = new List<Sprite>(); // 0 = Up, 1 = Right, 2 = Down, 3 = Left
|
public List<Sprite> sprites = new List<Sprite>(); // 0 = Up, 1 = Right, 2 = Down, 3 = Left
|
||||||
|
|
||||||
|
|
||||||
|
public float GetSpeed()
|
||||||
|
{
|
||||||
|
if (nextConveyor != null)
|
||||||
|
{
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<ConveyorPO> GetConveyorsAround()
|
private List<ConveyorPO> GetConveyorsAround()
|
||||||
{
|
{
|
||||||
@@ -36,35 +47,70 @@ public class ConveyorPO : PlacedObject
|
|||||||
|
|
||||||
private void SetConveyorChain()
|
private void SetConveyorChain()
|
||||||
{
|
{
|
||||||
ConveyorPO lastChoiceConveyor = null;
|
// TODO Last conveyor does not connect to first conveyor (circle)
|
||||||
|
List<ConveyorPO> possibleNextConveyors = GetConveyorsAround();
|
||||||
|
List<ConveyorPO> possiblePreviousConveyors = GetConveyorsAround();
|
||||||
|
|
||||||
|
if (previousConveyor != null && nextConveyor != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (ConveyorPO c in GetConveyorsAround())
|
foreach (ConveyorPO c in GetConveyorsAround())
|
||||||
{
|
{
|
||||||
if (c == nextConveyor || c == previousConveyor || c == this || c.previousConveyor == this || c.nextConveyor == this)
|
if (c == nextConveyor || c == previousConveyor || c == this || c.previousConveyor == this || c.nextConveyor == this)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.nextConveyor == null)
|
|
||||||
{
|
|
||||||
if (c.previousConveyor == null)
|
|
||||||
{
|
|
||||||
lastChoiceConveyor = c;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c.nextConveyor = this;
|
if (c.nextConveyor == null)
|
||||||
c.UpdateChain();
|
{
|
||||||
previousConveyor = c;
|
if (nextConveyor != c)
|
||||||
return;
|
{
|
||||||
|
possiblePreviousConveyors.Add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.previousConveyor == null)
|
||||||
|
{
|
||||||
|
if (previousConveyor != c)
|
||||||
|
{
|
||||||
|
possibleNextConveyors.Add(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastChoiceConveyor != null)
|
if (possiblePreviousConveyors.Count > 0 && previousConveyor == null)
|
||||||
{
|
{
|
||||||
lastChoiceConveyor.nextConveyor = this;
|
Debug.Log("PREV " + possiblePreviousConveyors.Count);
|
||||||
lastChoiceConveyor.UpdateChain();
|
foreach (ConveyorPO c in possiblePreviousConveyors)
|
||||||
previousConveyor = lastChoiceConveyor;
|
{
|
||||||
|
if (c.previousConveyor != this && c.nextConveyor == null)
|
||||||
|
{
|
||||||
|
previousConveyor = c; // Maybe prioritize Conveyor which is already in a chain?
|
||||||
|
previousConveyor.nextConveyor = this;
|
||||||
|
previousConveyor.UpdateChain();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (possibleNextConveyors.Count > 0 && nextConveyor == null)
|
||||||
|
{
|
||||||
|
Debug.Log("Next " + possibleNextConveyors.Count);
|
||||||
|
foreach (ConveyorPO c in possibleNextConveyors)
|
||||||
|
{
|
||||||
|
if (c.nextConveyor != this && c.previousConveyor == null)
|
||||||
|
{
|
||||||
|
nextConveyor = c; // Maybe prioritize Conveyor which is already in a chain?
|
||||||
|
nextConveyor.previousConveyor = this;
|
||||||
|
nextConveyor.UpdateChain();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ public class Grid<TGridObject>
|
|||||||
{
|
{
|
||||||
for (int y = 0; y < gridArray.GetLength(1); y++)
|
for (int y = 0; y < gridArray.GetLength(1); y++)
|
||||||
{
|
{
|
||||||
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
|
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 1000f);
|
||||||
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
|
Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 1000f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
|
Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 1000f);
|
||||||
Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
|
Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 1000f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,18 @@ public abstract class ItemObject : MonoBehaviour
|
|||||||
public int stackSize = 1;
|
public int stackSize = 1;
|
||||||
public ItemSO itemSO;
|
public ItemSO itemSO;
|
||||||
public float timeAlive = 0.0f;
|
public float timeAlive = 0.0f;
|
||||||
public float maxTimeAlive = 60.0f;
|
public float maxTimeAlive = 600.0f;
|
||||||
|
public float maxTimeWithoutConveyor = 10.0f;
|
||||||
|
public float timeWithoutConveyor = 0.0f;
|
||||||
|
|
||||||
|
private ConveyorPO lastTouchedConveyor; // current conveyor but not set to null
|
||||||
|
private float conveyorSpeed = 0.0f;
|
||||||
|
private Vector2 conveyorDirection = Vector2.zero;
|
||||||
|
|
||||||
public abstract void OnSpawn();
|
public abstract void OnSpawn();
|
||||||
|
|
||||||
|
private ConveyorPO currentConveyor;
|
||||||
|
|
||||||
private Rigidbody2D rb;
|
private Rigidbody2D rb;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
@@ -51,13 +60,100 @@ public abstract class ItemObject : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Despawn();
|
Despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Problem: Pivot point of an item is bottom-left, so its not proberly aligned with the conveyor
|
||||||
|
GridBuildingSystem gridBuildingSystem = GridBuildingSystem.instance;
|
||||||
|
|
||||||
|
//* Position has to change depending on which direction the item is heading, in order to stay on the conveyor
|
||||||
|
Vector3 tempPivotPosition = transform.position;
|
||||||
|
|
||||||
|
if (currentConveyor != null)
|
||||||
|
{
|
||||||
|
// TODO Freeze rigibody rotations based on direction
|
||||||
|
//* KEEP IN MIND -> PIVOT POINT IS BOTTOM-LEFT
|
||||||
|
|
||||||
|
// If direction changes
|
||||||
|
if (conveyorDirection != currentConveyor.GetDirection())
|
||||||
|
{
|
||||||
|
// Realign
|
||||||
|
gridBuildingSystem.buildingGrid.GetXY(lastTouchedConveyor.gameObject.transform.position, out int x, out int y);
|
||||||
|
transform.position = gridBuildingSystem.buildingGrid.GetWorldPosition(x, y);
|
||||||
|
conveyorDirection = currentConveyor.GetDirection();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conveyorDirection.y > 0) // Top
|
||||||
|
{
|
||||||
|
Debug.Log("Heading top");
|
||||||
|
tempPivotPosition = transform.position + new Vector3(transform.localScale.x / 2, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conveyorDirection.x > 0) // Right
|
||||||
|
{
|
||||||
|
Debug.Log("Heading right");
|
||||||
|
tempPivotPosition = transform.position + new Vector3(0, transform.localScale.y / 2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conveyorDirection.y < 0) // Bottom
|
||||||
|
{
|
||||||
|
Debug.Log("Heading bottom");
|
||||||
|
tempPivotPosition = transform.position + new Vector3(transform.localScale.x / 2, transform.localScale.y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conveyorDirection.x < 0) // Left
|
||||||
|
{
|
||||||
|
Debug.Log("Heading left");
|
||||||
|
tempPivotPosition = transform.position + new Vector3(transform.localScale.x, transform.localScale.y / 2, 0);
|
||||||
|
}
|
||||||
|
Debug.DrawLine(tempPivotPosition, Vector3.zero, Color.red);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gridBuildingSystem.buildingGrid.GetXY(tempPivotPosition, out int tempPivotX, out int tempPivotY);
|
||||||
|
|
||||||
|
GridBuildingSystem.GridObject gridObject = gridBuildingSystem.buildingGrid.GetGridObject(tempPivotX, tempPivotY);
|
||||||
|
|
||||||
|
if (gridObject.GetPlacedObject() != null)
|
||||||
|
{
|
||||||
|
if (gridObject.GetPlacedObject().gameObject.GetComponent<ConveyorPO>())
|
||||||
|
{
|
||||||
|
timeWithoutConveyor = 0.0f;
|
||||||
|
currentConveyor = gridObject.GetPlacedObject().gameObject.GetComponent<ConveyorPO>();
|
||||||
|
lastTouchedConveyor = currentConveyor;
|
||||||
|
conveyorSpeed = currentConveyor.GetSpeed();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateWithoutConveyor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateWithoutConveyor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateWithoutConveyor()
|
||||||
|
{
|
||||||
|
currentConveyor = null;
|
||||||
|
timeWithoutConveyor += Time.deltaTime;
|
||||||
|
if (timeWithoutConveyor > maxTimeWithoutConveyor)
|
||||||
|
{
|
||||||
|
Debug.Log("Not on conveyor -> DESPAWN");
|
||||||
|
Despawn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
float speed = 0.3f; // TODO Get speed from ConveyorBelt
|
if (currentConveyor != null)
|
||||||
Vector2 direction = new Vector2(1f, 0f); // TODO Get direction from ConveyorBelt
|
{
|
||||||
|
rb.MovePosition(rb.position + (conveyorDirection * conveyorSpeed) * Time.fixedDeltaTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO Interrupt all movement
|
||||||
|
}
|
||||||
|
|
||||||
rb.MovePosition(rb.position + (direction * speed) * Time.fixedDeltaTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user