Exemple #1
0
        public void OnSceneGUI(SceneView scene)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            RaycastHit info = new RaycastHit();

            GameObject selected = null;
            Ray        ray      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            if (Physics.Raycast(ray, out info /*, LayerMask.NameToLayer("Cells Layer")*/)) //TODO Arreglar esto porque al parecer la distancia no funciona correctamente
            {
                if (info.collider.transform.IsChildOf(this.map.transform))
                {
                    selected = info.collider.gameObject;
                }
            }



            bool moveEntity = false;

            if (Event.current.isMouse && Event.current.button == 0 && Event.current.type == EventType.MouseDown)
            {
                moveEntity = true;
            }


            if (selected != null)
            {
                Cell cs = selected.GetComponent <Cell>();
                if (cs != null)
                {
                    FaceNoSC f = cs.getFaceByPoint(info.point);
                    if (f != null)
                    {
                        if (moveEntity)
                        {
                            entity.Position = cs;
                        }

                        Vector3[] vertex  = f.SharedVertex;
                        int[]     indexes = f.VertexIndex;

                        Vector3[] puntos = new Vector3[4];
                        for (int i = 0; i < indexes.Length; i++)
                        {
                            puntos[i] = cs.transform.TransformPoint(vertex[indexes[i]]);
                        }

                        if (indexes.Length == 3)
                        {
                            puntos[3] = cs.transform.TransformPoint(vertex[indexes[2]]);
                        }

                        Handles.DrawSolidRectangleWithOutline(puntos, Color.yellow, Color.white);
                    }
                }
            }
        }
Exemple #2
0
        public void OnSceneGUI(SceneView scene)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            RaycastHit info = new RaycastHit();

            GameObject selected = null;
            Ray        ray      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            if (Physics.Raycast(ray, out info /*, LayerMask.NameToLayer("Cells Layer")*/)) //TODO Arreglar esto porque al parecer la distancia no funciona correctamente
            {
                if (info.collider.transform.IsChildOf(this.map.transform))
                {
                    selected = info.collider.gameObject;
                }
            }

            /**
             * Mouse Events of painting mode
             */

            bool decorateLater = false;

            if (Event.current.isMouse && Event.current.button == 0 && selected != null && Event.current.type == EventType.MouseUp)
            {
                decorateLater = true;
            }

            /**
             * Working zone
             */

            if (selected != null)
            {
                Cell cs = selected.GetComponent <Cell>();
                if (cs != null)
                {
                    FaceNoSC f = (cs != null) ? cs.getFaceByPoint(info.point) : null;
                    if (f != null)
                    {
                        Vector3 position = selected.transform.position;
                        if (cs != null)
                        {
                            position.y = cs.Height;
                        }

                        Vector3[] vertex  = f.SharedVertex;
                        int[]     indexes = f.VertexIndex;

                        Vector3[] puntos = new Vector3[5];
                        for (int i = 0; i < indexes.Length; i++)
                        {
                            puntos[i] = cs.transform.TransformPoint(vertex[indexes[i]]);
                        }
                        if (indexes.Length == 3)//Triangular faces
                        {
                            puntos[3] = cs.transform.TransformPoint(vertex[indexes[2]]);
                        }
                        puntos[puntos.Length - 1] = puntos[0]; // Closes the line
                        Handles.DrawPolyLine(puntos);

                        Vector2 directions = new Vector2(puntos[1].x - puntos[0].x, puntos[2].y - puntos[1].y);
                        int     ang        = 0;
                        if (directions.x == 0f)
                        {
                            if (directions.y == 0f)
                            {
                                ang = 0;
                            }
                            else
                            {
                                ang = 2;
                            }
                        }
                        else
                        {
                            ang = 1;
                        }

                        if (paintingIsoDecoration != null)
                        {
                            if (decorateLater)
                            {
                                GameObject tmpdec = cs.addDecoration(info.point, ang, parallelDecoration, (Event.current.shift) ? false : true, paintingIsoDecoration);

                                if (autoanimate)
                                {
                                    AutoAnimator tmpautoanim = tmpdec.AddComponent <AutoAnimator>() as AutoAnimator;

                                    tmpautoanim.FrameSecuence = this.FrameSecuence;
                                    tmpautoanim.FrameRate     = this.FrameRate;
                                }

                                cs.refresh();
                            }
                            else
                            {
                                map.ghostDecoration(cs, info.point, ang, parallelDecoration, (Event.current.shift) ? false : true, paintingIsoDecoration, 0.5f);
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
            public override void Prepare()
            {
                paintLater     = false;
                backupTextures = false;

                RaycastHit info = new RaycastHit();

                Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

                GameObject go = null;

                if (Physics.Raycast(ray, out info /*, LayerMask.NameToLayer("Cells Layer")*/)) //TODO Arreglar esto porque al parecer la distancia no funciona correctamente
                {
                    if (info.collider.transform.IsChildOf(paintModule.map.transform))
                    {
                        go = info.collider.gameObject;
                    }
                }

                if (Event.current.isMouse)
                {
                    if (Event.current.button == 0)
                    {
                        if (Event.current.shift)
                        {
                            if (Event.current.type == EventType.mouseDown)
                            {
                                collectTexture = true;
                            }
                            if (collectTexture && Event.current.type != EventType.MouseUp)
                            {
                                backupTextures = true;
                            }
                            else
                            {
                                collectTexture = false;
                            }
                        }
                        else if (Event.current.type == EventType.MouseDown)
                        {
                            painting   = true;
                            paintLater = true;
                        }
                        else if (Event.current.type == EventType.MouseUp)
                        {
                            painting = false;
                        }
                        else
                        {
                            if (painting)
                            {
                                paintLater = true;
                            }
                        }
                    }
                }
                if (go != null)
                {
                    cs = go.GetComponent <Cell>();
                }
                else
                {
                    cs = null;
                }
                if (cs != null)
                {
                    f = cs.getFaceByPoint(info.point);
                }
                else
                {
                    f = null;
                }
            }