private GameObject CreateFileSaveAs()
        {
            FileSaveAsFactory factory = Undoable.AddComponent <FileSaveAsFactory>(disposable);

            factory.parent   = parent;
            factory.keyboard = keyboard;
            GameObject panel = factory.Generate();

            fileSaveAsInstance = panel;
            GameObject fileSaveAsContainer = panel.transform.parent.gameObject;

            fileSaveAsContainer.transform.localPosition = fileSaveAsLocalPosition;
            fileSaveAs = fileSaveAsInstance.transform.Find("DrivesPanel").GetComponent <FileSaveAs>();
            fileManager.saveAsPanel = fileSaveAs;


#if UNITY_EDITOR
            var onSaveAs = fileSaveAs.onSaveAs;
            for (int i = 0; i < onSaveAs.GetPersistentEventCount(); i++)
            {
                UnityEventTools.RemovePersistentListener(onSaveAs, 0);
            }
            UnityEventTools.AddPersistentListener(onSaveAs, fileManager.SaveAs);
            fileSaveAs.onSaveAs = onSaveAs;
#endif

            return(panel);
        }
        void TryRegisterVoid(UnityEventBase poller, UnityAction f)
        {
            var count = poller.GetPersistentEventCount();

            if (this._clean_empty_no_target_events && count > 0)
            {
                //poller.PollEvent.RemoveAllListeners(); // Only non-persistant listeners.
                for (var i = 0; i < count; i++)
                {
                    if (poller.GetPersistentTarget(i) == null || poller.GetPersistentMethodName(i) == null)
                    {
                        UnityEventTools.RemovePersistentListener(poller, i);
                    }
                }
            }

            count = poller.GetPersistentEventCount();
            if (count == 0)
            {
                UnityEventTools.AddVoidPersistentListener(poller, f);
                poller.SetPersistentListenerState(0, this._unity_event_call_state);
            }
            else if (count > 0)
            {
        #if NEODROID_DEBUG
                if (this.Debugging)
                {
                    Debug.Log($"PollEvent on {poller} already has a listeners");
                }
        #endif
            }
        }
        private GameObject CreateFileOpen()
        {
            FileOpenFactory factory = Undoable.AddComponent <FileOpenFactory>(disposable);

            factory.parent = parent;
            GameObject panel = factory.Generate();

            fileOpenInstance = panel;
            GameObject fileOpenContainer = panel.transform.parent.gameObject;

            fileOpenContainer.transform.localPosition = fileOpenLocalPosition;
            fileOpen = fileOpenInstance.transform.Find("DrivesPanel").GetComponent <FileOpen>();

#if UNITY_EDITOR
            var onOpen = fileOpen.onOpen;
            for (int i = 0; i < onOpen.GetPersistentEventCount(); i++)
            {
                UnityEventTools.RemovePersistentListener(onOpen, 0);
            }
            UnityEventTools.AddPersistentListener(onOpen, fileManager.Open);
            fileOpen.onOpen = onOpen;
#endif

            return(panel);
        }
 void CleanPersistentListeners(UnityEvent evt)
 {
     for (int i = evt.GetPersistentEventCount() - 1; i >= 0; i--)
     {
         UnityEventTools.RemovePersistentListener(evt, i);
     }
 }
