コード例 #1
0
ファイル: FileManager.cs プロジェクト: Vicktooor/Inde01
    public static List <KeyValuePair <int, T> > GenerateIDList <T, T2>(List <T2> baseList) where T : class where T2 : class
    {
        int l = baseList.Count;

        if (l > 0)
        {
            if (CustomGeneric.HasProperty <T2>("key") && CustomGeneric.HasProperty <T2>("value"))
            {
                List <KeyValuePair <int, T> > list = new List <KeyValuePair <int, T> >();
                for (int i = 0; i < l; i++)
                {
                    T2  obj   = baseList[i];
                    int key   = (int)CustomGeneric.GetPropertyValue(obj, "key");
                    T   value = (T)CustomGeneric.GetPropertyValue(obj, "value");
                    KeyValuePair <int, T> pair = new KeyValuePair <int, T>(key, value);
                    list.Add(pair);
                }
                return(list);
            }
            else
            {
                Debug.LogError("property \"key\" or \"value\" doesn't exist in " + typeof(T2));
                return(null);
            }
        }
        else
        {
            return(null);
        }
    }
コード例 #2
0
ファイル: FileManager.cs プロジェクト: Vicktooor/Inde01
    public static Dictionary <T, T2> GenerateDicFromJson <T, T2>(DicWrapper <T2> wrapper) where T : struct, IConvertible where T2 : class
    {
        Dictionary <T, T2> dic = new Dictionary <T, T2>();

        foreach (PairWrapper <T2> obj in wrapper.objects)
        {
            T type = CustomGeneric.CastEnum <T>(obj.key);
            if (!dic.ContainsKey(type))
            {
                dic.Add(type, obj.value);
            }
        }
        return(dic);
    }
コード例 #3
0
    /// <summary>
    /// Convert a GroundMesh from a DataGround
    /// </summary>
    /// <param name="dataMesh">Dataground</param>
    /// <returns></returns>
    protected GroundMesh TrianglesToGroundMesh(DataGround dataMesh)
    {
        int        nbTriangle = dataMesh.triangles.Length;
        GroundMesh groundMesh = new GroundMesh(nbTriangle * 3, nbTriangle + 1, dataMesh.center);

        groundMesh.refTriangles = dataMesh.triangles;

        int[]     lTriangles = new int[groundMesh.triangles.Length];
        Vector3[] lVertex    = new Vector3[nbTriangle + 1];
        Vector3[] lNormals   = new Vector3[nbTriangle + 1];
        Vector2[] lUvs       = new Vector2[nbTriangle + 1];

        int ite = 0;

        for (int i = 0; i < nbTriangle; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                int index = CustomGeneric.ArrayContain(lVertex, refVertices[dataMesh.triangles[i].verticesindex[j]]);
                if (index < 0)
                {
                    lVertex[ite]  = refVertices[dataMesh.triangles[i].verticesindex[j]];
                    lNormals[ite] = refNormals[dataMesh.triangles[i].verticesindex[j]];
                    ite++;
                }
            }
        }

        for (int i = 0; i < nbTriangle; i++)
        {
            Vector3 center = groundMesh.centerPosition;
            for (int j = 0; j < 3; j++)
            {
                lTriangles[i * 3 + j] = CustomGeneric.ArrayContain(lVertex, refVertices[dataMesh.triangles[i].verticesindex[j]]);
            }
        }

        groundMesh.vertex    = lVertex;
        groundMesh.normals   = lNormals;
        groundMesh.triangles = lTriangles;

        return(groundMesh);
    }
コード例 #4
0
ファイル: Cell.cs プロジェクト: Vicktooor/OurGreatestChoices
 /// <summary>
 /// First init
 /// </summary>
 public void Init(GroundMesh meshObject)
 {
     meshObject.centerIndex = CustomGeneric.ArrayContain(meshObject.smoothVertex, meshObject.centerPosition);
     _indexes             = meshObject.indexes;
     _stateHealth         = 1;
     _walkable            = true;
     _elevation           = 1f;
     _isElevating         = false;
     _neighborElevationID = -1;
     _groundMesh          = meshObject;
     _poluted             = false;
     _deforested          = false;
     _axis              = GetCenterPosition();
     _personnalMesh     = GetComponent <MeshFilter>().mesh;
     _personnalCollider = GetComponents <MeshCollider>();
     _state             = CellState.MOSS;
     UpdateHeight(0);
     InitColor();
 }
