Пример #1
0
        private bool HasListenerFor(Interpolator interpolator)
        {
            int persistentEventCount = innerEvent.GetPersistentEventCount();

            for (int i = 0; i < persistentEventCount; i++)
            {
                if (innerEvent.GetPersistentTarget(i) == interpolator)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public void OnValidate()
        {
            if (interpolatorToAdd != null)
            {
                if (!HasListenerFor(interpolatorToAdd))
                {
                    UnityEditor.Events.UnityEventTools.AddPersistentListener(innerEvent, interpolatorToAdd.Interpolate);
                }

                interpolatorToAdd = null;
            }

            if (interpolatorsToAdd != null)
            {
                foreach (var interpolator in interpolatorsToAdd.GetComponents <Interpolator>())
                {
                    if (HasListenerFor(interpolator))
                    {
                        continue;
                    }

                    UnityEditor.Events.UnityEventTools.AddPersistentListener(innerEvent, interpolator.Interpolate);
                }

                interpolatorsToAdd = null;
            }

            int persistentListenerIndex = persistentEventCount;

            while (persistentListenerIndex < innerEvent.GetPersistentEventCount())
            {
                innerEvent.SetPersistentListenerState(persistentListenerIndex, UnityEventCallState.EditorAndRuntime);

                persistentListenerIndex++;
            }

            persistentEventCount = innerEvent.GetPersistentEventCount();
        }