Exemple #1
0
    public void fixedStart()
    {
        for (int i = 0; i < json.Count; i++)
        {
            Nodo nodo = JsonUtility.FromJson <Nodo>(json[i]);
            nodosIngresados.Add(nodo);
            GameObject        nodoActivo = Instantiate(tipoNodos[nodo.type], new Vector3(nodo.posx, nodo.posy, nodo.posz), Quaternion.identity);
            Seleccion_y_Union data       = nodoActivo.GetComponent <Seleccion_y_Union>();
            data.points         = nodo.points;
            data.total_nodes    = nodo.total_nodes;
            data.used_nodes     = nodo.used_nodes;
            data.owner          = nodo.owner;
            data.healingFactor  = nodo.healingFactor;
            data.dmgFactor      = nodo.dmgFactor;
            data.identifier     = nodo.identifier;
            data.turnController = this.gameObject;
            data.msgGameObject  = this.gameObject;
            nodos.Add(nodoActivo);
            Debug.Log(nodo.points + " Nodo Points");
            Debug.Log(data.points + " Data Points");
            GameObject textObject = nodoActivo.gameObject.transform.GetChild(0).GetChild(0).gameObject;
            textObject.GetComponent <TextMeshProUGUI>().text = data.points.ToString();
        }

        for (int i = 0; i < json.Count; i++)
        {
            Seleccion_y_Union data = nodos[i].GetComponent <Seleccion_y_Union>();
            for (int j = 0; j < data.total_nodes; j++)
            {
                try {
                    if (nodosIngresados[i].objectives[j] < j)
                    {
                        if (nodos[nodosIngresados[i].objectives[j]])
                        {
                            data.objectives.Add(null);
                            data.unions.Add(null);
                        }
                        continue;
                    }
                    else
                    {
                        Debug.Log(data.objectives.Count + " i " + i + "aaa " + nodosIngresados[i].objectives[j]);
                        data.objectives[i] = nodos[nodosIngresados[i].objectives[j]];
                        //Seleccion_y_Union.first = nodos[j];
                        //data.objectives[i].GetComponent<Seleccion_y_Union>().ArrowCreation(j, data, Seleccion_y_Union.first);
                        //Seleccion_y_Union.first = null;
                    }
                } catch {
                    data.objectives.Add(null);
                    data.unions.Add(null);
                    continue;
                }
            }
        }
    }
Exemple #2
0
        public Nodo(GameObject nodo)
        {
            this.posx = nodo.transform.position.x;
            this.posy = nodo.transform.position.y;
            this.posz = nodo.transform.position.z;

            Seleccion_y_Union data = nodo.GetComponent <Seleccion_y_Union>();

            this.type          = data.type;
            this.points        = data.points;
            this.total_nodes   = data.total_nodes;
            this.used_nodes    = data.used_nodes;
            this.owner         = data.owner;
            this.healingFactor = data.healingFactor;
            this.dmgFactor     = data.dmgFactor;
            this.identifier    = data.identifier;

            objectives = new List <int>();
        }
