File size: 2,466 Bytes
c80142e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;
using System.Collections.Generic;
using UnityEngine.Playables;
using TMPro;

public enum CrabBehavior
{
    Flee,
    Follow,
    PickingUp,
    DropItem,
    GoTo,
    StandStill,
    Race
}

public class GameManager : MonoBehaviour
{
    public static GameManager Instance { get; private set; }

    [System.Serializable]
    public class WordEffect
    {
        public string word;
        public CrabBehavior crabBehavior;
        public GameObject _target;
        public string targetType;
        public bool affectFlee = true;
        public bool affectTarget = true;
        public AudioClip soundword;
        public Sprite wordSprite;
    }

    private AudioSource audioSource;
    public PlayableDirector timelineToPlay;

    public List<WordEffect> wordEffectsList = new List<WordEffect>();
    private Dictionary<string, WordEffect> wordEffectsDictionary = new Dictionary<string, WordEffect>();
    public Animator borders; 

    void Awake()
    {
        // Check if the instance already exists
        if (Instance != null && Instance != this)
        {
            //Destroy(gameObject); 
        }   
        else
        {
            Instance = this; 
            //DontDestroyOnLoad(gameObject); 
        }
    }


    void Start()
    {
        audioSource = GetComponent<AudioSource>();

        foreach (var effect in wordEffectsList)
        {
            wordEffectsDictionary[effect.word] = effect;
        }
    }

    public WordEffect GetEffectForWord(string word)
    {
        if (wordEffectsDictionary.TryGetValue(word, out WordEffect effect))
        {
            return effect;
        }
        return null; 
    }

    public void PlaySoundForWord(string word)
    {
        WordEffect effect = GetEffectForWord(word);
        if (effect != null && effect.soundword != null && audioSource != null)
        {
            audioSource.PlayOneShot(effect.soundword);
        }
    }

    public void OnSliderValueChanged(float value)
    {
        if (Mathf.Approximately(value, 100f)) // Safer float comparison
        {
            if (timelineToPlay != null)
            {
                timelineToPlay.Play();
            }
            else
            {
                Debug.LogWarning("Timeline is not assigned.");
            }
        }
    }
}