/// <summary>
    /// Returns a randomized Vector3, each property is randomized seperately between their respective passed arguments. All limits are inclusive.
    /// </summary>
    public static Vector3 GetRandomizedVector3(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
    {
        Vector3Struct vs = new Vector3Struct();

        RandomizeVector3FRange(out vs, minX, maxX, minY, maxY, minZ, maxZ);
        return(ToVector(vs));
    }
    /// <summary>
    /// Returns a randomized Vector3, each property is randomized seperately between min and max.
    /// </summary>
    /// <param name="min">Lower limit for randomization.(Inclusive)</param>
    /// <param name="max">Upper limit for randomization.(Inclusive)</param>
    public static Vector3 GetRandomizedVector3(float min, float max)
    {
        Vector3Struct vs = new Vector3Struct();

        RandomizeVector3F(out vs, min, max);
        return(ToVector(vs));
    }
    /// <summary>
    /// Finds and returns the closest vector3 in an array to the given vector.
    /// </summary>
    /// <param name="arr"></param>
    /// <param name="comparison"></param>
    /// <returns></returns>
    public static Vector3 FindClosestVector(List <Vector3> arr, Vector3 comparison)
    {
        Vector3Struct s     = ToStruct(comparison);
        int           index = FindClosestV3(arr.ToArray(), ref s, arr.Count);

        return(arr[index]);
    }
    /// <summary>
    /// Finds and returns the closest vector3 in an array to the given vector.
    /// </summary>
    /// <param name="arr"></param>
    /// <param name="comparison"></param>
    /// <returns></returns>
    public static Vector3 FindClosestVector(Vector3[] arr, Vector3 comparison)
    {
        Vector3Struct s     = ToStruct(comparison);
        int           index = FindClosestV3(arr, ref s, arr.Length);

        return(arr[index]);
    }
Exemplo n.º 5
0
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        Vector3       vector3 = (Vector3)value;
        Vector3Struct result  = new Vector3Struct(vector3);

        serializer.Serialize(writer, result);
    }
Exemplo n.º 6
0
 public PlayerStruct(
     Vector3Struct position,
     Vector3Struct rotation
     )
 {
     this.position = position;
     this.rotation = rotation;
 }
    /// <summary>
    /// Returns a Vector3Struct out of a Vector3 type value.
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    private static Vector3Struct ToStruct(Vector3 v)
    {
        Vector3Struct vs = new Vector3Struct();

        vs.x = v.x;
        vs.y = v.y;
        vs.z = v.z;
        return(vs);
    }
    /// <summary>
    /// Returns a Vector3 out of a Vector3Struct type value.
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    private static Vector3 ToVector(Vector3Struct s)
    {
        Vector3 v = new Vector3();

        v.x = (float)s.x;
        v.y = (float)s.y;
        v.z = (float)s.z;
        return(v);
    }
Exemplo n.º 9
0
 public BlockStruct(
     string type,
     Vector3Struct position,
     Vector3Struct rotation
     )
 {
     this.type     = type;
     this.position = position;
     this.rotation = rotation;
 }
Exemplo n.º 10
0
    public PlayerStruct ToPlayerStruct()
    {
        Vector3Struct positionStruct = new Vector3Struct(gameObject.transform.position);
        Vector3Struct rotationStruct = new Vector3Struct(gameObject.transform.rotation.eulerAngles);

        return(new PlayerStruct(
                   positionStruct,
                   rotationStruct
                   ));
    }
Exemplo n.º 11
0
    public BlockStruct ToBlockStruct()
    {
        Vector3Struct positionStruct = new Vector3Struct(gameObject.transform.position);
        Vector3Struct rotationStruct = new Vector3Struct(gameObject.transform.rotation.eulerAngles);

        return(new BlockStruct(
                   script.blockType,
                   positionStruct,
                   rotationStruct
                   ));
    }
    /// <summary>
    /// Returns a pointer pointing to the first element of dynamically allocated array which contains given amount of points between the start & end points.
    /// </summary>
    public static Vector3[] GetPointsBetweenVectors(Vector3 start, Vector3 end, int size)
    {
        // Return if size is 0 or neg.
        if (size < 1)
        {
            Debug.LogError("Size of the required array can not be smaller than 1.");
            return(null);
        }

        // Init structs.
        Vector3Struct vS = ToStruct(start);
        Vector3Struct vE = ToStruct(end);

        // The method will return the pointer pointing to the beginning address of the allocated & calculated array.
        IntPtr arrayPointer = GetPointsBetweenVectorsV3(ref vS, ref vE, ref size);

        // Init point vectors to copy the data.
        Vector3[] points = new Vector3[size];

        // Offset is going to be used to increment the pointer by the size of pointSize.
        int offset = 0;

        // Size of a Vector3Struct type variable in the memory. Which is blittable with the V3 struct in C++ library.
        int pointSize = Marshal.SizeOf(typeof(Vector3Struct));

        // Increment the whole array.
        for (int i = 0; i < size; i++)
        {
            // Convert to structure from the pointer, which will be incremented by the size of V3 struct. Then convert the structure to Vector and assign.
            points[i] = ToVector((Vector3Struct)Marshal.PtrToStructure(new IntPtr(arrayPointer.ToInt32() + offset), typeof(Vector3Struct)));
            // Increment offset to shift the memory address forward.
            offset += pointSize;
        }

        // Free the memory which was allocated by C++ method.
        Marshal.FreeCoTaskMem(arrayPointer);

        return(points);
    }