Exemple #3
0
    void OnMouseDown()
    {
        if (!first)
        {
            if (turnController.GetComponent <Info>().player_turn == owner)
            {
                Debug.Log("Seleccionado" + this.gameObject);
                first = this.transform.gameObject;
            }
        }
        else if (first == this.transform.gameObject)
        {
            Debug.Log("Ya no hay first" + this.gameObject);
            Debug.Log("Todos los nodos eliminados" + this.gameObject);
            for (int i = 0; i < total_nodes; i++)
            {
                if (objectives[i] != null)
                {
                    int pointsToAdd = (int)(100f * Vector2.Distance(transform.position, objectives[i].transform.position) / Camera.main.GetComponent <CameraSize>().camWidth);
                    if (points + pointsToAdd >= 100)
                    {
                        points = 100;
                    }
                    else
                    {
                        points += pointsToAdd;
                    }
                }
                objectives[i] = null;
                try { Destroy(unions[i].gameObject); } catch { }
                unions[i] = null;
            }
            used_nodes = 0;
            first      = null;
        }
        else if (first != this.transform.gameObject)
        {
            Seleccion_y_Union first_code = first.GetComponent <Seleccion_y_Union>();
            //con este if, considero que quede al menos un "objective" en null
            if (first_code.used_nodes + 1 <= first_code.total_nodes)
            {
                //veo la union, si ya existe, la destruyo
                for (int i = 0; i < first_code.total_nodes; i++)
                {
                    if (first_code.objectives[i] == this.gameObject)
                    {
                        //ya existe, elimino la flecha y libero el cupo
                        first_code.used_nodes -= 1;
                        int pointsToAdd = (int)(100f * Vector2.Distance(gameObject.transform.position, first_code.transform.position) / Camera.main.GetComponent <CameraSize>().camWidth);
                        if (first_code.points + pointsToAdd >= 100)
                        {
                            first_code.points = 100;
                        }
                        else
                        {
                            first_code.points += pointsToAdd;
                        }
                        first_code.objectives[i] = null;
                        Destroy(first_code.unions[i].gameObject);
                        first_code.unions[i] = null;
                        //Debug.Log("nodo sacado" + this.gameObject);
                        first = null;
                        return;
                    }
                }
                int index_to_use = 0;
                //no existe, selecciono el espacio para agregar la union
                for (int i = 0; i < first_code.total_nodes; i++)
                {
                    // cuando encontremos uno vacio lo usaremos
                    if (first_code.objectives[i] == null)
                    {
                        first_code.objectives[i] = this.gameObject;
                        index_to_use             = i;
                        first_code.used_nodes   += 1;
                        break;
                    }
                }
                //finalmente, casteo la linea
                //Debug.Log(first.transform.position);
                float   distTotal = Vector2.Distance(first.transform.position, transform.position);
                float   distX     = Math.Abs(first.transform.position.x - transform.position.x);
                float   distY     = Math.Abs(first.transform.position.y - transform.position.y);
                float   middleX;
                float   middleY;
                Vector2 colliderClosest1 = collider.ClosestPoint(first.transform.position);
                Vector2 colliderClosest2 = first.GetComponent <CircleCollider2D>().ClosestPoint(transform.position);
                float   colliderDist     = Vector2.Distance(colliderClosest1, colliderClosest2);
                //calculos de puntos medios
                #region
                middleX = (first.transform.position.x + transform.position.x) / 2f;
                middleY = (first.transform.position.y + transform.position.y) / 2f;
                #endregion

                int angle;
                angle = (int)(Math.Atan(distY / distX) * 180 / Math.PI);
                //fixing angle depending on direction
                if (first.transform.position.x < transform.position.x && first.transform.position.y >= transform.position.y)
                {
                    angle *= -1;
                }
                else if (first.transform.position.x >= transform.position.x && first.transform.position.y >= transform.position.y)
                {
                    angle += 180;
                }
                else if (first.transform.position.x >= transform.position.x && first.transform.position.y < transform.position.y)
                {
                    angle += (90 - angle) * 2;
                }
                Debug.Log("angulo: " + angle);
                if ((int)(100f * distTotal / Camera.main.GetComponent <CameraSize>().camWidth) <= first.GetComponent <Seleccion_y_Union>().points)
                {
                    GameObject g = Instantiate(arrow, new Vector3(middleX, middleY, transform.position.z), Quaternion.identity);
                    g.transform.Rotate(0, 0, angle - 90);
                    g.transform.localScale          = new Vector3(0.3f, 0.15f * colliderDist, 1);
                    first_code.unions[index_to_use] = g;
                    Debug.Log("Union entre" + first + "and" + this.gameObject);
                    first.GetComponent <Seleccion_y_Union>().points -= (int)(100f * distTotal / Camera.main.GetComponent <CameraSize>().camWidth);
                    first = null;
                }
                else
                {
                    //no se completo la union por distancia, por lo tanto se libera el nodo
                    sendMessage("Too far!");
                    Debug.Log("Union entre" + first + "and" + this.gameObject + "no creada, mucha distancia.");
                    first_code.objectives[index_to_use] = null;
                    first_code.used_nodes -= 1;
                    first = null;
                }
            }
            else
            {
                for (int i = 0; i < first_code.total_nodes; i++)
                {
                    if (first_code.objectives[i] == this.gameObject)
                    {
                        //ya existe, elimino la flecha y libero el cupo
                        first_code.used_nodes   -= 1;
                        first_code.objectives[i] = null;
                        Destroy(first_code.unions[i].gameObject);
                        first_code.unions[i] = null;
                        Debug.Log("nodo sacado" + this.gameObject);
                        first = null;
                        return;
                    }
                    else
                    {
                        //Debug.Log("This node can´t have more nodes");
                        sendMessage("No connections left!");
                    }
                }
            }
        }
    }