void AdicionarPorta(TipoDePorta tipo, string nome="Porta") { Porta porta = new Porta((int)listaDePortas.Count / 2); porta.Nome = nome; porta.tipoDaPorta = tipo; porta.nodoDono=this; _listaDePortas.Add(porta); }
public void AdicionarPorta(Porta porta) { _listaDePortas.Add(porta); }
public void DesenharCurva(Porta portaInicial,Porta portaFinal) { Vector3 inicio = new Vector3(portaInicial.Posicao.x + 10, portaInicial.Posicao.y + 10, 0); Vector3 fim = new Vector3(portaFinal.Posicao.x + 10, portaFinal.Posicao.y + 10, 0); Vector3 TangenteInicial; Vector3 TangenteFinal; //essa parte tenta acertar as direções da curva if (portaInicial.Posicao.x < portaFinal.Posicao.x) { if (portaInicial.tipoDaPorta == TipoDePorta.ENTRADA) { //posicao inicial entrada mais a esquerda TangenteInicial = inicio + Vector3.left * 50; TangenteFinal = fim + Vector3.right * 50; } else { //posicao inicial saida mais a esquerda TangenteInicial = inicio + Vector3.right * 50; TangenteFinal = fim + Vector3.left * 50; } } else { if (portaInicial.tipoDaPorta == TipoDePorta.SAIDA) { //posicao inicial saida mais a direita TangenteInicial = inicio + Vector3.right * 50; TangenteFinal = fim + Vector3.left * 50; } else { //posicao inicial entrada mais a direita TangenteInicial = inicio + Vector3.left * 50; TangenteFinal = fim + Vector3.right * 50; } } Color corDeSombra = new Color(0, 0, 0, 0.06f); for (int i = 0; i < 3; i++) //desenha as sombras Handles.DrawBezier(inicio, fim, TangenteInicial, TangenteFinal, corDeSombra, null, (i + 1) * 5); Handles.DrawBezier(inicio, fim, TangenteInicial, TangenteFinal, portaInicial.cor, null, 5); }
public void DeleteNode(int i) { //TODO: talvez um pool object pra ecnommizar memoria? if(_portaSelecionadaAtualmente!=null) if (_portaSelecionadaAtualmente.nodoDono.Id == listaDeWNodes[i].Id) { _portaSelecionadaAtualmente = null; } int link = 0; while( (link = JaExisteEsseLink(listaDeWNodes[i])) !=-1) { listaDeLinks.RemoveAt(link); } //remove os links das portas conectadas a essa porta foreach(var porta in listaDeWNodes[i].listaDePortas) { if(porta.tipoDaPorta==TipoDePorta.ENTRADA) { if(porta.Link!=null) porta.Link.portaSaida().Link = null; } else { if (porta.Link != null) porta.Link.portaEntrada().Link = null; } } //limpa portas listaDeWNodes[i].RemoverTodasAsPortas(); //apaga o node LibertaID(listaDeWNodes[i].Id); listaDeWNodes.RemoveAt(i); }
public void Conectar(Porta porta1, Porta porta2) { // Debug.Log("criando conexão"); WLink NovoLink = new WLink(porta1, porta2); porta1.Link = NovoLink; porta2.Link = NovoLink; listaDeLinks.Add(NovoLink); }
void TerminaUmaConexao() { if (Event.current.type == EventType.MouseUp && modoAtualDoMouse == MouseMode.CONNECTING ) { if (Event.current.button == 0) { for (int i = 0; i < listaDeWNodes.Count; i++) { if (listaDeWNodes[i].MouseUp(Event.current.mousePosition) == true) { //cria conexão Porta porta = listaDeWNodes[i].MouseUpPorta(Event.current.mousePosition); //se alguma porta for null if (porta == null || _portaSelecionadaAtualmente == null) { modoAtualDoMouse = MouseMode.IDLE; Debug.Log("porta nula"); } else if (JaExisteEsseLink(porta,_portaSelecionadaAtualmente) == -1 && porta.cor==_portaSelecionadaAtualmente.cor ) //se forem de cores diferentes { //se as portas forem diferente if (_portaSelecionadaAtualmente.nodoDono.Id != porta.nodoDono.Id) { if (_portaSelecionadaAtualmente.tipoDaPorta == porta.tipoDaPorta) { modoAtualDoMouse = MouseMode.IDLE; Debug.Log("ops portas iguais"); } else { if (porta.Posicao.x < _portaSelecionadaAtualmente.Posicao.x || ( porta.Posicao.x > _portaSelecionadaAtualmente.Posicao.x && porta.tipoDaPorta == TipoDePorta.SAIDA) ) { modoAtualDoMouse = MouseMode.IDLE; Debug.Log("conectar para trás: considerei esse um comportamento incoreto, tirar esse if se tiver esse objetivo"); } else { // Debug.Log("criando conexão"); Conectar(_portaSelecionadaAtualmente, porta); modoAtualDoMouse = MouseMode.IDLE; } } } else { _portaSelecionadaAtualmente = null; modoAtualDoMouse = MouseMode.IDLE; Debug.Log("mesmo dono!"); } } else { modoAtualDoMouse = MouseMode.IDLE; _portaSelecionadaAtualmente = null; Debug.Log("ja existe esse link!"); } } } } if (Event.current.button == 1) { _portaSelecionadaAtualmente = null; modoAtualDoMouse = MouseMode.IDLE; } } if(Event.current.type == EventType.mouseDown && modoAtualDoMouse == MouseMode.CONNECTING) { if (Event.current.button == 1) { modoAtualDoMouse = MouseMode.IDLE; } } }
void ComecaUmaConexao() { if (Event.current.type == EventType.mouseDown && modoAtualDoMouse == MouseMode.IDLE ) { if(Event.current.button==0) { for(int i=0; i< listaDeWNodes.Count;i++) { Porta porta=listaDeWNodes[i].MouseDownPorta(Event.current.mousePosition, Event.current.button); if (porta!=null) { //verifica ja existe uma conexão if (JaExisteEsseLink(porta) == -1 || porta.tipoDaPorta == TipoDePorta.SAIDA) { _portaSelecionadaAtualmente = porta; modoAtualDoMouse = MouseMode.CONNECTING; } else //essa parte desconecta um nó já com link { int link = JaExisteEsseLink(porta); if (listaDeLinks[link].portas[0].nodoDono.Id == porta.nodoDono.Id) { _portaSelecionadaAtualmente = listaDeLinks[link].portas[1]; Debug.Log("o que?"); modoAtualDoMouse = MouseMode.CONNECTING; listaDeLinks.RemoveAt(link); } else { _portaSelecionadaAtualmente = listaDeLinks[link].portas[0]; //revisar essa parte do codigo obs: fazer pra que cada porta tenha um link somente! _portaSelecionadaAtualmente.Link = null; listaDeLinks[link].portas[1].Link = null; modoAtualDoMouse = MouseMode.CONNECTING; listaDeLinks.RemoveAt(link); } } } } } } }
public int JaExisteEsseLink(Porta porta) { //acha o link que tem essa porta for (int l = 0; l < listaDeLinks.Count; l++) { if (listaDeLinks[l].portas[0] == porta) { return l; } if (listaDeLinks[l].portas[1] == porta) { return l; } } return -1; }
public WLink(Porta _porta1,Porta _porta2) { portas[0] = _porta1; portas[1]= _porta2; }