Пример #1
0
    public static void SetupEvents(Equippable equip)
    {
        ItemPickup pickup   = equip.GetComponent <ItemPickup>();
        Collider   collider = equip.GetComponent <Collider>();

        bool pickupHides   = !pickup || !pickup.worldView;
        bool colliderHides = !(collider != null);
        bool skinShows     = !equip.equip;

        if (equip.equipped != null)
        {
            for (int i = 0; i < equip.equipped.GetPersistentEventCount(); i++)
            {
                string method       = equip.equipped.GetPersistentMethodName(i);
                var    targetObject = equip.equipped.GetPersistentTarget(i);

                if (!colliderHides && (method == "set_enabled") && (targetObject == collider))
                {
                    colliderHides = true;
                }
                else if (!skinShows && (method == "SetActive") && (targetObject == equip.equip.gameObject))
                {
                    skinShows = true;
                }
                else if (!pickupHides && (method == "SetActive") && (targetObject == pickup.worldView.gameObject))
                {
                    pickupHides = true;
                }
            }
        }

        if (equip.equipped == null)
        {
            equip.equipped = new UnityEngine.Events.UnityEvent();
        }

        if (!skinShows)
        {
            UnityEventTools.AddBoolPersistentListener(equip.equipped, new UnityEngine.Events.UnityAction <bool>(equip.equip.gameObject.SetActive), true);
        }
        if (!pickupHides)
        {
            UnityEventTools.AddBoolPersistentListener(equip.equipped, new UnityEngine.Events.UnityAction <bool>(pickup.worldView.gameObject.SetActive), false);
        }
        if (!colliderHides)
        {
            var test = Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction <bool>), collider, "set_enabled") as
                       UnityEngine.Events.UnityAction <bool>;

            UnityEventTools.AddBoolPersistentListener(equip.equipped, test, false);
        }
    }
Пример #2
0
    private static void M_ExampleUI()
    {
        string UIPath = "Assets/PUNMultiplayerInvectorAddon/UI/Example UI.prefab";

        UnityEngine.Object prefab = AssetDatabase.LoadMainAssetAtPath(UIPath);
        GameObject         target = (GameObject)prefab;
        GameObject         UI     = PrefabUtility.InstantiatePrefab(target) as GameObject;

        UI.transform.SetParent(FindObjectOfType <PUN_NetworkManager>().transform);

        //Add needed custom action to remove UI
        UnityAction <bool> action = UI.SetActive;

        UnityEventTools.AddBoolPersistentListener(FindObjectOfType <PUN_NetworkManager>()._customNetworkEvents._roomEvents._onJoinedRoom, action, false);
    }
Пример #3
0
            public void Bind(UnityEvent @event)
            {
#if UNITY_EDITOR
                if (value == null)
                {
                    System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                    if (targetinfo == null)
                    {
                        Debug.LogError("no method " + setMethodName + "() in " + target.ToString());
                    }
                    UnityAction action = Delegate.CreateDelegate(typeof(UnityAction), target, targetinfo, false) as UnityAction;
                    UnityEventTools.AddVoidPersistentListener(@event, action);
                }
                else if (value is int)
                {
                    UnityEventTools.AddIntPersistentListener(@event, GetAction <int>(target, setMethodName), (int)value);
                }
                else if (value is float)
                {
                    UnityEventTools.AddFloatPersistentListener(@event, GetAction <float>(target, setMethodName), (float)value);
                }
                else if (value is string)
                {
                    UnityEventTools.AddStringPersistentListener(@event, GetAction <string>(target, setMethodName), (string)value);
                }
                else if (value is bool)
                {
                    UnityEventTools.AddBoolPersistentListener(@event, GetAction <bool>(target, setMethodName), (bool)value);
                }
                else if (value is GameObject)
                {
                    Bind <GameObject>(@event);
                }
                else if (value is Transform)
                {
                    Bind <Transform>(@event);
                }
                else
                {
                    Debug.LogError("unable to assign " + value.GetType());
                }
#else
                System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                @event.AddListener(() => targetinfo.Invoke(target, new object[] { value }));
#endif
            }