Beispiel #5
0
    /// <summary>
    /// EDITOR ONLY
    /// </summary>
    public static void OnValidateOnlyAddEvent(this UnityEvent e, UnityAction action)
    {
#if UNITY_EDITOR
        UnityEventTools.RemovePersistentListener(e, action);
        UnityEventTools.AddPersistentListener(e, action);
#endif
    }
    public static void AddListenersToLines()
    {
        CampaignPlayerController playerController = GameObject.Find("GameManager").GetComponent <CampaignPlayerController>();

        //Debug.Log("Player Controller: " + playerController);

        GameObject[] lineButtonsInLevel = GameObject.FindGameObjectsWithTag("LinePlacement");
        //Debug.Log("Line Buttons: " + lineButtonsInLevel.Length);


        foreach (GameObject obj in lineButtonsInLevel)
        {
            UnityEvent btnOnClick = obj.GetComponent <Button>().onClick;

            //Remove 2 empty listeners that are part of the prefab
            UnityEventTools.RemovePersistentListener(btnOnClick, 0);
            UnityEventTools.RemovePersistentListener(btnOnClick, 0);

            //Create Actions for methods to add
            UnityAction drawMethod    = new UnityAction(playerController.PlayerDrawLine);
            UnityAction destroyMethod = new UnityAction(playerController.DestroyStaticLine);

            //Add persistent listeners in editor
            UnityEventTools.AddPersistentListener(btnOnClick, drawMethod);
            UnityEventTools.AddPersistentListener(btnOnClick, destroyMethod);
        }

        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        Debug.Log("Added listeners to " + lineButtonsInLevel.Length + " line buttons.");
    }
    private void PUN_ConvertvItemCollection(GameObject obj)
    {
        if (obj.GetComponent <vItemCollection>())
        {
            vItemCollection org = obj.GetComponent <vItemCollection>();
            if (!obj.GetComponent <PhotonView>())
            {
                obj.AddComponent <PhotonView>();
            }
            if (!obj.GetComponent <PUN_ItemCollect>())
            {
                obj.AddComponent <PUN_ItemCollect>();
                for (int i = 0; i < obj.GetComponent <vItemCollection>().onDoActionWithTarget.GetPersistentEventCount(); i++)
                {
                    if (obj.GetComponent <vItemCollection>().onDoActionWithTarget.GetPersistentMethodName(i) == "NetworkDestroy")
                    {
                        UnityEventTools.RemovePersistentListener(obj.GetComponent <vItemCollection>().onDoActionWithTarget, i);
                    }
                }
                obj.GetComponent <vItemCollection>().OnDoAction.AddListener(obj.GetComponent <PUN_ItemCollect>().NetworkDestory);
                UnityEventTools.AddPersistentListener(obj.GetComponent <vItemCollection>().OnDoAction, obj.GetComponent <PUN_ItemCollect>().NetworkDestory);
            }

            modified.Add(obj);
        }
    }
Beispiel #8
0
        /// <summary>
        /// Replace Close button callback on Cancel instead of the Hide for the Dialog components in the specified GameObject.
        /// </summary>
        /// <param name="go">GameObject.</param>
        public static void FixDialogCloseButton(GameObject go)
        {
            var dialogs = go.GetComponentsInChildren <Dialog>(true);

            foreach (var dialog in dialogs)
            {
                var button_go = dialog.transform.Find("Header/CloseButton");
                if (button_go == null)
                {
                    continue;
                }

                var button = button_go.GetComponent <Button>();
                if (button == null)
                {
                    continue;
                }

                if (IsEventCallMethod(button.onClick, dialog, "Hide"))
                {
                    UnityEventTools.RemovePersistentListener(button.onClick, dialog.Hide);
                    UnityEventTools.AddPersistentListener(button.onClick, dialog.Cancel);
                }
            }
        }
        private GameObject CreateToolsPanel()
        {
            ToolsExamplePanelFactory factory = Undoable.AddComponent <ToolsExamplePanelFactory>(disposable);

            factory.parent        = parent;
            factory.fileOpen      = fileOpen;
            factory.fileSaveAs    = fileSaveAs;
            factory.skyboxManager = skyboxManager;
            GameObject panel = factory.Generate();

            toolsInstance = panel;
            Vector3 localPosition = toolsInstance.transform.localPosition;

            localPosition.x = toolsLocalPosition.x;
            toolsInstance.transform.localPosition = localPosition;

#if UNITY_EDITOR
            var touchPadButtons = touchPadMenuController.touchPadButtons;
            for (int i = 0; i < touchPadButtons[0].onSelected.GetPersistentEventCount(); i++)
            {
                UnityEventTools.RemovePersistentListener(touchPadButtons[0].onSelected, 0);
            }
            UnityEventTools.AddPersistentListener(touchPadButtons[0].onSelected, toolsInstance.GetComponent <StandardPanel>().ToggleVisible);
            touchPadMenuController.touchPadButtons = touchPadButtons;
#endif

            return(panel);
        }
