public void SetUp()
 {
     containingObject = new GameObject();
     subject          = containingObject.AddComponent <StateEmitter>();
     actionObject     = new GameObject();
     action           = actionObject.AddComponent <BooleanAction>();
 }
Esempio n. 2
0
    private void Start()
    {
        if (!grabAction)
        {
            grabAction = GetComponent <BooleanAction>();
        }
        if (GetComponent <InteractorFacade>().GrabAction == null)
        {
            GetComponent <InteractorFacade>().GrabAction = grabAction;
        }

        RefreshInputMappings();

        if (Application.isPlaying)
        {
            for (int i = 0; i < inputMappings.Length; i++)
            {
                if (inputMappings[i].mapName.Contains("Grab"))
                {
                    inputMappings[i].Activated.AddListener(GrabActivated);
                    inputMappings[i].Deactivated.AddListener(GrabDeactivated);
                }
            }
        }
    }
Esempio n. 3
0
        public void DisableSource()
        {
            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();
            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = oneSourceActionObject,
                Action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = twoSourceActionObject,
                Action    = twoSourceAction
            };

            subject.Add(oneActionSource);
            subject.Add(twoActionSource);

            Assert.IsTrue(subject.NonSubscribableElements[0].Enabled);
            Assert.IsTrue(subject.NonSubscribableElements[1].Enabled);

            subject.DisableSource(oneSourceActionObject);

            Assert.IsFalse(subject.NonSubscribableElements[0].Enabled);
            Assert.IsTrue(subject.NonSubscribableElements[1].Enabled);

            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
Esempio n. 4
0
        public static void EquateUnityEditorPauseWithApplicationPause(BooleanAction b)
        {
#if UNITY_EDITOR
            // This method is run whenever the playmode state is changed.
            UnityEditor.EditorApplication.pauseStateChanged += (UnityEditor.PauseState ps) => {
                b(ps == UnityEditor.PauseState.Paused);
            };
#endif
        }
Esempio n. 5
0
            /// <summary>
            /// Sets the <see cref="InteractorFacade.GrabAction"/> to the value of <see cref="TargetGrabAction"/>.
            /// </summary>
            /// <param name="cacheCurrentGrabAction">Caches the current <see cref="InteractorFacade.GrabAction"/> value to be restored later.</param>
            public virtual void SetTargetGrabAction(bool cacheCurrentGrabAction)
            {
                if (cacheCurrentGrabAction)
                {
                    cachedGrabAction = TargetFacade.GrabAction;
                }

                TargetFacade.GrabAction = TargetGrabAction;
            }