コード例 #5
0
    /// <summary>
    /// Generate UV mapping
    /// </summary>
    /// <param name="groundMesh"></param>
    protected void GenerateTextureMap(GroundMesh groundMesh)
    {
        Vector3 cross    = Vector3.Cross(Vector3.up, groundMesh.centerPosition);
        Vector3 py       = groundMesh.centerPosition + cross;
        Vector3 pz       = groundMesh.centerPosition + Vector3.Cross(cross, groundMesh.centerPosition);
        Vector4 cellPlan = MathCustom.GetPlaneValues(groundMesh.centerPosition, py, pz);

        for (int i = 0; i < groundMesh.smoothVertex.Length; i++)
        {
            Vector3 vertex = groundMesh.smoothVertex[i];
            if (vertex == groundMesh.centerPosition)
            {
                groundMesh.UVs[i] = new Vector2(0.5f, 0.5f);
            }
            else
            {
                Vector3 planeCoord   = MathCustom.LineCutPlaneCoordinates(Vector3.zero, vertex, cellPlan);
                Vector3 cartesianPos = Quaternion.FromToRotation(groundMesh.centerPosition, Vector3.up) * planeCoord;
                float   lRadius;
                float   lPolar;
                float   lElevation;
                MathCustom.CartesianToSpherical(cartesianPos, out lRadius, out lPolar, out lElevation);
                float xAngle = Vector3.SignedAngle(groundMesh.centerPosition, vertex, groundMesh.centerPosition);
                float yAngle = Vector3.SignedAngle(Vector3.Cross(groundMesh.centerPosition, -Vector3.up), vertex, groundMesh.centerPosition);

                if (CustomGeneric.IntArrayContain(groundMesh.indexes.internVertexIndex, i) != -1)
                {
                    groundMesh.UVs[i] = new Vector2(0.5f + (Mathf.Cos(lPolar) * 0.9f), 0.5f + (Mathf.Sin(lPolar) * 0.9f));
                }
                else
                {
                    groundMesh.UVs[i] = new Vector2(0.5f + Mathf.Cos(lPolar), 0.5f + Mathf.Sin(lPolar));
                }
            }
        }
    }
コード例 #6
0
ファイル: Cell.cs プロジェクト: Vicktooor/OurGreatestChoices
        /// <summary>
        /// Update vertex colors
        /// </summary>
        public void SetVertexColors()
        {
            Color[] lcolors = new Color[_personnalMesh.vertices.Length];
            Color   lColor  = Color.white;

            for (int i = 0; i < _groundMesh.smoothVertex.Length; i++)
            {
                if (CustomGeneric.IntArrayContain(_groundMesh.indexes.cornerVertexIndex, i) != -1)
                {
                    lColor = _color;
                    List <Cell> lCells = GetVertexCellNeighbors(_groundMesh.smoothVertex[i]);
                    foreach (Cell lCell in lCells)
                    {
                        lColor += lCell.Color;
                    }
                    lColor *= 1 / 3f;
                }
                else if (CustomGeneric.IntArrayContain(_groundMesh.indexes.edgeVertexIndex, i) != -1)
                {
                    lColor = _color;
                    List <Cell> lCells = GetVertexCellNeighbors(_groundMesh.smoothVertex[i]);
                    foreach (Cell lCell in lCells)
                    {
                        lColor += lCell.Color;
                    }
                    lColor *= 0.5f;
                }
                else
                {
                    lColor = _color;
                }
                lcolors[i] = lColor;
            }

            _personnalMesh.colors = lcolors;
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var acc1 = new Account(100, "uah");  // id 1
            var acc2 = new Account(5454, "uah"); //   2
            var acc3 = new Account(200, "usd");  //   .
            var acc4 = new Account(1, "usd");

            acc1.Activate("Bank228");
            acc2.Activate("Bank228");
            acc3.Activate("Bank228");
            acc4.Activate("WorngPass");


            Console.WriteLine("---------------------Creating Bank Client");
            BankClient client  = BankClient.CreateBankClient();
            BankClient client2 = BankClient.CreateBankClient();

            Console.WriteLine("---------------------Creating Bank Client");


            client.AddAccountId(acc1.id);
            client.AddAccountId(acc3.id);
            client.ShowInfo();

            Console.WriteLine("---------------------Creating Bank Exmployee");
            var employee = BankEmployee.CreateBankEmployee();

            Console.WriteLine("---------------------Creating Bank Exmployee");

            User basicUser = new User("Andrii", "Koval", "login", "password");

            BankSystem.AddUser(employee);
            BankSystem.AddUser(client);  //1
            BankSystem.AddUser(client2); //2
            BankSystem.AddUser(basicUser);

            User user2 = new User("Bodia", "bogdan", "log", "pass");
            User user3 = new User("3", "3", "3", "3");

            User[] IComparableDemoArray = new User[] {
                basicUser,
                user3,
                user2
            };

            Array.Sort(IComparableDemoArray);
            Console.WriteLine("Sorting demo");
            foreach (User user in IComparableDemoArray)
            {
                user.ShowInfo();
            }
            Console.WriteLine("Sorting demo");


            // var foundUser = BankSystem.Users["a"];
            // if (foundUser != null)
            //     Console.WriteLine(foundUser.FullName);


            //extension
            Console.WriteLine(BankSystem.Users.GetBankClientsCount());

            SerializationDemoXML();
            SerializationDemoJSON();

            var obj = new CustomGeneric <BankEmployee>(employee);

            obj.getAllPossibilities();
        }
