コード例 #1
0
 public CellProperties(float height, CellTopType topType, int orientation, float width, FaceNoSC[] faces)
 {
     this.height      = height;
     this.top         = topType;
     this.orientation = orientation;
     this.width       = width;
     this.faces       = faces;
 }
コード例 #2
0
    //int selectedTexture;
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();

        serializedObject.Update();

        SerializedProperty height          = serializedObject.FindProperty("properties.height");
        SerializedProperty walkable        = serializedObject.FindProperty("walkable");
        SerializedProperty cellTopType     = serializedObject.FindProperty("properties.top");
        SerializedProperty cellTopRotation = serializedObject.FindProperty("properties.orientation");

        EditorGUI.showMixedValue = walkable.hasMultipleDifferentValues;
        EditorGUILayout.PropertyField(walkable);


        heightValue = height.floatValue;
        EditorGUI.showMixedValue = height.hasMultipleDifferentValues;
        heightValue = EditorGUILayout.FloatField("Height", heightValue);

        CellTopType topType = (CellTopType)cellTopType.enumValueIndex;

        EditorGUI.showMixedValue = cellTopType.hasMultipleDifferentValues;
        topType = (CellTopType)EditorGUILayout.EnumPopup("Top", topType);

        GUIStyle s = new GUIStyle();

        s.padding = new RectOffset(5, 5, 5, 5);

        int topRotation = cellTopRotation.intValue;

        GUIContent topRotationText = new GUIContent("Top Rotation: " + ((cellTopRotation.hasMultipleDifferentValues)?"Mixed":"" + topRotation * 90));

        if (GUI.Button(GUILayoutUtility.GetRect(topRotationText, s), topRotationText))
        {
            topRotation += 1;
        }


        GUIContent select = new GUIContent("Select Map");

        if (GUI.Button(GUILayoutUtility.GetRect(select, s), select))
        {
            selectMap();
        }

        if (EditorGUI.EndChangeCheck())
        {
            if (heightValue != height.floatValue)
            {
                foreach (Cell c in cell)
                {
                    c.Height = heightValue;
                }
            }
            if (topType != ((CellTopType)cellTopType.enumValueIndex))
            {
                foreach (Cell c in cell)
                {
                    c.CellTop = topType;
                }
                cellTopType = serializedObject.FindProperty("cellTop");
            }

            if (topRotation != cellTopRotation.intValue)
            {
                foreach (Cell c in cell)
                {
                    c.CellTopRotation = topRotation;
                }
                cellTopRotation = serializedObject.FindProperty("cellTopRotation");
            }
            foreach (Cell c in cell)
            {
                EditorUtility.SetDirty(c);
            }
        }

        serializedObject.ApplyModifiedProperties();

        /*vec = cell[0].Map.getNeightbours(cell[0]);
         * foreach (Cell ce in vec)
         *  EditorGUILayout.ObjectField(ce, typeof(Cell), true);*/
    }
コード例 #3
0
ファイル: MeshFactory.cs プロジェクト: nvidiosin/isoAbbeyTFG
        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);

            // 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 * 0.5f;

            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) ? 0.5f : 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[];
        }
コード例 #4
0
ファイル: MeshFactory.cs プロジェクト: juzaru18/TinyWorld
        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);

            // 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 * 0.5f;

            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) ? 0.5f : 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[];

        }