예제 #1
0
    // Use this for initialization
    void Start()
    {
        button = this.gameObject.GetComponent<Button> ();
        tileImage = this.gameObject.GetComponent<Image> ();
        element = this.gameObject.transform.GetChild (0).GetComponent<ElementBehaviour>();

        button.OnClickAsObservable().Subscribe(_ => {
            PutElement (ElementSelectBehaviour.Instance.GetSelectedElement ());
        });
    }
예제 #2
0
    void PutElement(ElementBehaviour element)
    {
        if (element != null) {
            Debug.Log ("copyed rank is " + element.rank.Value);
            CopyElement (element);

            MatchAndJoinImages ();

            if (TileMatchingManager.Instance.IsFullTiles()) {
                Application.LoadLevel ("Over");
            }

            ElementSelectBehaviour.Instance.UpdateElements();
        }
    }
예제 #3
0
 public bool IsSameElementImage(ElementBehaviour target)
 {
     return image.sprite.Equals (target.image.sprite);
 }
예제 #4
0
 void CopyElement(ElementBehaviour source)
 {
     this.element.rank.Value = source.rank.Value;
     ScoreManager.Instance.AddScoreByRank(this.element.rank.Value);
 }
예제 #5
0
    public void GeometryElementStyleChange(GeoElement geoElement, int style)
    {
        ElementBehaviour elementBehaviour = elementMap[geoElement];

        elementBehaviour.SetStyleIndex(style);
    }
예제 #6
0
    public void GeometryElementColorChange(GeoElement geoElement, int color)
    {
        ElementBehaviour elementBehaviour = elementMap[geoElement];

        elementBehaviour.SetColorIndex(color);
    }
예제 #7
0
 public DragState(ElementBehaviour element) : base(element)
 {
     _selection = element.Element.Parent.SelectionService;
 }
예제 #8
0
    IEnumerator MoveElectron(Vector3 start, Vector3 end, ElementBehaviour element, Vector3 center)
    {
        GameObject newElectron = (GameObject)Instantiate(electron, start, Quaternion.identity);

        WinLoseManager.nowtime = 0.4f;
        elementsUsed++;
        int i = 1;

        if (!UniMath.ApproximatelyEqual(start.x, end.x) && !UniMath.ApproximatelyEqual(start.y, end.y))
        {
            while (newElectron.transform.position != center)
            {
                newElectron.transform.position = Vector3.Lerp(start, center, 0.2f * i);
                i++;
                yield return(new WaitForFixedUpdate());
            }
            i = 1;
            while (newElectron.transform.position != end)
            {
                newElectron.transform.position = Vector3.Lerp(center, end, 0.2f * i);
                i++;
                yield return(new WaitForFixedUpdate());
            }
        }
        else
        {
            while (newElectron.transform.position != end)
            {
                newElectron.transform.position = Vector3.Lerp(start, end, 0.1f * i);
                i++;
                yield return(new WaitForFixedUpdate());
            }
        }
        if (element != null)                    //if we need to check further
        {
            element.CheckForCurcuit(end);
        }

        while (true)
        {
            i = 1;
            newElectron.transform.position = start;
            if (!UniMath.ApproximatelyEqual(start.x, end.x) && !UniMath.ApproximatelyEqual(start.y, end.y))
            {
                while (newElectron.transform.position != center)
                {
                    newElectron.transform.position = Vector3.Lerp(start, center, 0.2f * i);
                    i++;
                    yield return(new WaitForFixedUpdate());
                }
                i = 1;
                while (newElectron.transform.position != end)
                {
                    newElectron.transform.position = Vector3.Lerp(center, end, 0.2f * i);
                    i++;
                    yield return(new WaitForFixedUpdate());
                }
            }
            else
            {
                while (newElectron.transform.position != end)
                {
                    newElectron.transform.position = Vector3.Lerp(start, end, 0.1f * i);
                    i++;
                    yield return(new WaitForFixedUpdate());
                }
            }
        }
    }
