conveyorPO

This commit is contained in:
Janis
2022-06-05 10:52:27 +02:00
parent a31c6a16dd
commit 831f1423b5
21 changed files with 473 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 29f2e5b9a518fba4482682b589db2ae6
guid: a9c42c8d76fbddf418eca150815ab40a
folderAsset: yes
DefaultImporter:
externalObjects: {}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 278 B

View File

@@ -42,11 +42,11 @@ TextureImporter:
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
spriteMeshType: 0
alignment: 6
spritePivot: {x: 0.5, y: 0.5}
spritePivot: {x: 0, y: 0}
spritePixelsToUnits: 16
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
@@ -102,7 +102,91 @@ TextureImporter:
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
sprites:
- serializedVersion: 2
name: Conveyor_up
rect:
serializedVersion: 2
x: 0
y: 0
width: 16
height: 16
alignment: 6
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 0ffc466f384bdec43928d2882645eb1d
internalID: 713996374
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: Conveyor_right
rect:
serializedVersion: 2
x: 16
y: 0
width: 16
height: 16
alignment: 6
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 811efe0215668d24dafbd34d8571cd7a
internalID: 568985664
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: Conveyor_down
rect:
serializedVersion: 2
x: 32
y: 0
width: 16
height: 16
alignment: 6
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 9c01b50eb9891ac4c8f5fabe56a62b59
internalID: 1508833655
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: Conveyor_left
rect:
serializedVersion: 2
x: 48
y: 0
width: 16
height: 16
alignment: 6
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 05ae3c9287366f74db9ac847578f2252
internalID: -46495100
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
@@ -113,7 +197,11 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
nameFileIdTable:
Conveyor_down: 1508833655
Conveyor_up: 713996374
Conveyor_right: 568985664
Conveyor_left: -46495100
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

@@ -74,12 +74,12 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 1e674c36d7cd123419185513744b8fef, type: 3}
m_Sprite: {fileID: 713996374, guid: 1e674c36d7cd123419185513744b8fef, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.16, y: 0.16}
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@@ -98,4 +98,13 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
placedObjectTypeSO: {fileID: 11400000, guid: fbec66c9ae95b954d994cc26105f0302, type: 2}
origin: {x: 0, y: 0}
isBlueprint: 1
speed: 0.3
previousConveyor: {fileID: 0}
nextConveyor: {fileID: 0}
sprites:
- {fileID: 713996374, guid: 1e674c36d7cd123419185513744b8fef, type: 3}
- {fileID: 568985664, guid: 1e674c36d7cd123419185513744b8fef, type: 3}
- {fileID: 1508833655, guid: 1e674c36d7cd123419185513744b8fef, type: 3}
- {fileID: -46495100, guid: 1e674c36d7cd123419185513744b8fef, type: 3}

View File

@@ -1,9 +1,116 @@
using System.Collections.Generic;
using UnityEngine;
public class ConveyorPO : PlacedObject
{
public float speed = 0.3f;
public ConveyorPO previousConveyor;
public ConveyorPO nextConveyor;
public List<Sprite> sprites = new List<Sprite>(); // 0 = Up, 1 = Right, 2 = Down, 3 = Left
private List<ConveyorPO> GetConveyorsAround()
{
List<ConveyorPO> conveyors = new List<ConveyorPO>();
GridBuildingSystem gridBuildingSystem = GridBuildingSystem.instance;
List<GridBuildingSystem.GridObject> gridObjects = gridBuildingSystem.buildingGrid.GetGridObjectsAround(transform.position);
foreach (GridBuildingSystem.GridObject gridObject in gridObjects)
{
if (gridObject.GetPlacedObject() != null)
{
PlacedObject placedObject = gridObject.GetPlacedObject();
if (placedObject.gameObject.GetComponent<ConveyorPO>() != null)
{
conveyors.Add(placedObject.gameObject.GetComponent<ConveyorPO>());
}
}
}
return conveyors;
}
private void SetConveyorChain()
{
ConveyorPO lastChoiceConveyor = null;
foreach (ConveyorPO c in GetConveyorsAround())
{
if (c == nextConveyor || c == previousConveyor || c == this || c.previousConveyor == this || c.nextConveyor == this)
{
continue;
}
if (c.nextConveyor == null)
{
if (c.previousConveyor == null)
{
lastChoiceConveyor = c;
}
else
{
c.nextConveyor = this;
c.UpdateChain();
previousConveyor = c;
return;
}
}
}
if (lastChoiceConveyor != null)
{
lastChoiceConveyor.nextConveyor = this;
lastChoiceConveyor.UpdateChain();
previousConveyor = lastChoiceConveyor;
}
}
public Vector2 GetDirection()
{
if (nextConveyor != null)
{
return (nextConveyor.transform.position - transform.position).normalized;
}
else if (previousConveyor != null)
{
return (previousConveyor.transform.position - transform.position).normalized * -1;
}
return Vector2.up;
}
public void SetSpriteToDirection(Vector2 direction)
{
if (direction.x > 0)
{
GetComponent<SpriteRenderer>().sprite = sprites[1];
}
else if (direction.x < 0)
{
GetComponent<SpriteRenderer>().sprite = sprites[3];
}
else if (direction.y > 0)
{
GetComponent<SpriteRenderer>().sprite = sprites[0];
}
else if (direction.y < 0)
{
GetComponent<SpriteRenderer>().sprite = sprites[2];
}
}
public void UpdateChain()
{
SetConveyorChain();
SetSpriteToDirection(GetDirection());
}
public override void OnPlace()
{
Debug.Log("Conveyor placed");
UpdateChain();
}
}

View File

@@ -3,7 +3,8 @@ guid: 2ab4daa316d34c146bff8cdfc36db375
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
defaultReferences:
- placedObjectTypeSO: {fileID: 11400000, guid: fbec66c9ae95b954d994cc26105f0302, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9751bc22ff08bd849a9bc8a68a3ba98e
guid: 484bc68485888f04daf075ff0f8e3cf9
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9751bc22ff08bd849a9bc8a68a3ba98e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: