void Start()
    {
        currentSelectable = GetComponent <TestSelectable>();

        KMBombModule[]  modules      = FindObjectsOfType <KMBombModule>();
        KMNeedyModule[] needyModules = FindObjectsOfType <KMNeedyModule>();
        currentSelectable.Children = new TestSelectable[modules.Length + needyModules.Length];
        for (int i = 0; i < modules.Length; i++)
        {
            currentSelectable.Children[i] = modules[i].GetComponent <TestSelectable>();
            modules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            modules[i].OnPass   = delegate() { Debug.Log("Module Passed"); return(false); };
            modules[i].OnStrike = delegate() { Debug.Log("Strike"); return(false); };
        }

        for (int i = 0; i < needyModules.Length; i++)
        {
            currentSelectable.Children[modules.Length + i]         = needyModules[i].GetComponent <TestSelectable>();
            needyModules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            needyModules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                return(false);
            };
            needyModules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                return(false);
            };
        }

        currentSelectable.ActivateChildSelectableAreas();


        //Load all the audio clips in the asset database
        audioClips = new List <AudioClip>();
        string[] audioClipAssetGUIDs = AssetDatabase.FindAssets("t:AudioClip");

        foreach (var guid in audioClipAssetGUIDs)
        {
            AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>(AssetDatabase.GUIDToAssetPath(guid));

            if (clip != null)
            {
                audioClips.Add(clip);
            }
        }

        audioSource = gameObject.AddComponent <AudioSource>();
        KMAudio[] kmAudios = FindObjectsOfType <KMAudio>();
        foreach (KMAudio kmAudio in kmAudios)
        {
            kmAudio.HandlePlaySoundAtTransform += PlaySoundHandler;
        }
    }
Пример #2
0
 void Cancel()
 {
     if (currentSelectable.Parent != null && currentSelectable.Cancel())
     {
         currentSelectable.DeactivateChildSelectableAreas(currentSelectable.Parent);
         currentSelectable = currentSelectable.Parent;
         currentSelectable.ActivateChildSelectableAreas();
         lastSelected = currentSelectable.GetCurrentChild();
     }
 }
Пример #3
0
 void Interact()
 {
     if (currentSelectableArea != null && currentSelectableArea.Selectable.Interact())
     {
         currentSelectable.DeactivateChildSelectableAreas(currentSelectableArea.Selectable);
         currentSelectable = currentSelectableArea.Selectable;
         currentSelectable.ActivateChildSelectableAreas();
         lastSelected = currentSelectable.GetCurrentChild();
     }
 }
