示例#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);
                    }
                }
            }
        }
示例#2
0
文件: Cell.cs 项目: mperez01/TRPGTest
        public CellFace[] getSameSurfaceAdjacentFaces(FaceNoSC face)
        {
            List <CellFace> adjacents = new List <CellFace>();

            int index = getFaceIndex(face);

            Cell[] neighbors = this.Map.getNeightbours(this);

            if (index == this.Properties.faces.Length - 1)
            {
                // Es el top
                foreach (var n in neighbors)
                {
                    if (n != null)
                    {
                        if (n.Height == this.Height)
                        {
                            adjacents.Add(new CellFace(n, n.Properties.faces[n.Properties.faces.Length - 1]));
                        }
                    }
                }
            }
            else if (index != -1)
            {
                // The lower one
                if (index - 4 >= 0 && !isCoveredByOthers(this.Properties.faces[index - 4], index - 4, neighbors))
                {
                    adjacents.Add(new CellFace(this, this.Properties.faces[index - 4]));
                }
                // The upper one
                if (index + 4 < this.Properties.faces.Length - 1 && !isCoveredByOthers(this.Properties.faces[index + 4], index + 4, neighbors))
                {
                    adjacents.Add(new CellFace(this, this.Properties.faces[index + 4]));
                }


                int  direction = index % 4;
                Cell leftOne   = neighbors[(direction + 1) % 4];

                //The left one
                if (leftOne != null && index < leftOne.Properties.faces.Length - 1 && !isCoveredByOthers(leftOne.Properties.faces[index], index, leftOne.Map.getNeightbours(leftOne)))
                {
                    adjacents.Add(new CellFace(leftOne, leftOne.Properties.faces[index]));
                }

                Cell rightOne = neighbors[(direction + 3) % 4];
                //The rightOne
                if (rightOne != null && index < rightOne.Properties.faces.Length - 1 && !isCoveredByOthers(rightOne.Properties.faces[index], index, rightOne.Map.getNeightbours(rightOne)))
                {
                    adjacents.Add(new CellFace(rightOne, rightOne.Properties.faces[index]));
                }
            }

            return(adjacents.ToArray());
        }
示例#3
0
            private FaceNoSC createFace(int[] indexes, FaceNoSC copy, List <Vector3> vertexList, Vector3[] vertices)
            {
                FaceNoSC f = new FaceNoSC();

                f.FinalVertexList = vertexList;
                f.SharedVertex    = vertices;
                f.VertexIndex     = indexes;
                f.regenerateTriangles();

                if (copy != null)
                {
                    //			f.getAtribsFrom(copy);
                    f.Texture        = copy.Texture;
                    f.TextureMapping = copy.TextureMapping;
                }

                return(f);
            }
示例#4
0
            private FaceNoSC selectFaceFor(FaceNoSC[] faces, List <FaceNoSC> tmpFaces)
            {
                FaceNoSC selected = null;

                if (faces != null)
                {
                    if (faces.Length - 1 > tmpFaces.Count)
                    {
                        selected = faces[tmpFaces.Count];
                    }
                    else if (tmpFaces.Count - 4 >= 0)
                    {
                        selected = tmpFaces[tmpFaces.Count - 4];
                    }
                }

                return(selected);
            }
示例#5
0
            private Vector3[] getRealPointsOf(FaceNoSC f)
            {
                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]]);
                }

                return(puntos);
            }
示例#6
0
文件: Cell.cs 项目: mperez01/TRPGTest
        private int getFaceIndex(FaceNoSC f)
        {
            if (f == properties.faces[properties.faces.Length - 1])
            {
                return(properties.faces.Length - 1);
            }
            else
            {
                for (int i = 0; i < properties.faces.Length; i++)
                {
                    if (properties.faces[i] == f)
                    {
                        return(i);
                    }
                }
            }

            return(-1);
        }
