You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
7.5 KiB
C#
253 lines
7.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
public class instantiateprefab : MonoBehaviour
|
|
{
|
|
public GameObject prefab, panel;
|
|
public GameObject[] positionArray;
|
|
public Transform parentTf;
|
|
//public Text[] values;
|
|
// public int[] minValues;
|
|
// public int[] maxValues;
|
|
public List<LevelGroup> levelGroups;
|
|
public int minIndex = 0;
|
|
public int maxIndex = 8;
|
|
public int points;
|
|
public string Mode;
|
|
public string pointtext;
|
|
public AchievementManager manger;
|
|
public ScoreButton score;
|
|
public Button changeValueButton;
|
|
public GameManager gameManager;
|
|
private List<Slider> sliders = new List<Slider>();
|
|
public GamePlayManager gameplay;
|
|
public Slider sliderprefabalue, hintcheckvalue;
|
|
public string[] ModeNames;
|
|
public int value;
|
|
// public GameObject level;
|
|
public LevelGroupButton levelGroupButton;
|
|
public void Awake()
|
|
{
|
|
levelGroupButton=GetComponent<LevelGroupButton>();
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
for (int i = 0; i < positionArray.Length; i++)
|
|
{
|
|
if (positionArray[i] != null)
|
|
{
|
|
InstantiateSlider(i, positionArray[i].transform.position);
|
|
}
|
|
}
|
|
|
|
|
|
InstantiateSSlider(positionArray.Length, new Vector3(0, -100, 0));
|
|
InstantiateSSlider(positionArray.Length + 1, new Vector3(0, -200, 0));
|
|
InstantiateSSlider(positionArray.Length + 2, new Vector3(0, -300, 0));
|
|
InstantiateSSlider(positionArray.Length + 3, new Vector3(0, -400, 0));
|
|
|
|
|
|
// Add listener to the button
|
|
changeValueButton.onClick.AddListener(ChangeSliderValueAtIndex7);
|
|
changeValueButton.onClick.AddListener(SliderValueAtIndex9);
|
|
changeValueButton.onClick.AddListener(ChangeSliderValueAtIndex8);
|
|
changeValueButton.onClick.AddListener(SliderValueAtIndex10);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private void InstantiateSlider(int index, Vector3 position)
|
|
{
|
|
GameObject sliderObject = Instantiate(prefab, position, Quaternion.identity, parentTf);
|
|
sliderObject.GetComponent<ScoreButton>().myIndex = index + 1;
|
|
|
|
foreach (Transform child in sliderObject.transform)
|
|
{
|
|
if (child.name == Mode)
|
|
{
|
|
Text levelname = child.GetComponent<Text>();
|
|
levelname.text = manger.AchievementList[index].DisplayName.ToString();
|
|
}
|
|
if (child.name == pointtext)
|
|
{
|
|
Text progress = child.GetComponent<Text>();
|
|
progress.text = manger.AchievementList[index].ProgressGoal + " / " + manger.AchievementList[index].ProgressSuffix.ToString();
|
|
}
|
|
}
|
|
|
|
Slider slider = sliderObject.GetComponent<Slider>();
|
|
if (slider != null)
|
|
{
|
|
slider.minValue = 0;
|
|
slider.maxValue = levelGroups[index].TotalLevel;
|
|
slider.value = levelGroups[index].CompletedLevel;
|
|
|
|
sliders.Add(slider); // Store the slider in the list
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void InstantiateSSlider(int index, Vector3 position)
|
|
{
|
|
GameObject sliderObject = Instantiate(prefab, position, Quaternion.identity, parentTf);
|
|
sliderObject.GetComponent<ScoreButton>().myIndex = index + 1;
|
|
|
|
// Assign a name to the slider object based on the achievement list or create a fallback for extra sliders
|
|
if (index < manger.AchievementList.Count)
|
|
{
|
|
string achievementName = manger.AchievementList[index].DisplayName.ToString();
|
|
sliderObject.name = "Slider - " + achievementName;
|
|
}
|
|
else
|
|
{
|
|
sliderObject.name = "Slider - Extra " + (index - manger.AchievementList.Count + 1);
|
|
}
|
|
|
|
// Set the Mode text for extra sliders
|
|
foreach (Transform child in sliderObject.transform)
|
|
{
|
|
if (child.name == Mode)
|
|
{
|
|
Text modeText = child.GetComponent<Text>();
|
|
if (modeText != null)
|
|
{
|
|
if (index < ModeNames.Length)
|
|
{
|
|
modeText.text = ModeNames[index];
|
|
}
|
|
else
|
|
{
|
|
modeText.text = "Extra Mode " + (index - ModeNames.Length + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (child.name == pointtext)
|
|
{
|
|
Text progress = child.GetComponent<Text>();
|
|
progress.text = (index < manger.AchievementList.Count) ?
|
|
manger.AchievementList[index].ProgressGoal + " / " + manger.AchievementList[index].ProgressSuffix.ToString() :
|
|
"0 / 10"; // Fallback for extra sliders
|
|
}
|
|
}
|
|
|
|
Slider slider = sliderObject.GetComponent<Slider>();
|
|
if (slider != null)
|
|
{
|
|
slider.minValue = 0;
|
|
slider.maxValue = (index < manger.AchievementList.Count) ? manger.AchievementList[index].ProgressGoal : 10;
|
|
// slider.value = (index < manger.AchievementList.Count) ? manger.AchievementList[index].ProgressCurrent : 0;
|
|
|
|
sliders.Add(slider); // Store the slider in the list
|
|
}
|
|
}
|
|
|
|
public void ChangeSliderValueAtIndex7()
|
|
{
|
|
if (sliders.Count > 6)
|
|
{
|
|
Slider sliderAtIndex7 = sliders[6];
|
|
sliderAtIndex7.value += 1;
|
|
sliderAtIndex7.maxValue = 10;
|
|
sliderAtIndex7.minValue = 0;
|
|
// Ensure the name of the slider at index 7 matches the AchievementList
|
|
|
|
}
|
|
}
|
|
public void ChangeSliderValueAtIndex8()
|
|
{
|
|
if (sliders.Count > 7)
|
|
{
|
|
Slider sliderAtIndex8 = sliders[7];
|
|
sliderAtIndex8.value += 1;
|
|
sliderAtIndex8.maxValue = 20;
|
|
sliderAtIndex8.minValue = 0;
|
|
|
|
}
|
|
}
|
|
public void Update()
|
|
{
|
|
|
|
SliderValueAtIndex9();
|
|
SliderValueAtIndex10();
|
|
for (int i = 0; i < sliders.Count; i++)
|
|
{
|
|
if (levelGroups[i].CompletedLevel == levelGroups[i].TotalLevel)
|
|
{
|
|
sliders[i].maxValue = levelGroups[i].TotalLevel;
|
|
// Increment the TotalLevel by 5 immediately
|
|
levelGroups[i].TotalLevel += 5;
|
|
|
|
score.completetargets += 1;
|
|
score.points += 50 *score.myIndex;
|
|
|
|
|
|
// score. targetText.text = "" + completetargets.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
if (levelGroupButton != null)
|
|
{
|
|
levelGroupButton.UpdateUI();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SliderValueAtIndex9()
|
|
{
|
|
if (sliders.Count > 8)
|
|
{
|
|
Slider sliderAtIndex9 = sliders[8];
|
|
sliderAtIndex9.value = sliderprefabalue.value;
|
|
sliderAtIndex9.maxValue = 1000;
|
|
// score.completetargets = value;
|
|
|
|
|
|
}
|
|
}
|
|
public void SliderValueAtIndex10()
|
|
{
|
|
if (sliders.Count > 5)
|
|
{
|
|
Slider sliderAtIndex10 = sliders[5];
|
|
sliderAtIndex10.value = hintcheckvalue.value;
|
|
sliderAtIndex10.maxValue = 1000;
|
|
|
|
}
|
|
}
|
|
|
|
public void poppanel()
|
|
{
|
|
panel.SetActive(true);
|
|
|
|
|
|
}
|
|
public void MaxValueset()
|
|
{
|
|
if (sliders.Count > 7)
|
|
{
|
|
Slider sliderAtIndex8 = sliders[7];
|
|
sliderAtIndex8.maxValue = 20;
|
|
sliderAtIndex8.minValue = 0;
|
|
|
|
}
|
|
}
|
|
public void AchivementsetFalse()
|
|
{
|
|
panel.SetActive(false);
|
|
}
|
|
|
|
|
|
} |