Esempio n. 6
0
    private void ShowValueEvent(BooleanAction booleanAction)
    {
        var serializedAction = new SerializedObject(booleanAction);

        var activated    = serializedAction.FindProperty("Activated");
        var valueChanged = serializedAction.FindProperty("ValueChanged");
        var deactivated  = serializedAction.FindProperty("Deactivated");

        EditorGUILayout.PropertyField(activated);
        EditorGUILayout.PropertyField(valueChanged);
        EditorGUILayout.PropertyField(deactivated);

        serializedAction.ApplyModifiedProperties();
    }
        public IEnumerator UnregisterEvenIfDisabled()
        {
            subject.enabled = true;
            yield return(null);

            GameObject    targetActionObject = new GameObject();
            BooleanAction targetAction       = targetActionObject.AddComponent <BooleanAction>();

            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = oneSourceActionObject,
                Action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = twoSourceActionObject,
                Action    = twoSourceAction
            };

            subject.Target = targetAction;
            subject.Sources.Add(oneActionSource);
            subject.Sources.Add(twoActionSource);
            subject.SourceLimits.Add(oneSourceActionObject);
            subject.SourceLimits.Add(twoSourceActionObject);

            Assert.AreEqual(2, targetAction.ReadOnlySources.Count);

            oneActionSource.Enabled = false;

            subject.SourceLimits.Remove(oneSourceActionObject);

            Assert.AreEqual(1, targetAction.ReadOnlySources.Count);
            Assert.AreEqual(twoSourceAction, targetAction.ReadOnlySources[0]);

            Object.DestroyImmediate(targetActionObject);
            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
        public IEnumerator RegisterSpecific()
        {
            subject.enabled = true;
            yield return(null);

            GameObject    targetActionObject = new GameObject();
            BooleanAction targetAction       = targetActionObject.AddComponent <BooleanAction>();

            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = oneSourceActionObject,
                Action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                Enabled   = true,
                Container = twoSourceActionObject,
                Action    = twoSourceAction
            };

            subject.Target = targetAction;
            subject.Sources.Add(oneActionSource);
            subject.Sources.Add(twoActionSource);

            Assert.AreEqual(0, targetAction.ReadOnlySources.Count);

            subject.SourceLimits.Add(twoSourceActionObject);

            Assert.AreEqual(1, targetAction.ReadOnlySources.Count);
            Assert.AreEqual(twoSourceAction, targetAction.ReadOnlySources[0]);
            Assert.AreEqual(twoSourceActionObject, subject.SourceLimits.SubscribableElements[0]);

            Object.DestroyImmediate(targetActionObject);
            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
        public void UnregisterEvenIfDisabled()
        {
            GameObject    targetActionObject = new GameObject();
            BooleanAction targetAction       = targetActionObject.AddComponent <BooleanAction>();

            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = oneSourceActionObject,
                action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = twoSourceActionObject,
                action    = twoSourceAction
            };

            subject.target = targetAction;
            subject.sources.Add(oneActionSource);
            subject.sources.Add(twoActionSource);
            subject.ManualOnEnable();

            Assert.AreEqual(2, targetAction.Sources.Count);

            oneActionSource.enabled = false;

            subject.Unregister(oneSourceActionObject);

            Assert.AreEqual(1, targetAction.Sources.Count);
            Assert.AreEqual(twoSourceAction, targetAction.Sources[0]);

            Object.DestroyImmediate(targetActionObject);
            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
        public void RegisterSpecific()
        {
            GameObject    targetActionObject = new GameObject();
            BooleanAction targetAction       = targetActionObject.AddComponent <BooleanAction>();

            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                container = oneSourceActionObject,
                action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                container = twoSourceActionObject,
                action    = twoSourceAction
            };

            subject.registerOnEnable = false;
            subject.target           = targetAction;
            subject.sources.Add(oneActionSource);
            subject.sources.Add(twoActionSource);

            Assert.AreEqual(0, targetAction.Sources.Count);

            subject.ManualOnEnable();
            subject.Register(twoSourceActionObject);

            Assert.AreEqual(1, targetAction.Sources.Count);
            Assert.AreEqual(twoSourceAction, targetAction.Sources[0]);
            Assert.AreEqual(twoSourceActionObject, subject.SourceLimit);

            Object.DestroyImmediate(targetActionObject);
            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
        public void RegisterOnEnable()
        {
            GameObject    targetActionObject = new GameObject();
            BooleanAction targetAction       = targetActionObject.AddComponent <BooleanAction>();

            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = oneSourceActionObject,
                action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = twoSourceActionObject,
                action    = twoSourceAction
            };

            subject.target = targetAction;
            subject.sources.Add(oneActionSource);
            subject.sources.Add(twoActionSource);

            Assert.AreEqual(0, targetAction.Sources.Count);

            subject.ManualOnEnable();

            Assert.AreEqual(2, targetAction.Sources.Count);
            Assert.IsNull(subject.SourceLimit);

            Object.DestroyImmediate(targetActionObject);
            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
        public void DisableSource()
        {
            GameObject    oneSourceActionObject = new GameObject();
            BooleanAction oneSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();
            GameObject    twoSourceActionObject = new GameObject();
            BooleanAction twoSourceAction       = oneSourceActionObject.AddComponent <BooleanAction>();

            ActionRegistrar.ActionSource oneActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = oneSourceActionObject,
                action    = oneSourceAction
            };

            ActionRegistrar.ActionSource twoActionSource = new ActionRegistrar.ActionSource
            {
                enabled   = true,
                container = twoSourceActionObject,
                action    = twoSourceAction
            };

            subject.registerOnEnable = false;
            subject.sources.Add(oneActionSource);
            subject.sources.Add(twoActionSource);

            Assert.IsTrue(subject.sources[0].enabled);
            Assert.IsTrue(subject.sources[1].enabled);

            subject.DisableSource(oneSourceActionObject);

            Assert.IsFalse(subject.sources[0].enabled);
            Assert.IsTrue(subject.sources[1].enabled);

            Object.DestroyImmediate(oneSourceActionObject);
            Object.DestroyImmediate(twoSourceActionObject);
        }
Esempio n. 13
0
 protected virtual void OnAfterFacadeChange()
 {
     cachedGrabAction       = TargetFacade.GrabAction;
     cachedVelocityTracker  = TargetFacade.VelocityTracker;
     cachedGrabPrecognition = TargetFacade.GrabPrecognition;
 }
Esempio n. 14
0
 /// <summary>
 /// Sets the adds the <see cref="source"/> to the Sources collection of the <see cref="target"/> <see cref="BooleanAction"/>.
 /// </summary>
 /// <param name="source">The <see cref="BooleanAction"/> to add as a source.</param>
 /// <param name="target">The <see cref="BooleanAction"/> to have the Sources collection updated.</param>
 protected virtual void SetInputSource(BooleanAction source, BooleanAction target)
 {
     target.ClearSources();
     target.AddSource(source);
 }
Esempio n. 15
0
 /// <summary>
 /// Adds the given <see cref="source"/> to the <see cref="NegativeInput"/> Sources collection.
 /// </summary>
 /// <param name="source">The <see cref="BooleanAction"/> to add to the Sources collection.</param>
 public virtual void SetNegativeInputSource(BooleanAction source)
 {
     SetInputSource(source, NegativeInput);
 }
Esempio n. 16
0
 /// <summary>
 /// Adds the given <see cref="source"/> to the <see cref="PositiveInput"/> Sources collection.
 /// </summary>
 /// <param name="source">The <see cref="BooleanAction"/> to add to the Sources collection.</param>
 public virtual void SetPositiveInputSource(BooleanAction source)
 {
     SetInputSource(source, PositiveInput);
 }