mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 05:25:38 +03:00
04.07.2022
This commit is contained in:
59
Heli_with_panels/Assets/Scripts/Panel2D/ButtonCheckable3.cs
Normal file
59
Heli_with_panels/Assets/Scripts/Panel2D/ButtonCheckable3.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
/* Работает на любое количество спрайтов, переключает по очереди */
|
||||
public class ButtonCheckable3 : MonoBehaviour
|
||||
{
|
||||
//Dictionary<string, GameObject> buttonStatesList3 = new Dictionary<string, GameObject>();
|
||||
List<GameObject> buttonStatesList3 = new List<GameObject>();
|
||||
int click = 0;
|
||||
Manager man;
|
||||
|
||||
void Start()
|
||||
{
|
||||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||||
Transform[] buttonStates = this.GetComponentsInChildren<Transform>();
|
||||
for (int i = 0; i < buttonStates.Length; i++)
|
||||
if (buttonStates[i].name != this.name)
|
||||
{
|
||||
buttonStates[i].gameObject.SetActive(false);
|
||||
buttonStatesList3.Add(buttonStates[i].gameObject);
|
||||
}
|
||||
|
||||
//EnableSprite(click);
|
||||
UnityObject curUO = man.objects.FindHandler(this.gameObject.name);
|
||||
curUO.SetObjectState(click);
|
||||
|
||||
//debug:
|
||||
/*if (this.name == "mfi3_Lamp5_1")
|
||||
Debug.Log("Lamp5_1 states = " + (buttonStates.Length + 1) + " active = " + this.gameObject.active + " activeInHierarchy = " + this.gameObject.activeInHierarchy);
|
||||
for (int i = 0; i < buttonStates.Length; i++)
|
||||
if (buttonStates[i].name != this.name)
|
||||
{
|
||||
if (this.name == "mfi3_Lamp5_1")
|
||||
Debug.Log(buttonStates[i].name + " active = " + buttonStates[i].gameObject.active + " activeInHierarchy = " + buttonStates[i].gameObject.activeInHierarchy);
|
||||
} */
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (man.mode == "scedit" || man.mode == "play")
|
||||
return;
|
||||
click++;
|
||||
if (click > buttonStatesList3.Count - 1) click = 0;
|
||||
//Debug.Log("количество кликов + " + click);
|
||||
//EnableSprite(click);
|
||||
UnityObject curUO = man.objects.FindHandler(this.gameObject.name);
|
||||
curUO.SetObjectState(click);
|
||||
|
||||
}
|
||||
|
||||
public void EnableSprite(int n)
|
||||
{
|
||||
if (n >= buttonStatesList3.Count)
|
||||
return;
|
||||
buttonStatesList3.ForEach(_buttonStatesList3 => _buttonStatesList3.gameObject.SetActive(false));
|
||||
buttonStatesList3[n].gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user