Beispiel #10
0
        void TryRegister(DataPoller poller, UnityAction <DataPoller> f)
        {
            if (poller)
            {
                var count = poller.PollEvent.GetPersistentEventCount();
                if (this._clean_empty_no_target_events && count > 0)
                {
                    //poller.PollEvent.RemoveAllListeners(); // Only non-persistant listeners.
                    for (var i = 0; i < count; i++)
                    {
                        if (poller.PollEvent.GetPersistentTarget(i) == null ||
                            poller.PollEvent.GetPersistentMethodName(i) == null)
                        {
                            UnityEventTools.RemovePersistentListener(poller.PollEvent, i);
                        }
                    }
                }

                count = poller.PollEvent.GetPersistentEventCount();
                if (count == 0)
                {
                    UnityEventTools.AddObjectPersistentListener(poller.PollEvent, f, poller);
                    poller.PollEvent.SetPersistentListenerState(0, this._unity_event_call_state);
                }
                else if (count > 0 && poller.PollEvent.GetPersistentTarget(0) != poller)
                {
                    if (this.Debugging)
                    {
                        Debug.Log($"PollEvent on {poller} already has a listeners");
                    }
                }
            }
        }
Beispiel #11
0
 void RemoveAllPersistentListener(UnityEventBase e)
 {
     while (e.GetPersistentEventCount() > 0)
     {
         UnityEventTools.RemovePersistentListener(e, 0);
     }
 }
Beispiel #12
0
 public void RefreshUnityEventBase()
 {
     if (selectedUnityEventBase is UnityEvent)
     {
         UnityEventTools.RemovePersistentListener((UnityEvent)selectedUnityEventBase, EventTriggerHandler);
         UnityEventTools.AddPersistentListener((UnityEvent)selectedUnityEventBase, EventTriggerHandler);
     }
 }
        public static void RemovePresistentListener(this Button button, int index)
        {
            if (button.onClick.GetPersistentEventCount() <= 0)
            {
                return;
            }

            UnityEventTools.RemovePersistentListener(button.onClick, index);
        }
        public static void RemovePersistentListeners(this UnityEventBase self)
        {
            var count = self.GetPersistentEventCount();

            for (var i = 0; i < count; ++i)
            {
                UnityEventTools.RemovePersistentListener(self, i);
            }
        }
Beispiel #15
0
    public void OnDestroy()
    {
        b = GetComponent <Button>();

        if (b != null)
        {
            UnityEventTools.RemovePersistentListener(b.onClick, ClickFunction);
        }
        b = null;
    }
Beispiel #16
0
    public void OnValidate()
    {
        b = GetComponent <Button>();

        if (b != null)
        {
            UnityEventTools.RemovePersistentListener(b.onClick, ClickFunction);
            UnityEventTools.AddPersistentListener(b.onClick, ClickFunction);
        }
    }
    public void RefreshListeners()
    {
        MainMenuView mainMenuView = FindObjectOfType <MainMenuView>();

        if (mainMenuView == null)
        {
            Debug.LogWarning("Couldn't find main menu view in hierarchy. Ensure you're in the correct scene");
            return;
        }
        UnityAction <LevelData> levelSelectAction = new UnityAction <LevelData>(mainMenuView.SelectLevel);

        if (levelSelectAction == null)
        {
            Debug.LogWarning("Couldn't find function to select level on interatction handler.");
            return;
        }
        GameObject content = GameObject.Find("Content");

        if (content == null)
        {
            Debug.LogWarning("Couldn't find \"Content\". Skipped adding levelData to buttons. Prehaps the object is disabled.");
            return;
        }
        // Iterate over the content and add button listener to each level
        foreach (Transform child in content.transform)
        {
            Transform levelsInHierarchy = FindDeepChild(child, "Levels");
            string    groupName         = child.name;
            foreach (Transform level in levelsInHierarchy)
            {
                Button    button        = level.GetComponentInChildren <Button>();
                string    levelDataPath = levelDataResourcePath + groupName + "/" + level.GetSiblingIndex();
                LevelData levelData     = Resources.Load <LevelData>(levelDataPath);
                if (levelData == null)
                {
                    Debug.LogWarning(string.Format("Couldn't load LevelData at {0}", levelDataPath));
                }
                int numListeners = button.onClick.GetPersistentEventCount();

                // Remove all listeners just in case some extras got added
                for (int i = 0; i < numListeners; i++)
                {
                    UnityEventTools.RemovePersistentListener(button.onClick, button.onClick.GetPersistentEventCount() - 1);
                }

                // Add new listener with correct levelData
                UnityEventTools.AddObjectPersistentListener <LevelData>(button.onClick, levelSelectAction, levelData);

                // Required because we're modifing a prefab in the heirarchy
                PrefabUtility.RecordPrefabInstancePropertyModifications(button);
            }
        }
    }
        private void WireUpSave()
        {
#if UNITY_EDITOR
            var touchPadButtons = touchPadMenuController.touchPadButtons;
            for (int i = 0; i < touchPadButtons[1].onSelected.GetPersistentEventCount(); i++)
            {
                UnityEventTools.RemovePersistentListener(touchPadButtons[1].onSelected, 0);
            }
            UnityEventTools.AddPersistentListener(touchPadButtons[1].onSelected, fileManager.SaveFromUnityEvent);
            touchPadMenuController.touchPadButtons = touchPadButtons;
#endif
        }
Beispiel #19
0
 private static void AddResetOnClickListener(Button resetButton, VRC_SceneResetPosition[] sceneResetPositions)
 {
     if (sceneResetPositions != null)
     {
         GameObject resetObj = resetButton.gameObject;
         foreach (VRC_SceneResetPosition sceneResetPosition in sceneResetPositions)
         {
             UnityEventTools.RemovePersistentListener(resetButton.onClick, sceneResetPosition.ResetPosition);
             UnityEventTools.AddPersistentListener(resetButton.onClick, sceneResetPosition.ResetPosition);
         }
     }
 }
Beispiel #20
0
    private static void AddButtonListener(GameObject _go, ref bool _hasChange)
    {
        Button bt = _go.GetComponent <Button>();

        if (bt != null)
        {
            int num = bt.onClick.GetPersistentEventCount();

            List <int> delList = null;

            for (int i = 0; i < num; i++)
            {
                UnityEngine.Object t = bt.onClick.GetPersistentTarget(i);

                string methodName = bt.onClick.GetPersistentMethodName(i);

                if (t is MonoBehaviour)
                {
                    if (delList == null)
                    {
                        delList = new List <int>();
                    }

                    delList.Add(i);

                    MonoBehaviour target = t as MonoBehaviour;

                    AddButtonListener addButtonListener = target.gameObject.AddComponent <AddButtonListener>();

                    addButtonListener.button = bt;

                    addButtonListener.scriptName = target.name;

                    addButtonListener.methodName = methodName;

                    _hasChange = true;
                }
            }

            if (delList != null)
            {
                for (int i = 0; i < delList.Count; i++)
                {
                    UnityEventTools.RemovePersistentListener(bt.onClick, delList[i] - i);
                }
            }
        }

        for (int i = 0; i < _go.transform.childCount; i++)
        {
            AddButtonListener(_go.transform.GetChild(i).gameObject, ref _hasChange);
        }
    }
Beispiel #21
0
 void CleanButtons()
 {
     for (int i = 0; i < skinButtons.Length; i++)
     {
         skinButtons[i].interactable = false;
         skinButtons[i].GetComponent <Image>().color  = prevColor;
         skinButtons[i].GetComponent <Image>().sprite = null;
     }
     UnityEventTools.RemovePersistentListener(skinButtons[currentButtonIndex].onClick, OpenButtonToSee);
     skinButtons[currentButtonIndex].transform.GetChild(0).gameObject.SetActive(true);
     skinButtons[currentButtonIndex].transform.GetChild(1).gameObject.SetActive(true);
 }