Exemplo n.º 13
0
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        Vector3Struct value = serializer.Deserialize <Vector3Struct>(reader);

        return(value.ToVector3());
    }
 private static extern int FindClosestV3([In, Out] Vector3[] array, ref Vector3Struct comparison, int size);
Exemplo n.º 15
0
        public override void Read(IOMemoryStream ms, UAssetFile f)
        {
            //Is we're in an array, this will **ALWAYS** be a prop list struct.
            UStruct st;

            if (isArray)
            {
                structType = "(array)";
                unknown    = 0;
                st         = new PropListStruct();
                f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow);
            }
            else
            {
                structType = ms.ReadNameTableEntry(f);
                unknown    = ms.ReadInt();
                f.Debug("Read Array", $"====READ STRUCT BEGIN @ {ms.position} ({structType}, {unknown})====", ConsoleColor.Yellow);

                //Find the struct type. Unknown if real: ItemStatInfo
                if (structType == "ItemStatInfo" || structType == "ItemNetID" || structType == "ItemNetInfo" || structType == "Transform" || structType == "PrimalPlayerDataStruct" || structType == "PrimalPlayerCharacterConfigStruct" || structType == "PrimalPersistentCharacterStatsStruct" || structType == "TribeData" || structType == "TribeGovernment" || structType == "TerrainInfo" || structType == "ArkInventoryData" || structType == "DinoOrderGroup" || structType == "ARKDinoData")
                {
                    //Open this as a struct property list.
                    st = new PropListStruct();
                }
                else if (structType == "Vector" || structType == "Rotator")
                {
                    //3d vector or rotor
                    st = new Vector3Struct();
                }
                else if (structType == "Vector2D")
                {
                    //2d vector
                    st = new Vector2Struct();
                }
                else if (structType == "Quat")
                {
                    //Quat
                    st = new QuatStruct();
                }
                else if (structType == "Color")
                {
                    //Color
                    st = new ColorStruct();
                }
                else if (structType == "LinearColor")
                {
                    //Linear color
                    st = new LinearColorStruct();
                }
                else if (structType == "UniqueNetIdRepl")
                {
                    //Some net stuff
                    st = new UniqueNetIdStruct();
                }
                else if (structType == "Guid")
                {
                    //Some net stuff
                    st = new GuidStruct();
                }
                else if (structType == "IntPoint")
                {
                    //Some net stuff
                    st = new IntPointStruct();
                }
                else if (structType == "StringAssetReference")
                {
                    st = new StringAssetReferenceStruct();
                }
                else
                {
                    //Interpet this as a struct property list. Maybe raise a warning later?
                    f.Warn("Struct Warning", $"Unknown type '{structType}'. Interpeting as a struct property list...");
                    st = new PropListStruct();
                }
            }

            //Read
            st.ReadStruct(ms, f, this);
            data = st;

            f.Debug("Read Struct", $"====READ STRUCT END @ {ms.position}====", ConsoleColor.Yellow);
        }
 private static extern IntPtr GetPointsBetweenVectorsV3(ref Vector3Struct start, ref Vector3Struct end, ref int size);
 private static extern void RandomizeVector3F(out Vector3Struct vs, float min, float max);
 private static extern void RandomizeVector3IntRange(out Vector3Struct vs, int minX, int maxX, int minY, int maxY, int minZ, int maxZ);
 private static extern void RandomizeVector3FRange(out Vector3Struct vs, double minX, double maxX, double minY, double maxY, double minZ, double maxZ);
 private static extern void RandomizeVector3Int(out Vector3Struct vs, int min, int max);