Пример #4
0
    public static void AddSetActiveEventsToButton()
    {
        Button button = Selection.gameObjects.First(a => a.GetComponent <Button>() != null).GetComponent <Button>();

        foreach (var item in Selection.gameObjects)
        {
            UnityAction <bool> action = null;
            if (item != button.gameObject)
            {
                action = item.SetActive;
            }
            else
            {
                action = button.transform.parent.gameObject.SetActive;
            }
            UnityEventTools.AddBoolPersistentListener(button.onClick, action, false);
        }
    }
Пример #5
0
    private void Create()
    {
        // Create root gameobject

        GameObject gameObject = new GameObject("NewMissile");

        Selection.activeGameObject = gameObject;

        // Create 3D model

        if (missileModel != null)
        {
            GameObject meshObject = Instantiate(missileModel, gameObject.transform);
            meshObject.name = "Model";
            meshObject.transform.localPosition = Vector3.zero;
            meshObject.transform.localRotation = Quaternion.identity;
        }

        // Create the visual effects

        if (exhaustVisualEffects != null)
        {
            GameObject exhaustVisualEffectsObject = Instantiate(exhaustVisualEffects, gameObject.transform);
            exhaustVisualEffectsObject.name = "ExhaustVisualEffects";
            exhaustVisualEffectsObject.transform.localPosition = Vector3.zero;
            exhaustVisualEffectsObject.transform.localRotation = Quaternion.identity;
        }

        // ************************ AUDIO ***************************

        // Create an object to store the audio under
        GameObject audioObject = new GameObject("Audio");

        audioObject.transform.parent        = gameObject.transform;
        audioObject.transform.localPosition = Vector3.zero;
        audioObject.transform.localRotation = Quaternion.identity;

        // Create the launch audio

        if (launchAudioClip != null)
        {
            GameObject launchAudioObject = new GameObject("LaunchAudio");
            launchAudioObject.transform.parent        = audioObject.transform;
            launchAudioObject.transform.localPosition = Vector3.zero;
            launchAudioObject.transform.localRotation = Quaternion.identity;

            AudioSource launchAudioSource = launchAudioObject.AddComponent <AudioSource>();
            launchAudioSource.clip        = launchAudioClip;
            launchAudioSource.playOnAwake = true;
            launchAudioSource.loop        = false;
        }

        // Create the exhaust audio

        if (exhaustAudioClip != null)
        {
            GameObject exhaustAudioObject = new GameObject("ExhaustAudio");
            exhaustAudioObject.transform.parent        = audioObject.transform;
            exhaustAudioObject.transform.localPosition = Vector3.zero;
            exhaustAudioObject.transform.localRotation = Quaternion.identity;

            AudioSource exhaustAudioSource = exhaustAudioObject.AddComponent <AudioSource>();
            exhaustAudioSource.clip        = exhaustAudioClip;
            exhaustAudioSource.playOnAwake = true;
            exhaustAudioSource.loop        = true;
        }

        // ************************ Main Components ***************************

        // Add a rigidbody

        Rigidbody rBody = gameObject.AddComponent <Rigidbody>();

        rBody.useGravity = false;

        // Add the Missile component

        Missile          missile   = gameObject.AddComponent <Missile>();
        SerializedObject missileSO = new SerializedObject(missile);

        missileSO.Update();

        // Add a Target Locker

        TargetLocker     targetLocker   = gameObject.AddComponent <TargetLocker>();
        SerializedObject targetLockerSO = new SerializedObject(targetLocker);

        targetLockerSO.Update();

        targetLockerSO.FindProperty("lockingEnabled").boolValue = false;
        targetLockerSO.ApplyModifiedProperties();

        // Add a target leader

        TargetLeader     targetLeader   = gameObject.AddComponent <TargetLeader>();
        SerializedObject targetLeaderSO = new SerializedObject(targetLeader);

        targetLeaderSO.Update();

        // Add engines

        VehicleEngines3D engines   = gameObject.AddComponent <VehicleEngines3D>();
        SerializedObject enginesSO = new SerializedObject(engines);

        enginesSO.Update();

        // Add a guidance system

        GuidanceController guidanceController   = gameObject.AddComponent <GuidanceController>();
        SerializedObject   guidanceControllerSO = new SerializedObject(guidanceController);

        guidanceControllerSO.Update();

        // Update the guidance system settings
        guidanceControllerSO.FindProperty("engines").objectReferenceValue = engines;
        guidanceControllerSO.ApplyModifiedProperties();

        // Add a Detonator

        Detonator        detonator   = gameObject.AddComponent <Detonator>();
        SerializedObject detonatorSO = new SerializedObject(detonator);

        detonatorSO.Update();

        if (explosion != null)
        {
            detonatorSO.FindProperty("detonatingDuration").floatValue         = 2;
            detonatorSO.FindProperty("detonatingStateSpawnObjects").arraySize = 1;
            detonatorSO.FindProperty("detonatingStateSpawnObjects").GetArrayElementAtIndex(0).objectReferenceValue = explosion;
            detonatorSO.ApplyModifiedProperties();
        }

        UnityEventTools.AddBoolPersistentListener(detonator.onDetonating, engines.SetRigidbodyKinematic, true);
        UnityEventTools.AddBoolPersistentListener(detonator.onDetonated, gameObject.SetActive, false);
        UnityEventTools.AddBoolPersistentListener(detonator.onReset, engines.SetRigidbodyKinematic, false);

        // Add Health Modifier

        HealthModifier   healthModifier   = gameObject.AddComponent <HealthModifier>();
        SerializedObject healthModifierSO = new SerializedObject(healthModifier);

        healthModifierSO.Update();


        if (areaDamage)
        {
            // Add a damage receiver scanner for the area damage

            GameObject areaDamageScannerObject = new GameObject("AreaDamageScanner");
            areaDamageScannerObject.transform.parent        = gameObject.transform;
            areaDamageScannerObject.transform.localPosition = Vector3.zero;
            areaDamageScannerObject.transform.localRotation = Quaternion.identity;

            // Add a kinematic rigidbody

            Rigidbody areaDamageScannerRigidbody = areaDamageScannerObject.AddComponent <Rigidbody>();
            areaDamageScannerRigidbody.isKinematic = true;

            // Add a sphere trigger collider and set the radius

            SphereCollider areaDamageScannerCollider = areaDamageScannerObject.AddComponent <SphereCollider>();
            areaDamageScannerCollider.isTrigger = true;
            areaDamageScannerCollider.radius    = 20;

            // Add a damage receiver scanner

            DamageReceiverScanner areaDamageScanner   = areaDamageScannerObject.AddComponent <DamageReceiverScanner>();
            SerializedObject      areaDamageScannerSO = new SerializedObject(areaDamageScanner);
            areaDamageScannerSO.FindProperty("scannerTriggerCollider").objectReferenceValue = areaDamageScannerCollider;
            areaDamageScannerSO.ApplyModifiedProperties();

            healthModifierSO.FindProperty("areaDamageReceiverScanner").objectReferenceValue = areaDamageScanner;
            healthModifierSO.ApplyModifiedProperties();
        }

        // Add a collision scanner

        CollisionScanner collisionScanner   = gameObject.AddComponent <CollisionScanner>();
        SerializedObject collisionScannerSO = new SerializedObject(collisionScanner);

        collisionScannerSO.Update();

        // Collision scanner settings
        if (areaDamage)
        {
            UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, healthModifier.RaycastHitAreaDamage);
        }
        else
        {
            UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, healthModifier.RaycastHitDamage);
        }

        UnityEventTools.AddPersistentListener(collisionScanner.onHitDetected, detonator.Detonate);


        if (targetProximityDetonation)
        {
            // Add a target proximity trigger to the root transform

            TargetProximityTrigger targetProximityTrigger   = gameObject.AddComponent <TargetProximityTrigger>();
            SerializedObject       targetProximityTriggerSO = new SerializedObject(targetProximityTrigger);
            targetProximityTriggerSO.Update();


            // Create an object for the proximity scanner trigger collider

            GameObject proximityTriggerColliderObject = new GameObject("TargetProximityScanner");
            proximityTriggerColliderObject.transform.parent        = gameObject.transform;
            proximityTriggerColliderObject.transform.localPosition = Vector3.zero;
            proximityTriggerColliderObject.transform.localRotation = Quaternion.identity;

            // Add a kinematic rigidbody

            Rigidbody proximityTriggerColliderRigidbody = proximityTriggerColliderObject.AddComponent <Rigidbody>();
            proximityTriggerColliderRigidbody.isKinematic = true;

            // Add a sphere trigger collider and set the radius

            SphereCollider sphereCollider = proximityTriggerColliderObject.AddComponent <SphereCollider>();
            sphereCollider.isTrigger = true;
            sphereCollider.radius    = 20;

            // Add a damage receiver scanner

            DamageReceiverScanner damageReceiverScanner   = proximityTriggerColliderObject.AddComponent <DamageReceiverScanner>();
            SerializedObject      damageReceiverScannerSO = new SerializedObject(damageReceiverScanner);
            damageReceiverScannerSO.Update();

            // Link the collider to the damage receiver scanner

            damageReceiverScannerSO.FindProperty("scannerTriggerCollider").objectReferenceValue = sphereCollider;
            damageReceiverScannerSO.ApplyModifiedProperties();
            damageReceiverScannerSO.Update();

            // Link the scanner to the proximity trigger

            targetProximityTriggerSO.FindProperty("scanner").objectReferenceValue = damageReceiverScanner;
            targetProximityTriggerSO.ApplyModifiedProperties();
            targetProximityTriggerSO.Update();

            UnityEventTools.AddPersistentListener(targetProximityTrigger.onTriggered, healthModifier.EmitDamage);
            UnityEventTools.AddPersistentListener(targetProximityTrigger.onTriggered, detonator.Detonate);

            UnityEventTools.AddPersistentListener(targetLocker.onLocked, targetProximityTrigger.SetTarget);
        }

        // Update the target locker settings

        UnityEventTools.AddPersistentListener(targetLocker.onLocked, targetLeader.SetTarget);
        UnityEventTools.AddVoidPersistentListener(targetLocker.onNoLock, targetLeader.ClearTarget);
        UnityEventTools.AddFloatPersistentListener(targetLocker.onNoLock, detonator.BeginDelayedDetonation, 4);

        // Update the target leader settings
        UnityEventTools.AddPersistentListener(targetLeader.onLeadTargetPositionUpdated, guidanceController.SetTargetPosition);

        missileSO.FindProperty("targetLocker").objectReferenceValue = targetLocker;
        missileSO.ApplyModifiedProperties();
    }