Beispiel #22
0
 // Bu fonksiyon Unlock Button' a tıklandığında çalışır. Diğer fonksiyonları harekete geçirir.
 public void UnlockButton()
 {
     for (int i = 0; i < skinButtons.Length; i++)
     {
         skinButtons[i].interactable = false;                        // Başlangıçta bütün butonları işlevsiz hale getirmeliyiz.
         skinButtons[i].GetComponent <Image>().color  = secondColor; // hepsinin rengi gri olarak ayarlanır.
         skinButtons[i].GetComponent <Image>().sprite = null;        //aynı şekilde hepsinin sprite'ı başlangıçta null'dur.
     }
     UnityEventTools.RemovePersistentListener(skinButtons[index].onClick, ActivateButton);
     skinButtons[index].transform.GetChild(0).gameObject.SetActive(true);
     skinButtons[index].transform.GetChild(1).gameObject.SetActive(true);
     StartCoroutine(enumerator(speed)); // Random değer üretip yapılan işlemleri burada başlatırız.
 }
Beispiel #23
0
    //HologlaInputに初期の関連づけを行う.
    static void ApplyHologlaInputSetting(HologlaCameraManager hologlaCameraManager, HologlaInput hologlaInput)
    {
        GazeInput gazeInput;

        gazeInput = hologlaCameraManager.GetComponent <GazeInput>( );
        UnityEventTools.RemovePersistentListener(hologlaInput.onPressLeftAndRight, gazeInput.InputLeftAndRightEvent);
        UnityEventTools.AddPersistentListener(hologlaInput.onPressLeftAndRight, gazeInput.InputLeftAndRightEvent);
        UnityEventTools.RemovePersistentListener(hologlaInput.LeftButtonComp.onClick, gazeInput.InputLeftEvent);
        UnityEventTools.AddPersistentListener(hologlaInput.LeftButtonComp.onClick, gazeInput.InputLeftEvent);
        UnityEventTools.RemovePersistentListener(hologlaInput.RightButtonComp.onClick, gazeInput.InputRightEvent);
        UnityEventTools.AddPersistentListener(hologlaInput.RightButtonComp.onClick, gazeInput.InputRightEvent);

        return;
    }
Beispiel #24
0
        void OnValidate()
        {
            if (Application.isPlaying)
            {
                return;
            }

            b = GetComponent <Button>();

            if (b != null)
            {
                UnityEventTools.RemovePersistentListener(b.onClick, Undo);
                UnityEventTools.AddPersistentListener(b.onClick, Undo);
            }
        }
