mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 01:25:38 +03:00
111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class myButton : MonoBehaviour
|
|
{
|
|
Dictionary<string, GameObject> buttonStatesList = new Dictionary<string, GameObject>();
|
|
|
|
// int posCount;
|
|
// int currentPos;
|
|
GameObject goUp;
|
|
GameObject goDown;
|
|
Manager man;
|
|
Image goUp_Img = null, goDown_Img = null;
|
|
SpriteRenderer goUp_SR = null, goDown_SR = null;
|
|
|
|
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;
|
|
|
|
}
|
|
}
|
|
if (goUp == null || goDown == null)
|
|
return;
|
|
goUp_Img = goUp.GetComponent<Image>();
|
|
goUp_SR = goUp.GetComponent<SpriteRenderer>();
|
|
goDown_Img = goDown.GetComponent<Image>();
|
|
goDown_SR = goDown.GetComponent<SpriteRenderer>();
|
|
|
|
if (goUp_Img != null && goDown_Img != null)
|
|
{
|
|
goUp_Img.enabled = true;
|
|
goDown_Img.enabled = false;
|
|
}
|
|
else
|
|
{
|
|
goUp_SR.enabled = true;
|
|
goDown_SR.enabled = false;
|
|
}
|
|
}
|
|
|
|
public void OnMouseDown()
|
|
{
|
|
if (man.mode == "scedit" || man.mode == "play")
|
|
return;
|
|
OnDown();
|
|
man.player.SetObjectState(man.objects.Find(this.gameObject.name), 1);
|
|
}
|
|
public void OnDown()
|
|
{
|
|
if (goUp == null || goDown == null)
|
|
return;
|
|
|
|
if (goUp_Img != null && goDown_Img != null)
|
|
{
|
|
goUp_Img.enabled = false;
|
|
goDown_Img.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
goDown_SR.enabled = true;
|
|
goUp_SR.enabled = false;
|
|
}
|
|
}
|
|
void OnMouseUp()
|
|
{
|
|
if (man.mode == "scedit" || man.mode == "play")
|
|
return;
|
|
OnUp();
|
|
}
|
|
public void OnUp()
|
|
{
|
|
if (goUp == null || goDown == null)
|
|
return;
|
|
try
|
|
{
|
|
if (goUp_Img != null && goDown_Img != null)
|
|
{
|
|
goUp_Img.enabled = true;
|
|
goDown_Img.enabled = false;
|
|
}
|
|
else
|
|
{
|
|
goUp_SR.enabled = true;
|
|
goDown_SR.enabled = false;
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
Debug.LogError(e.Message);
|
|
}
|
|
}
|
|
}
|