示例#7
0
文件: Cell.cs 项目: mperez01/TRPGTest
        // Deserialization moment
        void Awake()
        {
#if UNITY_EDITOR
            if (Application.isEditor && !Application.isPlaying)
            {
                // Code to prevent losing information from old versions
                if (faces != null && faces.Length != 0)
                { // The first time i have to initialize those
                    FaceNoSC[] nfaces = new FaceNoSC[faces.Length];
                    for (int i = 0; i < faces.Length; i++)
                    {
                        if (faces[i] == null)
                        {
                            // Debug.Log("Null face detected at " + this + " at map " + Map);
                            break;
                        }

                        nfaces[i]                = new FaceNoSC();
                        nfaces[i].Texture        = faces[i].Texture;
                        nfaces[i].TextureMapping = faces[i].TextureMapping;
                    }


                    this.properties = new CellProperties(height, topType, cellTopRotation, 1, faces != null ? nfaces : new FaceNoSC[0]);
                    Debug.Log("No era null");
                    faces = null;
                }
            }
#endif

            // This will prevent older versions to lose face information about textures.

            /*if (this.faces == null) {
             *  faces = new Face[faceTextures.Length];
             *  for (int i = 0; i< faces.Length; i++) {
             *      faces[i].Texture = faceTextures[i];
             *      faces[i].TextureMapping = faceMappings[i];
             *  }
             *  faceTextures = null;
             *  faceMappings = null;
             * }		*/
        }
示例#8
0
文件: Cell.cs 项目: mperez01/TRPGTest
        private static void extractFacesFromMesh(Mesh mesh, CellProperties properties)
        {
            int numLateralFaces = Mathf.CeilToInt(properties.height) * 4;

            //Numero de vertices de la ultima capa
            int[] topFacesNumVertex = (properties.top == CellTopType.flat) ? new int[1] {
                4
            } : new int[4] {
                3, 4, 3, 4
            };

            int verticesForThisFace;
            int totalVertices = 0;

            for (int i = 0; i < numLateralFaces + topFacesNumVertex.Length; i++)
            {
                // Calculamos cuantos vertices tendra la cara. Si es lateral 4 y sino, los que esten preestablecidos.
                verticesForThisFace = (i < numLateralFaces) ? 4 : topFacesNumVertex[i - numLateralFaces];
                FaceNoSC.extractFaceInfoFromMesh(mesh, verticesForThisFace, totalVertices, properties.faces[i]);
                totalVertices += verticesForThisFace;
            }
        }
示例#9
0
文件: Cell.cs 项目: mperez01/TRPGTest
        public bool isCoveredByOthers(FaceNoSC f, int pos, Cell[] neighbors)
        {
            bool isCovered = false;

            float height    = ((pos / 4) + 1) * this.properties.width;
            int   direction = pos % 4;

            switch (direction)
            {
            case 0: direction = 2; break;

            case 2: direction = 0; break;
            }

            if (neighbors[direction] != null)
            {
                if (neighbors[direction].Height >= height)
                {
                    isCovered = true;
                }
            }

            return(isCovered);
        }
示例#10
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);
                            }
                        }
                    }
                }
            }
        }
示例#11
0
文件: Cell.cs 项目: mperez01/TRPGTest
 public CellFace(Cell c, FaceNoSC f)
 {
     this.c = c; this.f = f;
 }
