Files
Robii Aragon fd87a6ffd5 add ckg
plantilla base para movimiento básico
2026-02-05 05:07:55 -08:00

259 lines
7.3 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
public class pickUpManager : MonoBehaviour
{
public bool showIconsActive = true;
public List<pickUpElementInfo> mainPickUpList = new List<pickUpElementInfo> ();
public List<pickUpIconInfo> pickUpIconList = new List<pickUpIconInfo> ();
public List<playerPickupIconManager> playerPickupIconManagerList = new List<playerPickupIconManager> ();
int currentID = 0;
public const string mainManagerName = "Pickup Manager";
public static string getMainManagerName ()
{
return mainManagerName;
}
private static pickUpManager _pickUpManagerInstance;
public static pickUpManager Instance { get { return _pickUpManagerInstance; } }
bool instanceInitialized;
public void getComponentInstance ()
{
if (instanceInitialized) {
return;
}
if (_pickUpManagerInstance != null && _pickUpManagerInstance != this) {
Destroy (this.gameObject);
return;
}
_pickUpManagerInstance = this;
instanceInitialized = true;
}
void Awake ()
{
getComponentInstance ();
}
public void addNewPlayer (playerPickupIconManager newPlayer)
{
if (!showIconsActive) {
return;
}
playerPickupIconManagerList.Add (newPlayer);
int pickUpIconListCount = pickUpIconList.Count;
if (pickUpIconListCount > 0) {
for (int i = 0; i < pickUpIconListCount; i++) {
newPlayer.setPickUpIcon (
pickUpIconList [i].target,
pickUpIconList [i].iconTexture,
pickUpIconList [i].ID,
pickUpIconList [i].iconPrefab);
}
}
}
//set what type of pick up is this object, and the object that the icon has to follow
public void setPickUpIcon (GameObject target, string pickupIconGeneralName, string pickupIconName)
{
if (!showIconsActive) {
return;
}
int targetIndex = pickUpIconList.FindIndex (s => s.target == target);
if (targetIndex > -1) {
//print (target.name + " alredy added, cancelling");
return;
}
pickUpIconInfo newIcon = new pickUpIconInfo ();
newIcon.name = target.name;
newIcon.ID = currentID;
newIcon.target = target;
newIcon.targetTransform = target.transform;
Texture iconTexture = null;
GameObject iconPrefab = null;
int pickupListIndex = mainPickUpList.FindIndex (s => s.pickUpType.ToLower () == pickupIconGeneralName.ToLower ());
if (pickupListIndex > -1) {
pickUpElementInfo currentPickupElementInfo = mainPickUpList [pickupListIndex];
bool useGeneralIcon = currentPickupElementInfo.useGeneralIcon;
int customIndexTexture = -1;
if (!pickupIconName.Equals ("")) {
int pickupTypeIndex = currentPickupElementInfo.pickUpTypeList.FindIndex (s => s.Name.ToLower () == pickupIconName.ToLower ());
if (pickupTypeIndex > -1) {
customIndexTexture = pickupTypeIndex;
useGeneralIcon = false;
}
}
if (useGeneralIcon) {
iconTexture = currentPickupElementInfo.generalIcon;
} else {
if (customIndexTexture > -1) {
iconTexture = currentPickupElementInfo.pickUpTypeList [customIndexTexture].pickupIcon;
}
}
bool useCustomIconPrefab = currentPickupElementInfo.useCustomIconPrefab;
if (customIndexTexture > -1) {
if (currentPickupElementInfo.pickUpTypeList [customIndexTexture].useCustomIconPrefab) {
iconPrefab = currentPickupElementInfo.pickUpTypeList [customIndexTexture].customIconPrefab;
useCustomIconPrefab = false;
}
}
if (useCustomIconPrefab) {
iconPrefab = currentPickupElementInfo.customIconPrefab;
}
}
newIcon.iconTexture = iconTexture;
newIcon.iconPrefab = iconPrefab;
pickUpIconList.Add (newIcon);
for (int i = 0; i < playerPickupIconManagerList.Count; i++) {
playerPickupIconManagerList [i].setPickUpIcon (target, iconTexture, currentID, iconPrefab);
}
currentID++;
}
//destroy the icon
public void removeTarget (GameObject target)
{
if (!showIconsActive) {
return;
}
for (int i = 0; i < pickUpIconList.Count; i++) {
if (pickUpIconList [i].target != null) {
if (pickUpIconList [i].target == target) {
removeAtTarget (pickUpIconList [i].ID, i);
return;
}
}
}
}
public void removeAtTarget (int objectID, int objectIndex)
{
if (!showIconsActive) {
return;
}
for (int i = 0; i < playerPickupIconManagerList.Count; i++) {
playerPickupIconManagerList [i].removeAtTargetByID (objectID);
}
pickUpIconList.RemoveAt (objectIndex);
}
public void removeElementFromPickupListCalledByPlayer (int objectID)
{
if (!showIconsActive) {
return;
}
for (int i = 0; i < pickUpIconList.Count; i++) {
if (pickUpIconList [i].ID == objectID) {
pickUpIconList.RemoveAt (i);
return;
}
}
}
public void setPauseState (bool state, GameObject iconObject)
{
if (!showIconsActive) {
return;
}
for (int i = 0; i < pickUpIconList.Count; i++) {
if (pickUpIconList [i].target == iconObject) {
pickUpIconList [i].paused = state;
for (int j = 0; j < playerPickupIconManagerList.Count; j++) {
playerPickupIconManagerList [j].setPauseState (state, i);
}
}
}
}
public void setNamesConfigured (int currentIndex)
{
pickUpElementInfo currentpickUpElementInfo = mainPickUpList [currentIndex];
for (int i = 0; i < currentpickUpElementInfo.pickUpTypeList.Count; i++) {
if (currentpickUpElementInfo.pickUpTypeList [i].pickUpObject != null) {
currentpickUpElementInfo.pickUpTypeList [i].Name = currentpickUpElementInfo.pickUpTypeList [i].pickUpObject.name;
}
}
}
public void addNewPickup ()
{
pickUpElementInfo newPickupElementInfo = new pickUpElementInfo ();
newPickupElementInfo.pickUpType = "New Pickup Type";
mainPickUpList.Add (newPickupElementInfo);
udpateComponent ();
}
public void addNewPickupToList (int index)
{
pickUpElementInfo.pickUpTypeElementInfo newPickupTypeElementInfo = new pickUpElementInfo.pickUpTypeElementInfo ();
newPickupTypeElementInfo.Name = "New Pickup";
mainPickUpList [index].pickUpTypeList.Add (newPickupTypeElementInfo);
udpateComponent ();
}
public void udpateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Pickup Manager", gameObject);
}
}