Exemple #1
0
    public void CreateWorld(MapDescriptor descriptor, MapController map, PortalController portals, CameraController camera, Transform parent)
    {
        GameObject[, ][] worldTemplate = descriptor.Map;
        for (int x = 0; x < worldTemplate.GetLength(0); x++)
        {
            for (int y = 0; y < worldTemplate.GetLength(1); y++)
            {
                foreach (GameObject mapObj in worldTemplate[x, y])
                {
                    MapObjectBehaviour behaviour = Object.Instantiate(mapObj, new Vector3(x, y), Quaternion.identity).GetComponent <MapObjectBehaviour>();
                    behaviour.gameObject.SetActive(true);
                    behaviour.transform.SetParent(parent);
                    behaviour.AssignDescriptor(mapObj.GetComponent <MapObjectBehaviour>().CopyDescriptor());
                    behaviour.Initialize();
                    if (isPlayer(behaviour))
                    {
                        handleSetupPlayer(behaviour, map);
                    }
                    if (isPortal(behaviour))
                    {
                        handleSetupPortal(behaviour, portals);
                    }
                }
            }
        }
        Sprite background = new SpriteLoader().Load(descriptor.BackgroundSprite);

        camera.SetBackground(background);
    }
Exemple #2
0
    GameObject[] parseObjectsAtPosition(string[] keys, int x, int y)
    {
        GameObject[] objectsAtPosition = new GameObject[keys.Length];
        for (int i = 0; i < objectsAtPosition.Length; i++)
        {
            string   key;
            bool     hasDelegates     = false;
            string[] keyPlusDelegates = null;

            if (keys[i].Contains(delegateKey))
            {
                hasDelegates     = true;
                keyPlusDelegates = keys[i].Split(delegateKey.ToCharArray());
                key = keyPlusDelegates[0];
            }
            else
            {
                key = keys[i];
            }
            objectsAtPosition[i] = getPrefabFromKey(key);
            MapObjectBehaviour behaviour = objectsAtPosition[i].GetComponent <MapObjectBehaviour>();
            MapData            descriptor;
            if (behaviour && template.TryGetData(key, out descriptor))
            {
                behaviour.AssignDescriptor(descriptor);
                if (hasDelegates && keyPlusDelegates != null)
                {
                    string[] delegateVals = keyPlusDelegates[1].Split(delegateSeparatorKey.ToCharArray());
                    descriptor.SetDelegates(descriptor.Delegates, delegateVals);
                }
            }
        }
        return(objectsAtPosition);
    }