示例#12
0
            private FaceNoSC[] regenerateFaces(FaceNoSC[] faces, float height, CellTopType cellTop, float cellWidth, int CellTopRotation)
            {
                List <FaceNoSC> tmpFaces        = new List <FaceNoSC>();
                List <Vector3>  finalVertexList = new List <Vector3>();

                bool hasMediumTop = height != ((float)((int)height));
                int  numVert      = ((int)height + 1) * 4 + ((hasMediumTop) ? 4 : 0);

                Vector3[] vertices = new Vector3[numVert + ((cellTop != CellTopType.flat) ? 2 : 0)];
                float     down     = -height;

                switch (cellTop)
                {
                case CellTopType.plane: down -= 1f; break;

                case CellTopType.midPlane: down -= 0.5f; break;
                }

                // INDEXES FOR TOP FACE
                int vertTopLeft = vertices.Length - 4; int verTopRight = vertices.Length - 3;
                int vertBotLeft = vertices.Length - 1; int vertBotRight = vertices.Length - 2;

                //MAIN VARS FOR VERTICES
                float   halfWidth    = (cellWidth / 2.0f);
                Vector3 vectorHeight = new Vector3(0, cellWidth, 0);

                float extraHeight = height;

                while (extraHeight > cellWidth && cellWidth > 0)
                {
                    extraHeight -= cellWidth;
                }


                // BASE VERTICES
                vertices[0] = new Vector3(-halfWidth, 0, -halfWidth); vertices[1] = new Vector3(halfWidth, 0, -halfWidth);
                vertices[2] = new Vector3(halfWidth, 0, halfWidth); vertices[3] = new Vector3(-halfWidth, 0, halfWidth);
                if (height >= 1)
                {
                    vertices[4] = vertices[0] + vectorHeight;
                }
                else if (hasMediumTop)
                {
                    vertices[4] = vertices[0] + vectorHeight * extraHeight;
                }

                FaceNoSC last = null;

                //MAIN LATERAL FACE GENERATOR
                for (int i = 4; i < numVert; i++)
                {
                    int cutted = (i % 4 == 3) ? 1 : 0;
                    if (i + 1 < numVert)
                    {
                        vertices[i + 1] = vertices[i - 3] + vectorHeight * ((hasMediumTop && (i + 1) >= numVert - 4) ? extraHeight : 1f);
                    }

                    last = selectFaceFor(faces, tmpFaces);
                    tmpFaces.Add(createFace(new int[4] {
                        i - 4, i - 3 - (4 * cutted), i + 1 - (4 * cutted), i
                    }, last, finalVertexList, vertices));
                }

                //EXTRA FACES GENERATOR
                if (cellTop != CellTopType.flat)
                {
                    float aumHeight = (cellTop == CellTopType.midPlane) ? 0.5f : 1f;

                    int topBotLeft  = numVert - (4 - (CellTopRotation + 0) % 4),
                        topBotRight = numVert - (4 - (CellTopRotation + 1) % 4),
                        topTopRight = numVert - (4 - (CellTopRotation + 2) % 4),
                        topTopLeft  = numVert - (4 - (CellTopRotation + 3) % 4);

                    vertices[numVert]     = vertices[topBotRight] + vectorHeight * aumHeight;
                    vertices[numVert + 1] = vertices[topTopRight] + vectorHeight * aumHeight;

                    //NEW TOP FACE
                    int[] topFaceIndexes = new int[4] {
                        topTopLeft, numVert + 1, numVert, topBotLeft
                    };
                    vertBotLeft  = topFaceIndexes[CellTopRotation];
                    vertTopLeft  = topFaceIndexes[(3 + CellTopRotation) % 4];
                    verTopRight  = topFaceIndexes[(2 + CellTopRotation) % 4];
                    vertBotRight = topFaceIndexes[(1 + CellTopRotation) % 4];

                    // Lado Derecho
                    last = selectFaceFor(faces, tmpFaces);
                    tmpFaces.Add(createFace(new int[3] {
                        numVert, topBotLeft, topBotRight
                    }, last, finalVertexList, vertices));

                    //Lado Izquierdo
                    last = selectFaceFor(faces, tmpFaces);
                    tmpFaces.Add(createFace(new int[3] {
                        numVert + 1, topTopRight, topTopLeft
                    }, last, finalVertexList, vertices));

                    //Parte de atras
                    last = selectFaceFor(faces, tmpFaces);
                    tmpFaces.Add(createFace(new int[4] {
                        topBotRight, topTopRight, numVert + 1, numVert
                    }, last, finalVertexList, vertices));
                }

                //TOP FACE GENERATOR
                if (faces != null && faces.Length >= 1)
                {
                    last = faces[faces.Length - 1];
                }
                tmpFaces.Add(createFace(new int[4] {
                    vertBotLeft, vertTopLeft, verTopRight, vertBotRight
                }, last, finalVertexList, vertices));

                return(tmpFaces.ToArray());//..ToArray(typeof(Face)) as Face[];
            }
示例#13
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;
                }
            }