// Start is called before the first frame update public void OnEnable() { m_RootElement = new VisualElement(); m_ModulesVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>( baseAssetPath + "/AbstractComponentTypeSelectionEditor.uxml" ); var stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>( baseAssetPath + "/AbstractComponentTypeSelectionEditor.uss" ); m_RootElement.styleSheets.Add(stylesheet); // Cleanup any strings which correspond to types that no longer exist. var allTypes = new ComponentCollector().GetAllTypes(System.AppDomain.CurrentDomain); var serializedTypeStrings = new List <string>(); var componentsSerialized = serializedObject.FindProperty("Components"); var count = componentsSerialized.arraySize; for (var i = count - 1; i >= 0; i--) { var type = componentsSerialized.GetArrayElementAtIndex(i).stringValue; if (!allTypes.Any(x => x.AssemblyQualifiedName == type)) { componentsSerialized.DeleteArrayElementAtIndex(i); } } serializedObject.ApplyModifiedProperties(); // Go through each item in list and check if it in allTypes. If it isn't, delete. }
private void Awake() { T[] components = GetComponents <T>(); foreach (T component in components) { ComponentCollector.Add(component); } }
private void Update() { var fields = ComponentCollector.Get(typeof(InputFieldWrapper)); foreach (var field in fields) { if (((InputFieldWrapper)field).isFocused) { return; } } foreach (var toggleUi in toggleUis) { if (Input.GetKeyDown(toggleUi.key)) { var ui = toggleUi.ui; ui.Toggle(); } } }
public override VisualElement CreateInspectorGUI() { var container = m_RootElement; container.Clear(); m_ModulesVisualTree.CloneTree(container); var allTypes = new ComponentCollector().GetAllTypes(System.AppDomain.CurrentDomain); var componentsSerialized = serializedObject.FindProperty("Components"); var serializedTypeStrings = new List <string>(); var count = componentsSerialized.arraySize; for (var i = 0; i < count; i++) { serializedTypeStrings.Add(componentsSerialized.GetArrayElementAtIndex(i).stringValue); } foreach (var type in allTypes) { // Look for a "DisplayName" attribute var displayNameAttribute = (AbilitySystemDisplayNameAttribute)System.Attribute.GetCustomAttribute(type, typeof(AbilitySystemDisplayNameAttribute)); string displayName = ""; if (displayNameAttribute != null) { displayName = displayNameAttribute.Name; } var button = new Button(() => { var existingIndex = serializedTypeStrings.FindIndex(x => x == type.AssemblyQualifiedName); // if this already exists in the list, delete it if (existingIndex >= 0) { componentsSerialized.DeleteArrayElementAtIndex(existingIndex); serializedObject.ApplyModifiedProperties(); } else { // Add it to list componentsSerialized.InsertArrayElementAtIndex(0); componentsSerialized.GetArrayElementAtIndex(0).stringValue = type.AssemblyQualifiedName; serializedObject.ApplyModifiedProperties(); } CreateInspectorGUI(); }) { text = displayName == "" ? type.FullName : displayName }; // If this type is in the list of selected components, mark it enabled if (serializedTypeStrings.Any(x => x == type.AssemblyQualifiedName)) { button.AddToClassList("enabled-button"); } container.Add(button); } return(container); }
protected virtual void UpdateInput() { var fields = ComponentCollector.Get(typeof(InputFieldWrapper)); foreach (var field in fields) { if (((InputFieldWrapper)field).isFocused) { destination = null; PlayerCharacterEntity.StopMove(); return; } } if (CacheGameplayCameraControls != null) { CacheGameplayCameraControls.updateRotation = InputManager.GetButton("CameraRotate"); } if (PlayerCharacterEntity.IsDead()) { return; } // If it's building something, don't allow to activate NPC/Warp/Pickup Item if (currentBuildingEntity == null) { // Activate nearby npcs / players / activable buildings if (InputManager.GetButtonDown("Activate")) { targetPlayer = null; targetNpc = null; tempCount = OverlapObjects(CharacterTransform.position, gameInstance.conversationDistance, gameInstance.characterLayer.Mask); for (tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempGameObject = GetOverlapObject(tempCounter); if (targetPlayer == null) { targetPlayer = tempGameObject.GetComponent <BasePlayerCharacterEntity>(); if (targetPlayer == PlayerCharacterEntity) { targetPlayer = null; } } if (targetNpc == null) { targetNpc = tempGameObject.GetComponent <NpcEntity>(); } } // Priority Player -> Npc -> Buildings if (targetPlayer != null && CacheUISceneGameplay != null) { CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer); } else if (targetNpc != null) { PlayerCharacterEntity.RequestNpcActivate(targetNpc.ObjectId); } if (overlapColliders.Length == 0) { PlayerCharacterEntity.RequestEnterWarp(); } } // Pick up nearby items if (InputManager.GetButtonDown("PickUpItem")) { tempCount = OverlapObjects(CharacterTransform.position, gameInstance.pickUpItemDistance, gameInstance.itemDropLayer.Mask); for (tempCounter = 0; tempCounter < tempCount; ++tempCounter) { tempGameObject = GetOverlapObject(tempCounter); targetItemDrop = tempGameObject.GetComponent <ItemDropEntity>(); if (targetItemDrop != null) { PlayerCharacterEntity.RequestPickupItem(targetItemDrop.ObjectId); break; } } } } UpdatePointClickInput(); UpdateWASDInput(); UpdateBuilding(); }