Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using UnityEditor.MPE;
- using UnityEngine;
- public class LevelProcessor : MonoBehaviour
- {
- private GameController _controller;
- private JObject _levelInfo;
- public int to_deliver;
- public int score;
- private Dictionary<string, Type> req_to_type;
- private void Awake()
- {
- Dictionary<string, Type> req_to_type = new Dictionary<string, Type>(){
- {"deliver_object", typeof(DeliveryRequirement)},
- {"score", typeof(ScoreRequirement)},
- };
- _controller = GameObject.FindObjectOfType<GameController>();
- }
- private void Start()
- {
- foreach (JObject requirement in _levelInfo["requirements"])
- {
- var parsedRequirement = requirement.ToObject(req_to_type[requirement["req_type"].ToString()]);
- _controller.AddNewEventProcessor(parsedRequirement.event_type);
- }
- }
- }
- class DeliveryRequirement : IEventProcessor
- {
- public EventType event_type = EventType.object_delivered;
- private string req_type;
- private string object_type;
- private int min_condition;
- private int delivery_count = 0;
- public DeliveryRequirement() { }
- public DeliveryRequirement(string req_type, string object_type, int min_condition, int _deliveryCount)
- {
- this.req_type = req_type;
- this.object_type = object_type;
- this.min_condition = min_condition;
- this.delivery_count = _deliveryCount;
- }
- public void ProcessEvent(GameEvent game_event)
- {
- if (game_event.type == EventType.object_delivered && (bool)game_event.data["delivery_is_ok"])
- {
- this.delivery_count -= 1;
- }
- }
- }
- class ScoreRequirement : IEventProcessor
- {
- public EventType eventType = EventType.score_changed;
- private string object_type;
- private int total_score;
- public ScoreRequirement()
- { }
- public ScoreRequirement(string object_type, int _totalScore)
- {
- this.object_type = object_type;
- this.total_score = _totalScore;
- }
- public void ProcessEvent(GameEvent game_event)
- {
- if (game_event.type == EventType.object_delivered && (bool)game_event.data["delivery_is_ok"])
- {
- this.total_score += (int)game_event.data["delivery_data"]["score"];
- }
- if (game_event.type == EventType.score_changed)
- {
- total_score += (int)game_event.data["change_count"];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement