Better ui and placement soon done

This commit is contained in:
BOT Alex 2024-04-21 01:43:22 +02:00
parent 1a6280101f
commit 7cdf72cf24
6 changed files with 616 additions and 645 deletions

View File

@ -8,8 +8,8 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Close
- m_ConditionMode: 2
m_ConditionEvent: IsOpen
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 2682460963827588746}
@ -25,58 +25,6 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-7641027645006483654
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Open
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -2280432560819215181}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0
m_HasExitTime: 0
m_HasFixedDuration: 0
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &-2280432560819215181
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: FullOut
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 8958318208459601179}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: a9f8f24edd1852c4e829d921b091c37d, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-2135777584370832094
AnimatorState:
serializedVersion: 6
@ -88,7 +36,6 @@ AnimatorState:
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: -7641027645006483654}
- {fileID: -8896916857368744256}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
@ -120,9 +67,6 @@ AnimatorStateMachine:
- serializedVersion: 1
m_State: {fileID: -2135777584370832094}
m_Position: {x: 240, y: 30, z: 0}
- serializedVersion: 1
m_State: {fileID: -2280432560819215181}
m_Position: {x: 490, y: 30, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
@ -142,14 +86,8 @@ AnimatorController:
m_Name: cocksex
serializedVersion: 5
m_AnimatorParameters:
- m_Name: Open
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Close
m_Type: 9
- m_Name: IsOpen
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
@ -203,7 +141,7 @@ AnimatorStateTransition:
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Open
m_ConditionEvent: IsOpen
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -2135777584370832094}
@ -219,28 +157,3 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &8958318208459601179
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Close
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 2682460963827588746}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.2
m_TransitionOffset: 0
m_ExitTime: 0
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
using System;
using UnityEngine;
public class GameManager : MonoBehaviour
@ -8,8 +9,6 @@ public class GameManager : MonoBehaviour
public bool IsBuildMode = false;
private Tower selectedTower;
public TowerInfo ShopSelectedTower;
public Tower SelectedTower { get { return selectedTower; } set {
if (selectedTower != null)
selectedTower.TowerSelected(false);
@ -25,4 +24,26 @@ public class GameManager : MonoBehaviour
Destroy(Instance);
Instance = this;
}
private void OnEnable()
{
MoneyManager.OnShopSelected += m_OnTowerShopSelected;
TowerPlacementManager.OnTowerPlaced += m_finishBuildmode;
}
private void OnDisable()
{
MoneyManager.OnShopSelected -= m_OnTowerShopSelected;
TowerPlacementManager.OnTowerPlaced -= m_finishBuildmode;
}
private void m_OnTowerShopSelected(TowerInfo info)
{
IsBuildMode = true;
}
private void m_finishBuildmode(TowerInfo info)
{
IsBuildMode = false;
}
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
@ -11,6 +12,11 @@ public class MoneyManager : MonoBehaviour
public GameObject[] ShopButtons;
public TMP_Text[] MoneyTexts;
/// <summary>
/// Invoked when player selects tower from shop
/// </summary>
public static event Action<TowerInfo> OnShopSelected;
private void OnEnable()
{
for (int i = 0; i < ShopButtons.Length; i++)
@ -35,7 +41,6 @@ public class MoneyManager : MonoBehaviour
{
Assert.AreNotEqual(index, -1, "Shop button not init-ed with index");
GameManager.Instance.ShopSelectedTower = towerCollection.Towers[index];
GameManager.Instance.IsBuildMode = true;
OnShopSelected?.Invoke(towerCollection.Towers[index]);
}
}

View File

@ -8,26 +8,28 @@ using UnityEngine;
public class TowerPlacementManager : MonoBehaviour
{
/// <summary>
/// Sender
/// </summary>
public static TowerPlacementManager Instance;
// Spawning grid events
public static event Action<TowerPlacementManager> OnSpawnGridRequested;
public static event Action<TowerPlacementManager> OnGridDeleteRequested;
public static TowerPlacementManager Instance;
// Placing tower
public static event Action<TowerInfo> OnTowerPlaced;
[Header("Debug")]
[SerializeField] private bool RebuildGrid = false;
// Section: Mouse
private SlotManager CurrentSelectedSlot;
private SlotManager CurrentHovered; // Not implemented
private int CurrentRotation = 0; // 0, 1, 2, 3
private GameObject SilhouettedObject;
private TowerInfo SelectedTowerInfo;
// Section: Debug
public GameObject DebugTowerPrefab;
private GameObject SelectedTowerPrefab => SelectedTowerInfo.prefab;
private void Start()
{
@ -59,12 +61,27 @@ public class TowerPlacementManager : MonoBehaviour
}
}
private void OnEnable()
{
MoneyManager.OnShopSelected += OnShopSelected;
}
private void OnDisable()
{
MoneyManager.OnShopSelected -= OnShopSelected;
}
private void OnShopSelected(TowerInfo info)
{
SelectedTowerInfo = info;
}
public void OnSlotClicked(SlotManager slot, GridManager grid, int x, int y)
{
slot.gameObject.GetComponentInChildren<Renderer>().material.color = Color.blue;
OnSelectSlot(slot);
SpawnTowerAtSelected(DebugTowerPrefab);
SpawnTowerAtSelected(SelectedTowerPrefab);
}
// Called when a slot is selected
@ -94,13 +111,13 @@ public class TowerPlacementManager : MonoBehaviour
public void OnSlotHovered(SlotManager slot, GridManager grid, int x, int y)
{
if (SilhouettedObject == null)
SilhouettedObject = ToSilhouette(DebugTowerPrefab);
SilhouettedObject = ToSilhouette(SelectedTowerPrefab);
// Sets tower rotation
Quaternion newRotation = Quaternion.AngleAxis(CurrentRotation * 90f, transform.up);
SilhouettedObject.transform.localRotation = newRotation;
Vector3 offset = DebugTowerPrefab.transform.position;
Vector3 offset = SelectedTowerPrefab.transform.position;
//SilhouettedObject.SetActive(true);
SilhouettedObject.transform.parent = slot.TowerSpawnPoint.transform;

View File

@ -1,53 +1,72 @@
using System;
using UnityEditor.PackageManager;
using UnityEngine;
using UnityEngine.EventSystems;
public class UIManager : MonoBehaviour
{
public Animator anim;
public string animationCall;
[SerializeField] private Animator anim;
[SerializeField] private EventTrigger OpenerTrigger;
[SerializeField] private EventTrigger CloseTrigger;
public GameObject activateGo;
public bool deactivateSelf;
private bool OpenerIsHovered = false;
private bool CloseIsHovered = false;
public UIManager affectedObj;
private bool CurrentShopState = false;
public bool count;
public int maxCount = 1;
public int currentCount = 0;
private void Awake()
private void OnEnable()
{
if(count)
currentCount = 0;
// Subscribe to PointerEnter event
EventTrigger.Entry pointerOpenerEnter = new EventTrigger.Entry();
pointerOpenerEnter.eventID = EventTriggerType.PointerEnter;
pointerOpenerEnter.callback.AddListener((data) => { OnOpenerEnter((PointerEventData)data); });
OpenerTrigger.triggers.Add(pointerOpenerEnter);
// Subscribe to PointerExit event
EventTrigger.Entry pointerOpenerExit = new EventTrigger.Entry();
pointerOpenerExit.eventID = EventTriggerType.PointerExit;
pointerOpenerExit.callback.AddListener((data) => { OnOpenerExit((PointerEventData)data); });
OpenerTrigger.triggers.Add(pointerOpenerExit);
// Subscribe to PointerEnter event
EventTrigger.Entry pointerCloseTriggerEnter = new EventTrigger.Entry();
pointerCloseTriggerEnter.eventID = EventTriggerType.PointerEnter;
pointerCloseTriggerEnter.callback.AddListener((data) => { OnCloseTriggerEnter((PointerEventData)data); });
CloseTrigger.triggers.Add(pointerCloseTriggerEnter);
// Subscribe to PointerExit event
EventTrigger.Entry pointerCloseTriggerExit = new EventTrigger.Entry();
pointerCloseTriggerExit.eventID = EventTriggerType.PointerExit;
pointerCloseTriggerExit.callback.AddListener((data) => { OnCloseTriggerExit((PointerEventData)data); });
CloseTrigger.triggers.Add(pointerCloseTriggerExit);
}
public void OnMouseEnter()
private void OnCloseTriggerEnter(PointerEventData data)
{
anim.SetTrigger(animationCall);
CloseIsHovered = true;
UpdateShopState();
}
if (activateGo != null)
activateGo.SetActive(true);
if (deactivateSelf)
private void OnCloseTriggerExit(PointerEventData data)
{
gameObject.SetActive(false);
if (count)
ResetCount();
CloseIsHovered = false;
UpdateShopState();
}
//gameObject.SetActive(false);
if (count)
currentCount++;
if (currentCount >= maxCount && count)
gameObject.SetActive(false);
if (affectedObj != null && affectedObj.currentCount >= affectedObj.maxCount && affectedObj.count)
ResetCount();
}
public void ResetCount()
private void OnOpenerEnter(PointerEventData data)
{
affectedObj.gameObject.SetActive(true);
affectedObj.currentCount = 0;
OpenerIsHovered = true;
UpdateShopState();
}
private void OnOpenerExit(PointerEventData data)
{
OpenerIsHovered = false;
UpdateShopState();
}
private void UpdateShopState()
{
CurrentShopState = (CurrentShopState && !CloseIsHovered) || (OpenerIsHovered && !CloseIsHovered);
anim.SetBool("IsOpen", CurrentShopState);
}
}