コード例 #8
0
    /// <summary>
    /// Cut the mesh to create a smoothable cell
    /// </summary>
    /// <param name="groundMesh">GroundMesh</param>
    protected void PrepareMeshForSmooth(GroundMesh groundMesh)
    {
        Vector3[] internVertex  = new Vector3[2];
        Vector3   midEdgeVertex = Vector3.zero;

        Vector3[] edgeVertex = new Vector3[2];

        Vector3[] smoothVertex = new Vector3[(groundMesh.triangles.Length * 4) + groundMesh.triangles.Length];
        int       iterator     = 0;

        for (int i = 0; i < groundMesh.computedTriangles.Length / 3; i++)
        {
            if (groundMesh.computedVertex[groundMesh.computedTriangles[i * 3]] == Vector3.zero)
            {
                continue;
            }

            Vector3 ver1 = groundMesh.computedVertex[groundMesh.computedTriangles[(i * 3) + 1]];
            Vector3 ver2 = groundMesh.computedVertex[groundMesh.computedTriangles[(i * 3) + 2]];
            internVertex[0] = (groundMesh.centerPosition + ver1) / 2f;
            internVertex[1] = (groundMesh.centerPosition + ver2) / 2f;

            Vector3 vDir1 = (internVertex[0] - groundMesh.centerPosition);
            Vector3 vDir2 = (internVertex[1] - groundMesh.centerPosition);
            internVertex[0] = internVertex[0] + (vDir1 * CellWidth);
            internVertex[1] = internVertex[1] + (vDir2 * CellWidth);

            float d = Vector3.Distance(internVertex[0], internVertex[1]) / 2f;
            midEdgeVertex = (ver1 + ver2) / 2f;
            edgeVertex[0] = midEdgeVertex + (midEdgeVertex - ver1).normalized * d;
            edgeVertex[1] = midEdgeVertex + (midEdgeVertex - ver2).normalized * d;

            for (int j = 0; j < 5; j++)
            {
                switch (j)
                {
                case 0:
                    smoothVertex[iterator * 3]       = groundMesh.centerPosition;
                    smoothVertex[(iterator * 3) + 1] = internVertex[0];
                    smoothVertex[(iterator * 3) + 2] = internVertex[1];
                    break;

                case 1:
                    smoothVertex[iterator * 3] = internVertex[0];
                    if (Vector3.Distance(ver1, internVertex[0]) > Vector3.Distance(ver2, internVertex[0]))
                    {
                        smoothVertex[iterator * 3 + 1] = ver2;
                    }
                    else
                    {
                        smoothVertex[iterator * 3 + 1] = ver1;
                    }
                    if (Vector3.Distance(edgeVertex[0], internVertex[0]) > Vector3.Distance(edgeVertex[1], internVertex[0]))
                    {
                        smoothVertex[iterator * 3 + 2] = edgeVertex[1];
                    }
                    else
                    {
                        smoothVertex[iterator * 3 + 2] = edgeVertex[0];
                    }
                    break;

                case 2:
                    smoothVertex[iterator * 3] = internVertex[1];
                    if (Vector3.Distance(edgeVertex[0], internVertex[1]) > Vector3.Distance(edgeVertex[1], internVertex[1]))
                    {
                        smoothVertex[iterator * 3 + 1] = edgeVertex[1];
                    }
                    else
                    {
                        smoothVertex[iterator * 3 + 1] = edgeVertex[0];
                    }
                    if (Vector3.Distance(ver1, internVertex[1]) > Vector3.Distance(ver2, internVertex[1]))
                    {
                        smoothVertex[iterator * 3 + 2] = ver2;
                    }
                    else
                    {
                        smoothVertex[iterator * 3 + 2] = ver1;
                    }
                    break;

                case 3:
                    smoothVertex[iterator * 3]     = internVertex[1];
                    smoothVertex[iterator * 3 + 1] = internVertex[0];
                    if (Vector3.Distance(edgeVertex[0], internVertex[1]) > Vector3.Distance(edgeVertex[1], internVertex[1]))
                    {
                        smoothVertex[iterator * 3 + 2] = edgeVertex[1];
                    }
                    else
                    {
                        smoothVertex[iterator * 3 + 2] = edgeVertex[0];
                    }
                    break;

                case 4:
                    smoothVertex[iterator * 3]     = internVertex[0];
                    smoothVertex[iterator * 3 + 1] = edgeVertex[1];
                    smoothVertex[iterator * 3 + 2] = edgeVertex[0];
                    break;
                }

                iterator++;
            }
        }

        iterator = 0;
        int coordNumber = smoothVertex.Length;

        for (int i = 0; i < coordNumber; i++)
        {
            int found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, smoothVertex[i]);
            if (found == -1)
            {
                groundMesh.smoothVertex[iterator]  = smoothVertex[i];
                groundMesh.smoothNormals[iterator] = smoothVertex[i].normalized;
                groundMesh.smoothTriangles[i]      = CustomGeneric.ArrayContain(groundMesh.smoothVertex, smoothVertex[i]);
                iterator++;
            }
            else
            {
                groundMesh.smoothTriangles[i] = found;
            }
        }

        for (int i = 0; i < groundMesh.computedTriangles.Length / 3; i++)
        {
            if (groundMesh.computedVertex[groundMesh.computedTriangles[i * 3]] == Vector3.zero)
            {
                continue;
            }

            Vector3 ver1 = groundMesh.computedVertex[groundMesh.computedTriangles[(i * 3) + 1]];
            Vector3 ver2 = groundMesh.computedVertex[groundMesh.computedTriangles[(i * 3) + 2]];
            internVertex[0] = (groundMesh.centerPosition + ver1) / 2f;
            internVertex[1] = (groundMesh.centerPosition + ver2) / 2f;

            Vector3 vDir1 = (internVertex[0] - groundMesh.centerPosition);
            Vector3 vDir2 = (internVertex[1] - groundMesh.centerPosition);
            internVertex[0] = internVertex[0] + (vDir1 * CellWidth);
            internVertex[1] = internVertex[1] + (vDir2 * CellWidth);

            float d = Vector3.Distance(internVertex[0], internVertex[1]) / 2f;
            midEdgeVertex = (ver1 + ver2) / 2f;
            edgeVertex[0] = midEdgeVertex + (midEdgeVertex - ver1).normalized * d;
            edgeVertex[1] = midEdgeVertex + (midEdgeVertex - ver2).normalized * d;

            int found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, edgeVertex[0]);
            if (found != -1)
            {
                groundMesh.indexes.edgeVertexIndex[i * 2] = found;
            }

            found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, edgeVertex[1]);
            if (found != -1)
            {
                groundMesh.indexes.edgeVertexIndex[i * 2 + 1] = found;
            }

            found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, ver1);
            if (found != -1)
            {
                groundMesh.indexes.cornerVertexIndex[i] = found;
            }

            found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, ver2);
            if (found != -1)
            {
                groundMesh.indexes.cornerVertexIndex[i] = found;
            }

            found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, internVertex[0]);
            if (found != -1)
            {
                groundMesh.indexes.internVertexIndex[i] = found;
            }

            found = CustomGeneric.ArrayContain(groundMesh.smoothVertex, internVertex[1]);
            if (found != -1)
            {
                groundMesh.indexes.internVertexIndex[i] = found;
            }
        }
    }
