Exemplo n.º 1
0
        private int processMaterial(Material mat)
        {
            if (mat == null || mat.shader == null)
            {
                return(-1);
            }

            // already stored ?
            for (int i = 0; i < materialList.Count; i++)
            {
                if (materialList[i].mat.GetInstanceID() == mat.GetInstanceID())
                {
                    return(i);
                }
            }

            // create
            MaterialPackage matPack = new MaterialPackage();

            matPack.mat  = mat;
            matPack.name = mat.name;

            // if material within Resources/VPET than use load material
            string   matName = mat.name.Replace("(Instance)", "").Trim();
            Material _mat    = Resources.Load(string.Format("VPET/Materials/{0}", matName), typeof(Material)) as Material;

            if (_mat)
            {
                print("mat tyoe" + 1 + " material " + mat.name);
                matPack.type = 1;
                matPack.src  = matName;
            }
            else
            {
                print("mat tyoe" + 2 + " shader " + mat.shader.name);
                matPack.type = 2;
                matPack.src  = mat.shader.name;
            }


            materialList.Add(matPack);
            return(materialList.Count - 1);
        }
Exemplo n.º 2
0
        private void convertMaterialsByteStream()
        {
            m_materialList = new List <MaterialPackage>();

            int dataIdx = 0;

            while (dataIdx < m_materialsByteData.Length - 1)
            {
                MaterialPackage matPack = new MaterialPackage();

                // get type
                int intValue = BitConverter.ToInt32(m_materialsByteData, dataIdx);
                dataIdx     += size_int;
                matPack.type = intValue;

                // get material name length
                intValue = BitConverter.ToInt32(m_materialsByteData, dataIdx);
                dataIdx += size_int;

                // get material name
                byte[] nameByte = new byte[intValue];
                Buffer.BlockCopy(m_materialsByteData, dataIdx, nameByte, 0, intValue);
                dataIdx     += intValue;
                matPack.name = Encoding.ASCII.GetString(nameByte);


                // get material src length
                intValue = BitConverter.ToInt32(m_materialsByteData, dataIdx);
                dataIdx += size_int;

                // get material src
                nameByte = new byte[intValue];
                Buffer.BlockCopy(m_materialsByteData, dataIdx, nameByte, 0, intValue);
                dataIdx    += intValue;
                matPack.src = Encoding.ASCII.GetString(nameByte);

                m_materialList.Add(matPack);
            }

            Array.Clear(m_materialsByteData, 0, m_materialsByteData.Length);
            m_materialsByteData = null;
            GC.Collect();
        }