Exemplo n.º 1
0
    public void HighlightFact(Fact startFact)
    {
        highlightedPushoutFact = startFact;

        if (typeof(PointFact).IsInstanceOfType(highlightedPushoutFact))
        {
            PointFact fact = (PointFact)highlightedPushoutFact;
            tempMaterial = fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material;
            fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material = pushoutMaterial;
        }
        else if (typeof(LineFact).IsInstanceOfType(highlightedPushoutFact))
        {
            LineFact fact = (LineFact)highlightedPushoutFact;
            tempMaterial = fact.Representation.transform.GetChild(0).GetChild(1).GetComponent <MeshRenderer>().material;
            fact.Representation.transform.GetChild(0).GetChild(1).GetComponent <MeshRenderer>().material = pushoutMaterial;
        }
        else if (typeof(AngleFact).IsInstanceOfType(highlightedPushoutFact))
        {
            AngleFact fact = (AngleFact)highlightedPushoutFact;
            tempMaterial = fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material;
            fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material = pushoutMaterial;
        }

        //Activate Timer
        this.pushoutFail     = false;
        this.slowDownCounter = 0;
        this.timerActive     = true;
    }
Exemplo n.º 2
0
    public void StopHighlighting()
    {
        if (typeof(PointFact).IsInstanceOfType(highlightedPushoutFact))
        {
            PointFact fact = (PointFact)highlightedPushoutFact;
            fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material = tempMaterial;
        }
        else if (typeof(LineFact).IsInstanceOfType(highlightedPushoutFact))
        {
            LineFact fact = (LineFact)highlightedPushoutFact;
            fact.Representation.transform.GetChild(0).GetChild(1).GetComponent <MeshRenderer>().material = tempMaterial;
        }
        else if (typeof(AngleFact).IsInstanceOfType(highlightedPushoutFact))
        {
            AngleFact fact = (AngleFact)highlightedPushoutFact;
            fact.Representation.transform.GetChild(0).GetComponent <MeshRenderer>().material = tempMaterial;
        }

        if (this.extraHighlight != null)
        {
            GameObject.Destroy(this.extraHighlight);
            this.extraHighlight = null;
        }

        //Event for the happy Task-Charakter
        CommunicationEvents.PushoutFactEndEvent.Invoke(null);
    }
Exemplo n.º 3
0
    //Spawn an angle: point with id = angleFact.Pid2 is the point where the angle gets applied
    public Fact SpawnAngle(Fact fact)
    {
        AngleFact angleFact = (AngleFact)fact;

        Vector3 point1 = (StageStatic.stage.factState[angleFact.Pid1] as PointFact).Point;
        Vector3 point2 = (StageStatic.stage.factState[angleFact.Pid2] as PointFact).Point;
        Vector3 point3 = (StageStatic.stage.factState[angleFact.Pid3] as PointFact).Point;

        //Length of the Angle relative to the Length of the shortest of the two lines (point2->point1) and (point2->point3)
        float lengthFactor = 0.3f;

        float length = 0;

        if ((point1 - point2).magnitude >= (point3 - point2).magnitude)
        {
            length = lengthFactor * (point3 - point2).magnitude;
        }
        else
        {
            length = lengthFactor * (point1 - point2).magnitude;
        }

        //Change FactRepresentation to Angle
        this.FactRepresentation = Angle;
        GameObject angle = GameObject.Instantiate(FactRepresentation);

        //Calculate Angle:
        Vector3 from       = (point3 - point2).normalized;
        Vector3 to         = (point1 - point2).normalized;
        float   angleValue = Vector3.Angle(from, to); //We always get an angle between 0 and 180° here

        //Change scale and rotation, so that the angle is in between the two lines
        var v3T = angle.transform.localScale;

        v3T = new Vector3(length, v3T.y, length);

        Vector3 up = Vector3.Cross(to, from);

        angle.transform.rotation = Quaternion.LookRotation(Vector3.Cross((from + to).normalized, up), up);

        //Place the Angle at position of point2
        angle.transform.position = point2;

        //Set text of angle
        TextMeshPro[] texts = angle.GetComponentsInChildren <TextMeshPro>();
        foreach (TextMeshPro t in texts)
        {
            //Change Text not to the id, but to the angle-value (from both sides) AND change font-size relative to length of the angle (from both sides)
            t.text     = Math.Round((double)angleValue, 2) + "°";
            t.fontSize = angle.GetComponentInChildren <TextMeshPro>().fontSize *angle.transform.GetChild(0).transform.GetChild(0).localScale.x;
        }

        //Generate angle mesh
        CircleSegmentGenerator[] segments = angle.GetComponentsInChildren <CircleSegmentGenerator>();
        foreach (CircleSegmentGenerator c in segments)
        {
            c.setAngle(angleValue);
        }

        angle.GetComponentInChildren <FactObject>().URI = angleFact.Id;
        angleFact.Representation = angle;
        return(angleFact);
    }