mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:45:39 +03:00
166 lines
5.2 KiB
C#
166 lines
5.2 KiB
C#
<<<<<<< HEAD
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ButtonCheckable : MonoBehaviour
|
||
{
|
||
Dictionary<string, GameObject> buttonStatesList = new Dictionary<string, GameObject>();
|
||
|
||
// int posCount;
|
||
// int currentPos;
|
||
GameObject goUp;
|
||
GameObject goDown;
|
||
public bool isChecked = false;
|
||
public bool isStarted = false;
|
||
Image goUp_Img=null, goDown_Img=null;
|
||
SpriteRenderer goUp_SR = null, goDown_SR = null;
|
||
Manager man;
|
||
|
||
void Start()
|
||
{
|
||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||
// Debug.Log(go.name);
|
||
Transform[] buttonStates = this.GetComponentsInChildren<Transform>();
|
||
// Debug.Log(btnList.Length);
|
||
// goUp = new GameObject();
|
||
// goDown = new GameObject();
|
||
for (int i = 0; i < buttonStates.Length; i++)
|
||
{
|
||
if (i == 0) continue;
|
||
if (string.Compare(buttonStates[i].name.Substring(buttonStates[i].name.Length - 2), "up") == 0) // this.name.Length - 3
|
||
goUp = buttonStates[i].gameObject;
|
||
if (string.Compare(buttonStates[i].name.Substring(buttonStates[i].name.Length - 4), "down") == 0) // this.name.Length - 3
|
||
goDown = buttonStates[i].gameObject;
|
||
}
|
||
goUp_Img = goUp.GetComponent<Image>();
|
||
goUp_SR = goUp.GetComponent<SpriteRenderer>();
|
||
goDown_Img = goDown.GetComponent<Image>();
|
||
goDown_SR = goDown.GetComponent<SpriteRenderer>();
|
||
|
||
if (goUp_Img != null) goUp_Img.enabled = !isChecked;
|
||
if (goUp_SR != null) goUp_SR.enabled = !isChecked;
|
||
if (goDown_Img != null) goDown_Img.enabled = isChecked;
|
||
if (goDown_SR != null) goDown_SR.enabled = isChecked;
|
||
isStarted = true;
|
||
}
|
||
|
||
void OnMouseDown()
|
||
{
|
||
if (man.mode == "scedit" || man.mode == "play")
|
||
return;
|
||
OnCheck();
|
||
}
|
||
|
||
|
||
public void OnCheck()
|
||
{
|
||
if (goUp == null || goDown == null) Start();
|
||
if (goUp == null || goDown == null) return;
|
||
|
||
try
|
||
{
|
||
isChecked = !isChecked;
|
||
if (goUp_Img != null) goUp_Img.enabled = !isChecked;
|
||
if (goUp_SR != null) goUp_SR.enabled = !isChecked;
|
||
if (goDown_Img != null) goDown_Img.enabled = isChecked;
|
||
if (goDown_SR != null) goDown_SR.enabled = isChecked;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.LogError(e.Message);
|
||
}
|
||
|
||
}
|
||
|
||
public void SetState(int st)
|
||
{
|
||
if (st == 0) isChecked = true; else isChecked = false;
|
||
OnCheck();
|
||
}
|
||
}
|
||
=======
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ButtonCheckable : MonoBehaviour
|
||
{
|
||
Dictionary<string, GameObject> buttonStatesList = new Dictionary<string, GameObject>();
|
||
|
||
// int posCount;
|
||
// int currentPos;
|
||
GameObject goUp;
|
||
GameObject goDown;
|
||
public bool isChecked = false;
|
||
public bool isStarted = false;
|
||
Image goUp_Img=null, goDown_Img=null;
|
||
SpriteRenderer goUp_SR = null, goDown_SR = null;
|
||
Manager man;
|
||
|
||
void Start()
|
||
{
|
||
man = GameObject.Find("Manager").GetComponent<Manager>();
|
||
// Debug.Log(go.name);
|
||
Transform[] buttonStates = this.GetComponentsInChildren<Transform>();
|
||
// Debug.Log(btnList.Length);
|
||
// goUp = new GameObject();
|
||
// goDown = new GameObject();
|
||
for (int i = 0; i < buttonStates.Length; i++)
|
||
{
|
||
if (i == 0) continue;
|
||
if (string.Compare(buttonStates[i].name.Substring(buttonStates[i].name.Length - 2), "up") == 0) // this.name.Length - 3
|
||
goUp = buttonStates[i].gameObject;
|
||
if (string.Compare(buttonStates[i].name.Substring(buttonStates[i].name.Length - 4), "down") == 0) // this.name.Length - 3
|
||
goDown = buttonStates[i].gameObject;
|
||
}
|
||
goUp_Img = goUp.GetComponent<Image>();
|
||
goUp_SR = goUp.GetComponent<SpriteRenderer>();
|
||
goDown_Img = goDown.GetComponent<Image>();
|
||
goDown_SR = goDown.GetComponent<SpriteRenderer>();
|
||
|
||
if (goUp_Img != null) goUp_Img.enabled = !isChecked;
|
||
if (goUp_SR != null) goUp_SR.enabled = !isChecked;
|
||
if (goDown_Img != null) goDown_Img.enabled = isChecked;
|
||
if (goDown_SR != null) goDown_SR.enabled = isChecked;
|
||
isStarted = true;
|
||
}
|
||
|
||
void OnMouseDown()
|
||
{
|
||
if (man.mode == "scedit" || man.mode == "play")
|
||
return;
|
||
OnCheck();
|
||
}
|
||
|
||
|
||
public void OnCheck()
|
||
{
|
||
if (goUp == null || goDown == null) Start();
|
||
if (goUp == null || goDown == null) return;
|
||
|
||
try
|
||
{
|
||
isChecked = !isChecked;
|
||
if (goUp_Img != null) goUp_Img.enabled = !isChecked;
|
||
if (goUp_SR != null) goUp_SR.enabled = !isChecked;
|
||
if (goDown_Img != null) goDown_Img.enabled = isChecked;
|
||
if (goDown_SR != null) goDown_SR.enabled = isChecked;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.LogError(e.Message);
|
||
}
|
||
|
||
}
|
||
|
||
public void SetState(int st)
|
||
{
|
||
if (st == 0) isChecked = true; else isChecked = false;
|
||
OnCheck();
|
||
}
|
||
}
|
||
>>>>>>> 3b1b9479a46e90d056b92897ea9f8422b25fc052
|