Пример #6
0
    private void AddCameraEventsForTrackingEngine(TrackingEngine engine)
    {
        Camera     camera     = null;
        UnityEvent startEvent = null;
        UnityEvent stopEvent  = null;

        if (engine == TrackingEngine.ARCore)
        {
            if (aryzonTracking.arCoreTransform)
            {
                camera     = aryzonTracking.arCoreTransform.gameObject.GetComponent <Camera> ();
                startEvent = aryzonTracking.onARCoreStart;
                stopEvent  = aryzonTracking.onARCoreStop;
            }
            else
            {
                return;
            }
        }
        else if (engine == TrackingEngine.ARKit)
        {
            if (aryzonTracking.arKitTransform)
            {
                camera     = aryzonTracking.arKitTransform.gameObject.GetComponent <Camera> ();
                startEvent = aryzonTracking.onARKitStart;
                stopEvent  = aryzonTracking.onARKitStop;
            }
            else
            {
                return;
            }
        }
        else if (engine == TrackingEngine.Vuforia)
        {
            if (aryzonTracking.vuforiaTransform)
            {
                camera     = aryzonTracking.vuforiaTransform.gameObject.GetComponent <Camera> ();
                startEvent = aryzonTracking.onVuforiaStart;
                stopEvent  = aryzonTracking.onVuforiaStop;
            }
            else
            {
                return;
            }
        }
        else if (engine == TrackingEngine.Other)
        {
            if (aryzonTracking.otherTransform)
            {
                camera     = aryzonTracking.otherTransform.gameObject.GetComponent <Camera> ();
                startEvent = aryzonTracking.onOtherStart;
                stopEvent  = aryzonTracking.onOtherStop;
            }
            else
            {
                return;
            }
        }
        else if (engine == TrackingEngine.None)
        {
            return;
        }

        if (camera == null)
        {
            return;
        }

        int startCount = startEvent.GetPersistentEventCount();
        int stopCount  = stopEvent.GetPersistentEventCount();

        bool startEventFound = false;
        bool stopEventFound  = false;

        for (int i = 0; i < startCount; i++)
        {
            if (startEvent.GetPersistentTarget(i) == camera && startEvent.GetPersistentMethodName(i) == "set_enabled")
            {
                startEventFound = true;
                break;
            }
        }

        for (int i = 0; i < stopCount; i++)
        {
            if (stopEvent.GetPersistentTarget(i) == camera && stopEvent.GetPersistentMethodName(i) == "set_enabled")
            {
                stopEventFound = true;
                break;
            }
        }

        MethodInfo method = null;

        if (!startEventFound || !stopEventFound)
        {
            method = typeof(UnityEngine.Camera).GetMethod("set_enabled");
            if (engine == TrackingEngine.ARCore)
            {
                //aryzonTracking.showARCoreEvents = true;
                EditorPrefs.SetBool("showARCoreEvents", true);
            }
            else if (engine == TrackingEngine.ARKit)
            {
                //aryzonTracking.showARKitEvents = true;
                EditorPrefs.SetBool("showARKitEvents", true);
            }
            else if (engine == TrackingEngine.Vuforia)
            {
                //aryzonTracking.showVuforiaEvents = true;
                EditorPrefs.SetBool("showVuforiaEvents", true);
            }
            else if (engine == TrackingEngine.Other)
            {
                //aryzonTracking.showOtherEvents = true;
                EditorPrefs.SetBool("showOtherEvents", true);
            }
        }

        if (!startEventFound)
        {
            UnityAction <bool> startAction = System.Delegate.CreateDelegate(typeof(UnityAction <bool>), camera, method) as UnityAction <bool>;
            UnityEventTools.AddBoolPersistentListener(startEvent, startAction, false);
        }

        if (!stopEventFound)
        {
            UnityAction <bool> stopAction = System.Delegate.CreateDelegate(typeof(UnityAction <bool>), camera, method) as UnityAction <bool>;
            UnityEventTools.AddBoolPersistentListener(stopEvent, stopAction, true);
        }
    }
