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); }
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); }
bool checkForMapObjCollideEvent(Collider2D collider, out MapObjectBehaviour obj) { if (obj = collider.GetComponent <MapObjectBehaviour>()) { return(true); } else { return(false); } }
// TODO: Solve the portal loop (two portals that are gatways to each other) public void HandlePortalEnter(MapObjectBehaviour target, MapObjectBehaviour portal) { if (hasDestination(portal)) { MapObjectBehaviour destination = GetDestination(portal); Transform targetTrans = target.transform; float preserveZPos = targetTrans.position.z; Vector3 destPos = destination.transform.position; destPos.z = preserveZPos; targetTrans.position = destPos; } }
void handleSetupPlayer(MapObjectBehaviour obj, MapController map) { PlayerController player = obj.GetComponent <PlayerController>(); if (player) { player.Setup(map); } else { Debug.LogErrorFormat("{0} does not contain a [PlayerController] instance"); } }
public MapObjectBehaviour GetDestination(MapObjectBehaviour gateway) { string destinationId = getDelegateStr(gateway, tuning.DestinationDelegate); MapObjectBehaviour destination; if (tryGetPortal(destinationId, out destination)) { return(destination); } else { Debug.LogErrorFormat("Destination with id {0} was not found", destinationId); return(null); } }
public void TrackPortal(MapObjectBehaviour mapObject) { string id = getDelegateStr(mapObject, tuning.IdDelegate); if (id != null) { if (activePortals.ContainsKey(id)) { activePortals[id] = mapObject; } else { activePortals.Add(id, mapObject); } } }
public void HandlePortalEnter(MapObjectBehaviour target, MapObjectBehaviour portal) { portals.HandlePortalEnter(target, portal); }
void handleSetupPortal(MapObjectBehaviour obj, PortalController portals) { portals.TrackPortal(obj); }
bool checkForPortalCollideEvent(MapObjectBehaviour obj) { return(obj.Descriptor.IsPortal); }
bool isPlayer(MapObjectBehaviour obj) { return(obj.GetComponent <PlayerController>()); }
protected string getDelegateStr(MapObjectBehaviour obj, string delegateId) { return(obj.Descriptor.DelegateStr(delegateId)); }
protected object getDelegate(MapObjectBehaviour obj, string delegateId) { return(obj.Descriptor.DelegateValue(delegateId)); }
void handlePortalCollider(MapObjectBehaviour obj) { map.HandlePortalEnter(player, obj); }
bool tryGetPortal(string portalId, out MapObjectBehaviour obj) { return(activePortals.TryGetValue(portalId, out obj)); }
bool hasDestination(MapObjectBehaviour obj) { return(obj.Descriptor.HasDelegate(tuning.DestinationDelegate)); }
bool isPortal(MapObjectBehaviour obj) { return(obj.Descriptor.IsPortal); }