private void CreateConnectionObjects(int maxCount) { for (int i = 0; i < maxCount; i++) { ConnectionBehaviour connection = CreateConnectionObject(); connectionListPool.Add(connection); } }
private void Start() { connectableObj = Resources.Load("Prefabs/Connectable"); CreateConnectableObjects(MaxObjectCount); connectionObj = Resources.Load("Prefabs/Connection"); CreateConnectionObjects(CONNECTION_POOL_SIZE); // Объект, к которому будет присоединяться "линия связи", когда делаем Drag от одного коннектора к другому fakeConnector = new GameObject("fakeConnector"); fakeConnector.transform.SetParent(ConnectableRoot); // "Линия связи", которую тянем от выделенного коннектора к курсору fakeConnection = CreateConnectionObject(); fakeConnection.SetStartRoot(null); fakeConnection.gameObject.name = "fakeConnection"; }
private ConnectionBehaviour GetConnectionObjectFromPool() { ConnectionBehaviour connection = null; if (connectionListPool.Count > 0) { int lastIndex = connectionListPool.Count - 1; connection = connectionListPool[lastIndex]; connectionListPool.RemoveAt(lastIndex); return(connection); } else { CreateConnectionObjects(CONNECTION_POOL_SIZE); return(GetConnectionObjectFromPool()); } }
private void SetConnection(ConnectableObject startObject, ConnectableObject endObject) { if (startObject.Id == endObject.Id) { return; } string hash = startObject.Id.ToString() + endObject.Id.ToString(); // если связь между этими двумя объектами уже установлена, то ничего не делаем if (connectionListInUse.ContainsKey(hash)) { return; } ConnectionBehaviour connection = GetConnectionObjectFromPool(); connection.SetStartRoot(startObject.Root.transform); connection.SetEndRoot(endObject.Root.transform); connectionListInUse.Add(hash, connection); }