예제 #9
0
    private void AddState(Auxiliary auxiliary, FormInput form)
    {
        Type type = Type.GetType(tool.Name + "AuxiliaryState");

        if (type != null)
        {
            AuxiliaryState auxiliaryState = (AuxiliaryState)Activator.CreateInstance(type, tool, auxiliary, geometry);
            auxiliaryState.OnClickDelete = () => geoController.RemoveAuxiliaryOperation(auxiliary);

            //state单击
            auxiliaryState.DoubleClick = () => this.TurnToFront(auxiliary, form);

            //Action OnElementHighLight  0925 Requirement_1
            auxiliaryState.OnElementHighlight = () =>
            {
                //Hightlight face
                ChangeFaceColorIndex((GeoFace)auxiliary.elements[0], 1);

                //Hide coordinate
                geoUI.navPanel.OnCoordinateButtonClick(1);
                geoUI.navPanel.SetCoordinateButtonStatus(1); //Change Button status

                //Hide grid
                geoUI.navPanel.OnGridButtonClick(1);
                geoUI.navPanel.SetGridButtonStatus(1);


                //Measure Line length
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    for (int i = 0; i < geoFace.Ids.Length; i++)
                    {
                        int vertex1 = i;
                        int vertex2 = (i + 1) % geoFace.Ids.Length;

                        Measure measure = new LineLengthMeasure(geoFace.Ids[vertex1], geoFace.Ids[vertex2]);

                        measure_list.Add((Measure)measure);

                        measure.InitWithGeometry(geometry);
                        bool result = geometry.Implement.AddMeasure(measure);
                        if (result)
                        {
                            List <ToolGroup> toolGroups            = geoUI.toolPanel.ToolGroups();
                            Tool             lineLengthMeasureTool = toolGroups[3].Tools[0];
                            AddState_Measure(measure, lineLengthMeasureTool);

                            Gizmo[] gizmos = measure.gizmos;
                            if (gizmos != null)
                            {
                                foreach (Gizmo gizmo in gizmos)
                                {
                                    geometry.AddGizmo(gizmo);
                                    geometryBehaviour.AddGizmo(gizmo);
                                }
                            }
                        }
                        else
                        {
                            // TODO
                        }
                    }
                }
                //Measure CornerAngle
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    for (int i = 0; i < geoFace.Ids.Length; i++)
                    {
                        int vertex1 = i;
                        int vertex2 = (i + 1) % geoFace.Ids.Length;
                        int vertex3 = (i + 2) % geoFace.Ids.Length;

                        Measure measure = new CornerAngleMeasure(geoFace.Ids[vertex1], geoFace.Ids[vertex2], geoFace.Ids[vertex3]);

                        measure_list.Add((Measure)measure);

                        measure.InitWithGeometry(geometry);


                        bool result = geometry.Implement.AddMeasure(measure);

                        if (result)
                        {
                            List <ToolGroup> toolGroups             = geoUI.toolPanel.ToolGroups();
                            Tool             cornerAngleMeasureTool = toolGroups[3].Tools[1];
                            AddState_Measure(measure, cornerAngleMeasureTool);

                            Gizmo[] gizmos = measure.gizmos;
                            if (gizmos != null)
                            {
                                foreach (Gizmo gizmo in gizmos)
                                {
                                    geometry.AddGizmo(gizmo);
                                    geometryBehaviour.AddGizmo(gizmo);
                                }
                            }
                        }
                        else
                        {
                            // TODO
                        }
                    }
                }
                //Measure Plane Area
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    //Debug.Log(geoFace.Ids);
                    Measure measure = new PlaneAreaMeasure(geoFace.Ids);

                    measure_list.Add(measure);

                    measure.InitWithGeometry(geometry);


                    bool result = geometry.Implement.AddMeasure(measure);

                    if (result)
                    {
                        List <ToolGroup> toolGroups           = geoUI.toolPanel.ToolGroups();
                        Tool             planeAreaMeasureTool = toolGroups[3].Tools[2];
                        AddState_Measure(measure, planeAreaMeasureTool);

                        Gizmo[] gizmos = measure.gizmos;
                        if (gizmos != null)
                        {
                            foreach (Gizmo gizmo in gizmos)
                            {
                                geometry.AddGizmo(gizmo);
                                geometryBehaviour.AddGizmo(gizmo);
                            }
                        }
                    }
                    else
                    {
                        // TODO
                    }
                }

                // Hide elements beyond the Highlighted face
                GeoVertex[] geoVertices = geometry.GeoVertices();
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace      geoFace      = (GeoFace)auxiliary.elements[0];
                    VertexUnit[] faceVertices = geoFace.get_vertices();
                    Vector3      side1        = faceVertices[0].Position() - faceVertices[1].Position();
                    Vector3      side2        = faceVertices[2].Position() - faceVertices[1].Position();
                    Vector3      normalVector = Vector3.Cross(side1, side2);

                    if (normalVector.x < 0)
                    {
                        normalVector.x = -normalVector.x;
                        normalVector.y = -normalVector.y;
                        normalVector.z = -normalVector.z;
                    }
                    if (normalVector.x == 0)
                    {
                        if (normalVector.z < 0)
                        {
                            normalVector.y = -normalVector.y;
                            normalVector.z = -normalVector.z;
                        }
                    }

                    Vector3 anchor = faceVertices[1].Position() + normalVector * 2;

                    float     min   = 1000;
                    GeoEdge[] edges = geometry.GeoEdges();
                    foreach (VertexUnit vertexUnit in geoFace.get_vertices())
                    {
                        float face_vertex_distance = Vector3.Distance(vertexUnit.Position(), anchor);
                        if (face_vertex_distance < min)
                        {
                            min = face_vertex_distance;
                        }
                    }
                    foreach (GeoVertex geoVertex in geoVertices)
                    {
                        float distance = Vector3.Distance(geoVertex.VertexUnit().Position(), anchor);
                        if (distance < min)
                        {
                            //隐藏该顶点
                            ElementBehaviour vertexElementBehaviour = geometryBehaviour.elementMap[geoVertex];
                            vertexElementBehaviour.SetVisible(false);
                            elementBehaviour_list.Add(vertexElementBehaviour);
                            //隐藏该顶点起始的所有边
                            foreach (GeoEdge geoEdge in edges)
                            {
                                if (geoVertex.Id == geoEdge.Id1 || geoVertex.Id == geoEdge.Id2)
                                {
                                    ElementBehaviour edgeElementBehaviour = geometryBehaviour.elementMap[geoEdge];
                                    edgeElementBehaviour.SetVisible(false);
                                    elementBehaviour_list.Add(edgeElementBehaviour);
                                }
                            }
                        }
                    }
                }
            };

            auxiliaryState.UndoFaceHighlight = () =>
            {
                //Undo Hightlight face
                ChangeFaceColorIndex((GeoFace)auxiliary.elements[0], 0);


                //Undo Hide coordinate
                geoUI.navPanel.OnCoordinateButtonClick(0);
                geoUI.navPanel.SetCoordinateButtonStatus(0); //Change Button status

                //Hide grid
                geoUI.navPanel.OnGridButtonClick(0);
                geoUI.navPanel.SetGridButtonStatus(0);

                //Claer All Face_MeasureStates
                foreach (Measure measure in measure_list)
                {
                    geoController.RemoveMeasure(measure);
                }
                foreach (ElementBehaviour elementBehaviour in elementBehaviour_list)
                {
                    elementBehaviour.SetVisible(true);
                }
            };



            stateController.AddAuxiliaryState(auxiliaryState);
        }
    }