04.07.2022

This commit is contained in:
Plotnikov
2022-07-04 13:15:35 +03:00
parent 5fad2bcf6b
commit 696daa0b2e
7224 changed files with 3814576 additions and 0 deletions

View File

@@ -0,0 +1,214 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
public class ScrollViewAdapter : MonoBehaviour
{
public RectTransform prefab;
public RectTransform content;
public int curAction;
ScEditor sce;
Scenario sc;
Manager man;
Scrollbar scroll=null;
public void Init()
{
sc = GameObject.Find("ScEditor").GetComponent<ScEditor>().SC;
man = GameObject.Find("Manager").GetComponent<Manager>();
if (sc == null)
{
Debug.Log(" Panel2 Start: sc = null");
return;
}
sce = GameObject.Find("ScEditor").GetComponent<ScEditor>();
sc = sce.SC;
scroll = GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>();
//Debug.Log(" Start: sc.curModeSc.acts.Count = " + sc.curModeSc.acts.Count);
InvokeRepeating("MyFixedUpdate", 0, 0.25f);
}
public void MyFixedUpdate()
{
if (sc == null)
{
//Debug.Log(" Panel2 FixedUpdate: sc == null ");
return;
}
if (sc.curModeSc == null)
{
//Debug.Log(" Panel2 FixedUpdate: sc.curModeSc == null ");
return;
}
if (scroll == null) return;
if (sc.curModeSc.acts.Count == 0) return;
int min;
int cnt = sc.curModeSc.acts.Count;
if (cnt > 16) cnt -= 16;
min = Mathf.FloorToInt((1.0f - scroll.value) * cnt);
for (int i = min; i < min+17; i++) //for (int i = 0; i < sc.curModeSc.acts.Count; i++)
{
GameObject go_ai = GameObject.Find("ActionItem" + i);
if (go_ai == null)
{
//Debug.Log("ActionItem" + i + " not found. curModeActs = " + sc.curModeSc.acts.Count);
continue;
}
Button btn = go_ai.GetComponent<Button>();
ColorBlock colors = btn.colors;
colors.normalColor = Color.white;
if (i == curAction)
{
colors.normalColor = new Color(160f / 255f, 230f / 255f, 160f / 255f);
}
btn.colors = colors;
}
//Debug.Log(" FixedUpdate curAction = " + curAction + " sc.curModeActs.Count = " + sc.curModeSc.acts.Count);
}
public void UpdateItems()
{
sc = GameObject.Find("ScEditor").GetComponent<ScEditor>().SC;
var models = new TestItemModel[sc.curModeSc.acts.Count];
for (int i = 0; i < sc.curModeSc.acts.Count; i++)
{
models[i] = new TestItemModel();
models[i].name = "ActionItem" + i;
models[i].buttonText = (i+1) + ". " + sc.curModeSc.acts[i].title;
models[i].index = i;
}
foreach (Transform child in content)
Destroy(child.gameObject);
foreach (var model in models)
{
var instance = GameObject.Instantiate(prefab.gameObject) as GameObject;
instance.transform.SetParent(content, false);
InitializeItemView(instance, model);
}
if (models.Length == 0)
curAction = -1;
else
onActionViewChange(0);
//Debug.Log("UpdateItems curAction = " + curAction + " sc.curModeActs.Count = " + sc.curModeSc.acts.Count + " model.len = " + models.Length);
}
void InitializeItemView(GameObject viewGameObject, TestItemModel model)
{
TestItemView view = new TestItemView(viewGameObject.transform);
view.clickButton.name = model.name;
view.clickButton.GetComponentInChildren<Text>().text = model.buttonText;
view.clickButton.onClick.AddListener(
() =>
{
onActionViewChange(model.index);
}
);
}
public int tap = 0;
public void onActionViewChange(int index)
{
if(index == -1)
{
sce.SetCurObject(null);
return;
}
curAction = index;
UnityObject uo = man.objects.Find(sc.curModeSc.acts[curAction].objName);
UnityObject tmp_uo = uo;
string panel = "";
if (uo != null && uo.dim == "2D")
{
while (tmp_uo != null)
{
if (tmp_uo.type == "panel2D")
{
panel = tmp_uo.name; break;
}
tmp_uo = tmp_uo.parent;
}
}
tap++;
if (tap == 1)
{
if (curAction >= sc.curModeSc.acts.Count) curAction = sc.curModeSc.acts.Count - 1;
//Debug.Log("changed = " + curAction + ", acts = "+ sc.curModeActs.Count);
for (int i = 0; i < sc.curModeSc.acts.Count; i++)
{
var colors = GameObject.Find("ActionItem" + i).GetComponent<Button>().colors;
colors.normalColor = Color.white;
if (i == index)
colors.normalColor = new Color(160f / 255f, 230f / 255f, 160f / 255f); //Color.yellow;
GameObject.Find("ActionItem" + i).GetComponent<Button>().colors = colors;
}
if (sc.curModeSc.acts[curAction].objName != "" && sc.curModeSc.acts[curAction].type != "switchMFIScreen")
sce.SetCurObject(man.objects.Find(sc.curModeSc.acts[curAction].objName).gameObject);
//else
// sce.SetCurObject(null);
ScAction lastCamAct = null; // переезд камеры в последнее установленное в сценарии положение
for (int i = curAction; i >= 0; i--)
if (sc.curModeSc.acts[i].type == "setCurCameraPos")
{
lastCamAct = sc.curModeSc.acts[i];
break;
}
if (lastCamAct != null && man.player.state != "play" && man.is3D)
{
if(!man.is3D && panel != "" && man.opened2Dpanel != panel)
man.SwitchTo3D();
man.player.isScEditorCameraMoving = true;
man.player.RunAction(lastCamAct);
man.mouseEnterUI();
}
StartCoroutine(DoubleTapInterval());
}
else if (tap == 2 && uo != null) // двойной клик на действии в списке
{
if (uo.dim == "2D" && panel != "") // если объект в действии "2Д" - открываем его панель
{
if (!man.is3D && man.opened2Dpanel != panel)
man.SwitchTo3D();
if (man.is3D)
man.SwitchTo2D(panel);
}
if (uo.dim == "3D") // если "3Д" - просто возвращаемся в 3Д
{
if (!man.is3D) man.SwitchTo3D();
}
tap = 0;
}
}
IEnumerator DoubleTapInterval()
{
yield return new WaitForSeconds(0.5f);
this.tap = 0;
}
public class TestItemView
{
public Button clickButton;
public TestItemView(Transform rootView)
{
clickButton = rootView.Find("ActionClickButton").GetComponent<Button>();
if (clickButton == null) Debug.Log("prefab clickButton = null");
}
}
public class TestItemModel
{
public string name;
public string buttonText;
public int index;
}
}