Пример #7
0
        void C_vItemCollection(GameObject target)
        {
            if (_cvItemCollections == false)
            {
                return;
            }
            if (!target.GetComponent <vItemCollection>())
            {
                return;
            }
            E_Helpers.SetObjectIcon(target, E_Core.h_genericIcon);
            if (!target.GetComponent <PhotonView>())
            {
                target.AddComponent <PhotonView>();
            }
            if (!target.transform.GetComponentInParent <PhotonView>() && !target.GetComponent <PhotonView>())
            {
                target.AddComponent <PhotonView>();
            }
            if (!target.GetComponent <SyncItemCollection>())
            {
                target.AddComponent <SyncItemCollection>();
            }
            bool useTarget = (target.GetComponent <vItemCollection>().onPressActionInputWithTarget.GetPersistentEventCount() > 0);

            // Copy Original Values to MP component
            target.GetComponent <SyncItemCollection>().onPressActionDelay           = target.GetComponent <vItemCollection>().onPressActionDelay;
            target.GetComponent <SyncItemCollection>().OnPressActionInput           = target.GetComponent <vItemCollection>().OnPressActionInput;
            target.GetComponent <SyncItemCollection>().onPressActionInputWithTarget = target.GetComponent <vItemCollection>().onPressActionInputWithTarget;

            target.GetComponent <SyncItemCollection>().GetType().GetField("syncCreateDestroy", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), false);
            target.GetComponent <SyncItemCollection>().GetType().GetField("skipStartCheck", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), target.GetComponent <vItemCollection>().items.Count > 0);

            // Clear Original Values
            target.GetComponent <vItemCollection>().onPressActionDelay           = 0.0f;
            target.GetComponent <vItemCollection>().OnPressActionInput           = new UnityEvent();
            target.GetComponent <vItemCollection>().onPressActionInputWithTarget = new OnDoActionWithTarget();

            // Set Scene Sync Options
            target.GetComponent <SyncItemCollection>().GetType().GetField("syncCrossScenes", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), true);
            target.GetComponent <SyncItemCollection>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(target.GetComponent <SyncItemCollection>(), target.transform);

            if (target.GetComponent <vItemCollection>().destroyAfter == true)
            {
                target.GetComponent <SyncItemCollection>().OnSceneEnterUpdate = new UnityEvent();
                UnityEventTools.AddBoolPersistentListener(target.GetComponent <SyncItemCollection>().OnSceneEnterUpdate, target.SetActive, false);
            }

            // Set OpenChest Listener on original component
            if (useTarget == true)
            {
                UnityEventTools.AddPersistentListener(target.GetComponent <vItemCollection>().onPressActionInputWithTarget, target.GetComponent <SyncItemCollection>().Collect);
            }
            else
            {
                UnityEventTools.AddPersistentListener(target.GetComponent <vItemCollection>().OnPressActionInput, target.GetComponent <SyncItemCollection>().Collect);
            }
            //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<SyncItemCollection>().OnSceneEnterUpdate, "SetActive", target))
            //{
            //    UnityEventTools.AddBoolPersistentListener(target.GetComponent<SyncItemCollection>().OnSceneEnterUpdate, target.SetActive, false);
            //}
        }
