Beispiel #1
0
    // Add a creation to CreationMgr (multi-player)
    public static CreationData NewCreation(int object_id, ulong res_hash, float rand_seed)
    {
        CreationData creation_data = new CreationData();

        creation_data.m_ObjectID   = object_id;
        creation_data.m_HashCode   = res_hash;
        creation_data.m_RandomSeed = rand_seed;
        if (creation_data.LoadRes())
        {
            creation_data.GenCreationAttr();
            creation_data.BuildPrefab();
            creation_data.Register();
            CreationMgr.AddCreation(creation_data);
            //creation_data.m_Hp = creation_data.m_Attribute.m_Durability;
            //creation_data.m_Fuel = creation_data.m_Attribute.m_MaxFuel;
            Debug.Log("new creation succeed !");
            creation_data.UpdateUseTime();
            return(creation_data);
        }
        else
        {
            Debug.LogError("creation generate failed.");
        }
        return(null);
    }
Beispiel #2
0
    // Import content from a byte buffer
    public static void Import(byte[] buffer)
    {
        if (buffer == null)
        {
            return;
        }
        if (buffer.Length < 8)
        {
            return;
        }
        Init();
        MemoryStream ms      = new MemoryStream(buffer);
        BinaryReader r       = new BinaryReader(ms);
        int          version = r.ReadInt32();

        if (VERSION != version)
        {
            Debug.LogWarning("The version of CreationMgr is newer than the record.");
        }
        switch (version)
        {
        case 0x2001:
        {
            int count = r.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                CreationData creation_data = new CreationData();
                creation_data.m_ObjectID   = r.ReadInt32();
                creation_data.m_HashCode   = r.ReadUInt64();
                creation_data.m_RandomSeed = r.ReadSingle();
                //creation_data.m_Hp = r.ReadSingle();
                //creation_data.m_Fuel = r.ReadSingle();
                //				if ( creation_data.m_Hp < 0 )
                //				{
                //					Debug.LogWarning("Creation " + creation_data.m_ObjectID.ToString() +
                //						             " had been crashed, will not load any more..");
                //					continue;
                //				}
                if (creation_data.LoadRes())
                {
                    creation_data.GenCreationAttr();
                    creation_data.BuildPrefab();
                    creation_data.Register();
                    m_Creations.Add(creation_data.m_ObjectID, creation_data);
                }
                else
                {
                    creation_data.Destroy();
                    creation_data = null;
                }
            }
            break;
        }

        default:
            break;
        }
        r.Close();
        ms.Close();
    }