Пример #4
0
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(ray.origin, ray.direction);
        RaycastHit hit;
        int        layerMask           = 1 << 11;
        bool       rayCastHitSomething = Physics.Raycast(ray, out hit, 1000, layerMask);

        if (rayCastHitSomething)
        {
            TestSelectableArea hitArea = hit.collider.GetComponent <TestSelectableArea>();
            if (hitArea != null)
            {
                if (currentSelectableArea != hitArea)
                {
                    if (currentSelectableArea != null)
                    {
                        currentSelectableArea.Selectable.Deselect();
                    }

                    hitArea.Selectable.Select();
                    currentSelectableArea = hitArea;
                }
            }
            else
            {
                if (currentSelectableArea != null)
                {
                    currentSelectableArea.Selectable.Deselect();
                    currentSelectableArea = null;
                }
            }
        }
        else
        {
            if (currentSelectableArea != null)
            {
                currentSelectableArea.Selectable.Deselect();
                currentSelectableArea = null;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (currentSelectableArea != null && currentSelectableArea.Selectable.Interact())
            {
                currentSelectable.DeactivateChildSelectableAreas(currentSelectableArea.Selectable);
                currentSelectable = currentSelectableArea.Selectable;
                currentSelectable.ActivateChildSelectableAreas();
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (currentSelectableArea != null)
            {
                currentSelectableArea.Selectable.InteractEnded();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (currentSelectable.Parent != null && currentSelectable.Cancel())
            {
                currentSelectable.DeactivateChildSelectableAreas(currentSelectable.Parent);
                currentSelectable = currentSelectable.Parent;
                currentSelectable.ActivateChildSelectableAreas();
            }
        }
    }
Пример #5
0
    void Start()
    {
        MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();
        foreach (MonoBehaviour s in scripts)
        {
            IEnumerable <FieldInfo> fields = s.GetType().GetFields();
            foreach (FieldInfo f in fields)
            {
                if (f.FieldType.Equals(typeof(KMBombInfo)))
                {
                    KMBombInfo component = (KMBombInfo)f.GetValue(s);
                    if (component.OnBombExploded != null)
                    {
                        fakeInfo.Detonate += new FakeBombInfo.OnDetonate(component.OnBombExploded);
                    }
                    if (component.OnBombSolved != null)
                    {
                        fakeInfo.HandleSolved += new FakeBombInfo.OnSolved(component.OnBombSolved);
                    }
                    continue;
                }
            }
        }

        currentSelectable = GetComponent <TestSelectable>();

        KMBombModule[]  modules      = FindObjectsOfType <KMBombModule>();
        KMNeedyModule[] needyModules = FindObjectsOfType <KMNeedyModule>();
        fakeInfo.needyModules      = needyModules.ToList();
        currentSelectable.Children = new TestSelectable[modules.Length + needyModules.Length];
        for (int i = 0; i < modules.Length; i++)
        {
            KMBombModule mod = modules[i];

            currentSelectable.Children[i] = modules[i].GetComponent <TestSelectable>();
            modules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(modules[i], false));
            modules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                fakeInfo.modules.Remove(fakeInfo.modules.First(t => t.Key.Equals(mod)));
                fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(mod, true));
                bool allSolved = true;
                foreach (KeyValuePair <KMBombModule, bool> m in fakeInfo.modules)
                {
                    if (!m.Value)
                    {
                        allSolved = false;
                        break;
                    }
                }
                if (allSolved)
                {
                    fakeInfo.Solved();
                }
                return(false);
            };
            modules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        for (int i = 0; i < needyModules.Length; i++)
        {
            currentSelectable.Children[modules.Length + i]         = needyModules[i].GetComponent <TestSelectable>();
            needyModules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            needyModules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                return(false);
            };
            needyModules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        currentSelectable.ActivateChildSelectableAreas();


        //Load all the audio clips in the asset database
        audioClips = new List <AudioClip>();
        string[] audioClipAssetGUIDs = AssetDatabase.FindAssets("t:AudioClip");

        foreach (var guid in audioClipAssetGUIDs)
        {
            AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>(AssetDatabase.GUIDToAssetPath(guid));

            if (clip != null)
            {
                audioClips.Add(clip);
            }
        }

        audioSource = gameObject.AddComponent <AudioSource>();
        KMAudio[] kmAudios = FindObjectsOfType <KMAudio>();
        foreach (KMAudio kmAudio in kmAudios)
        {
            kmAudio.HandlePlaySoundAtTransform += PlaySoundHandler;
        }
    }