コード例 #9
0
    /// <summary>
    /// Get the dual transformation of a GroundMesh
    /// </summary>
    /// <param name="groundMesh">GroundMesh</param>
    protected void DualTransformation(GroundMesh groundMesh)
    {
        Vector3[] computedVertices = new Vector3[groundMesh.computedVertex.Length];
        Vector3[] computedNormals  = new Vector3[groundMesh.computedVertex.Length];

        for (int i = 0; i < groundMesh.triangles.Length / 3; i++)
        {
            Vector3 addVector = Vector3.zero + groundMesh.centerPosition;
            if (groundMesh.vertex[groundMesh.triangles[i * 3]] != groundMesh.centerPosition)
            {
                addVector += groundMesh.vertex[groundMesh.triangles[i * 3]];
            }
            if (groundMesh.vertex[groundMesh.triangles[i * 3 + 1]] != groundMesh.centerPosition)
            {
                addVector += groundMesh.vertex[groundMesh.triangles[i * 3 + 1]];
            }
            if (groundMesh.vertex[groundMesh.triangles[i * 3 + 2]] != groundMesh.centerPosition)
            {
                addVector += groundMesh.vertex[groundMesh.triangles[i * 3 + 2]];
            }

            computedVertices[i] = addVector.normalized * radius;
            computedNormals[i]  = computedVertices[i].normalized;
        }

        computedVertices[computedVertices.Length - 2] = Vector3.zero;
        computedNormals[computedNormals.Length - 2]   = -groundMesh.centerPosition.normalized;

        computedVertices[computedVertices.Length - 1] = groundMesh.centerPosition;
        computedNormals[computedNormals.Length - 1]   = groundMesh.centerPosition.normalized;

        groundMesh.computedVertex  = computedVertices;
        groundMesh.computedNormals = computedNormals;

        // Creation of the dual triangles array

        int nbTriangle = groundMesh.triangles.Length / 3;

        VertexCouple[] couples = new VertexCouple[nbTriangle];

        for (int i = 0; i < nbTriangle; i++)
        {
            couples[i] = new VertexCouple(Vector3.zero, Vector3.zero);
        }

        int ite = 0;

        for (int j = 0; j < groundMesh.computedVertex.Length; j++)
        {
            for (int k = 0; k < groundMesh.computedVertex.Length; k++)
            {
                if (groundMesh.computedVertex[j] != groundMesh.centerPosition && groundMesh.computedVertex[k] != groundMesh.centerPosition && groundMesh.computedVertex[j] != Vector3.zero && groundMesh.computedVertex[k] != Vector3.zero)
                {
                    float angle = Vector3.Angle(groundMesh.centerPosition - groundMesh.computedVertex[j], groundMesh.centerPosition - groundMesh.computedVertex[k]);
                    if (angle > 2 && angle < 70)
                    {
                        VertexCouple newCouple = new VertexCouple(groundMesh.computedVertex[j], groundMesh.computedVertex[k]);
                        if (!CoupleExist(couples, newCouple))
                        {
                            couples[ite] = newCouple;
                            ite++;
                        }
                    }
                }
            }
        }

        int[] lTriangles = new int[groundMesh.triangles.Length * 2];
        for (int i = 0; i < couples.Length; i++)
        {
            Vector3 surfaceNormal = Vector3.Cross(groundMesh.centerPosition + couples[i].vertices[0], groundMesh.centerPosition + couples[i].vertices[1]);
            float   angle         = Vector3.Angle(gameObject.transform.position + groundMesh.centerPosition, surfaceNormal);

            if (angle < 90)
            {
                lTriangles[i * 3]     = CustomGeneric.ArrayContain(groundMesh.computedVertex, groundMesh.centerPosition);
                lTriangles[i * 3 + 1] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[0]);
                lTriangles[i * 3 + 2] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[1]);
            }
            else
            {
                lTriangles[i * 3]     = CustomGeneric.ArrayContain(groundMesh.computedVertex, groundMesh.centerPosition);
                lTriangles[i * 3 + 1] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[1]);
                lTriangles[i * 3 + 2] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[0]);
            }

            Vector4 face = MathCustom.GetPlaneValues(Vector3.zero, couples[i].vertices[1], couples[i].vertices[0]);
            if (MathCustom.GetDistanceToPlane(groundMesh.centerPosition, face) > 0)
            {
                lTriangles[groundMesh.triangles.Length + i * 3]     = CustomGeneric.ArrayContain(groundMesh.computedVertex, Vector3.zero);
                lTriangles[groundMesh.triangles.Length + i * 3 + 1] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[0]);
                lTriangles[groundMesh.triangles.Length + i * 3 + 2] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[1]);
            }
            else
            {
                lTriangles[groundMesh.triangles.Length + i * 3]     = CustomGeneric.ArrayContain(groundMesh.computedVertex, Vector3.zero);
                lTriangles[groundMesh.triangles.Length + i * 3 + 1] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[1]);
                lTriangles[groundMesh.triangles.Length + i * 3 + 2] = CustomGeneric.ArrayContain(groundMesh.computedVertex, couples[i].vertices[0]);
            }
        }
        groundMesh.computedTriangles = lTriangles;
    }