Пример #8
0
        public static void CB_AddGlobalChatBox()
        {
            if (!FindObjectOfType <NetworkManager>())
            {
                if (EditorUtility.DisplayDialog("Missing Network Manager", "No NetworkManager object was found in this scene. In order for this component to work properly there must be a network manager in the scene. Please add a \"NetworkManager\" component to the scene.",
                                                "Okay"))
                {
                }
            }
            else if (FindObjectOfType <ChatBox>())
            {
                Selection.activeGameObject = FindObjectOfType <ChatBox>().gameObject;
                if (EditorUtility.DisplayDialog("Scene Already Has ChatBox", "This scene already contains a \"ChatBox\" component. You should never add more than one at a time to a scene.",
                                                "Okay"))
                {
                }
            }
            else
            {
                string     chatBoxPrefabPath = string.Format("Assets{0}InvectorMultiplayer{0}UI{0}ChatBox.prefab", Path.DirectorySeparatorChar);
                GameObject ChatBox           = E_Helpers.CreatePrefabFromPath(chatBoxPrefabPath);
                ChatBox.transform.SetParent(FindObjectOfType <NetworkManager>().transform);
                ChatBox.GetComponent <ChatBox>().nm = FindObjectOfType <NetworkManager>();
                ChatBox.GetComponent <ChatBox>().GetType().GetField("openChatWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "T"
                });
                ChatBox.GetComponent <ChatBox>().GetType().GetField("closeWindowOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "Escape"
                });
                ChatBox.GetComponent <ChatBox>().GetType().GetField("sendChatOnPress", E_Helpers.allBindings).SetValue(ChatBox.GetComponent <ChatBox>(), new List <string> {
                    "KeypadEnter", "Return"
                });
                E_Helpers.SetObjectIcon(ChatBox, E_Core.h_textChatIcon);

                //Join Room Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "SetActiveRoomAsChannelName", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().SetActiveRoomAsChannelName);
                }
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "Connect", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().Connect);
                }
                if (E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinedRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, true);
                }

                //Left Room Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, "EnableVisualBox", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onLeftRoom, ChatBox.GetComponent <ChatBox>().EnableVisualBox, false);
                }

                //Joined Room Failed Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, "SetActiveChannel", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().roomEvents._onJoinRoomFailed, ChatBox.GetComponent <ChatBox>().SetActiveChannel, "lobbyChat");
                }

                // Misc - OnDisconnect Events
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "Disconnect", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddStringPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().Disconnect, "");
                }
                if (!E_PlayerEvents.HasUnityEvent(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, "EnableChat", ChatBox.GetComponent <ChatBox>()))
                {
                    UnityEventTools.AddBoolPersistentListener(FindObjectOfType <NetworkManager>().otherEvents._onDisconnected, ChatBox.GetComponent <ChatBox>().EnableChat, false);
                }
            }
        }