Beispiel #25
0
        public static void RemoveListenerAuto <T0, T1, T2, T3>(this UnityEvent <T0, T1, T2, T3> @event, UnityAction <T0, T1, T2, T3> listener)
        {
#if UNITY_EDITOR
            try
            {
                UnityEventTools.RemovePersistentListener(@event, listener);
            }
            catch (ArgumentException)
            {
                Debug.LogWarning(MessageWarnFallbackRemove);
                @event.RemoveListener(listener);
            }
#else
            @event.RemoveListener(listener);
#endif
        }
    public virtual void LoadData()
    {
        CursorTarget target = GetComponent <CursorTarget>();

        UnityEventTools.RemovePersistentListener <CursorBehaviour>(target.CursorEnterEvent, OnEnter);
        UnityEventTools.RemovePersistentListener <CursorBehaviour>(target.CursorOverEvent, OnOver);
        UnityEventTools.RemovePersistentListener <CursorBehaviour>(target.CursorExitEvent, OnExit);
        UnityEventTools.RemovePersistentListener <CursorBehaviour>(target.CursorAButtonEvent, OnAButton);
        UnityEventTools.RemovePersistentListener <CursorBehaviour>(target.CursorBButtonEvent, OnBButton);

        UnityEventTools.AddPersistentListener(target.CursorEnterEvent, OnEnter);
        UnityEventTools.AddPersistentListener(target.CursorOverEvent, OnOver);
        UnityEventTools.AddPersistentListener(target.CursorExitEvent, OnExit);
        UnityEventTools.AddPersistentListener(target.CursorAButtonEvent, OnAButton);
        UnityEventTools.AddPersistentListener(target.CursorBButtonEvent, OnBButton);
    }
        public static void Bind(Transform root, MonoBehaviour context, int parentLevel = 0, string suffix = "_OnClick")
        {
            var ctx = context.GetType();

            Debug.Log($"Bind Buttons to *{suffix} Methods of {ctx} type");
            var methods      = ctx.GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            var scopeMethods = from m in methods
                               where m.Name.Contains(suffix)
                               select m;

            var btns      = root.GetComponentsInChildren <Button>();
            var scopeBtns = parentLevel <= 0 ? btns :
                            from b in btns
                            where b.transform.GetParentLevel(root) <= parentLevel
                            select b;

            foreach (var item in scopeBtns)
            {
                while (item.onClick.GetPersistentEventCount() > 0)
                {
                    UnityEventTools.RemovePersistentListener(item.onClick, item.onClick.GetPersistentEventCount() - 1);
                }

                var clickMethods = from m in scopeMethods
                                   where m.Name.ToLower().Contains(item.name.ToLower())
                                   select m;

                foreach (var cm in clickMethods)
                {
                    Debug.Log($"<Color=green>bind : {item.name} to {cm.Name} </Color>");
                    try
                    {
                        var callback = Delegate.CreateDelegate(typeof(UnityAction), context, cm.Name) as UnityAction;
                        UnityEventTools.AddPersistentListener(item.onClick, callback);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError($"Bind {item.name} to {cm.Name} is Falied with : " + ex);
                    }
                }

                if (item.onClick.GetPersistentEventCount() == 0)
                {
                    Debug.Log($"<Color=red>Method is not found for button : {item.name}. Please add {ctx}.{item.name}{suffix}() method to bint it to {item.name} button</Color>");
                }
            }
        }
Beispiel #28
0
        void OnValidate()
        {
            if (Application.isPlaying)
            {
                return;
            }

            iconImage.sprite = icon;

            b = GetComponent <Button>();

            if (b != null)
            {
                UnityEventTools.RemovePersistentListener(b.onClick, ChangeTool);
                UnityEventTools.AddPersistentListener(b.onClick, ChangeTool);
            }
        }
Beispiel #29
0
        // Remove a link between two nodes.
        public static void RemoveLinkNodes(
            Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent,
            Wiring.NodeBase nodeTo, MethodInfo targetMethod
        )
        {
            var methodName = targetMethod.Name;

            var eventCount = triggerEvent.GetPersistentEventCount();
            for (var i = 0; i < eventCount; i++)
            {
                if (nodeTo == triggerEvent.GetPersistentTarget(i) &&
                    methodName == triggerEvent.GetPersistentMethodName(i))
                {
                    UnityEventTools.RemovePersistentListener(triggerEvent, i);
                    break;
                }
            }
        }
Beispiel #30
0
        // Disconnect given two slots.
        public static void DisconnectSlots(Graphs.Slot fromSlot, Graphs.Slot toSlot)
        {
            var nodeTo       = ((Node)toSlot.node).runtimeInstance;
            var triggerEvent = GetEventOfOutputSlot(fromSlot);
            var targetMethod = GetMethodOfInputSlot(toSlot);

            var methodName = targetMethod.Name;

            var eventCount = triggerEvent.GetPersistentEventCount();

            for (var i = 0; i < eventCount; i++)
            {
                if (nodeTo == triggerEvent.GetPersistentTarget(i) &&
                    methodName == triggerEvent.GetPersistentMethodName(i))
                {
                    UnityEventTools.RemovePersistentListener(triggerEvent, i);
                    break;
                }
            }
        }