void AddEventToTpInput() { var tpInput = track.GetComponent <vThirdPersonInput>(); if (tpInput) { bool containsListener = false; for (int i = 0; i < tpInput.OnLateUpdate.GetPersistentEventCount(); i++) { if (tpInput.OnLateUpdate.GetPersistentTarget(i).GetType().Equals(typeof(vHeadTrack)) && tpInput.OnLateUpdate.GetPersistentMethodName(i).Equals("UpdateHeadTrack")) { containsListener = true; break; } } if (!containsListener) { UnityEventTools.AddPersistentListener(tpInput.OnLateUpdate, track.UpdateHeadTrack); SerializedObject tpI = new SerializedObject(tpInput); EditorUtility.SetDirty(tpInput); tpI.ApplyModifiedProperties(); } } }
// Disconnect given two slots. public static void DisconnectSlots(Graphs.Slot fromSlot, Graphs.Slot toSlot) { var nodeTo = ((Block)toSlot.node).runtimeInstance; var triggerEvent = GetEventOfOutputSlot(fromSlot); var targetMethod = GetMethodOfInputSlot(toSlot); if (targetMethod == null) { return; } var methodName = targetMethod.Name; var eventCount = triggerEvent.GetPersistentEventCount(); for (var i = 0; i < eventCount; i++) { if (nodeTo == triggerEvent.GetPersistentTarget(i) && methodName == triggerEvent.GetPersistentMethodName(i)) { UnityEventTools.RemovePersistentListener(triggerEvent, i); break; } } }
private static void SetupARFoundationComponentsGameObjects() { var sessionOrigin = GameObject.Find("AR Session Origin"); var camera = GameObject.Find("AR Camera"); var cameraManager = camera.AddOrGetComponent <ARCameraManager>(); var light = GameObject.Find("Directional Light"); var lightEstimation = light.AddOrGetComponent <ARLightEstimation>(); lightEstimation.cameraManager = cameraManager; var planeEvents = sessionOrigin.AddOrGetComponent <ARPlaneEvents>(); var placeObjectsOnPlane = sessionOrigin.AddOrGetComponent <ARPlaceObjectOnPlane>(); Selection.activeGameObject = sessionOrigin; UnityEventTools.AddPersistentListener(planeEvents.PlaneTouchedWithTouchPosition, placeObjectsOnPlane.PlaceObjectOnPlane); const string cubePrefabPath = "Assets/Cube.prefab"; var cubePrefab = AssetDatabase.LoadAssetAtPath <GameObject>(cubePrefabPath); if (!cubePrefab) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.localScale = Vector3.one * 0.1f; cubePrefab = PrefabUtility.SaveAsPrefabAsset(cube, "Assets/Cube.prefab"); Object.DestroyImmediate(cube); } placeObjectsOnPlane.objectToPlace = cubePrefab; placeObjectsOnPlane.placeMultiple = true; }
// void createToggle() { t = PrefabUtility.InstantiatePrefab(w.prefabs[0]) as GameObject; // add name to new weapon string ttt = toggleName; t.name = ttt; toggles.Add(t.name); // add new toggle to "Weapons" ScriptableObject. //t = new GameObject WeaponsPanel = GameObject.Find("WeaponsPanel"); t.transform.SetParent(WeaponsPanel.transform); WeaponsPanel.GetComponent <MyToggleGroup>().toggles.Add(t.GetComponent <Toggle>()); int chc = t.transform.childCount; Transform Chc = t.transform.GetChild(chc - 1); Chc.GetComponent <Image>().sprite = ToggleWeaponImage; Toggle tuggen = t.GetComponent <Toggle>(); SelectionMenu SelMenu = FindObjectOfType <SelectionMenu>(); UnityAction <string> action = new UnityAction <string>(SelMenu.SelectWeapon); UnityEventTools.AddStringPersistentListener(tuggen.onValueChanged, action, WeaponToggleNumber); PrefabUtility.DisconnectPrefabInstance(t); }
public virtual void LoadData() { listener = GetComponent <PlayerInputListener>(); UnityEventTools.RemovePersistentListener(listener.CursorAButtonEvent, OnAButton); UnityEventTools.RemovePersistentListener(listener.CursorBButtonEvent, OnBButton); UnityEventTools.RemovePersistentListener(listener.CursorRButtonEvent, OnRButton); UnityEventTools.RemovePersistentListener(listener.CursorLButtonEvent, OnLButton); UnityEventTools.RemovePersistentListener(listener.CursorXButtonEvent, OnXButton); UnityEventTools.RemovePersistentListener(listener.CursorYButtonEvent, OnYButton); UnityEventTools.RemovePersistentListener(listener.CursorStartButtonEvent, OnStartButton); UnityEventTools.RemovePersistentListener <Vector2>(listener.CursorMoveEvent, OnMove); UnityEventTools.AddPersistentListener(listener.CursorAButtonEvent, OnAButton); UnityEventTools.AddPersistentListener(listener.CursorBButtonEvent, OnBButton); UnityEventTools.AddPersistentListener(listener.CursorRButtonEvent, OnRButton); UnityEventTools.AddPersistentListener(listener.CursorLButtonEvent, OnLButton); UnityEventTools.AddPersistentListener(listener.CursorXButtonEvent, OnXButton); UnityEventTools.AddPersistentListener(listener.CursorYButtonEvent, OnYButton); UnityEventTools.AddPersistentListener(listener.CursorStartButtonEvent, OnStartButton); UnityEventTools.AddPersistentListener(listener.CursorMoveEvent, OnMove); }
public static void CreateEntryPoint() { if (GameObject.FindObjectOfType(typeof(UnitySocialEntryPointController)) != null) { EditorUtility.DisplayDialog("Unity Social Entry Point already exists", "New Entry Point was not added.", "Ok", null); return; } Canvas targetCanvas = GetTargetCanvas(); if (targetCanvas != null) { GameObject container = new GameObject("US_EntryPointContainer", typeof(RectTransform), typeof(UnitySocialEntryPointController)); GameObject entryPoint = new GameObject("US_EntryPoint", typeof(CanvasRenderer), typeof(Image), typeof(Button)); GameObject entryPointIcon = new GameObject("US_EntryPointIcon", typeof(Image)); GameObject notificationBadge = new GameObject("US_NotificationBadge", typeof(Image)); GameObject notificationCount = new GameObject("US_NotificationCount", typeof(Text)); if (container != null && entryPoint != null && entryPointIcon != null && notificationBadge != null && notificationCount != null) { container.transform.SetParent(targetCanvas.transform); container.layer = LayerMask.NameToLayer(kUILayerName); entryPoint.transform.SetParent(container.transform); entryPoint.layer = LayerMask.NameToLayer(kUILayerName); entryPointIcon.transform.SetParent(entryPoint.transform); entryPointIcon.layer = LayerMask.NameToLayer(kUILayerName); notificationBadge.transform.SetParent(container.transform.transform); notificationBadge.layer = LayerMask.NameToLayer(kUILayerName); notificationCount.transform.SetParent(notificationBadge.transform); notificationCount.layer = LayerMask.NameToLayer(kUILayerName); RectTransform containerRectTransform = container.GetComponent <RectTransform>(); if (containerRectTransform != null) { containerRectTransform.anchorMin = Vector2.zero; containerRectTransform.anchorMax = Vector2.zero; containerRectTransform.pivot = Vector2.zero; containerRectTransform.position = new Vector2(16.0f, 16.0f); } Image entryPointImage = entryPoint.GetComponent <Image>(); if (entryPointImage != null) { entryPointImage.material = AssetDatabase.LoadAssetAtPath(kSampleAssetFolder + "Materials/UI-CircleDefault.mat", typeof(Material)) as Material; entryPointImage.sprite = AssetDatabase.LoadAssetAtPath(kSampleAssetFolder + "Textures/social-btn-circle.png", typeof(Sprite)) as Sprite; } Image entryPointIconImage = entryPointIcon.GetComponent <Image>(); if (entryPointIconImage != null) { entryPointIconImage.material = AssetDatabase.LoadAssetAtPath(kSampleAssetFolder + "Materials/UI-CircleDefault.mat", typeof(Material)) as Material; entryPointIconImage.sprite = AssetDatabase.LoadAssetAtPath(kSampleAssetFolder + "Textures/social-btn-icon.png", typeof(Sprite)) as Sprite; entryPointIconImage.color = new Color(98.0f / 255.0f, 52.0f / 255.0f, 165.0f / 255.0f, 255.0f); } Image notificationBadgeImage = notificationBadge.GetComponent <Image>(); if (notificationBadgeImage != null) { notificationBadgeImage.sprite = AssetDatabase.LoadAssetAtPath(kSampleAssetFolder + "Textures/notification-badge.png", typeof(Sprite)) as Sprite; notificationBadgeImage.rectTransform.sizeDelta = new Vector2(35.0f, 35.0f); notificationBadgeImage.rectTransform.anchorMin = new Vector2(1.0f, 1.0f); notificationBadgeImage.rectTransform.anchorMax = new Vector2(1.0f, 1.0f); notificationBadgeImage.rectTransform.anchoredPosition = new Vector3(-15.0f, -15.0f, 0.0f); } Text notificationBadgeCountText = notificationCount.GetComponent <Text>(); if (notificationBadgeCountText != null) { notificationBadgeCountText.rectTransform.sizeDelta = new Vector2(35.0f, 35.0f); notificationBadgeCountText.alignment = TextAnchor.MiddleCenter; notificationBadgeCountText.text = "9+"; notificationBadgeCountText.fontSize = 20; notificationBadgeCountText.fontStyle = FontStyle.Bold; } Button button = entryPoint.GetComponent <Button>(); if (button != null) { UnitySocialEntryPointController entryPointController = container.GetComponent <UnitySocialEntryPointController>(); if (entryPointController != null) { UnityEventTools.AddPersistentListener(button.onClick, entryPointController.OpenUnitySocial); entryPointController.entryPointIconImage = entryPointIconImage; entryPointController.notificationBadge = notificationBadge; entryPointController.notificationBadgeCountText = notificationBadgeCountText; } } } } Debug.Log("Unity Social entrypoint created."); }
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(); }
public static void CB_AddDeathCamera() { GameObject deathCam = E_Helpers.CreatePrefabFromPath("InvectorMultiplayer/DeathCamera.prefab"); NetworkManager nm = FindObjectOfType <NetworkManager>(); if (nm == null) { if (EditorUtility.DisplayDialog("Missing Network Manager", "This component was added to the scene but there was not NetworkManager found in this scene. " + "It is highly suggested that you make this a child of the NetworkManager or of something " + "that is persistant between scenes.", "Okay")) { } } else { deathCam.transform.SetParent(nm.gameObject.transform); Selection.activeGameObject = deathCam; if (FindObjectOfType <SyncPlayer>()) { if (EditorUtility.DisplayDialog("Player Found In Scene", "A convert multiplayer character was found in the scene do you want to add the unity events " + "necessary to enable the death camera system on player death?", "Yes", "No")) { foreach (SyncPlayer player in FindObjectsOfType <SyncPlayer>()) { if (!E_PlayerEvents.HasUnityEvent(player.gameObject.GetComponent <vThirdPersonController>().onDead, "DeadEnableDeathCam", player)) { UnityEventTools.AddPersistentListener(player.gameObject.GetComponent <vThirdPersonController>().onDead, player.DeadEnableDeathCam); } } if (EditorUtility.DisplayDialog("Remember To Save!", "Remember to save the changes back to the prefab on these converted players!", "Okay Thanks!")) { } } else { DisplayEventRequirement(); } } else { DisplayEventRequirement(); } } void DisplayEventRequirement() { if (EditorUtility.DisplayDialog("Friendly Reminder For Missing Events", "This will not trigger by itself. You will be required to trigger it when you want to " + "allow the player to switch to targeting other players. A chain of events is available " + "for you to add if you would like:\n\n" + "vThirdPersonController (On Dead Event): Add SyncPlayer.DeadEnableDeathCam event", "Okay Thanks!")) { } } }
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); } }
/// <summary> /// Adds the game manager script and sets its values, also sets the /// player input component /// </summary> /// <param name="node">Game manager game object</param> private static void TraverseGameManager(GameObject node) { var count = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(node); if (count == 0) { DestroyImmediate(node.GetComponent <GameManager>()); } // script var gameManager = node.AddComponent <GameManager>(); // references gameManager.LevelScene = "Level"; gameManager.MenuScene = "Main Menu"; gameManager.Board = root.transform.Find("Board").gameObject; gameManager.Cam = root.transform.Find("Main Camera").gameObject; gameManager.Test = true; gameManager.TestLevel = "Campaign/Tutorial"; gameManager.BearPrefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Bear.prefab"); gameManager.OrbPrefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Orb.prefab"); gameManager.TilePrefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Tile.prefab"); gameManager.OrbMessageUIAnimator = root.transform.Find("Game UI").Find("Orb Message").GetComponent <Animator>(); gameManager.OrbCountUI = root.transform.Find("Game UI").Find("Orb Count Text").gameObject; gameManager.OrbMessageUI = root.transform.Find("Game UI").Find("Orb Message").gameObject; gameManager.PauseMenuUI = root.transform.Find("Pause Menu").Find("Pause Menu UI").gameObject; gameManager.WinMenuUI = root.transform.Find("Win Menu").Find("Win Menu UI").gameObject; gameManager.NextLevelButton = root.transform.Find("Win Menu").Find("Win Menu UI").Find("Next Button").gameObject; // events gameManager.WinLevel = new UnityEvent(); LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Win Menu").GetComponent <WinMenuUI>(), "Show" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(gameManager.WinLevel, action); }; // player input (Input system 1.0.0) var playerInput = gameManager.GetComponent <PlayerInput>(); // settings playerInput.actions = AssetDatabase.LoadAssetAtPath <InputActionAsset>("Assets/Scripts/Level/controls.inputactions"); playerInput.defaultControlScheme = "Keyboard&Mouse"; playerInput.defaultActionMap = "Player"; playerInput.notificationBehavior = PlayerNotifications.InvokeUnityEvents; // events foreach (var item in playerInput.actionEvents) { // name of events are like this: Player/Center[/Keyboard/c] // so only take the part before [] var eventName = item.actionName.Split('[')[0]; // remove all of its listeners try { for (int i = 0; ; i++) { UnityEventTools.RemovePersistentListener(item, i); } } catch (ArgumentOutOfRangeException) { } switch (eventName) { case "Player/Move": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Board").GetComponent <Board>(), "MoveAllPlayers" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; case "Player/Look": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Main Camera").GetComponent <CameraController>(), "Move" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; case "Player/Center": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Main Camera").GetComponent <CameraController>(), "Center" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; case "Player/Flip": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Board").GetComponent <Board>(), "Flip" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; case "Player/Pause": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Pause" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; case "Paused/Resume": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction <InputAction.CallbackContext>), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Resume" ) as UnityAction <InputAction.CallbackContext>; UnityEventTools.AddPersistentListener(item, action); }; break; // ignore other events default: break; } } }
void C_vTriggerGenericActions(GameObject target) { if (!target.GetComponent <vTriggerGenericAction>()) { return; } if (target.GetComponent <vItemCollection>()) { return; } /* #region Shooter Template * if (target.GetComponent<vThrowCollectable>()) return; #endregion*/ _convertedGenericTriggers = true; if (!target.GetComponent <CallNetworkEvents>()) { target.AddComponent <CallNetworkEvents>(); } target.GetComponent <CallNetworkEvents>().GetType().GetField("holder", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.transform); //No Input UnityEvents if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vTriggerGenericAction>().OnPressActionInput, "CallNetworkInvoke1", target.GetComponent <CallNetworkEvents>())) { target.GetComponent <CallNetworkEvents>().GetType().GetField("NetworkInvoke1", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.GetComponent <vTriggerGenericAction>().OnPressActionInput); target.GetComponent <vTriggerGenericAction>().OnPressActionInput = new UnityEvent(); UnityEventTools.AddPersistentListener(target.GetComponent <vTriggerGenericAction>().OnPressActionInput, target.GetComponent <CallNetworkEvents>().CallNetworkInvoke1); } if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vTriggerGenericAction>().OnCancelActionInput, "CallNetworkInvoke2", target.GetComponent <CallNetworkEvents>())) { target.GetComponent <CallNetworkEvents>().GetType().GetField("NetworkInvoke2", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.GetComponent <vTriggerGenericAction>().OnCancelActionInput); target.GetComponent <vTriggerGenericAction>().OnCancelActionInput = new UnityEvent(); UnityEventTools.AddPersistentListener(target.GetComponent <vTriggerGenericAction>().OnCancelActionInput, target.GetComponent <CallNetworkEvents>().CallNetworkInvoke2); } if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vTriggerGenericAction>().OnFinishActionInput, "CallNetworkInvoke3", target.GetComponent <CallNetworkEvents>())) { target.GetComponent <CallNetworkEvents>().GetType().GetField("NetworkInvoke3", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.GetComponent <vTriggerGenericAction>().OnFinishActionInput); target.GetComponent <vTriggerGenericAction>().OnFinishActionInput = new UnityEvent(); UnityEventTools.AddPersistentListener(target.GetComponent <vTriggerGenericAction>().OnFinishActionInput, target.GetComponent <CallNetworkEvents>().CallNetworkInvoke3); } if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vTriggerGenericAction>().OnStartAnimation, "CallNetworkInvoke4", target.GetComponent <CallNetworkEvents>())) { target.GetComponent <CallNetworkEvents>().GetType().GetField("NetworkInvoke4", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.GetComponent <vTriggerGenericAction>().OnStartAnimation); target.GetComponent <vTriggerGenericAction>().OnStartAnimation = new UnityEvent(); UnityEventTools.AddPersistentListener(target.GetComponent <vTriggerGenericAction>().OnStartAnimation, target.GetComponent <CallNetworkEvents>().CallNetworkInvoke4); } if (!E_PlayerEvents.HasUnityEvent(target.GetComponent <vTriggerGenericAction>().OnEndAnimation, "CallNetworkInvoke5", target.GetComponent <CallNetworkEvents>())) { target.GetComponent <CallNetworkEvents>().GetType().GetField("NetworkInvoke5", E_Helpers.allBindings).SetValue(target.GetComponent <CallNetworkEvents>(), target.GetComponent <vTriggerGenericAction>().OnEndAnimation); target.GetComponent <vTriggerGenericAction>().OnEndAnimation = new UnityEvent(); UnityEventTools.AddPersistentListener(target.GetComponent <vTriggerGenericAction>().OnEndAnimation, target.GetComponent <CallNetworkEvents>().CallNetworkInvoke5); } ////GameObject Input UnityEvents //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<vTriggerGenericAction>().onPressActionInputWithTarget, "CallGameObjectInvoke1", target.GetComponent<CallNetworkEvents>())) //{ // target.GetComponent<CallNetworkEvents>().GetType().GetField("NetworkGameObjectInvoke1", E_Helpers.allBindings).SetValue(target.GetComponent<CallNetworkEvents>(), target.GetComponent<vTriggerGenericAction>().onPressActionInputWithTarget); // target.GetComponent<vTriggerGenericAction>().onPressActionInputWithTarget = new OnDoActionWithTarget(); // UnityEventTools.AddPersistentListener(target.GetComponent<vTriggerGenericAction>().onPressActionInputWithTarget, target.GetComponent<CallNetworkEvents>().CallGameObjectInvoke1); //} //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<vTriggerGenericAction>().OnPlayerEnter, "CallGameObjectInvoke2", target.GetComponent<CallNetworkEvents>())) //{ // target.GetComponent<CallNetworkEvents>().GetType().GetField("NetworkGameObjectInvoke2", E_Helpers.allBindings).SetValue(target.GetComponent<CallNetworkEvents>(), target.GetComponent<vTriggerGenericAction>().OnPlayerEnter); // target.GetComponent<vTriggerGenericAction>().OnPlayerEnter = new OnDoActionWithTarget(); // UnityEventTools.AddPersistentListener(target.GetComponent<vTriggerGenericAction>().OnPlayerEnter, target.GetComponent<CallNetworkEvents>().CallGameObjectInvoke2); //} //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<vTriggerGenericAction>().OnPlayerStay, "CallGameObjectInvoke3", target.GetComponent<CallNetworkEvents>())) //{ // target.GetComponent<CallNetworkEvents>().GetType().GetField("NetworkGameObjectInvoke3", E_Helpers.allBindings).SetValue(target.GetComponent<CallNetworkEvents>(), target.GetComponent<vTriggerGenericAction>().OnPlayerStay); // target.GetComponent<vTriggerGenericAction>().OnPlayerStay = new OnDoActionWithTarget(); // UnityEventTools.AddPersistentListener(target.GetComponent<vTriggerGenericAction>().OnPlayerStay, target.GetComponent<CallNetworkEvents>().CallGameObjectInvoke3); //} //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<vTriggerGenericAction>().OnPlayerExit, "CallGameObjectInvoke4", target.GetComponent<CallNetworkEvents>())) //{ // target.GetComponent<CallNetworkEvents>().GetType().GetField("NetworkGameObjectInvoke4", E_Helpers.allBindings).SetValue(target.GetComponent<CallNetworkEvents>(), target.GetComponent<vTriggerGenericAction>().OnPlayerExit); // target.GetComponent<vTriggerGenericAction>().OnPlayerExit = new OnDoActionWithTarget(); // UnityEventTools.AddPersistentListener(target.GetComponent<vTriggerGenericAction>().OnPlayerExit, target.GetComponent<CallNetworkEvents>().CallGameObjectInvoke4); //} ////Float Input UnityEvents //if (!E_PlayerEvents.HasUnityEvent(target.GetComponent<vTriggerGenericAction>().OnUpdateButtonTimer, "CallFloatInvoke1", target.GetComponent<CallNetworkEvents>())) //{ // target.GetComponent<CallNetworkEvents>().GetType().GetField("NetworkSingleInvoke1", E_Helpers.allBindings).SetValue(target.GetComponent<CallNetworkEvents>(), target.GetComponent<vTriggerGenericAction>().OnUpdateButtonTimer); // target.GetComponent<vTriggerGenericAction>().OnUpdateButtonTimer = new vTriggerGenericAction.OnUpdateValue(); // UnityEventTools.AddPersistentListener(target.GetComponent<vTriggerGenericAction>().OnUpdateButtonTimer, target.GetComponent<CallNetworkEvents>().CallFloatInvoke1); //} }
/// <summary> /// Adds function to event /// </summary> public void AddOnSetDepthTextureEvent(UnityAction func) { UnityEventTools.AddPersistentListener(onSetDepthTextureEvent, func); }
private void SetChunkManager(List <BuildingAssetInfo> buildings) { Debug.Log("SetChunkManager"); LoadInfo(); if (buildings.Count > 0) { //ReplaceBoxAll(buildings); ReplaceSimpleAll(buildings); } ChunkManager cm = GameObject.FindObjectOfType <ChunkManager>(); if (cm) { var buildingBoxes = GameObject.FindObjectsOfType <BuildingBox>(); List <ChunkManager.Chunk> chunkList = new List <ChunkManager.Chunk>(); for (int i = 0; i < buildingBoxes.Length; i++) { var box = buildingBoxes[i]; var info = box.info; if (info == null) { Debug.LogWarning("info==null:" + box); continue; } //if (info.SceneName.ToLower() != "u3") //{ // continue; //} var chunk = new ChunkManager.Chunk(); chunk.sceneName = info.SceneName; chunk.center = info.Position; chunk.loadDistance = info.LoadDistance; chunk.unloadDistance = info.UnloadDistance; if (chunk.onLoad == null) { chunk.onLoad = new OnLoadUnityEvent(); } //chunk.onLoad.AddListener(box.Hide); UnityEventTools.AddPersistentListener(chunk.onLoad, box.Hide); if (chunk.onUnload == null) { chunk.onUnload = new OnLoadUnityEvent(); } //chunk.onUnload.AddListener(box.Show); UnityEventTools.AddPersistentListener(chunk.onUnload, box.Show); ChunkManager.BundleDef bundle = new ChunkManager.BundleDef(); bundle.bundleName = info.AssetName.ToLower();//这里要加ToLower(),不然会出错 bundle.fromFile = true; bundle.checkVersion = false; chunk.bundleList = new ChunkManager.BundleDef[] { bundle }; Debug.Log("bundle:" + bundle); Debug.Log("chunk:" + chunk); chunkList.Add(chunk); } cm.chunks = chunkList.ToArray(); Debug.Log("chunks:--------------" + cm.chunks.Length); for (int i = 0; i < cm.chunks.Length; i++) { var chunk = cm.chunks[i]; Debug.Log("chunk:" + chunk); foreach (var item in chunk.bundleList) { Debug.Log("bundle:" + item); } } } }
static void GenerateUdonMenu() { //Declare some variables + settings. Navigation no_nav = new Navigation(); no_nav.mode = Navigation.Mode.None; //declare toggle resource settings DefaultControls.Resources toggleresources = new DefaultControls.Resources(); //Set the Toggle Background Image someBgSprite; toggleresources.standard = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/InputFieldBackground.psd"); //Set the Toggle Checkmark Image someCheckmarkSprite; toggleresources.checkmark = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/Checkmark.psd"); DefaultControls.Resources rootpanelresources = new DefaultControls.Resources(); rootpanelresources.background = AssetDatabase.GetBuiltinExtraResource <Sprite> ("UI/Skin/Background.psd"); DefaultControls.Resources txtresources = new DefaultControls.Resources(); int layer = 8; //int rowoffset=860; int columnoffset = 200; int rowseperation = 100; int columnseperation = 1000; //int togglesizedelta=80; int numberpercolumn = 14; int menusizex = 5300; int menusizey = 1600; int headersizey = 60; int textpadding = 10; int headerbuttonspacing = 100; int buttonsizey = 100; int buttonsizex = 900; int menubuttonystart = textpadding + headersizey + buttonsizey + 80; Vector2 backbuttonsize = new Vector2(menusizey - headersizey - textpadding - headerbuttonspacing, buttonsizey); Vector2 buttonsize = new Vector2(buttonsizex, buttonsizey); Vector2 menusize = new Vector2(menusizex, menusizey); Vector3 menurootposition = new Vector3(1.5f, 0, 16); Vector3 canvasscale = new Vector3(.001f, .001f, .001f); Vector2 zerovector2 = new Vector2(0, 0); Vector3 zerovector3 = new Vector3(0, 0, 0); /***************************************** * START OF PROGRAM *****************************************/ GameObject menuroot = new GameObject("Udon Menu System"); //creates a new "Menu Root gameobject which will be the parent of all newly created objects in the script. menuroot.transform.position = menurootposition; menuroot.GetOrAddComponent <UdonBehaviour>().programSource = AssetDatabase.LoadAssetAtPath <AbstractUdonProgramSource>("Assets/UdonSharpSourceCode/MenuControl.asset"); //menuroot.transform.SetParent(parent.transform, false); menuroot.layer = layer; GameObject videocontainer = GameObject.Find("/VideoCanvas"); /* * GameObject videocontainer = new GameObject("Video Container"); //container go to hold all videos. Allows a world option that turns on/off videos completely. * videocontainer.transform.position = new Vector3(-3.75f, 1, 0); * videocontainer.transform.SetParent(menuroot.transform, false); * videocontainer.layer = layer; */ GameObject rootcanvas = new GameObject("Root Canvas"); rootcanvas.transform.SetParent(menuroot.transform, false); rootcanvas.layer = layer; rootcanvas.transform.localScale = canvasscale; rootcanvas.AddComponent <RectTransform> (); rootcanvas.GetComponent <RectTransform> ().localPosition = zerovector3; rootcanvas.GetComponent <RectTransform> ().sizeDelta = menusize; rootcanvas.GetComponent <RectTransform> ().anchorMax = zerovector2; rootcanvas.GetComponent <RectTransform> ().anchorMin = zerovector2; rootcanvas.GetComponent <RectTransform> ().pivot = zerovector2; rootcanvas.AddComponent <Canvas> (); //adds canvas to root canvas gameobject rootcanvas.GetComponent <Canvas> ().renderMode = RenderMode.WorldSpace; rootcanvas.AddComponent <CanvasScaler>(); rootcanvas.AddComponent <GraphicRaycaster>(); rootcanvas.AddComponent <VRCUiShape>(); //wtf ToggleGroup rootcanvastogglegroup = rootcanvas.AddComponent <ToggleGroup>(); rootcanvastogglegroup.allowSwitchOff = true; GameObject rootpanel = DefaultControls.CreatePanel(rootpanelresources); rootpanel.transform.SetParent(rootcanvas.transform, false); rootpanel.layer = layer; rootpanel.GetComponent <RectTransform> ().sizeDelta = menusize; rootpanel.GetComponent <RectTransform> ().anchorMax = zerovector2; rootpanel.GetComponent <RectTransform> ().anchorMin = zerovector2; rootpanel.GetComponent <RectTransform> ().pivot = zerovector2; rootpanel.GetComponent <Image> ().color = new Color(0.07f, 0.07f, 0.07f, 1); //gets rid of transparency - also can change panel color if I want here. 1=255. /* * if(mode=="Global"){ * rootpanel.GetComponent<Image> ().color = new Color(1,.90f,.90f,1); //gets rid of transparency - also can change panel color if I want here. 1=255. * }else{ * rootpanel.GetComponent<Image> ().color = new Color(.90f,.90f,1,1); //gets rid of transparency - also can change panel color if I want here. 1=255. * } * */ GameObject menubuttons = new GameObject("Menu Buttons"); menubuttons.transform.SetParent(rootcanvas.transform, false); menubuttons.layer = layer; GameObject menubuttonsheader = DefaultControls.CreateText(txtresources); menubuttonsheader.transform.SetParent(rootcanvas.transform, false); menubuttonsheader.name = "Menu Header"; menubuttonsheader.layer = layer; menubuttonsheader.GetComponent <Text> ().text = "Header"; menubuttonsheader.GetComponent <Text> ().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; menubuttonsheader.GetComponent <Text> ().fontStyle = FontStyle.Bold; menubuttonsheader.GetComponent <Text> ().fontSize = 50; menubuttonsheader.GetComponent <Text> ().color = Color.white; menubuttonsheader.GetComponent <Text> ().alignment = TextAnchor.MiddleLeft; menubuttonsheader.GetComponent <RectTransform> ().sizeDelta = new Vector2(menusizex, headersizey); menubuttonsheader.GetComponent <RectTransform> ().anchoredPosition = new Vector2(textpadding, menusizey - headersizey - textpadding); menubuttonsheader.GetComponent <RectTransform> ().anchorMax = zerovector2; menubuttonsheader.GetComponent <RectTransform> ().anchorMin = zerovector2; menubuttonsheader.GetComponent <RectTransform> ().pivot = zerovector2; GameObject menubuttonssubheader = DefaultControls.CreateText(txtresources); menubuttonssubheader.transform.SetParent(rootcanvas.transform, false); menubuttonssubheader.name = "SubHeader"; menubuttonssubheader.layer = layer; menubuttonssubheader.GetComponent <Text> ().text = "SubHeader"; menubuttonssubheader.GetComponent <Text> ().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; menubuttonssubheader.GetComponent <Text> ().fontStyle = FontStyle.Bold; menubuttonssubheader.GetComponent <Text> ().fontSize = 50; menubuttonssubheader.GetComponent <Text> ().color = Color.white; menubuttonssubheader.GetComponent <Text> ().alignment = TextAnchor.MiddleLeft; menubuttonssubheader.GetComponent <RectTransform> ().sizeDelta = new Vector2(menusizex, headersizey); menubuttonssubheader.GetComponent <RectTransform> ().anchoredPosition = new Vector2(textpadding, menusizey - (headersizey * 2) - textpadding); menubuttonssubheader.GetComponent <RectTransform> ().anchorMax = zerovector2; menubuttonssubheader.GetComponent <RectTransform> ().anchorMin = zerovector2; menubuttonssubheader.GetComponent <RectTransform> ().pivot = zerovector2; /* * GameObject menubuttonsheader = new GameObject("Menu Header"); * menubuttonsheader.transform.SetParent (rootcanvas.transform, false); * menubuttonsheader.layer = layer; * menubuttonsheader.AddComponent<CanvasRenderer>(); * menubuttonsheader.AddComponent<TextMeshProUGUI> ().text="Header"; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontStyle = FontStyles.Bold; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSize = 50; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().color = Color.white; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().alignment = TextAlignmentOptions.Left; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().autoSizeTextContainer=true; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSizeMax=50; * menubuttonsheader.GetComponent<TextMeshProUGUI> ().fontSizeMin=18; * menubuttonsheader.GetComponent<RectTransform> ().sizeDelta = new Vector2 (menusizex, headersizey); * menubuttonsheader.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (textpadding, menusizey-headersizey-textpadding); * menubuttonsheader.GetComponent<RectTransform> ().anchorMax = zerovector2; * menubuttonsheader.GetComponent<RectTransform> ().anchorMin = zerovector2; * menubuttonsheader.GetComponent<RectTransform> ().pivot = zerovector2; * * GameObject menubuttonssubheader = DefaultControls.CreateText(txtresources); * menubuttonssubheader.transform.SetParent (rootcanvas.transform, false); * menubuttonssubheader.name="Menu SubHeader"; * menubuttonssubheader.layer = layer; * DestroyImmediate(menubuttonssubheader.GetComponent<Text> ()); * menubuttonssubheader.GetOrAddComponent<TextMeshProUGUI> ().text="SubHeader"; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().text = "SubHeader"; * //menubuttonssubheader.GetComponent<TextMesh> ().font = Resources.GetBuiltinResource (typeof(Font), "Arial.ttf") as Font; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().font = Resources.Load("LiberationSans SDF", typeof(TMP_FontAsset)) as TMP_FontAsset; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontStyle = FontStyles.Bold; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSize = 50; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().color = Color.white; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().alignment = TextAlignmentOptions.Left; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().autoSizeTextContainer=true; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSizeMax=50; * menubuttonssubheader.GetComponent<TextMeshProUGUI> ().fontSizeMin=18; * menubuttonssubheader.GetComponent<RectTransform> ().sizeDelta = new Vector2 (menusizex, headersizey); * menubuttonssubheader.GetComponent<RectTransform> ().anchoredPosition = new Vector2 (textpadding, menusizey-(headersizey*2)-textpadding); * menubuttonssubheader.GetComponent<RectTransform> ().anchorMax = zerovector2; * menubuttonssubheader.GetComponent<RectTransform> ().anchorMin = zerovector2; * menubuttonssubheader.GetComponent<RectTransform> ().pivot = zerovector2; */ /***************************************** * Regenerates Next/Prev Button Events *****************************************/ GameObject prevbutton = GameObject.Find("/Signing Avatars/Canvas/PrevButton"); GameObject nextbutton = GameObject.Find("/Signing Avatars/Canvas/NextButton"); prevbutton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); nextbutton.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); UnityEventTools.AddStringPersistentListener(prevbutton.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "PrevB"); UnityEventTools.AddStringPersistentListener(nextbutton.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "NextB"); /***************************************** * Regenerates Quiz Button Events *****************************************/ GameObject quizbuttona = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/A"); GameObject quizbuttonb = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/B"); GameObject quizbuttonc = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/C"); GameObject quizbuttond = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/D"); GameObject quizbuttonbig = GameObject.Find("/Signing Avatars/Canvas/QuizPanel/BigButton"); quizbuttona.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); quizbuttonb.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); quizbuttonc.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); quizbuttond.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); quizbuttonbig.GetComponent <Button>().onClick = new Button.ButtonClickedEvent(); UnityEventTools.AddStringPersistentListener(quizbuttona.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "QuizA"); UnityEventTools.AddStringPersistentListener(quizbuttonb.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "QuizB"); UnityEventTools.AddStringPersistentListener(quizbuttonc.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "QuizC"); UnityEventTools.AddStringPersistentListener(quizbuttond.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "QuizD"); UnityEventTools.AddStringPersistentListener(quizbuttonbig.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "QuizBigButtonPushed"); /***************************************** * Regenerates Preferences Items *****************************************/ Toggle HandToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Hand Toggle").GetComponent <Toggle>(); HandToggle.onValueChanged = new Toggle.ToggleEvent(); UnityEventTools.AddStringPersistentListener(HandToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() , "SendCustomEvent") as UnityAction <string>, "ToggleHand"); Toggle GlobalToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Global Mode").GetComponent <Toggle>(); GlobalToggle.onValueChanged = new Toggle.ToggleEvent(); UnityEventTools.AddStringPersistentListener(GlobalToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() , "SendCustomEvent") as UnityAction <string>, "ToggleGlobal"); Toggle QuizToggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Quiz Mode").GetComponent <Toggle>(); QuizToggle.onValueChanged = new Toggle.ToggleEvent(); UnityEventTools.AddStringPersistentListener(QuizToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() , "SendCustomEvent") as UnityAction <string>, "ToggleQuiz"); Slider avatarscaleslider = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Avatar Scale Slider").GetComponent <Slider>(); avatarscaleslider.onValueChanged = new Slider.SliderEvent(); UnityEventTools.AddStringPersistentListener(avatarscaleslider.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() , "SendCustomEvent") as UnityAction <string>, "AvatarScaleSliderValueChanged"); Toggle DarkToggle = GameObject.Find("/Preferencesv2/Canvas/Right Panel/Dark Mode").GetComponent <Toggle>(); DarkToggle.onValueChanged = new Toggle.ToggleEvent(); UnityEventTools.AddStringPersistentListener(DarkToggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() , "SendCustomEvent") as UnityAction <string>, "ToggleDark"); /* * * GameObject prevbutton=createbutton2(parent:menubuttons, name:"PrevButton", * sizedelta:new Vector2(625,100),localPosition:new Vector3 (-2125,600,-2000), * text:"Previous Sign",txtsizedelta:new Vector2 (625, 100),txtanchoredPosition:new Vector2 (0,0), alignment:TextAnchor.MiddleCenter, * nav:no_nav,layer:layer); * * UnityEventTools.AddStringPersistentListener(prevbutton.GetOrAddComponent<Button>().onClick, //the button/toggle that triggers the action * System.Delegate.CreateDelegate(typeof(UnityAction<string>), menuroot.GetOrAddComponent<UdonBehaviour>()//the target of the action * , "SendCustomEvent") as UnityAction<string>,"PrevB"); * * GameObject nextbutton=createbutton2(parent:menubuttons, name:"NextButton", * sizedelta:new Vector2(625,100),localPosition:new Vector3 (-1500,600,-2000), * text:"Next Sign",txtsizedelta:new Vector2 (625, 100),txtanchoredPosition:new Vector2 (0,0), alignment:TextAnchor.MiddleCenter, * nav:no_nav,layer:layer); * * UnityEventTools.AddStringPersistentListener(nextbutton.GetOrAddComponent<Button>().onClick, //the button/toggle that triggers the action * System.Delegate.CreateDelegate(typeof(UnityAction<string>), menuroot.GetOrAddComponent<UdonBehaviour>()//the target of the action * , "SendCustomEvent") as UnityAction<string>,"NextB"); * */ /***************************************** * Create the main array of buttons here *****************************************/ int menucolumn = 0; int menurow = 0; for (int x = 0; x < 70; x++) { if (x != 0) { if (x % numberpercolumn == 0) //display 9 items per column { menucolumn++; menurow = 0; } } GameObject buttongo = createbutton2(parent: menubuttons, name: "Button " + (x), sizedelta: buttonsize, localPosition: new Vector2(columnoffset + (menucolumn * columnseperation), (menusizey - headersizey - textpadding - buttonsizey - 100 - (menurow * rowseperation))), text: " Button " + (x), txtsizedelta: new Vector2(750, 100), txtanchoredPosition: new Vector2(32, 0), alignment: TextAnchor.MiddleLeft, nav: no_nav, layer: layer); //alignment:TextAlignmentOptions.Left UnityEventTools.AddStringPersistentListener(buttongo.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "B" + (x)); //var targetBehaviour = GameObject.Find("MyObject").GetComponent<UdonBehaviour>(); // menuroot.GetOrAddComponent<UdonBehaviour>().publicVariables.TrySetVariableValue("",); //colors the buttons to indicate what's working and what's not. /* * if(x<2){ * var colors = b.colors; * colors.normalColor = new Color32( 0xFF, 0xFF, 0x98, 0xFF ); //FF9898FF light yellow * b.colors = colors; * } * if(x>=2){ * var colors = b.colors; * colors.normalColor = new Color32( 0xFF, 0x98, 0x98, 0xFF ); //FF9898FF light red * b.colors = colors; * }*/ //Don't forget to create the "selected" button with checkmark (optional) //Use color-changing buttons to indicated currently selected. /* * GameObject homeicongo = new GameObject("Home Icon"); * homeicongo.transform.SetParent(buttongo.transform, false); * homeicongo.layer=layer; * homeicongo.AddComponent<RectTransform> (); * homeicongo.GetComponent<RectTransform> ().localPosition = new Vector3(450,68,0); * homeicongo.GetComponent<RectTransform> ().sizeDelta = new Vector2(64,64); * homeicongo.GetComponent<RectTransform> ().anchorMax = zerovector2; * homeicongo.GetComponent<RectTransform> ().anchorMin = zerovector2; * homeicongo.GetComponent<RectTransform> ().pivot = zerovector2; * Image homeicon= homeicongo.AddComponent<Image>(); * homeicon.sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Icons/homeicon3.png"); */ //5th value is VR index or regular 0=indexonly , 1=generalvr,2=both GameObject indexicongo = new GameObject("Index VR Icon"); indexicongo.transform.SetParent(buttongo.transform, false); indexicongo.layer = layer; indexicongo.AddComponent <RectTransform> (); indexicongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0); indexicongo.GetComponent <RectTransform> ().sizeDelta = new Vector2(64, 64); indexicongo.GetComponent <RectTransform> ().anchorMax = zerovector2; indexicongo.GetComponent <RectTransform> ().anchorMin = zerovector2; indexicongo.GetComponent <RectTransform> ().pivot = zerovector2; Image indexicon = indexicongo.AddComponent <Image>(); indexicon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/left_index_controllerdark.png"); GameObject vricongo = new GameObject("Regular VR Icon"); vricongo.transform.SetParent(buttongo.transform, false); vricongo.layer = layer; vricongo.AddComponent <RectTransform> (); vricongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0); vricongo.GetComponent <RectTransform> ().sizeDelta = new Vector2(64, 64); vricongo.GetComponent <RectTransform> ().anchorMax = zerovector2; vricongo.GetComponent <RectTransform> ().anchorMin = zerovector2; vricongo.GetComponent <RectTransform> ().pivot = zerovector2; Image vricon = vricongo.AddComponent <Image>(); vricon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/left_htc_controllerdark.png"); GameObject allvricongo = new GameObject("Both VR Icon"); allvricongo.transform.SetParent(buttongo.transform, false); allvricongo.layer = layer; allvricongo.AddComponent <RectTransform> (); allvricongo.GetComponent <RectTransform> ().localPosition = new Vector3(450, 68, 0); allvricongo.GetComponent <RectTransform> ().sizeDelta = new Vector2(64, 64); allvricongo.GetComponent <RectTransform> ().anchorMax = zerovector2; allvricongo.GetComponent <RectTransform> ().anchorMin = zerovector2; allvricongo.GetComponent <RectTransform> ().pivot = zerovector2; Image allvricon = allvricongo.AddComponent <Image>(); allvricon.sprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Icons/bothvricondark.png"); //indexicongo.SetActive(false); //vricongo.SetActive(false); //allvricongo.SetActive(false); menurow++; } //Create back button GameObject backtolessongo = createbutton2(parent: menubuttons, name: "Left Back Button", sizedelta: backbuttonsize, localPosition: new Vector2(buttonsizey, 0), text: "Back to Previous Menu", fontSize: 50, txtsizedelta: backbuttonsize, txtanchoredPosition: new Vector2(20, 0), alignment: TextAnchor.MiddleCenter, nav: no_nav, rotatez: 90, layer: layer); //alignment:TextAlignmentOptions.Center, //backtolessongo.GetOrAddComponent<Button>().onClick=new Button.ButtonClickedEvent(); UnityEventTools.AddStringPersistentListener(backtolessongo.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "BackB"); //Create back button GameObject backtolessongo2 = createbutton2(parent: menubuttons, name: "Right Back Button", sizedelta: backbuttonsize, localPosition: new Vector2(menusizex, 0), text: "Back to Previous Menu", fontSize: 50, txtsizedelta: backbuttonsize, txtanchoredPosition: new Vector2(20, 0), alignment: TextAnchor.MiddleCenter, nav: no_nav, rotatez: 90, layer: layer); //alignment:TextAlignmentOptions.Center, //backtolessongo.GetOrAddComponent<Button>().onClick=new Button.ButtonClickedEvent(); UnityEventTools.AddStringPersistentListener(backtolessongo2.GetOrAddComponent <Button>().onClick, //the button/toggle that triggers the action System.Delegate.CreateDelegate(typeof(UnityAction <string>), menuroot.GetOrAddComponent <UdonBehaviour>() //the target of the action , "SendCustomEvent") as UnityAction <string>, "BackB"); /***************************************** * Update menu system to point to newly created objects. *****************************************/ //recreate toggle to fix reference? /* * Toggle oldvideotoggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Video Toggle").GetOrAddComponent<Toggle>(); * DestroyImmediate(oldvideotoggle); * Toggle newvideotoggle = GameObject.Find("/Preferencesv2/Canvas/Left Panel/Video Toggle").GetOrAddComponent<Toggle>(); * newvideotoggle.navigation = no_nav; * newvideotoggle.isOn = true; * newvideotoggle.graphic=newvideotoggle.transform.Find("Background").gameObject.transform.Find("Checkmark").GetComponent<Image>(); * newvideotoggle.transition= Selectable.Transition.None; * newvideotoggle.toggleTransition= Toggle.ToggleTransition.None; * newvideotoggle.onValueChanged = new Toggle.ToggleEvent(); * UnityEventTools.AddPersistentListener(newvideotoggle.onValueChanged, System.Delegate.CreateDelegate(typeof(UnityAction<bool>), * videocontainer, "SetActive") as UnityAction<bool>); */ }//End of main program
/// <summary> /// Add listener to call the specified action. /// </summary> /// <param name="listener">Listener.</param> /// <param name="action">Action.</param> protected static void AddListener(UnityEvent listener, UnityAction action) { UnityEventTools.AddPersistentListener(listener, action); }
/// <summary> /// Create button event, adds all components. /// </summary> void Create() { if (Selection.activeGameObject != null) { // fail safe // add melee manager for when shooter if (!Selection.activeGameObject.GetComponent <vMeleeManager>()) { Selection.activeGameObject.AddComponent <vMeleeManager>(); } // inventory vItemManager itemManager = Selection.activeGameObject.GetComponent <vItemManager>(); if (!itemManager) { itemManager = Selection.activeGameObject.AddComponent <vItemManager>(); vItemManagerUtilities.CreateDefaultEquipPoints(itemManager, itemManager.GetComponent <vMeleeManager>()); } itemManager.inventoryPrefab = InventoryPrefab; itemManager.itemListData = ItemListData; itemManager.itemsFilter.Add(vItemType.MeleeWeapon); itemManager.itemsFilter.Add(vItemType.Spell); // hit damage particle vHitDamageParticle hitDamageParticle = Selection.activeGameObject.GetComponent <vHitDamageParticle>(); if (!hitDamageParticle) { hitDamageParticle = Selection.activeGameObject.AddComponent <vHitDamageParticle>(); } hitDamageParticle.defaultDamageEffect = HitDamageParticle; // UI GameObject goItemCollectionDisplay = PrefabUtility.InstantiatePrefab(ItemCollectionDisplay) as GameObject; goItemCollectionDisplay.transform.SetParent(UIBase.transform); GameObject goInventoryPrefab = PrefabUtility.InstantiatePrefab(InventoryPrefab.gameObject) as GameObject; goInventoryPrefab.name = "Inventory_MeleeMagic_Auto"; // leveling system CharacterInstance levelingsystem = Selection.activeGameObject.GetComponent <CharacterInstance>(); if (!levelingsystem) { levelingsystem = Selection.activeGameObject.AddComponent <CharacterInstance>(); } // link the invector character damage event to the leveling system vThirdPersonController thirdp = Selection.activeGameObject.GetComponent <vThirdPersonController>(); UnityEventTools.AddPersistentListener(thirdp.onReceiveDamage, levelingsystem.OnRecieveDamage); // link the melee manager hits to the leveling system vMeleeManager meleeM = Selection.activeGameObject.GetComponent <vMeleeManager>(); if (meleeM) { if (meleeM.onDamageHit == null) { meleeM.onDamageHit = new vOnHitEvent(); } UnityEventTools.AddPersistentListener(meleeM.onDamageHit, levelingsystem.OnSendHit); } // add conditions and update particles to use the LOD 1 mesh levelingsystem.Conditions = new List <BaseCondition>(); levelingsystem.Conditions.Add(new BaseCondition() { Type = BaseDamage.Physical }); GameObject goConditionsRoot = new GameObject("Conditions"); goConditionsRoot.transform.SetParent(Selection.activeGameObject.transform); goConditionsRoot.transform.position = new Vector3(0f, 0f, 0f); foreach (BaseCondition bc in Conditions) { GameObject goCondition = null; if (bc.Display) { // load the prefab goCondition = PrefabUtility.InstantiatePrefab(bc.Display) as GameObject; goCondition.transform.SetParent(goConditionsRoot.transform); goCondition.transform.position = new Vector3(0f, 0f, 0f); // update all particles to use the mesh renderer from LOD1 goCondition.SetActive(true); ParticleSystem[] ConditionParticles = goCondition.GetComponentsInChildren <ParticleSystem>(); foreach (ParticleSystem p in ConditionParticles) { if (p.shape.enabled) { if (p.shape.shapeType == ParticleSystemShapeType.SkinnedMeshRenderer) { ParticleSystem.ShapeModule editableShape = p.shape; editableShape.skinnedMeshRenderer = LOD1BodyMesh[iWhichMesh]; } } } goCondition.SetActive(false); } // add to the levelling system levelingsystem.Conditions.Add(new BaseCondition() { Type = bc.Type, Length = 0, Display = goCondition }); } // add the magic spawn point GameObject goMagicSpawn = new GameObject("Magic Spawn"); goMagicSpawn.transform.SetParent(Selection.activeGameObject.transform); goMagicSpawn.transform.position = new Vector3(0f, 1.5f, 0.9f); // magic input MagicSettings magicIO = Selection.activeGameObject.GetComponent <MagicSettings>(); if (!magicIO) { magicIO = Selection.activeGameObject.AddComponent <MagicSettings>(); } magicIO.PooledMagic = true; magicIO.MagicSpawnPoint = goMagicSpawn.transform; magicIO.onUseMana = new UnityIntEvent(); UnityEventTools.AddPersistentListener(magicIO.onUseMana, levelingsystem.UseMana); #if !VANILLA // set spell triggers F1-F5 GameObject goInventoryWindow = goInventoryPrefab.transform.Find("InventoryWindow").gameObject; // grab inventory window GameObject goEquipmentInventory = goInventoryWindow.transform.Find("EquipmentInventory").gameObject; // and the equip slot parent goEquipmentInventory.SetActive(true); // enable for component search int iNext = 1; vEquipSlot[] allSlots = goInventoryPrefab.GetComponentsInChildren <vEquipSlot>(); foreach (vEquipSlot slot in allSlots) { if (slot.transform.parent.parent.name == "EquipMentArea_Spells") { // is a spell inventory area MagicSpellTrigger trigger = new MagicSpellTrigger(); // create the trigger trigger.EquipSlots = new vEquipSlot[] { slot }; // set the inventory slot trigger.Input = new GenericInput("F" + iNext.ToString(), null, null); // set the input key trigger.Input.useInput = true; // enable vEquipmentDisplay[] allDisplays = goInventoryPrefab.GetComponentsInChildren <vEquipmentDisplay>(); // find all displays foreach (vEquipmentDisplay disp in allDisplays) { // check all if (disp.gameObject.name == slot.gameObject.name.Replace("EquipSlot ", "EquipDisplay_Spell ")) { // found matching name? trigger.EquipDisplay = disp; // success, apply UnityEventTools.AddPersistentListener(slot.onAddItem, magicIO.SpellEquiped); // listen for spells equiped UnityEventTools.AddPersistentListener(slot.onRemoveItem, magicIO.SpellUnEquiped); // and unequiped break; // drop out } } magicIO.SpellsTriggers.Add(trigger); // add the trigger iNext += 1; // next please } } goEquipmentInventory.SetActive(false); // deactivate the inventory display #endif // link the UI further Transform tHUD = UIBase.transform.Find("HUD"); magicIO.XPText = tHUD.Find("XP").GetComponent <UnityEngine.UI.Text>(); magicIO.LevelText = tHUD.Find("Level").GetComponent <UnityEngine.UI.Text>(); magicIO.LevelUpText = tHUD.Find("Level up").GetComponent <UnityEngine.UI.Text>(); magicIO.ManaSlider = tHUD.Find("mana").GetComponent <UnityEngine.UI.Slider>(); #if !VANILLA itemManager.onUseItem = new OnHandleItemEvent(); UnityEventTools.AddPersistentListener(itemManager.onUseItem, magicIO.UsePotion); // also lock input when inventory open itemManager.onOpenCloseInventory = new OnOpenCloseInventory(); vMeleeCombatInput MeleeInput = Selection.activeGameObject.GetComponent <vMeleeCombatInput>(); if (MeleeInput) { UnityEventTools.AddPersistentListener(itemManager.onOpenCloseInventory, MeleeInput.SetLockMeleeInput); } #endif // work complete this.Close(); } else { Debug.Log("Please select the Player to add these components."); } }
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); //} }
/// <summary> /// Add a check UI links validator to the default inspector window. /// </summary> public override void OnInspectorGUI() { defaultSkin = GUI.skin; if (skin) { GUI.skin = skin; } GUILayout.BeginVertical("MAGIC SETTINGS", "window"); GUILayout.Space(30); // validate the interface to player links if (GUILayout.Button("Check UI->Player Links", GUILayout.ExpandWidth(true))) { // setup GameObject player = Selection.activeGameObject; MagicSettings settings = player.GetComponent <MagicSettings>(); CharacterBase levelingSystem = player.GetComponent <CharacterBase>(); lastUICheckResults = ""; int changeCount = 0; // check magic spawn point if (!settings.MagicSpawnPoint) { Transform tMagicSpawn = player.transform.Find("Magic Spawn"); if (!tMagicSpawn) { GameObject goMagicSpawn = new GameObject("Magic Spawn"); goMagicSpawn.transform.SetParent(player.transform); goMagicSpawn.transform.position = new Vector3(0f, 1.5f, 0.9f); settings.MagicSpawnPoint = goMagicSpawn.transform; } else { settings.MagicSpawnPoint = tMagicSpawn; } changeCount += 1; lastUICheckResults += "Added Magic Spawn Point\r\n"; } // leveling system on use mana connection if (levelingSystem) { settings.onUseMana = new UnityIntEvent(); UnityEventTools.AddPersistentListener(settings.onUseMana, levelingSystem.UseMana); changeCount += 1; lastUICheckResults += "Re-Linked leveling system to onUseMana\r\n"; } else { lastUICheckResults += "Optional Leveling system is missing, onUseMana not handled\r\n"; } // check links between inventory ui and the player vItemManager itemManager = player.GetComponent <vItemManager>(); if (!itemManager) { lastUICheckResults += "vItemManager is MISSING\r\n"; } else // found, checking slot links { GameObject goInventoryWindow = itemManager.inventoryPrefab.transform.Find("InventoryWindow").gameObject; // grab inventory window GameObject goEquipmentInventory = goInventoryWindow.transform.Find("EquipmentInventory").gameObject; // and the equip slot parent goEquipmentInventory.SetActive(true); // enable for component search int iNext = 1; vEquipSlot[] allSlots = itemManager.inventoryPrefab.transform.GetComponentsInChildren <vEquipSlot>(); settings.SpellsTriggers.Clear(); foreach (vEquipSlot slot in allSlots) { if (slot.transform.parent.parent.name == "EquipMentArea_Spells") // is a spell inventory area { slot.onAddItem = new OnHandleItemEvent(); slot.onRemoveItem = new OnHandleItemEvent(); MagicSpellTrigger trigger = new MagicSpellTrigger(); // create the trigger trigger.EquipSlots = new vEquipSlot[] { slot }; // set the inventory slot trigger.Input = new GenericInput("F" + iNext.ToString(), null, null); // set the input key trigger.Input.useInput = true; // enable vEquipmentDisplay[] allDisplays = itemManager.inventoryPrefab.transform.GetComponentsInChildren <vEquipmentDisplay>(); // find all displays foreach (vEquipmentDisplay disp in allDisplays) // check all { if (disp.gameObject.name == slot.gameObject.name.Replace("EquipSlot ", "EquipDisplay_Spell ")) // found matching name? { trigger.EquipDisplay = disp; // success, apply UnityEventTools.AddPersistentListener(slot.onAddItem, settings.SpellEquiped); // listen for spells equiped UnityEventTools.AddPersistentListener(slot.onRemoveItem, settings.SpellUnEquiped); // and unequiped break; // drop out } } settings.SpellsTriggers.Add(trigger); // add the trigger iNext += 1; // next please } } goEquipmentInventory.SetActive(false); // deactivate the inventory display changeCount += 1; lastUICheckResults += "Re-Linked inventory/UI display slots to the player\r\n"; // check use potion links itemManager.onUseItem = new OnHandleItemEvent(); UnityEventTools.AddPersistentListener(itemManager.onUseItem, settings.UsePotion); changeCount += 1; lastUICheckResults += "Re-Linked item manager use potion to the player\r\n"; } // finish up lastUICheckResults += "All done " + changeCount.ToString() + " changes applied\r\n\r\n"; } GUILayout.Label(lastUICheckResults, GUILayout.ExpandWidth(true)); // output the base inspector window GUI.skin = defaultSkin; base.OnInspectorGUI(); GUI.skin = skin; GUILayout.EndVertical(); GUI.skin = defaultSkin; }
/// <summary> /// Attaches the correct onClick listener to the given button /// </summary> /// <param name="node"></param> private static void TraverseButton(GameObject node) { var button = node.GetComponent <Button>(); button.onClick = new Button.ButtonClickedEvent(); switch (node.transform.parent.name) { case "Game UI": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Pause" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; case "Pause Menu UI": switch (node.name) { case "Resume Button": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Resume" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; case "Restart Button": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Restart" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; case "Quit Button": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Menu" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; default: break; } break; case "Win Menu UI": switch (node.name) { case "Next Button": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Win Menu").GetComponent <WinMenuUI>(), "NextLevel" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; case "Quit Button": LinkEvents += () => { var action = Delegate.CreateDelegate( typeof(UnityAction), root.transform.Find("Pause Menu").GetComponent <PauseMenu>(), "Menu" ) as UnityAction; UnityEventTools.AddVoidPersistentListener(button.onClick, action); }; break; default: break; } break; default: break; } }
public static void RemovePersistentEvent(this UnityEvent _event, UnityAction _action) { UnityEventTools.RemovePersistentListener(_event, _action); }
// 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 }
public static void AddPersistentEvent <T0>(this UnityEvent <T0> _event, UnityAction <T0> _action) { UnityEventTools.AddPersistentListener(_event, _action); }
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; } }
// 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 override void OnInspectorGUI() { // base.OnInspectorGUI(); var buttonEvent = Selection.activeGameObject.GetComponent <ButtonTween>(); GUILayout.BeginHorizontal(); GUI.enabled = null == buttonEvent.GetComponent <TweenScale>(); if (GUILayout.Button("Scale")) { var tween = buttonEvent.gameObject.AddComponent <TweenScale>(); tween.isPlayOnStart = false; tween.To = new Vector3(0.1f, 0.1f, 0); tween.TotalTime = 0.2f; tween.Curve = AnimationCurve.EaseInOut(0, 0, 1, 1); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerDown, tween.PlayForward); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerUp, tween.PlayReverse); } GUI.enabled = null == buttonEvent.GetComponent <TweenRotation>(); if (GUILayout.Button("Rotation")) { var tween = buttonEvent.gameObject.AddComponent <TweenRotation>(); tween.isPlayOnStart = false; tween.To = new Vector3(1, 1, 1); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerDown, tween.PlayForward); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerUp, tween.PlayReverse); } GUI.enabled = null == buttonEvent.GetComponent <TweenPosition>(); if (GUILayout.Button("Position")) { var tween = buttonEvent.gameObject.AddComponent <TweenPosition>(); tween.isPlayOnStart = false; tween.To = new Vector3(1, 1, 1); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerDown, tween.PlayForward); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerUp, tween.PlayReverse); } GUI.enabled = null == buttonEvent.GetComponent <UITweenColorAlpha>(); if (GUILayout.Button("ColorAlpha")) { var tween = buttonEvent.gameObject.AddComponent <UITweenColorAlpha>(); tween.isPlayOnStart = false; UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerDown, tween.PlayForward); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerUp, tween.PlayReverse); } GUI.enabled = null == buttonEvent.GetComponent <TweenTransform>(); if (GUILayout.Button("Transform")) { var tween = buttonEvent.gameObject.AddComponent <TweenTransform>(); tween.isPlayOnStart = false; UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerDown, tween.PlayForward); UnityEventTools.AddPersistentListener(buttonEvent.EventOnPointerUp, tween.PlayReverse); } GUILayout.EndHorizontal(); }
// Start is called before the first frame update void Start() { var sr = GetComponent <SpriteRenderer>(); if (sr != null) { sr.enabled = !IsTrigger; } // 저장된 데이터와 해당 아이디간의 관계를 따지고 if (DeleteAfter) { #if DEBUG var targetinfo = UnityEventBase.GetValidMethodInfo(DataManager.instance, "SaveTrigger", new Type[] { typeof(GameObject) }); UnityAction <GameObject> action = Delegate.CreateDelegate(typeof(UnityAction <GameObject>), DataManager.instance, targetinfo, false) as UnityAction <GameObject>; UnityEventTools.AddObjectPersistentListener(After, action, gameObject); #else After.AddListener(delegate { DataManager.instance.SaveTrigger(gameObject); }); #endif } if (conditional_Conversations.Count > 0) { // 반대로 해야하는 이유는, 선행되는 조건에 대화가 묶여있는 것을 예방하기 위함 for (int i = conditional_Conversations.Count - 1; i > -1; i--) { bool CanOpen = CheckCondition(conditional_Conversations[i].condition); if (CanOpen) { index = i; break; } } } if (index == -1) { // 어디까지 대화를 들었는 지 체크 if (DataManager.Data.isinitialized[3]) { try { NPC.initialize(DataManager.Data.NPC_Conversation[NPC.FileName]); } catch (KeyNotFoundException) { NPC.initialize(); } } else { NPC.initialize(); } // 해당 아이디가 가진 대화 스크립트 저장하기 DataManager.Data.SaveConversation(NPC.FileName, NPC.GetCurrentConversation_ID()); //Debug.Log(DataManager.Data.NPC_Conversation); // 대화 스크립트 NPC.LoadConversation(NPC.GetCurrentConversation_ID()); } else { var NPC = conditional_Conversations[index].NPC; if (DataManager.Data.isinitialized[3]) { try { NPC.initialize(DataManager.Data.NPC_Conversation[NPC.FileName]); } catch (KeyNotFoundException) { NPC.initialize(); } } else { NPC.initialize(); } NPC.LoadConversation(NPC.GetCurrentConversation_ID()); } }
// 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 }
// 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 }
//---------------------------------------------------------------------------------------------------------------------------------------- public void DrawExtrasAndDoAutoFill(Rect r) { // process auto fill for (var i = 0; i < _evnt.GetPersistentEventCount(); i++) { var target = _evnt.GetPersistentTarget(i); if (target) { continue; } if (_eventOwner is Component) { UnityEventTools.RegisterStringPersistentListener(_evnt, i, (_eventOwner as Component).SendMessage, ""); ResetMethodInProperty(i); } } var stl = new GUIStyle(GUI.skin.button) { padding = new RectOffset(), margin = new RectOffset(), overflow = new RectOffset(), normal = GUI.skin.label.normal }; // Draw Extra buttons var pec = _evnt.GetPersistentEventCount(); for (var i = 0; i < pec; i++) { switch (_mode) { case Mode.Browse: if (GUI.Button(new Rect(r.xMin - 14, r.yMin + (i * 43) + 25, 20, 33), eIcons.Get("icons/d_viewtoolzoom on.png"), stl)) { eEventDialog.Execute(BuildHackedData(i), _evnt.GetPersistentTarget(i)); } break; case Mode.Reorder: if (i > 0 && GUI.Button(new Rect(r.xMin - 14, r.yMin + (i * 43) + 20, 20, 20), "▲", stl)) { MoveUpHack(i); } if (i < (pec - 1) && GUI.Button(new Rect(r.xMin - 14, r.yMin + (i * 43) + 40, 20, 20), "▼", stl)) { MoveDownHack(i); } break; case Mode.Delete: if (GUI.Button(new Rect(r.xMin - 14, r.yMin + (i * 43) + 25, 20, 33), eIcons.Get("icons/d_winbtn_win_close.png"), stl)) { UnityEventTools.RemovePersistentListener(_evnt, i); } break; } } // draw Clear button if (GUI.Button(new Rect(r.xMax - 19, r.yMin + 1, 18, 16), eIcons.Get("icons/d_winbtn_win_close.png"), stl)) { while (_evnt.GetPersistentEventCount() > 0) { UnityEventTools.RemovePersistentListener(_evnt, 0); } } // draw Toolbar buttons eGUI.SetFGColor(new Color(1, 1, 1, 0), 0.9f); if (_mode == Mode.Browse) { eGUI.ResetColors(); } if (GUI.Button(new Rect(r.center.x - 39, r.yMax - 17, 26, 18), eIcons.Get("icons/d_viewtoolzoom on.png"), stl)) { _mode = Mode.Browse; } if (_mode == Mode.Browse) { eGUI.SetFGColor(new Color(1, 1, 1, 0), 0.9f); } if (_mode == Mode.Reorder) { eGUI.ResetColors(); } if (GUI.Button(new Rect(r.center.x - 13, r.yMax - 17, 26, 18), eIcons.Get("icons/d_rotatetool on.png"), stl)) { _mode = Mode.Reorder; } if (_mode == Mode.Reorder) { eGUI.SetFGColor(new Color(1, 1, 1, 0), 0.9f); } if (_mode == Mode.Delete) { eGUI.ResetColors(); } if (GUI.Button(new Rect(r.center.x + 13, r.yMax - 17, 26, 18), eIcons.Get("d_treeeditor.trash"), stl)) { _mode = Mode.Delete; } // draw Runtime count if (_runtimeCount > 0) { eGUI.SetFGColor(new Color(1, 0.3f, 0.3f), 0.9f); GUI.Label(new Rect(r.xMin, r.yMax - 16, 96, 16), "Runtime: " + _runtimeCount, EditorStyles.boldLabel); } }
public void MyValidate(bool autoSetTriggers = false) { if (Elements == null) { return; } if (Application.isPlaying) { return; } if (gameObject.IsPrefab()) { #if UNITY_EDITOR Debug.LogError("MyValidate None"); //Debug.LogError(mono.GetType()+"on +"+ mono.gameObject+ " PrefabType=" + prefabType); #endif return; } if (!autoSetTriggers) { CheckError(); return; } //countElements = Elements.Length; EventTrigger.Entry onDown, onUp; UIButtonInfo _elem; for (int i = 0; i < Elements.Count; i++) { _elem = Elements[i]; if (_elem.TriggerTarget == null) { Debug.LogWarning(GetType() + " error: " + gameObject + " TriggerTarget(self image on this) is null in element"); continue; } EventTrigger[] triggers = _elem.TriggerTarget.GetComponents <EventTrigger>(); for (int j = 1; j < triggers.Length; j++) { DestroyImmediate(triggers[j]); } if (_elem.Trigger == null) { _elem.Trigger = _elem.TriggerTarget.gameObject.AddComponent <EventTrigger>(); } _elem.Trigger.triggers.Clear(); onUp = new EventTrigger.Entry(); onUp.eventID = EventTriggerType.PointerUp; onDown = new EventTrigger.Entry(); onDown.eventID = EventTriggerType.PointerDown; _elem.ID = _elem.ID > -1 ? _elem.ID : i; UnityEventTools.AddIntPersistentListener(onUp.callback, UpTrigger, _elem.ID); UnityEventTools.AddIntPersistentListener(onDown.callback, DownTrigger, _elem.ID); _elem.Trigger.triggers.Add(onDown); _elem.Trigger.triggers.Add(onUp); _elem.isImage = _elem.Image != null; _elem.isSprite = _elem.isImage && _elem.SpriteDown != null && _elem.SpriteUp != null; if (_elem.isSprite) { _elem.Image.sprite = _elem.SpriteUp; } if (!_elem.TriggerTarget.raycastTarget) { Debug.LogError(GetType() + " error: " + gameObject + " image is not raycastTarget true in element"); } } CheckError(); }