mirror of
https://github.com/DerTyp7/industrialize-unity.git
synced 2025-10-29 12:32:12 +01:00
conveyorPO
This commit is contained in:
55
.vscode/settings.json
vendored
Normal file
55
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"files.exclude":
|
||||
{
|
||||
"**/.DS_Store":true,
|
||||
"**/.git":true,
|
||||
"**/.gitmodules":true,
|
||||
"**/*.booproj":true,
|
||||
"**/*.pidb":true,
|
||||
"**/*.suo":true,
|
||||
"**/*.user":true,
|
||||
"**/*.userprefs":true,
|
||||
"**/*.unityproj":true,
|
||||
"**/*.dll":true,
|
||||
"**/*.exe":true,
|
||||
"**/*.pdf":true,
|
||||
"**/*.mid":true,
|
||||
"**/*.midi":true,
|
||||
"**/*.wav":true,
|
||||
"**/*.gif":true,
|
||||
"**/*.ico":true,
|
||||
"**/*.jpg":true,
|
||||
"**/*.jpeg":true,
|
||||
"**/*.png":true,
|
||||
"**/*.psd":true,
|
||||
"**/*.tga":true,
|
||||
"**/*.tif":true,
|
||||
"**/*.tiff":true,
|
||||
"**/*.3ds":true,
|
||||
"**/*.3DS":true,
|
||||
"**/*.fbx":true,
|
||||
"**/*.FBX":true,
|
||||
"**/*.lxo":true,
|
||||
"**/*.LXO":true,
|
||||
"**/*.ma":true,
|
||||
"**/*.MA":true,
|
||||
"**/*.obj":true,
|
||||
"**/*.OBJ":true,
|
||||
"**/*.asset":true,
|
||||
"**/*.cubemap":true,
|
||||
"**/*.flare":true,
|
||||
"**/*.mat":true,
|
||||
"**/*.meta":true,
|
||||
"**/*.prefab":true,
|
||||
"**/*.unity":true,
|
||||
"build/":true,
|
||||
"Build/":true,
|
||||
"Library/":true,
|
||||
"library/":true,
|
||||
"obj/":true,
|
||||
"Obj/":true,
|
||||
"ProjectSettings/":true,
|
||||
"temp/":true,
|
||||
"Temp/":true
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ GameObject:
|
||||
- component: {fileID: 8936059402275091559}
|
||||
- component: {fileID: 8936059402275091552}
|
||||
- component: {fileID: 8936059402275091553}
|
||||
- component: {fileID: 3180622400512972912}
|
||||
- component: {fileID: 3996583985504607898}
|
||||
m_Layer: 0
|
||||
m_Name: TestItemPrefab
|
||||
m_TagString: Untagged
|
||||
@@ -97,3 +99,55 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 13d2bec61636f894382663d9818c4fc9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
maxStackSize: 5
|
||||
stackSize: 1
|
||||
itemSO: {fileID: 0}
|
||||
timeAlive: 0
|
||||
maxTimeAlive: 60
|
||||
--- !u!61 &3180622400512972912
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8936059402275091554}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0.5, y: 0.5}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
oldSize: {x: 1, y: 1}
|
||||
newSize: {x: 0.16, y: 0.16}
|
||||
adaptiveTilingThreshold: 0.5
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.5, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!50 &3996583985504607898
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8936059402275091554}
|
||||
m_BodyType: 0
|
||||
m_Simulated: 1
|
||||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 0.0001
|
||||
m_LinearDrag: 0
|
||||
m_AngularDrag: 0
|
||||
m_GravityScale: 0
|
||||
m_Material: {fileID: 0}
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 1
|
||||
m_Constraints: 4
|
||||
|
||||
@@ -14,5 +14,5 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: item_test
|
||||
name: TestItem
|
||||
prefab: {fileID: 0}
|
||||
prefab: {fileID: 8936059402275091554, guid: 984beb37a1541ed40a2271c6ecb1162d, type: 3}
|
||||
icon: {fileID: 21300000, guid: f703c137a9648eb4bbffb1f6b1aed05e, type: 3}
|
||||
|
||||
@@ -45,7 +45,7 @@ TextureImporter:
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
alignment: 6
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 16
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class testItemObject : ItemObject
|
||||
{
|
||||
public override void OnSpawn()
|
||||
{
|
||||
Debug.Log("testItemObject.OnSpawn()");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 |
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9751bc22ff08bd849a9bc8a68a3ba98e
|
||||
guid: 484bc68485888f04daf075ff0f8e3cf9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
8
Assets/PlacedObjects/TestObject/TestObject.meta
Normal file
8
Assets/PlacedObjects/TestObject/TestObject.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9751bc22ff08bd849a9bc8a68a3ba98e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Grid<TGridObject>
|
||||
@@ -47,6 +48,32 @@ public class Grid<TGridObject>
|
||||
|
||||
}
|
||||
|
||||
public List<TGridObject> GetGridObjectsAround(Vector3 position)
|
||||
{
|
||||
List<TGridObject> gridObjects = new List<TGridObject>();
|
||||
|
||||
GetXY(position, out int x, out int y);
|
||||
|
||||
if (x - 1 >= 0)
|
||||
{
|
||||
gridObjects.Add(gridArray[x - 1, y]);
|
||||
}
|
||||
if (x + 1 < width)
|
||||
{
|
||||
gridObjects.Add(gridArray[x + 1, y]);
|
||||
}
|
||||
if (y - 1 >= 0)
|
||||
{
|
||||
gridObjects.Add(gridArray[x, y - 1]);
|
||||
}
|
||||
if (y + 1 < height)
|
||||
{
|
||||
gridObjects.Add(gridArray[x, y + 1]);
|
||||
}
|
||||
|
||||
return gridObjects;
|
||||
}
|
||||
|
||||
public Vector3 GetWorldPosition(int x, int y)
|
||||
{
|
||||
return new Vector3(x, y) * cellSize + originPosition;
|
||||
|
||||
@@ -11,8 +11,9 @@ public abstract class PlacedObject : MonoBehaviour
|
||||
placedObject.placedObjectTypeSO = placedObjectTypeSO;
|
||||
placedObject.origin = origin;
|
||||
|
||||
placedObject.OnPlace();
|
||||
|
||||
placedObject.SetIsBlueprint(false);
|
||||
placedObject.OnPlace();
|
||||
|
||||
if (placedObjectTypeSO.isWalkable)
|
||||
{
|
||||
|
||||
17
Assets/Scripts/Items/ItemManager.cs
Normal file
17
Assets/Scripts/Items/ItemManager.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemManager : MonoBehaviour
|
||||
{
|
||||
public static ItemManager instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Items/ItemManager.cs.meta
Normal file
11
Assets/Scripts/Items/ItemManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27ab07ac74967d54c86450327d86934a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,63 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemObject : ScriptableObject
|
||||
public abstract class ItemObject : MonoBehaviour
|
||||
{
|
||||
public int maxStackSize = 5;
|
||||
public int stackSize = 1;
|
||||
public ItemSO itemSO;
|
||||
public float timeAlive = 0.0f;
|
||||
public float maxTimeAlive = 60.0f;
|
||||
public abstract void OnSpawn();
|
||||
|
||||
private Rigidbody2D rb;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
public void Despawn()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.GetComponent<ItemObject>() != null)
|
||||
{
|
||||
ItemObject collisionItemObject = collision.gameObject.GetComponent<ItemObject>();
|
||||
int addedStackSize = stackSize + collisionItemObject.stackSize;
|
||||
|
||||
if (collisionItemObject.timeAlive < timeAlive) // The other item stacks to me
|
||||
{
|
||||
if (addedStackSize <= maxStackSize)
|
||||
{
|
||||
stackSize = addedStackSize;
|
||||
collisionItemObject.Despawn();
|
||||
}
|
||||
else
|
||||
{
|
||||
stackSize = maxStackSize;
|
||||
collisionItemObject.stackSize = addedStackSize - maxStackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
timeAlive += Time.deltaTime;
|
||||
if (timeAlive > maxTimeAlive)
|
||||
{
|
||||
Despawn();
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
float speed = 0.3f; // TODO Get speed from ConveyorBelt
|
||||
Vector2 direction = new Vector2(1f, 0f); // TODO Get direction from ConveyorBelt
|
||||
|
||||
rb.MovePosition(rb.position + (direction * speed) * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,22 @@ using UnityEngine;
|
||||
public class ItemSO : ScriptableObject
|
||||
{
|
||||
public string id;
|
||||
public string name;
|
||||
public string itemName;
|
||||
public GameObject prefab;
|
||||
public Sprite icon;
|
||||
|
||||
public void Spawn(Vector3 position)
|
||||
public GameObject Spawn(Vector3 position)
|
||||
{
|
||||
GameObject item = Instantiate(prefab, position, Quaternion.identity);
|
||||
// Snap to grid
|
||||
|
||||
GridBuildingSystem.instance.buildingGrid.GetXY(position, out int x, out int y);
|
||||
|
||||
position = GridBuildingSystem.instance.buildingGrid.GetWorldPosition(x, y);
|
||||
|
||||
GameObject item = Instantiate(prefab, new Vector3(position.x, position.y, 0), Quaternion.identity);
|
||||
item.name = name;
|
||||
item.GetComponent<ItemObject>().itemSO = this;
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ public class PlayerController : MonoBehaviour
|
||||
GridBuildingSystem.instance.SelectMovingPlacedObject(postion);
|
||||
movingMode = false;
|
||||
}
|
||||
|
||||
//! DEBUG SPAWNING ITEMS
|
||||
if (Input.GetKeyDown(KeyCode.Y))
|
||||
{
|
||||
Vector3 postion = cam.ScreenToWorldPoint(Input.mousePosition);
|
||||
ItemDictionary.instance.entries[0].Spawn(postion);
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleDemolishMode()
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user