/// <summary> /// Add an action to the UnityEvent displayed in the editor. /// </summary> /// <param name="button">The object that will listen to the event.</param> /// <param name="action">The action to trigger.</param> /// <returns>Success state.</returns> public static bool AddPersistentEvent(this UnityEvent @event, UnityEngine.Object caller, UnityAction <float> method, float argument) { #if !UNITY_EDITOR return(false); #else if (@event.HasCall(caller, method.Method.Name)) { return(false); } var targetInfo = UnityEventBase.GetValidMethodInfo(caller, method.Method.Name, new Type[] { typeof(float) }); UnityAction <float> methodDelegate = Delegate.CreateDelegate(typeof(UnityAction <float>), caller, targetInfo) as UnityAction <float>; UnityEventTools.AddFloatPersistentListener(@event, methodDelegate, argument); UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); #endif return(true); }
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 }
// Create a connection between two slots. public static bool ConnectSlots(Graphs.Slot fromSlot, Graphs.Slot toSlot) { EnumTypes(); var nodeTo = ((Node)toSlot.node).runtimeInstance; var triggerEvent = GetEventOfOutputSlot(fromSlot); var targetMethod = GetMethodOfInputSlot(toSlot); // 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 = 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 <float>)) { UnityEventTools.AddFloatPersistentListener( triggerEvent, (UnityAction <float>)targetAction, 1.0f ); 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 <int> ) { // The trigger event has a int parameter. // Then the target method should have a 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 <string> ) { // The trigger event has a string parameter. // Then the target method should have a string parameter too. if (actionType == typeof(UnityAction <string>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <string>)triggerEvent, (UnityAction <string>)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 <Quaternion> ) { // The trigger event has a Quaternion parameter. // Then the target method should have a Quaternion parameter too. if (actionType == typeof(UnityAction <Quaternion>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Quaternion>)triggerEvent, (UnityAction <Quaternion>)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); } } else if (triggerEvent is UnityEvent <Texture> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Texture>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Texture>)triggerEvent, (UnityAction <Texture>)targetAction ); return(true); } } return(false); // trigger-target mismatch }
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(); }
private void EcrireEffets() { SerializedProperty effet; SerializedProperty cible; SerializedProperty methode; SerializedProperty argumentFloat; SerializedProperty argumentInt; SerializedObject so = new SerializedObject(buff); effet = so.FindProperty("effets.m_PersistentCalls.m_Calls.Array"); InitialiserListeRetour(buff.listeEffetsRetours, effet.arraySize); EffetBonus bonus = effetRef.GetComponent <EffetBonus>(); for (int i = 0; i < effet.arraySize; i++) { cible = effet.FindPropertyRelative("data[" + i + "].m_Target"); methode = effet.FindPropertyRelative("data[" + i + "].m_MethodName"); argumentFloat = effet.FindPropertyRelative("data[" + i + "].m_Arguments.m_FloatArgument"); argumentInt = effet.FindPropertyRelative("data[" + i + "].m_Arguments.m_IntArgument"); string retour = ""; //Remet à 0 le nombre de listener persitent for (int j = 0; j < buff.antiEffets.GetPersistentEventCount(); j++) { UnityEventTools.RemovePersistentListener(buff.antiEffets, j); } if (methode.stringValue.Contains("Bonus")) { if (methode.stringValue.Contains("Attaque")) { char pluriel = '\0'; if (Math.Abs(argumentInt.intValue) != 1) { pluriel = 's'; } if (argumentInt.intValue > 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+" + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " d'attaque"; } else if (argumentInt.intValue < 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " d'attaque"; } UnityAction <int> callback = new UnityAction <int>(bonus.ajouterBonusAttaque); UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else if (methode.stringValue.Contains("Defense")) { char pluriel = '\0'; if (Math.Abs(argumentInt.intValue) != 1) { pluriel = 's'; } if (argumentInt.intValue > 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+" + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " de défense"; } else if (argumentInt.intValue < 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " de défense"; } UnityAction <int> callback = new UnityAction <int>(bonus.ajouterBonusDefense); UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else if (methode.stringValue.Contains("DegatMoral")) { if (argumentInt.intValue > 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">++" + "<color=\"white\"> dégat moral"; } else if (argumentInt.intValue < 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">--" + "<color=\"white\"> dégat moral"; } UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDegatMoral); UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else if (methode.stringValue.Contains("Deplacement")) { char pluriel = '\0'; if (Math.Abs(argumentInt.intValue) != 1) { pluriel = 's'; } if (argumentInt.intValue > 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+" + argumentInt.intValue + "<color=\"white\"> point" + pluriel + " de déplacement"; } else if (argumentInt.intValue < 0) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + argumentInt.intValue + "<color=\"white\"> point" + pluriel + " de déplacement"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDeplacementToutesTribus); UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDeplacement); UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else if (methode.stringValue.Contains("MultiplicateurCoutPop")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Cout d'une population"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Cout d'une population"; } if (argumentFloat.floatValue == 0) { retour = "Cout d'une populaiton< color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + "> gratuit"; } UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultiplicateurCoutPop); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentFloat.floatValue * -1); } else if (methode.stringValue.Contains("MultiplicateurStockage")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Capacité de stockage"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Capacité de stockage"; } if (argumentFloat.floatValue == 0) { retour = "Capacité de stockage< color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMutliplicateurStockage); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentFloat.floatValue * -1); } else if (methode.stringValue.Contains("MultProd")) { if (methode.stringValue.Contains("Nourriture")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production Nourriture"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production Nourriture"; } if (argumentFloat.floatValue == 0) { retour = "Production Nourriture<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdNourritureToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdNourriture); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else if (methode.stringValue.Contains("Pierre")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production Pierre"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production Pierre"; } if (argumentFloat.floatValue == 0) { retour = "Production Pierre<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPierreToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPierre); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else if (methode.stringValue.Contains("Peau")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production Peau"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production Peau"; } if (argumentFloat.floatValue == 0) { retour = "Production Peau<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPeauToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPeau); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else if (methode.stringValue.Contains("Outil")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production Outil"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production Outil"; } if (argumentFloat.floatValue == 0) { retour = "Production Outil<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdOutilToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdOutil); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else if (methode.stringValue.Contains("Pigment")) { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production Pigment"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production Pigment"; } if (argumentFloat.floatValue == 0) { retour = "Production Pigment<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPigmentToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPigment); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } else { if (argumentFloat.floatValue > 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" + "++<color=\"white\"> Production"; } else if (argumentFloat.floatValue < 1) { retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" + "--<color=\"white\"> Production"; } if (argumentFloat.floatValue == 0) { retour = "Production<color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE"; } if (methode.stringValue.Contains("ToutesTribus")) { retour += " pour toutes les tribus"; UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdToutesTribus); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } else { UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProd); UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1); } } } } if (buff.compteurTour) { if (!buff.name.Contains("SpawnTroupeau")) { char pluriel = '\0'; if (buff.nombreTour > 0) { pluriel = 's'; } retour += " pendant " + buff.nombreTour + " tour" + pluriel; } else { retour = ""; } } else if (buff.tpsDuneTechno) { } else if (buff.tpsDunEvent) { retour += " jusqu'à la fin de l'évenement"; } buff.listeEffetsRetours[i] = retour; } }
// Try to create a link between two nodes. // Returns true if the link is established successfully. public static bool TryLinkNodes( NodeBase nodeFrom, Outlet outlet, NodeBase nodeTo, MethodInfo targetMethod ) { var triggerEvent = outlet.boundEvent; // 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 = 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 <float>)) { UnityEventTools.AddFloatPersistentListener( triggerEvent, (UnityAction <float>)targetAction, 1.0f ); return(true); } //if (actionType == typeof(UnityAction<object>)) //{ // UnityEventTools.AddPersistentListener( // triggerEvent, (UnityAction<object>)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 <int> ) { // The trigger event has a float parameter. // Then the target method should have a float 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 <string> ) { // The trigger event has a float parameter. // Then the target method should have a float parameter too. if (actionType == typeof(UnityAction <string>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <string>)triggerEvent, (UnityAction <string>)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 <Quaternion> ) { // The trigger event has a Quaternion parameter. // Then the target method should have a Quaternion parameter too. if (actionType == typeof(UnityAction <Quaternion>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Quaternion>)triggerEvent, (UnityAction <Quaternion>)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); } } else if (triggerEvent is UnityEvent <GameObject> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <GameObject>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <GameObject>)triggerEvent, (UnityAction <GameObject>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Transform> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Transform>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Transform>)triggerEvent, (UnityAction <Transform>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Collision> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Collision>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Collision>)triggerEvent, (UnityAction <Collision>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Collider> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Collider>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Collider>)triggerEvent, (UnityAction <Collider>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Rigidbody> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Rigidbody>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Rigidbody>)triggerEvent, (UnityAction <Rigidbody>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Collision2D> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Collision2D>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Collision2D>)triggerEvent, (UnityAction <Collision2D>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Collider2D> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Collider2D>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Collider2D>)triggerEvent, (UnityAction <Collider2D>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Rigidbody2D> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Rigidbody2D>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Rigidbody2D>)triggerEvent, (UnityAction <Rigidbody2D>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <ContactPoint> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <ContactPoint>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <ContactPoint>)triggerEvent, (UnityAction <ContactPoint>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <ContactPoint2D> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <ContactPoint2D>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <ContactPoint2D>)triggerEvent, (UnityAction <ContactPoint2D>)targetAction ); return(true); } } else if (triggerEvent is UnityEvent <Bounds> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Bounds>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Bounds>)triggerEvent, (UnityAction <Bounds>)targetAction ); return(true); } } if (actionType == typeof(UnityAction)) { UnityEventTools.AddVoidPersistentListener(triggerEvent, (UnityAction)targetAction); return(true); } return(false); // trigger-target mismatch }
// 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 = 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 <float>)) { UnityEventTools.AddFloatPersistentListener( triggerEvent, (UnityAction <float>)targetAction, 1.0f ); 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 <Quaternion> ) { // The trigger event has a Quaternion parameter. // Then the target method should have a Quaternion parameter too. if (actionType == typeof(UnityAction <Quaternion>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Quaternion>)triggerEvent, (UnityAction <Quaternion>)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 }
// Create a connection between two slots. public static bool ConnectSlots(Graphs.Slot fromSlot, Graphs.Slot toSlot) { EnumTypes(); var nodeTo = ((Block)toSlot.node).runtimeInstance; var triggerEvent = GetEventOfOutputSlot(fromSlot); var targetMethod = GetMethodOfInputSlot(toSlot); // 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 = 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 <float>)) { UnityEventTools.AddFloatPersistentListener( triggerEvent, (UnityAction <float>)targetAction, 1.0f ); 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 <int> ) { // The trigger event has a int parameter. // Then the target method should have a 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 <string> ) { // The trigger event has a string parameter. // Then the target method should have a string parameter too. if (actionType == typeof(UnityAction <string>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <string>)triggerEvent, (UnityAction <string>)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<Quaternion>) { * // The trigger event has a Quaternion parameter. * // Then the target method should have a Quaternion parameter too. * if (actionType == typeof(UnityAction<Quaternion>)) { * // Add the action to the event. * UnityEventTools.AddPersistentListener ( * (UnityEvent<Quaternion>)triggerEvent, * (UnityAction<Quaternion>)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); } } else if (triggerEvent is UnityEvent <Texture> ) { // The trigger event has a color parameter. // Then the target method should have a color parameter too. if (actionType == typeof(UnityAction <Texture>)) { // Add the action to the event. UnityEventTools.AddPersistentListener( (UnityEvent <Texture>)triggerEvent, (UnityAction <Texture>)targetAction ); return(true); } } else { var act = GetActionDataType(actionType); var evt = GetEventDataType(triggerEvent.GetType()); if (act == evt) //same type // UnityEventTools.AddPersistentListener(triggerEvent as UnityEvent,targetAction as UnityAction); { if (_AddPersistenceListener == null) { var mi = typeof(UnityEventTools) .GetMethods(); foreach (var m in mi) { if (m.Name == "AddPersistentListener" && m.IsGenericMethod && m.GetGenericArguments().Length == 1) { _AddPersistenceListener = m; break; } } } var actType = GetActionBaseType(targetAction.GetType()); var evtType = GetEventBaseType(triggerEvent.GetType()); /* object action,trigger; * * MethodInfo castMethod = typeof(ConnectionTools).GetMethod("Cast",BindingFlags.Static | BindingFlags.Public ); * action=castMethod.MakeGenericMethod(actType).Invoke (null, new object[]{ targetAction }); * * trigger=castMethod.MakeGenericMethod(evtType).Invoke (null, new object[]{ triggerEvent });*/ var mv = _AddPersistenceListener.MakeGenericMethod(new[] { evt }); mv.Invoke(null, new object[] { triggerEvent, targetAction }); return(true); } } return(false); // trigger-target mismatch }
public static void AddPersistentListener(this UnityEventBase self, UnityAction <float> unityAction, float argument) { UnityEventTools.AddFloatPersistentListener(self, unityAction, argument); }