Пример #9
0
        // Try to create a link between two nodes.
        // Returns true if the link is established successfully.
        public static bool TryLinkNodes(
            Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent,
            Wiring.NodeBase nodeTo, MethodInfo targetMethod
        )
        {
            // Determine the type of the target action.
            var actionType = GetUnityActionToInvokeMethod(targetMethod);

            if (actionType == null) return false; // invalid target method type

            // Create an action that is bound to the target method.
            var targetAction = System.Delegate.CreateDelegate(
                actionType, nodeTo, targetMethod
            );

            if (triggerEvent is UnityEvent)
            {
                // The trigger event has no parameter.
                // Add the action to the event with a default parameter.
                if (actionType == typeof(UnityAction))
                {
                    UnityEventTools.AddVoidPersistentListener(
                        triggerEvent, (UnityAction)targetAction
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<bool>))
                {
                    UnityEventTools.AddBoolPersistentListener(
                        triggerEvent, (UnityAction<bool>)targetAction, false
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<int>))
                {
                    UnityEventTools.AddIntPersistentListener(
                        triggerEvent, (UnityAction<int>)targetAction, 0
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<float>))
                {
                    UnityEventTools.AddFloatPersistentListener(
                        triggerEvent, (UnityAction<float>)targetAction, 0.0f
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<bool>)
            {
                // The trigger event has a bool parameter.
                // Then the target method should have a bool parameter too.
                if (actionType == typeof(UnityAction<bool>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<bool>)triggerEvent,
                       (UnityAction<bool>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<int>)
            {
                // The trigger event has an int parameter.
                // Then the target method should have an int parameter too.
                if (actionType == typeof(UnityAction<int>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<int>)triggerEvent,
                       (UnityAction<int>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<float>)
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction<float>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<float>)triggerEvent,
                       (UnityAction<float>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Vector3>)
            {
                // The trigger event has a Vector3 parameter.
                // Then the target method should have a Vector3 parameter too.
                if (actionType == typeof(UnityAction<Vector3>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Vector3>)triggerEvent,
                       (UnityAction<Vector3>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Color>)
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction<Color>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Color>)triggerEvent,
                       (UnityAction<Color>)targetAction
                    );
                    return true;
                }
            }

            return false; // trigger-target mismatch
        }
Пример #10
0
 public static void AddPersistentListener(this UnityEventBase self, UnityAction <bool> unityAction, bool argument)
 {
     UnityEventTools.AddBoolPersistentListener(self, unityAction, argument);
 }