public static void ResetSimulation(JsonAssembly assembly = null) { rbs.Clear(); ConnectionVoxelContainer.RemoveAllConnections(); CollisionVoxelContainer.RemoveAllGos(); foreach (KeyValuePair <int, Vector3> pos in savePositions) { GameObject go = GlobalReferences.FrozenParts[pos.Key]; go.transform.parent = null; go.transform.position = pos.Value; go.transform.rotation = saveRotations[pos.Key]; Part part = go.GetComponent <Part>(); CollisionVoxelContainer.StoreGameObject(go); foreach (int i in part.ActiveConnections) { ConnectionVoxelContainer.StoreConnection(part.Connections[i]); } } savePositions.Clear(); saveRotations.Clear(); simulationDone = false; }
public void SetActive(int conID) { if (!ActiveConnections.Contains(conID) && connections.Count > conID && conID >= 0) { activeConnections.Add(conID); ConnectionVoxelContainer.StoreConnection(connections[conID]); } }
public static void UpdateData(byte[] data) { LoadAggregationContainer container = ReadData(data); Dictionary <int, GameObject> checkFrozen = new Dictionary <int, GameObject>(); foreach (KeyValuePair <int, GameObject> pair in GlobalReferences.FrozenParts) { checkFrozen.Add(pair.Key, pair.Value); } foreach (PartSpawnData item in container.data) { GameObject checkGo = GlobalReferences.FrozenParts[item.id]; if (checkGo == null) { Debug.LogError("Part " + item.id + " not found in check"); continue; } Vector3 oldPos = checkGo.transform.position; List <Connection> connections = checkGo.GetComponent <Part>().Connections; if (Vector3.Distance(oldPos, item.Position) > 0.001f) { CollisionVoxelContainer.RemoveGameObject(checkGo); foreach (Connection con in connections) { ConnectionVoxelContainer.RemoveConnection(con); } } checkGo.transform.position = item.Position; checkGo.transform.rotation = item.Rotation; if (Vector3.Distance(oldPos, item.Position) > 0.001f) { CollisionVoxelContainer.StoreGameObject(checkGo); foreach (Connection con in connections) { ConnectionVoxelContainer.StoreConnection(con); } } checkFrozen.Remove(item.id); } GameObject[] leftovers = checkFrozen.Values.ToArray <GameObject>(); for (int i = leftovers.Length - 1; i >= 0; --i) { GameObject go = leftovers[i]; Part leftover = go.GetComponent <Part>(); Debug.LogError("Part " + leftover.ID + " was left over in check and will be deleted"); leftover.LocalDelete(); } }
public static void AfterSimulation(TIExportAR exportItem = null, bool export = false) { ++handlerCallBack; if (handlerCallBack >= handlers.Count) { if (!export) { ConnectionVoxelContainer.RemoveAllConnections(); CollisionVoxelContainer.RemoveAllGos(); foreach (GameObject go in GlobalReferences.FrozenParts.Values) { go.transform.parent = null; Part part = go.GetComponent <Part>(); CollisionVoxelContainer.StoreGameObject(go); foreach (int i in part.ActiveConnections) { ConnectionVoxelContainer.StoreConnection(part.Connections[i]); } } for (int i = rbs.Count - 1; i >= 0; --i) { MonoBehaviour.Destroy(rbs[i]); } simulationInProgress = false; simulationDone = false; } else { string c = expCount.ToString(); while (c.Length < countDigits) { c = "0" + c; } SaveLoad.SaveGame(c + "_", true, folder); } for (int i = handlers.Count - 1; i >= 0; --i) { MonoBehaviour.Destroy(handlers[i]); } handlers.Clear(); handlerCallBack = 0; if (export) { Export(exportItem); } } }
public void Enable() { if (!disabled) { return; } foreach (int i in ActiveConnections) { ConnectionVoxelContainer.StoreConnection(Connections[i]); } GetComponent <MeshRenderer>().material = MaterialHolder.EnabledMat; disabled = false; }
public void SetActive(Connection c) { int i = 0; foreach (Connection con in Connections) { if (c == con) { if (!ActiveConnections.Contains(i)) { activeConnections.Add(i); ConnectionVoxelContainer.StoreConnection(con); return; } } ++i; } }
public override void OnEvent(EndSimulation evnt) { if (!evnt.FromSelf) { ConnectionVoxelContainer.RemoveAllConnections(); CollisionVoxelContainer.RemoveAllGos(); foreach (GameObject go in GlobalReferences.FrozenParts.Values) { Part part = go.GetComponent <Part>(); CollisionVoxelContainer.StoreGameObject(go); foreach (int i in part.ActiveConnections) { ConnectionVoxelContainer.StoreConnection(part.Connections[i]); } } } PlacementReferences.Scanning = true; }
public void FreezePart(int?_id = null) { placedMat = Resources.Load <Material>("Materials/PlacedMaterial"); gameObject.GetComponent <MeshRenderer>().material = placedMat; gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; gameObject.layer = 9; Destroy(gameObject.GetComponent <PartBehaviour>()); Destroy(gameObject.GetComponent <ConnectionScanning>()); foreach (int i in ActiveConnections) { ConnectionVoxelContainer.StoreConnection(connections[i]); } CollisionVoxelContainer.StoreGameObject(gameObject); if (GlobalReferences.AffectedParts.Contains(gameObject)) { GlobalReferences.AffectedParts.Remove(gameObject); } if (GlobalReferences.FreeParts.Contains(gameObject)) { GlobalReferences.FreeParts.Remove(gameObject); } if (_id == null) { id = GlobalReferences.NumOfParts; ++GlobalReferences.NumOfParts; } else { id = _id; } GlobalReferences.FrozenParts.Add((int)ID, gameObject); gameObject.name = name + "_" + id; }
private void EnableDisable(Collider other) { if (Enable && AddRem == AddRemove.Remove) { Part p = other.gameObject.GetComponent <Part>(); if (p != null && !Removed.ContainsKey((int)p.ID)) { List <Connection> tempCons = new List <Connection>(); foreach (int i in p.ActiveConnections) { ConnectionVoxelContainer.RemoveConnection(p.Connections[i]); tempCons.Add(p.Connections[i]); } Removed.Add((int)p.ID, tempCons); } other.GetComponent <MeshRenderer>().material = disableMat; } else if (Enable && AddRem == AddRemove.Add) { Part p = other.gameObject.GetComponent <Part>(); if (p != null && Removed.ContainsKey((int)p.ID)) { foreach (Connection c in Removed[(int)p.ID]) { ConnectionVoxelContainer.StoreConnection(c); } Removed.Remove((int)p.ID); other.GetComponent <MeshRenderer>().material = enableMat; } } else { purgatory.Add(other); } }
public void FreezePart(int _id = -1) { if (!TestDeleteSpawn()) { Destroy(gameObject); return; } placedMat = Resources.Load <Material>("Materials/" + MaterialHolder.MatSet + "/PlacedMaterial"); gameObject.GetComponent <MeshRenderer>().material = placedMat; gameObject.layer = 9; if (GetComponent <ConstantForce>() != null) { Destroy(gameObject.GetComponent <ConstantForce>()); } if (GetComponent <Rigidbody>() != null) { Destroy(gameObject.GetComponent <Rigidbody>()); } if (GetComponent <PartBehaviour>() != null) { Destroy(gameObject.GetComponent <PartBehaviour>()); } if (GetComponent <ConnectionScanning>() != null) { Destroy(gameObject.GetComponent <ConnectionScanning>()); } if (GetComponent <KillTimer>() != null) { Destroy(GetComponent <KillTimer>()); } gameObject.isStatic = true; foreach (int i in ActiveConnections) { ConnectionVoxelContainer.StoreConnection(connections[i]); } CollisionVoxelContainer.StoreGameObject(gameObject); if (GlobalReferences.AffectedParts.Contains(gameObject)) { GlobalReferences.AffectedParts.Remove(gameObject); } if (GlobalReferences.FreeParts.Contains(gameObject)) { GlobalReferences.FreeParts.Remove(gameObject); } if (_id == -1) { id = GlobalReferences.GetNextID(); } else { id = _id; } GlobalReferences.FrozenParts.Add((int)ID, gameObject); gameObject.name = name + "_" + id; if (TICtrlZ.LastID != ID) { TICtrlZ.History.Push(new HistoryItem(ID)); } //Debug.Log("#43 Block Transform Frozen: " + ID + ", Position = " + transform.position.ToString("F2") + ", Rotation = " + transform.rotation.eulerAngles.ToString("F2")); }
public static void DeletePart(int id) { GameObject go = frozenParts[id]; int? parentID = go.GetComponent <Part>().Parent; if (parentID != null && frozenParts.ContainsKey((int)parentID)) { List <int> _children = frozenParts[(int)parentID].GetComponent <Part>().Children; for (int i = _children.Count - 1; i >= 0; --i) { if (_children[i] == id) { Part parentP = frozenParts[(int)parentID].GetComponent <Part>(); Part p = go.GetComponent <Part>(); parentP.Children.RemoveAt(i); if (parentP.ChildCons.Count > i) { parentP.ChildCons.RemoveAt(i); } foreach (int j in go.GetComponent <Part>().ChildCons) { Part parentPart = frozenParts[(int)parentID].GetComponent <Part>(); if (parentPart.Connections.Count > j && j != -1) { parentPart.SetActive(parentPart.Connections[j]); } } if (p.ChildCons.Count > i) { try { ConnectionVoxelContainer.StoreConnection(frozenParts[p.Children[i]].GetComponent <Part>().Connections[p.ChildCons[i]]); } catch { Debug.Log("Connection not found"); } //ConnectionVoxelContainer.StoreConnection(p.ChildCons[i]); } } } } Part part = go.GetComponent <Part>(); int[] children = part.Children.ToArray(); for (int i = 0; i < children.Length; ++i) { int child = children[i]; if (frozenParts.ContainsKey(child)) { Part childPart = frozenParts[child].GetComponent <Part>(); childPart.Parent = -1; childPart.ParentCon = -1; childPart.SetActive(childPart.ConToParent); childPart.ConToParent = -1; } int parent = part.Parent; if (parent != -1 && frozenParts.ContainsKey(parent)) { Part parentPart = frozenParts[parent].GetComponent <Part>(); if (go.GetComponent <Part>().ParentCon != -1) { parentPart.SetActive(part.ParentCon); for (int j = 0; j < parentPart.Children.Count; ++j) { if (parentPart.Children[j] == part.ID) { parentPart.Children.RemoveAt(j); parentPart.ChildCons.RemoveAt(j); break; } } } } } Destroy(go); }
public static void DeletePart(int id) { GameObject go = frozenParts[id]; int? parentID = go.GetComponent <Part>().Parent; if (parentID != null && frozenParts.ContainsKey((int)parentID)) { List <int> _children = frozenParts[(int)parentID].GetComponent <Part>().Children; for (int i = _children.Count - 1; i >= 0; --i) { if (_children[i] == id) { Part parentP = frozenParts[(int)parentID].GetComponent <Part>(); Part p = go.GetComponent <Part>(); parentP.Children.RemoveAt(i); if (parentP.ChildCons.Count > i) { parentP.ChildCons.RemoveAt(i); } foreach (int j in go.GetComponent <Part>().ChildCons) { Part parentPart = frozenParts[(int)parentID].GetComponent <Part>(); if (parentPart.Connections.Count > j) { parentPart.SetActive(parentPart.Connections[j]); } } if (p.ChildCons.Count > i) { ConnectionVoxelContainer.StoreConnection(frozenParts[p.Children[i]].GetComponent <Part>().Connections[p.ChildCons[i]]); //ConnectionVoxelContainer.StoreConnection(p.ChildCons[i]); } } } } int[] children = go.GetComponent <Part>().Children.ToArray(); for (int i = 0; i < children.Length; ++i) { int child = children[i]; if (frozenParts.ContainsKey(child)) { frozenParts[child].GetComponent <Part>().Parent = null; frozenParts[child].GetComponent <Part>().ParentCon = null; } int?parent = go.GetComponent <Part>().Parent; if (parent != null && frozenParts.ContainsKey((int)parent)) { Part parentPart = frozenParts[(int)parent].GetComponent <Part>(); Connection parentCon = parentPart.Connections[(int)go.GetComponent <Part>().ParentCon]; frozenParts[children[i]].GetComponent <Part>().SetActive(parentCon); ConnectionVoxelContainer.StoreConnection(parentCon); } //frozenParts[children[i]].GetComponent<Part>().SetActive(go.GetComponent<Part>().ParentCon); } frozenParts.Remove(id); parts.Remove(go); Destroy(go); }