diff --git a/Assets/Play Mode/Interpreter/SaverLoader.cs b/Assets/Play Mode/Interpreter/SaverLoader.cs deleted file mode 100644 index 00a23ff..0000000 --- a/Assets/Play Mode/Interpreter/SaverLoader.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class SaverLoader -{ - public void Save(string fileName) - { - - } - public void Load(string fileName) - { - - } -} diff --git a/Assets/Player/Building Mechanic/Scripts/BuildingScript.cs b/Assets/Player/Building Mechanic/Scripts/BuildingScript.cs index 1177302..dc3517d 100644 --- a/Assets/Player/Building Mechanic/Scripts/BuildingScript.cs +++ b/Assets/Player/Building Mechanic/Scripts/BuildingScript.cs @@ -12,6 +12,7 @@ public class BuildingScript : MonoBehaviour private AnchorScript newanchor;//The new anchor to add the new block to private LayerMask mask;//Mask used to disable anchors in collision private GameObject PreviewPiece;//The gameobject of the spawned preview piece + private int pieceNumber;//Piece number to help saving and loading // Start is called before the first frame update void Start() { @@ -84,10 +85,12 @@ public void AddBuildingPiece(AnchorScript anchor)//Add piece to the anchor, then { GameObject newpiece = Instantiate(SelectedBuildingPiecePrefab, anchor.transform.position, anchor.transform.rotation);//Spawn the piece FixedJoint newjoint = newpiece.AddComponent();//Adds the joint to not let it move + newpiece.name = SelectedBuildingPiecePrefab.name + "-" + pieceNumber; newjoint.connectedBody = anchor.parent;//Connect the new piece to the anchor's parent piece anchor.gameObject.SetActive(false);//Disable the anchor sine we place a piece at it's place UpdateAnchors(null); newpiece.transform.parent = MainPlayerGameobject.transform; + pieceNumber++; } } } diff --git a/Assets/Player/Building Mechanic/Scripts/SaverLoader.cs b/Assets/Player/Building Mechanic/Scripts/SaverLoader.cs new file mode 100644 index 0000000..3c5fe70 --- /dev/null +++ b/Assets/Player/Building Mechanic/Scripts/SaverLoader.cs @@ -0,0 +1,55 @@ +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +public class SaverLoader +{ + public void Save(string fileName, Rigidbody[] pieces) //Save pieces + { + Piece[] newPieces = new Piece[pieces.Length]; + string finalText; + for (int i = 0; i < pieces.Length; i++) + { + newPieces[i].pieceName = pieces[i].name;//Set name of piece + if (pieces[i].GetComponent() != null)//Only for pieces who are not start piece + { + newPieces[i].parentPiece = pieces[i].GetComponent().connectedBody;//Set parent piece + } + if (pieces[i].name == "StructuralPiece") + { + newPieces[i].pieceType = PieceType.StructuralPiece; + } + if (pieces[i].name == "ControlUnit") + { + newPieces[i].pieceType = PieceType.ControlUnit; + } + newPieces[i].position = pieces[i].transform.position;//Set position + } + string path = Application.dataPath + "/SavedMachines/" + fileName; + if (!Directory.Exists(Application.dataPath + "/SavedMachines"))//Dirrectory handling + { + Directory.CreateDirectory(Application.dataPath + "/SavedMachines"); + } + foreach (var newpiece in newPieces) + { + //finalText.Insert(); + } + //File.WriteAllText(); + } + public void Load(string fileName) //Load pieces + { + + } + private struct Piece + { + public string pieceName; + public Rigidbody parentPiece; + public PieceType pieceType; + public Vector3 position; + } + private enum PieceType + { + StructuralPiece, ControlUnit + } +}