mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 01:15:41 +03:00
06.07.2022
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
<<<<<<< HEAD
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -94,100 +93,3 @@ public class drCol112 : MonoBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
=======
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class drCol112 : MonoBehaviour
|
||||
{
|
||||
protected Vector3 mousePosition;
|
||||
protected Vector2 a; // Vector2 deltaPosition
|
||||
public string typeDrag = null;
|
||||
public float dragMin, dragMax;
|
||||
public bool clamp = false;
|
||||
|
||||
[HideInInspector] public Vector2 dd;//для передачи в connection
|
||||
[HideInInspector] public bool _delta = false;//для передачи в connection
|
||||
|
||||
[HideInInspector] public bool isDrag = false;
|
||||
Manager man;
|
||||
|
||||
Camera cam;//камера для канваса с панелями
|
||||
private void Awake()
|
||||
{
|
||||
dd = new Vector2(transform.localPosition.x, transform.localPosition.y);
|
||||
if (man == null) man = GameObject.Find("Manager").GetComponent<Manager>();
|
||||
cam = man.cam;
|
||||
}
|
||||
public void OnMouseDown()
|
||||
{
|
||||
calculationBegin();
|
||||
}
|
||||
public void OnMouseDrag()
|
||||
{
|
||||
calculationDrag();
|
||||
|
||||
}
|
||||
|
||||
public void OnMouseUp()
|
||||
{
|
||||
dd = new Vector2(transform.localPosition.x, transform.localPosition.y);
|
||||
if (typeDrag == "x" && (dd.x == dragMin || dd.x == dragMax))
|
||||
{
|
||||
_delta = true;
|
||||
}
|
||||
else if (typeDrag == "y" && (dd.y == dragMin || dd.y == dragMax))
|
||||
{
|
||||
_delta = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_delta = false;
|
||||
}
|
||||
isDrag = false;
|
||||
}
|
||||
public void calculationBegin()
|
||||
{
|
||||
//a = new Vector2(Input.mousePosition.x - transform.localPosition.x, Input.mousePosition.y - transform.localPosition.y);
|
||||
mousePosition = cam.ScreenToWorldPoint(Input.mousePosition);//mousePosition = Input.mousePosition;
|
||||
a = new Vector2(mousePosition.x - transform.localPosition.x, mousePosition.y - transform.localPosition.y);
|
||||
isDrag = true;
|
||||
}
|
||||
public void calculationDrag()
|
||||
{
|
||||
if (man.mode == "scedit" || man.mode == "play")
|
||||
return;
|
||||
mousePosition = cam.ScreenToWorldPoint(Input.mousePosition);//mousePosition = Input.mousePosition;
|
||||
Vector2 q = new Vector2(mousePosition.x, mousePosition.y);
|
||||
Vector3 b = new Vector3(q.x - a.x, q.y - a.y, transform.localPosition.z);
|
||||
|
||||
if (typeDrag == "x")
|
||||
{
|
||||
b.x = (clamp) ? Mathf.Clamp(b.x, dragMin, dragMax) : b.x;
|
||||
transform.localPosition = new Vector3(b.x, transform.localPosition.y, transform.localPosition.z);
|
||||
}
|
||||
else
|
||||
if (typeDrag == "y")
|
||||
{
|
||||
b.y = (clamp) ? Mathf.Clamp(b.y, dragMin, dragMax) : b.y;
|
||||
transform.localPosition = new Vector3(transform.localPosition.x, b.y, transform.localPosition.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = b;
|
||||
}
|
||||
}
|
||||
public void SetState(int b)
|
||||
{
|
||||
float bf = (clamp) ? Mathf.Clamp((float)b/100f, dragMin, dragMax) : b/100;
|
||||
//b += (int)(dragMax - dragMin) / 2;
|
||||
if (typeDrag == "x")
|
||||
transform.localPosition = new Vector3(bf, transform.localPosition.y, transform.localPosition.z);
|
||||
else
|
||||
if (typeDrag == "y")
|
||||
transform.localPosition = new Vector3(transform.localPosition.x, bf, transform.localPosition.z);
|
||||
}
|
||||
|
||||
}
|
||||
>>>>>>> 3b1b9479a46e90d056b92897ea9f8422b25fc052
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<<<<<<< HEAD
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -80,86 +79,3 @@ public class ButtonCheckable : MonoBehaviour
|
||||
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
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<<<<<<< HEAD
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -46,52 +45,3 @@ public class Switch : MonoBehaviour
|
||||
switcheStatesList[swName].switchOn();
|
||||
}
|
||||
}
|
||||
=======
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Switch : MonoBehaviour
|
||||
{
|
||||
List<string> switcheStatesListNames = new List<string>();
|
||||
//Dictionary<string, GameObject> switcheStatesList = new Dictionary<string, GameObject>();
|
||||
public Dictionary<string, SwitchState> switcheStatesList = new Dictionary<string, SwitchState>();
|
||||
bool isStarted = false;
|
||||
|
||||
// int posCount;
|
||||
// int currentPos;
|
||||
void Start()
|
||||
{
|
||||
if (isStarted) return;
|
||||
// Debug.Log(go.name);
|
||||
Transform[] switchStates = this.GetComponentsInChildren<Transform>();
|
||||
// Debug.Log(btnList.Length);
|
||||
for (int i = 0; i < switchStates.Length; i++)
|
||||
{
|
||||
if (i == 0) continue;
|
||||
// Debug.Log(btnList[i].gameObject.name);
|
||||
switchStates[i].gameObject.AddComponent<SwitchState>();
|
||||
switcheStatesListNames.Add(switchStates[i].gameObject.name);
|
||||
switcheStatesList.Add(switchStates[i].gameObject.name, switchStates[i].gameObject.GetComponent<SwitchState>());
|
||||
}
|
||||
switcheStatesListNames.Sort();
|
||||
if(switcheStatesListNames.Count>0)
|
||||
switcheStatesList[switcheStatesListNames[0]].switchOn();
|
||||
isStarted = true;
|
||||
//setState(1);
|
||||
}
|
||||
|
||||
public void setState(int state)
|
||||
{
|
||||
if (!isStarted) Start();
|
||||
if (state >= 0 && state < switcheStatesListNames.Count)
|
||||
switcheStatesList[switcheStatesListNames[state]].switchOn();
|
||||
else
|
||||
Debug.LogError("Ошибка установки состояния " + state + " объекта " + this.gameObject.name);
|
||||
}
|
||||
public void setState(string swName)
|
||||
{
|
||||
if (!isStarted) Start();
|
||||
switcheStatesList[swName].switchOn();
|
||||
}
|
||||
}
|
||||
>>>>>>> 3b1b9479a46e90d056b92897ea9f8422b25fc052
|
||||
|
||||
Reference in New Issue
Block a user