Пример #6
0
    void Start()
    {
        MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();
        foreach (MonoBehaviour s in scripts)
        {
            IEnumerable <FieldInfo> fields = s.GetType().GetFields();
            foreach (FieldInfo f in fields)
            {
                if (f.FieldType.Equals(typeof(KMBombInfo)))
                {
                    KMBombInfo component = (KMBombInfo)f.GetValue(s);
                    fakeInfo.Detonate += delegate { if (component.OnBombExploded != null)
                                                    {
                                                        component.OnBombExploded();
                                                    }
                    };
                    fakeInfo.HandleSolved += delegate { if (component.OnBombSolved != null)
                                                        {
                                                            component.OnBombSolved();
                                                        }
                    };
                }
            }
        }

        currentSelectable = GetComponent <TestSelectable>();

        KMBombModule[]  modules      = FindObjectsOfType <KMBombModule>();
        KMNeedyModule[] needyModules = FindObjectsOfType <KMNeedyModule>();
        fakeInfo.needyModules            = needyModules.ToList();
        currentSelectable.Children       = new TestSelectable[modules.Length + needyModules.Length];
        currentSelectable.ChildRowLength = currentSelectable.Children.Length;
        for (int i = 0; i < modules.Length; i++)
        {
            KMBombModule mod = modules[i];

            TestSelectable testSelectable = modules[i].GetComponent <TestSelectable>();
            currentSelectable.Children[i] = testSelectable;
            testSelectable.Parent         = currentSelectable;
            testSelectable.x = i;

            fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(modules[i], false));
            modules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                fakeInfo.modules.Remove(fakeInfo.modules.First(t => t.Key.Equals(mod)));
                fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(mod, true));
                bool allSolved = true;
                foreach (KeyValuePair <KMBombModule, bool> m in fakeInfo.modules)
                {
                    if (!m.Value)
                    {
                        allSolved = false;
                        break;
                    }
                }
                if (allSolved)
                {
                    fakeInfo.Solved();
                }
                return(false);
            };
            modules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        for (int i = 0; i < needyModules.Length; i++)
        {
            TestSelectable testSelectable = needyModules[i].GetComponent <TestSelectable>();
            currentSelectable.Children[modules.Length + i] = testSelectable;
            testSelectable.Parent = currentSelectable;
            testSelectable.x      = modules.Length + i;

            needyModules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                return(false);
            };
            needyModules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        currentSelectable.ActivateChildSelectableAreas();

        audioSource = gameObject.AddComponent <AudioSource>();
        KMAudio[] kmAudios = FindObjectsOfType <KMAudio>();
        foreach (KMAudio kmAudio in kmAudios)
        {
            kmAudio.HandlePlaySoundAtTransform += PlaySoundHandler;
        }
    }
Пример #7
0
    void Start()
    {
        MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();

        currentSelectable = GetComponent <TestSelectable>();

        var modules      = Modules;
        var needyModules = NeedyModules;

        fakeInfo.needyModules      = needyModules.ToList();
        currentSelectable.Children = new TestSelectable[modules.Length + needyModules.Length];
        for (int i = 0; i < modules.Length; i++)
        {
            KMBombModule mod = modules[i];

            currentSelectable.Children[i] = modules[i].GetComponent <TestSelectable>();
            modules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(modules[i], false));

            modules[i].OnPass = delegate() {
                Debug.Log("Module Passed");
                fakeInfo.modules.Remove(fakeInfo.modules.First(t => t.Key.Equals(mod)));
                fakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(mod, true));
                bool allSolved = true;
                foreach (KeyValuePair <KMBombModule, bool> m in fakeInfo.modules)
                {
                    if (!m.Value)
                    {
                        allSolved = false;
                        break;
                    }
                }
                if (allSolved)
                {
                    fakeInfo.Solved();
                }
                return(false);
            };
            modules[i].OnStrike = delegate() {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        for (int i = 0; i < needyModules.Length; i++)
        {
            currentSelectable.Children[modules.Length + i]         = needyModules[i].GetComponent <TestSelectable>();
            needyModules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            Handlers(needyModules[i].GetComponent <KMBombInfo>());

            needyModules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                return(false);
            };
            needyModules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                fakeInfo.HandleStrike();
                return(false);
            };
        }

        currentSelectable.ActivateChildSelectableAreas();

        audioSource = gameObject.AddComponent <AudioSource>();
        KMAudio[] kmAudios = FindObjectsOfType <KMAudio>();
        foreach (KMAudio kmAudio in kmAudios)
        {
            kmAudio.HandlePlaySoundAtTransform += PlaySoundHandler;
        }
    }
