# automatically generated by the FlatBuffers compiler, do not modify

# namespace: NestedUnion

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class Vec3(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = Vec3()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsVec3(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # Vec3
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Vec3
    def X(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos)
        return 0.0

    # Vec3
    def Y(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos)
        return 0.0

    # Vec3
    def Z(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos)
        return 0.0

    # Vec3
    def Test1(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos)
        return 0.0

    # Vec3
    def Test2(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
        return 0

    # Vec3
    def Test3(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            x = o + self._tab.Pos
            from MyGame.Example.NestedUnion.Test import Test
            obj = Test()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

def Vec3Start(builder): builder.StartObject(6)
def Start(builder):
    return Vec3Start(builder)
def Vec3AddX(builder, x): builder.PrependFloat64Slot(0, x, 0.0)
def AddX(builder, x):
    return Vec3AddX(builder, x)
def Vec3AddY(builder, y): builder.PrependFloat64Slot(1, y, 0.0)
def AddY(builder, y):
    return Vec3AddY(builder, y)
def Vec3AddZ(builder, z): builder.PrependFloat64Slot(2, z, 0.0)
def AddZ(builder, z):
    return Vec3AddZ(builder, z)
def Vec3AddTest1(builder, test1): builder.PrependFloat64Slot(3, test1, 0.0)
def AddTest1(builder, test1):
    return Vec3AddTest1(builder, test1)
def Vec3AddTest2(builder, test2): builder.PrependUint8Slot(4, test2, 0)
def AddTest2(builder, test2):
    return Vec3AddTest2(builder, test2)
def Vec3AddTest3(builder, test3): builder.PrependStructSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(test3), 0)
def AddTest3(builder, test3):
    return Vec3AddTest3(builder, test3)
def Vec3End(builder): return builder.EndObject()
def End(builder):
    return Vec3End(builder)
import MyGame.Example.NestedUnion.Test
try:
    from typing import Optional
except:
    pass

class Vec3T(object):

    # Vec3T
    def __init__(self):
        self.x = 0.0  # type: float
        self.y = 0.0  # type: float
        self.z = 0.0  # type: float
        self.test1 = 0.0  # type: float
        self.test2 = 0  # type: int
        self.test3 = None  # type: Optional[MyGame.Example.NestedUnion.Test.TestT]

    @classmethod
    def InitFromBuf(cls, buf, pos):
        vec3 = Vec3()
        vec3.Init(buf, pos)
        return cls.InitFromObj(vec3)

    @classmethod
    def InitFromPackedBuf(cls, buf, pos=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
        return cls.InitFromBuf(buf, pos+n)

    @classmethod
    def InitFromObj(cls, vec3):
        x = Vec3T()
        x._UnPack(vec3)
        return x

    # Vec3T
    def _UnPack(self, vec3):
        if vec3 is None:
            return
        self.x = vec3.X()
        self.y = vec3.Y()
        self.z = vec3.Z()
        self.test1 = vec3.Test1()
        self.test2 = vec3.Test2()
        if vec3.Test3() is not None:
            self.test3 = MyGame.Example.NestedUnion.Test.TestT.InitFromObj(vec3.Test3())

    # Vec3T
    def Pack(self, builder):
        Vec3Start(builder)
        Vec3AddX(builder, self.x)
        Vec3AddY(builder, self.y)
        Vec3AddZ(builder, self.z)
        Vec3AddTest1(builder, self.test1)
        Vec3AddTest2(builder, self.test2)
        if self.test3 is not None:
            test3 = self.test3.Pack(builder)
            Vec3AddTest3(builder, test3)
        vec3 = Vec3End(builder)
        return vec3
