public void Serialize()
    {
        LevelObject[] objects = FindObjectsOfType<LevelObject>();

        string[] encodedObjects = new string[objects.Length];

        for (int i = 0; i < objects.Length; ++i)
        {
            LevelObjectData data = objects[i].Get();

            string json = JsonUtility.ToJson(data);

            string encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));

            encodedObjects[i] = encoded;
        }

        string code = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Join(";", encodedObjects)));

        using (StreamWriter writer = new StreamWriter("Assets/Resources/Data/NewLevel.txt"))
        {
            writer.WriteLine(code);
        }

        Debug.Log("Wrote level to NewLevel.txt");
    }
예제 #2
0
        public void SetObject(SceneObjectContainer selectObject, Vector3 position, bool instancing = false)
        {
            var sceneObject = GUIAuxiliar.Instanciate(selectObject.Prefab, transform, position, selectObject.Rotation, selectObject.Scale, instancing);
            var dataObject  = new LevelObjectData(sceneObject, position);

            listOfObjects.Add(dataObject);
        }
        private void Init(LevelObjectData data)
        {
            /* Create the link between the instance and it's type */

            if (m_lot == null)
            {
                /* ERROR: Could not find the type in the data definition */
                System.Diagnostics.Debug.Assert(false);
                return;
            }

            if (m_lot.ModelFileName.Length > 0)
            {
                Model model = null;
                data.FetchModel(m_lot.ModelFileName, m_services, out model);

                System.Diagnostics.Debug.Assert(model != null);
                m_model = model;

                List<Effect> list = new List<Effect>();
                foreach (ModelMesh mesh in m_model.Meshes)
                {
                    foreach (Effect effect in mesh.Effects)
                    {
                        list.Add(effect);
                    }
                }

                m_effects = new ReadOnlyCollection<Effect>(list);
            }
        }
    void CreateLevel()
    {
        string code = Levels.GetLevelString(Levels.GetNextLevel());

        byte[] codeBytes = Convert.FromBase64String(code);

        code = Encoding.UTF8.GetString(codeBytes, 0, codeBytes.Length);

        string[] encodedObjects = code.Split(';');

        for (int i = 0; i < encodedObjects.Length; ++i)
        {
            byte[] bytes = Convert.FromBase64String(encodedObjects[i]);

            string json = Encoding.UTF8.GetString(bytes, 0, bytes.Length);

            LevelObjectData data = JsonUtility.FromJson <LevelObjectData>(json);

            GameObject toSpawn = Resources.Load <GameObject>("Objects/" + data.type.ToString());

            GameObject obj = Instantiate(toSpawn, data.position, Quaternion.identity, transform);

            obj.transform.localScale = data.scale;

            obj.transform.eulerAngles = data.rotation;
        }
    }
예제 #5
0
    private List <LevelObjectData> findLevelObjects()
    {
        List <LevelObjectData> levelObjects = new List <LevelObjectData>();

        levelCompleteNumber = 0;

        foreach (GameObject foundObject in GameObject.FindGameObjectsWithTag("LevelObject"))
        {
            if (foundObject.GetComponent <LevelObject>())
            {
                LevelObjectData tempObject = foundObject.GetComponent <LevelObject>().objectData;
                tempObject.objTransform.position = new SerializeVector3(foundObject.transform.position);
                tempObject.objTransform.rotation = new SerializeQuaternion(foundObject.transform.rotation);
                tempObject.objTransform.scale    = new SerializeVector3(foundObject.transform.localScale);

                levelObjects.Add(tempObject);

                if (tempObject.isCollectable)
                {
                    levelCompleteNumber++;
                }
            }
        }

        return(levelObjects);
    }
예제 #6
0
 public void CopyValues(LevelObjectData newObjectValues)
 {
     objTransform  = newObjectValues.objTransform;
     isCollectable = newObjectValues.isCollectable;
     meshType      = newObjectValues.meshType;
 }
예제 #7
0
        /// <summary>
        /// Serializes an object in our level for our XML.
        /// </summary>
        /// <param name="levelObject">The object we wish to serialize into our XML.</param>
        /// <returns>Returns the XML struct for our data.</returns>
        private LevelObjectData SerializeLevelObject(LevelDesignObject levelObject)
        {
            LevelObjectData objectData = new LevelObjectData();
            objectData.TextureAsset = levelObject.TextureAsset;
            objectData.Position = levelObject.WorldPosition;
            objectData.Rotation = levelObject.WorldRotation;
            objectData.Collision = levelObject.UsesCollider;

            return objectData;
        }
예제 #8
0
        /// <summary>
        /// A function which creates a UIObject for the inputted data and adds it to the appropriate LevelObjects list.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="size"></param>
        /// <returns>Returns the newly created UIObject we have made from the inputted data</returns>
        private LevelDesignObject DeserializeLevelObject(LevelObjectData data, LevelDesignType type, Vector2 size)
        {
            LevelDesignObject newObject = AddEnvironmentObject(new LevelDesignObject(size, data.Position, data.TextureAsset)) as LevelDesignObject;
            newObject.LocalRotation = data.Rotation;
            newObject.UsesCollider = data.Collision;

            LevelObjects[type].Add(newObject);

            return newObject;
        }
 public DrawableLevelObjectType(LevelObjectType type, LevelObjectData data, ServiceManager services)
 {
     m_lot = type;
     m_services = services;
     Init(data);
 }
 /// <summary>
 /// Create a background object for our level using the XML data.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="size"></param>
 private void DeserializeLevelObject(LevelObjectData data, Vector2 size)
 {
     Image newObject = AddEnvironmentObject(new Image(size, data.Position, data.TextureAsset)) as Image;
     newObject.LocalRotation = data.Rotation;
     newObject.UsesCollider = data.Collision;
 }