private async Task CreateBugPart(Type fuction) { BugPart part = Instantiate(GetPrefab(fuction), new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0)).GetComponent <BugPart>(); Tuple <IConnectable, Connection[]> tuple = await GetRandomConnector(); RegisterPartRandom(part, tuple.Item2, tuple.Item1); }
private void RegisterPartRandom(BugPart part, Connection[] posibleConnections, IConnectable parent) { if (part.SetConnection(M.Mathn.SelectRandmo(posibleConnections, GeneratorController.SafeRandom()), parent, ((MonoBehaviour)parent).gameObject, this)) { Locations.Add(part.transform.position); mBugParts.Add(part); if (part is IConnectable) { mConnectables.Add(part as IConnectable); } if (mFuctionParts.ContainsKey(part.GetType())) { mFuctionParts[part.GetType()].Add(part); } } }
private void RegisterPart(BugPart part, Connection parentConnection, int parentID) { if (GetBugPart(parentID) == null) { throw new Exception("NULL"); } if (part.SetConnection(parentConnection, GetBugPart(parentID) as IConnectable, ((MonoBehaviour)GetBugPart(parentID)).gameObject, this)) { Locations.Add(part.transform.position); mBugParts.Add(part); if (part is IConnectable) { mConnectables.Add(part as IConnectable); } if (mFuctionParts.ContainsKey(part.GetType())) { mFuctionParts[part.GetType()].Add(part); } } }
public static Connection[] GetOpenConnections(Dictionary <Connection, int> connections, List <Vector3> locations, Vector3 parentPos, float distance, float paretenScale) { List <Connection> buffer = new List <Connection>(); foreach (Connection item in Enum.GetValues(typeof(Connection))) { if (item != Connection.None) { Vector3 futurePos = BugPart.GetConnectionPos(item, parentPos, distance * paretenScale); if (connections[item] == -1 && CheckLocation(locations, futurePos)) { buffer.Add(item); } } } if (buffer.Count == 0) { buffer.Add(Connection.None); } return(buffer.ToArray()); }
private void CreateBugPart(Type fuction, Connection parentConnection, int parentID) { BugPart part = Instantiate(GetPrefab(fuction), new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0)).GetComponent <BugPart>(); RegisterPart(part, parentConnection, parentID); }