コード例 #1
0
        public void Implement()
        {
            Console.WriteLine("\nLearning Observer Pattern\n");
            WeatherData weatherData = new WeatherData(temperature: 40, pressure: 120, humidity: 20);

            Console.WriteLine(weatherData.ToString());
            IObserver sObserver = new StatisticsDisplay();

            weatherData.RegisterObserver(sObserver);
            IObserver fObserver = new ForecastDisplay();

            weatherData.RegisterObserver(fObserver);
            IObserver gObserver = new GeneralDisplay();

            weatherData.RegisterObserver(gObserver);
            weatherData.NotifyObserver();
            sObserver.Display();
            fObserver.Display();
            gObserver.Display();

            weatherData.DataChanged(temperature: 20, pressure: 80, humidity: 10);  //Just a dummy method which updates the weather data
            Console.WriteLine($"\nWeather changed {weatherData.ToString()}");
            sObserver.Display();
            fObserver.Display();
            gObserver.Display();

            Console.WriteLine("\nObserver Removed: General Display");
            weatherData.RemoveObserver(gObserver);
            weatherData.DataChanged(temperature: -20, pressure: 20, humidity: 0);  //Just a dummy method which updates the weather data
            sObserver.Display();
            fObserver.Display();
            gObserver.Display();
        }
コード例 #2
0
 public void PlayerCompanyChange(Company company)
 {
     if (company != null)
     {
         display.Display(company);
     }
 }
コード例 #3
0
 public void Display(IDisplayed[] toDisplay)
 {
     displayPool.ReleaseAll();
     foreach (IDisplayed d in toDisplay)
     {
         GameObject     g       = displayPool.GetGameObject();
         GeneralDisplay display = g.GetComponent <GeneralDisplay>();
         display.Display(d);
         display.OnSelectEvent -= OnSelect;
         display.selectable     = this.selectable;
         if (selectable)
         {
             display.OnSelectEvent += OnSelect;
         }
     }
 }
コード例 #4
0
    private void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            cursorObject.transform.position = hit.transform.position;
            foreach (MonoBehaviour m in hit.transform.gameObject.GetComponents <MonoBehaviour>())
            {
                IDisplayed iDisplayed = (IDisplayed)m;
                if (iDisplayed != null)
                {
                    cursorDisplay.Display(iDisplayed);
                }
            }
        }
    }
コード例 #5
0
 public void DisplayPlayer(Person player)
 {
     display.Display(player);
 }