Пример #8
0
    void Start()
    {
        MonoBehaviour[] scripts = MonoBehaviour.FindObjectsOfType <MonoBehaviour>();
        foreach (MonoBehaviour s in scripts)
        {
            IEnumerable <FieldInfo> fields = s.GetType().GetFields();
            foreach (FieldInfo f in fields)
            {
                if (f.FieldType.Equals(typeof(KMBombInfo)))
                {
                    KMBombInfo component = (KMBombInfo)f.GetValue(s);
                    if (component.OnBombExploded != null)
                    {
                        FakeInfo.Detonate += new FakeBombInfo.OnDetonate(component.OnBombExploded);
                    }
                    if (component.OnBombSolved != null)
                    {
                        FakeInfo.HandleSolved += new FakeBombInfo.OnSolved(component.OnBombSolved);
                    }
                    continue;
                }
            }
        }

        FakeInfo.Detonate     += OnBombExploded;
        FakeInfo.HandleSolved += OnBombSolved;

        currentSelectable = GetComponent <TestSelectable>();

        KMBombModule[]    modules      = FindObjectsOfType <KMBombModule>();
        KMNeedyModule[]   needyModules = FindObjectsOfType <KMNeedyModule>();
        KMWidget[]        widgets      = FindObjectsOfType <KMWidget>();
        KMSoundOverride[] overrides    = FindObjectsOfType <KMSoundOverride>();
        FakeInfo.needyModules      = needyModules.ToList();
        currentSelectable.Children = new TestSelectable[modules.Length + needyModules.Length];

        FakeInfo.kmWidgets.AddRange(widgets);

        foreach (KMSoundOverride sound in overrides)
        {
            SoundEffects.OverwriteClips(sound);
        }

        for (int i = 0; i < modules.Length; i++)
        {
            KMBombModule mod = modules[i];

            KMStatusLightParent statuslightparent = modules[i].GetComponentInChildren <KMStatusLightParent>();
            var statuslight = Instantiate <StatusLight>(StatusLightPrefab);
            statuslight.transform.parent        = statuslightparent.transform;
            statuslight.transform.localPosition = Vector3.zero;
            statuslight.transform.localScale    = Vector3.one;
            statuslight.transform.localRotation = Quaternion.identity;
            statuslight.SetInActive();

            currentSelectable.Children[i] = modules[i].GetComponent <TestSelectable>();
            modules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            FakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(modules[i], false));
            modules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                statuslight.SetPass();

                FakeInfo.modules.Remove(FakeInfo.modules.First(t => t.Key.Equals(mod)));
                FakeInfo.modules.Add(new KeyValuePair <KMBombModule, bool>(mod, true));
                bool allSolved = !FakeInfo.detonated;
                foreach (KeyValuePair <KMBombModule, bool> m in FakeInfo.modules)
                {
                    if (!allSolved)
                    {
                        break;
                    }
                    allSolved &= m.Value;
                }
                if (allSolved)
                {
                    FakeInfo.Solved();
                }
                return(false);
            };
            modules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                statuslight.FlashStrike();
                FakeInfo.HandleStrike();
                if (!FakeInfo.detonated)
                {
                    PlayGameSoundHandler(KMSoundOverride.SoundEffect.Strike, transform);
                }
                return(false);
            };
        }

        for (int i = 0; i < needyModules.Length; i++)
        {
            currentSelectable.Children[modules.Length + i]         = needyModules[i].GetComponent <TestSelectable>();
            needyModules[i].GetComponent <TestSelectable>().Parent = currentSelectable;

            needyModules[i].OnPass = delegate()
            {
                Debug.Log("Module Passed");
                return(false);
            };
            needyModules[i].OnStrike = delegate()
            {
                Debug.Log("Strike");
                FakeInfo.HandleStrike();
                if (!FakeInfo.detonated)
                {
                    PlayGameSoundHandler(KMSoundOverride.SoundEffect.Strike, transform);
                }
                return(false);
            };
        }

        currentSelectable.ActivateChildSelectableAreas();

        _alarmAudioSource = gameObject.AddComponent <AudioSource>();
        _alarmAudioSource.transform.position = transform.position;
        _alarmAudioSource.loop = true;
        audioSource            = gameObject.AddComponent <AudioSource>();
        KMAudio[] kmAudios = FindObjectsOfType <KMAudio>();
        foreach (KMAudio kmAudio in kmAudios)
        {
            kmAudio.HandlePlaySoundAtTransform            += PlaySoundHandler;
            kmAudio.HandlePlayGameSoundAtTransform        += PlayGameSoundHandler;
            kmAudio.HandlePlaySoundAtTransformWithRef     += PlaySoundwithRefHandler;
            kmAudio.HandlePlayGameSoundAtTransformWithRef += PlayGameSoundHandlerWithRef;
        }
    }