Files
MI-38/Heli_with_panels/Assets/Scripts/ScEditor/ScEditor.cs
2022-07-06 12:36:49 +03:00

765 lines
33 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml.Serialization;
using System.IO;
using System;
using System.Xml;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;
//using UnityEngine.UIElements;
public class ScEditor : MonoBehaviour
{
public Scenario SC;
public Manager man;
Player player;
public GameObject go_scDropdown, go_scExecDropdown, go_initPush, go_demoPush, go_trainPush, go_examPush, go_scNameInput, go_scTitleInput;
public GameObject go_objName, go_objType, go_objDescript, go_objState, go_objAudioDropdown;
ScrollViewAdapter actionsView;
public GameObject curGO;
public UnityObject curObject;
Renderer[] curObjRenderers;
List<Material> curObjMaterials = new List<Material>();
List<Material> curObjGreenMaterials = new List<Material>();
SpriteRenderer[] curObjSpriteRenderers;
Image[] curObjImages;
TextMeshPro[] curObjTMPs;
List<Color> curObjSpriteColors = new List<Color>();
List<Color> curObjImageColors = new List<Color>();
List<Color> curObjTMPColors = new List<Color>();
bool curObjFlashState = true;
bool canChangeScDropdownVal = true;
GameObject viewCamera, cabinCamera;
void Start()
{
man = GameObject.Find("Manager").GetComponent<Manager>();
player = man.player;
if (man.mode != "scedit")
{
GameObject.Find("EditorCanvas").SetActive(false);
return;
}
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
Debug.LogError("Cannot run scEdit mode in WebGL");
GameObject.Find("EditorCanvas").SetActive(false);
return;
}
curObject = null;
//Debug.Log("ScEditor.Start: InvokeRepeating FlashCurrentObject");
InvokeRepeating("FlashCurrentObject", 0, 0.5f); // CancelInvoke (methodName : string)
player.SC = new Scenario(); SC = player.SC;
SC.title = "Новый сценарий"; SC.name = SC.title; scModifyed("");
GameObject.Find("Panel1Content").GetComponent<ScrollViewAdapterPanel1>().Init();
GameObject.Find("ActsViewContent").GetComponent<ScrollViewAdapter>().Init();
GameObject.Find("pathLbl").GetComponent<Text>().text = Path.Combine(Application.streamingAssetsPath, "Scenario");
go_scDropdown = GameObject.Find("ScDropdown");
go_scExecDropdown = GameObject.Find("DropdownCallScenario");
go_objAudioDropdown = GameObject.Find("DropdownPlayAudio");
// dropdown.value = dropdown.options.FindIndex(option => options.text == "an Option");
go_initPush = GameObject.Find("InitPush");
go_demoPush = GameObject.Find("DemoPush");
go_trainPush = GameObject.Find("TrainPush");
go_examPush = GameObject.Find("ExamPush");
go_scTitleInput = GameObject.Find("ScTitleInput");
go_scNameInput = GameObject.Find("ScNameInput");
actionsView = GameObject.Find("ActsViewContent").GetComponent<ScrollViewAdapter>();
go_objName = GameObject.Find("IFObjName");
go_objType = GameObject.Find("IFObjType");
go_objDescript = GameObject.Find("IFObjDescr");
go_objState = GameObject.Find("IFObjState");
viewCamera = man.viewCamera;
cabinCamera = man.cabinCamera;
FillScDropdown();
go_scDropdown.GetComponent<Dropdown>().value = -1; go_scDropdown.GetComponent<Dropdown>().value = 0;
SC.isModifyed = false; GameObject.Find("ScSaveButton").GetComponent<Button>().interactable = false;
//changeMode(1);
// при сборке редактора сценариев закоментировать:
//scLoad("qwe"); man.mouseExitUI();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject curCamera;
if (cabinCamera.activeInHierarchy)
curCamera = cabinCamera;
else
curCamera = viewCamera;
Ray ray = curCamera.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
if (hit.transform.gameObject != null && hit.transform.gameObject.layer != LayerMask.NameToLayer("Ignore Raycast"))
{
//if (hit.rigidbody != null)
// hit.rigidbody.AddForceAtPosition(- hit.normal * 25, hit.point);//ray.direction hit.point
SetCurObject(hit.transform.gameObject);
//Debug.Log("~Clicked " + hit.transform.gameObject.name);
}
}
if (Input.GetMouseButtonDown(2))
{
GameObject curCamera;
if (cabinCamera.activeInHierarchy)
curCamera = cabinCamera;
else
curCamera = viewCamera;
Ray ray = curCamera.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
if (hit.transform.gameObject != null && hit.transform.gameObject.layer != LayerMask.NameToLayer("Ignore Raycast")) // переделать Ignore Raycast
{
SetCurObject(hit.transform.gameObject);
UnityObject handlerObj = man.objects.FindHandler(hit.transform.gameObject.name);
if(handlerObj == null)
{
Debug.LogError("Handler объекта " + hit.transform.gameObject.name + " не найден.");
return;
}
string handler3D = handlerObj.name;
//Debug.Log("Open 2D: clicked " + hit.transform.gameObject.name + ", handler " + handler3D);
if (handler3D.Substring(handler3D.Length - 3) == "_3D")
{
string panel2D = handler3D.Substring(0, handler3D.Length - 3);
//Debug.Log("Open 2D: panel2D = " + panel2D);
UnityObject obj2D = man.objects.Find(panel2D);
if(obj2D != null)
man.SwitchTo2D(obj2D.name);
else
Debug.Log("Не могу найти 2D-панель: " + panel2D);
}
}
}
if (Input.GetKeyUp(KeyCode.Space) && Input.GetKey(KeyCode.LeftControl))
GameObject.Find("ButtonWaitForTime").GetComponent<Button>().onClick.Invoke();
if (Input.GetKeyUp(KeyCode.Q) && Input.GetKey(KeyCode.LeftControl))
Application.Quit();
}
public void SetCurObject(GameObject go)
{
//Debug.Log("Loaded = " + man.objects.isLoaded);
if (man.objects == null)
{
Debug.Log("SetCurObject: objects = null. WTF?");
return;
}
if (go == null)
{
SetDefaultMaterialsToCurrentObject();
go_objName.GetComponent<TMP_InputField>().text = "";
go_objType.GetComponent<TMP_InputField>().text = "";
go_objDescript.GetComponent<TMP_InputField>().text = "";
go_objState.GetComponent<TMP_InputField>().text = "";
go_scExecDropdown.GetComponent<Dropdown>().value = -1;
GameObject.Find("Panel1Content").GetComponent<ScrollViewAdapterPanel1>().UpdateItems();
curObject = null;
return;
}
//Debug.Log("SetCurObject: " + go.name);
UnityObject tmpObject = man.objects.FindHandler(go.name);
if (tmpObject == null) return;
//Debug.Log(go.name + " " + tmpObject.name);
//curObject = null;
SetDefaultMaterialsToCurrentObject();
curObject = tmpObject;
//Debug.Log("SetCurObject: clicked " + go.name + ", handler " + curObject.name);
SetNewMaterialsToCurrentObject(curObject.gameObject);
//Debug.Log("SetCurObject: '" + curObject.name + "' '" + curObject.type + "' '" + curObject.description + "' " + curObject.curState);
go_objName.GetComponent<TMP_InputField>().text = curObject.name;
go_objType.GetComponent<TMP_InputField>().text = curObject.type;
go_objDescript.GetComponent<TMP_InputField>().text = "";
if (curObject.description != null)
go_objDescript.GetComponent<TMP_InputField>().text = curObject.description.text;
int stateMin = -1; int stateMax = -1;
//if (curObject.defaultState != null)
// curObject.curState = curObject.defaultState.value;
//else
// curObject.curState = 0;
go_objState.GetComponent<TMP_InputField>().text = "Не определено";
go_scExecDropdown.GetComponent<Dropdown>().value = -1;
bool isStates = true;
if (curObject.states == null || curObject.states.Count == 0) isStates = false;
if (curObject.stateInRange != null && !isStates)
{
stateMin = curObject.stateInRange.min; stateMax = curObject.stateInRange.max;
//Debug.Log("stateRange: curState " + curObject.curState + " min " + stateMin + " max " + stateMax);
if (curObject.curState >= stateMin && curObject.curState <= stateMax)
go_objState.GetComponent<TMP_InputField>().text = curObject.curState.ToString();
}
if (isStates)
{
stateMin = 0; stateMax = curObject.states.Count-1;
if (curObject.curState >= stateMin && curObject.curState <= stateMax)
go_objState.GetComponent<TMP_InputField>().text = curObject.states[curObject.curState].name;
}
if(GameObject.Find("SaveObjectsXMLBtn") !=null && GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>() != null)
GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>().interactable = false;
GameObject.Find("Panel1Content").GetComponent<ScrollViewAdapterPanel1>().UpdateItems();
}
void FlashCurrentObject()
{
if (curObject == null) return;
if (curObject.dim == "3D" && curObjRenderers == null) return;
foreach (Player.highlightObj ho in player.highlightList)
if (ho.obj == curObject) return;
if (curObjFlashState && player.state != "play")
{
if (curObject.dim == "3D")
for (int i = 0; i < curObjRenderers.Length; i++)
curObjRenderers[i].material = curObjGreenMaterials[i];
else
{
for (int i = 0; i < curObjSpriteRenderers.Length; i++)
if(!curObjSpriteRenderers[i].name.Contains("Indicator"))
curObjSpriteRenderers[i].color = Color.green; //yellow
else
curObjSpriteRenderers[i].color = Color.white;
for (int i = 0; i < curObjImages.Length; i++)
curObjImages[i].color = Color.green; //green
for (int i = 0; i < curObjTMPs.Length; i++)
curObjTMPs[i].color = Color.white;
}
}
else
SetDefaultMaterialsToCurrentObject();
curObjFlashState = !curObjFlashState;
}
void SetNewMaterialsToCurrentObject(GameObject go)
{
if (curObject.dim == "3D")
{
curObjRenderers = go.transform.GetComponentsInChildren<Renderer>(); //parent.
foreach (Renderer r in curObjRenderers)
{
MakeActive obj_ma = r.gameObject.GetComponent<MakeActive>();
if(obj_ma != null)
if(obj_ma.materialsReplaced)
obj_ma.RestoreChildrenMaterials();
}
//if (go.GetComponent<MakeActive>().materialsReplaced)
// go.GetComponent<MakeActive>().RestoreChildrenMaterials();
curObjMaterials.Clear(); curObjGreenMaterials.Clear();
for (int i = 0; i < curObjRenderers.Length; i++)
{
curObjMaterials.Add(curObjRenderers[i].material);
Material greenMat = new Material(curObjRenderers[i].material);
greenMat.SetColor("_EmissionColor", new Color(0 / 255f, 50f / 255f, 0f / 255f)); // 0 50 0
curObjGreenMaterials.Add(greenMat);
}
}
else
{
curObjSpriteRenderers = go.transform.GetComponentsInChildren<SpriteRenderer>(); //parent.
curObjImages = go.transform.GetComponentsInChildren<Image>();
curObjTMPs = go.transform.GetComponentsInChildren<TextMeshPro>();
Indicator[] indicatorList = go.transform.GetComponentsInChildren<Indicator>();
for (int i = 0; i < indicatorList.Length; i++) {
UnityObject indUO = man.objects.Find(indicatorList[i].gameObject.name);
if(indUO != null)
man.objects.SetCurrentValues(indUO); //RepaintNumberIndicator();
}
curObjSpriteColors.Clear(); curObjImageColors.Clear(); curObjTMPColors.Clear();
for (int i = 0; i < curObjSpriteRenderers.Length; i++)
curObjSpriteColors.Add(curObjSpriteRenderers[i].color);
for (int i = 0; i < curObjImages.Length; i++)
curObjImageColors.Add(curObjImages[i].color);
for (int i = 0; i < curObjTMPs.Length; i++)
curObjTMPColors.Add(curObjTMPs[i].color);
}
}
public void SetDefaultMaterialsToCurrentObject()
{
if (curObject == null) return;
if (curObject.dim == "3D")
{
if (curObjRenderers == null) return;
if (curObjMaterials.Count == 0) return;
for (int i = 0; i < curObjRenderers.Length; i++)
curObjRenderers[i].material = curObjMaterials[i];
}
else
{
for (int i = 0; i < curObjSpriteRenderers.Length; i++)
curObjSpriteRenderers[i].color = curObjSpriteColors[i];
for (int i = 0; i < curObjImages.Length; i++)
curObjImages[i].color = curObjImageColors[i];
for (int i = 0; i < curObjTMPs.Length; i++)
curObjTMPs[i].color = curObjTMPColors[i];
}
}
public void Clicked2D(BaseEventData evData)
{
if (man.mode != "scedit") return;
RaycastHit2D hit;
Ray ray = GameObject.Find("Camera").GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
hit = Physics2D.Raycast(ray.origin, Vector2.up);
if (hit.transform != null)
SetCurObject(hit.transform.gameObject);
PointerEventData _pointer = evData as PointerEventData;
switch (_pointer.button)
{
case PointerEventData.InputButton.Left:
break;
case PointerEventData.InputButton.Right:
break;
case PointerEventData.InputButton.Middle:
if (curObject == null) break;
Cover coverObj = curObject.gameObject.GetComponent<Cover>();
if (coverObj != null)
curObject.SetObjectState(1);
Cover2 cover2Obj = curObject.gameObject.GetComponent<Cover2>();
if (cover2Obj != null)
curObject.SetObjectState(1);
//Debug.Log("Open Cover: " + curObject.name);
if (curObject != null && curObject.type == "cubeButton")
curObject.gameObject.GetComponent<ButtonCubik>().ChangeView();
if (curObject.name.StartsWith("mfi") && curObject.type == "buttonAutoUncheck") // кнопки переключения экранов МФИ (mfi1Button1)
player.SetObjectState(curObject, 1);
if (curObject.name.StartsWith("Button") && curObject.parent.name == "Panel0201")
{
int mfpuBtnNum = -1;
int.TryParse(curObject.name.Substring(6, curObject.name.IndexOf("_") - 6), out mfpuBtnNum);
man.mfpuScript.ButtonPressed(mfpuBtnNum);
}
break;
}
}
public void OnObjectDescrChange(string newstr)
{
if (go_objDescript.GetComponent<TMP_InputField>().text != "")
{
if (curObject.description == null)
curObject.description = new ObjectDescription();
curObject.description.text = go_objDescript.GetComponent<TMP_InputField>().text;
}
if (GameObject.Find("SaveObjectsXMLBtn") != null && GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>() != null)
GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>().interactable = true;
}
public void OnObjectTypeChange(string _)
{
//curObject.type = go_objType.GetComponent<TMP_InputField>().text;
if(GameObject.Find("SaveObjectsXMLBtn") !=null && GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>()!=null)
GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>().interactable = true;
}
public void scSave()
{
SC.isModifyed = false; GameObject.Find("ScSaveButton").GetComponent<Button>().interactable = false;
if(SC.name == go_scNameInput.GetComponent<TMP_InputField>().text)
{
SC.title = go_scTitleInput.GetComponent<TMP_InputField>().text;
SC.needExamCompleted = GameObject.Find("needExamCheck").GetComponent<UnityEngine.UI.Toggle>().isOn;
Serialize(SC, Path.Combine(Application.streamingAssetsPath, "Scenario", SC.name + ".xml"));
}
else
{
SC.name = go_scNameInput.GetComponent<TMP_InputField>().text;
SC.title = go_scTitleInput.GetComponent<TMP_InputField>().text;
SC.needExamCompleted = GameObject.Find("needExamCheck").GetComponent<UnityEngine.UI.Toggle>().isOn;
Serialize(SC, Path.Combine(Application.streamingAssetsPath, "Scenario", SC.name + ".xml"));
int ind = 0;
FillScDropdown();
Dropdown.OptionData dt;
for(int i=0;i< go_scDropdown.GetComponent<Dropdown>().options.Count;i++)
{
dt = go_scDropdown.GetComponent<Dropdown>().options[i];
if (dt.text == SC.name)
ind = i;
}
go_scDropdown.GetComponent<Dropdown>().value = -1; go_scDropdown.GetComponent<Dropdown>().value = ind;
}
changeMode(SC.curMode);
}
public bool scLoad(string scName)
{
SC.init.acts.Clear(); SC.demo.acts.Clear(); SC.train.acts.Clear(); SC.exam.acts.Clear();
string fn = Path.Combine(Application.streamingAssetsPath, "Scenario", scName + ".xml");
if (CanDeserialize<Scenario>(fn))
{
//player.SC = Deserialize<Scenario>(fn);
player.LoadScenario(scName);
SC = player.SC;
SC.name = scName;
SC.isModifyed = false; GameObject.Find("ScSaveButton").GetComponent<Button>().interactable = false;
go_scNameInput.GetComponent<TMP_InputField>().text = SC.name;
go_scTitleInput.GetComponent<TMP_InputField>().text = SC.title;
GameObject.Find("needExamCheck").GetComponent<UnityEngine.UI.Toggle>().isOn = SC.needExamCompleted;
changeMode(1);
int ind = 0;
Dropdown.OptionData dt;
for (int i = 0; i < go_scDropdown.GetComponent<Dropdown>().options.Count; i++)
{
dt = go_scDropdown.GetComponent<Dropdown>().options[i];
if (dt.text == SC.name)
ind = i;
}
canChangeScDropdownVal = false;
go_scDropdown.GetComponent<Dropdown>().value = ind;
canChangeScDropdownVal = true;
//GameObject.Find("ScDropdownLabel").GetComponent<Text>().text = SC.name;
// список аудио для левой панели
Dropdown audioDD = go_objAudioDropdown.GetComponent<Dropdown>();
audioDD.ClearOptions();
List<Dropdown.OptionData> audioList = new List<Dropdown.OptionData>();
Dropdown.OptionData od;
DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.streamingAssetsPath, "Scenario", SC.name));
FileInfo[] files = new FileInfo[0];
try
{
files = di.GetFiles("*.*", SearchOption.TopDirectoryOnly);
}
catch (IOException) //IOException ioex
{
//Debug.Log($"exception: {ioex.Message}");
}
od = new Dropdown.OptionData();
od.text = ""; audioList.Add(od);
foreach (FileInfo file in files)
if (file.Extension == ".wav" || file.Extension == ".mp3")
{
od = new Dropdown.OptionData();
od.text = file.Name;
audioList.Add(od);
}
audioDD.AddOptions(audioList);
audioDD.value = 0;
player.state = "ready";
return true;
}
else
return false;
}
public void scDelete()
{
player.ScenarioMsg5sec("По просьбам пострадавших пользователей автоматическое удаление сценария не выполняется.\nВы можете самостоятельно удалить файл сценария:\n" + Application.streamingAssetsPath+"/Scenario/"+SC.name+".xml");
/* SC.name = go_scNameInput.GetComponent<TMP_InputField>().text;
string fn = Path.Combine(Application.streamingAssetsPath, "Scenario", SC.name + ".xml");
if (File.Exists(fn))
File.Delete(fn);
FillScDropdown();
go_scDropdown.GetComponent<Dropdown>().value = 0; */
}
private void FillScDropdown()
{
go_scDropdown.GetComponent<Dropdown>().options.Clear();
go_scExecDropdown.GetComponent<Dropdown>().options.Clear();
go_scDropdown.GetComponent<Dropdown>().options.Add(new Dropdown.OptionData("new scenario"));
DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.streamingAssetsPath, "Scenario"));
FileInfo[] files = di.GetFiles("*.xml", SearchOption.TopDirectoryOnly);
foreach (FileInfo file in files)
if(CanDeserialize<Scenario>(file.FullName))
{
string scName = file.Name; scName = scName.Remove(scName.IndexOf(file.Extension));
go_scDropdown.GetComponent<Dropdown>().options.Add(new Dropdown.OptionData(scName));
if(scName != SC.name) // список сценарием для левой панели
go_scExecDropdown.GetComponent<Dropdown>().options.Add(new Dropdown.OptionData(scName));
}
}
public void changeMode(int mode)
{
SC.curMode = mode;
go_initPush.SetActive(false); go_demoPush.SetActive(false); go_trainPush.SetActive(false); go_examPush.SetActive(false);
if (mode == 0) { go_initPush.SetActive(true); SC.curModeSc = SC.init; }
if (mode == 1) { go_demoPush.SetActive(true); SC.curModeSc = SC.demo; man.player.SetMode("demo"); }
if (mode == 2) { go_trainPush.SetActive(true); SC.curModeSc = SC.train; man.player.SetMode("train"); }
if (mode == 3) { go_examPush.SetActive(true); SC.curModeSc = SC.exam; man.player.SetMode("exam"); }
// заполнение списка действий
actionsView.UpdateItems();
}
public void ScDropdownChanged()
{
if (!canChangeScDropdownVal) return;
GameObject.Find("ScDeleteButton").GetComponent<Button>().interactable = false; ;
int value = go_scDropdown.GetComponent<Dropdown>().value;
if (value < 0)
return;
if (value == 0)
{
CreateNewScenario();
return;
}
if (!scLoad(go_scDropdown.GetComponent<Dropdown>().options[value].text))
return;
GameObject.Find("ScDeleteButton").GetComponent<Button>().interactable = true;
return;
}
public void CreateNewScenario()
{
SC = new Scenario();
SC.title = "Новый сценарий";
SC.name = "Новый сценарий";
go_scNameInput.GetComponent<TMP_InputField>().text = SC.name;
go_scTitleInput.GetComponent<TMP_InputField>().text = SC.title;
SC.isModifyed = false;
changeMode(1);
}
public void scModifyed(string _null="")
{
SC.isModifyed = true;
player.state = "ready";
GameObject.Find("ScSaveButton").GetComponent<Button>().interactable = true;
}
public void scModifyed(bool _null)
{
scModifyed("");
}
public void actionUp()
{
int curActionInd = actionsView.curAction;
if (curActionInd <= 0) return;
SC.curModeSc.acts.Insert(curActionInd - 1, SC.curModeSc.acts[curActionInd].clone());
SC.curModeSc.acts.RemoveAt(curActionInd + 1);
float scrollVal = GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value;
actionsView.UpdateItems(); actionsView.tap = 0;
GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value = scrollVal;
actionsView.onActionViewChange(curActionInd - 1);
scModifyed();
}
public void actionDown()
{
int curActionInd = actionsView.curAction;
if (curActionInd >= SC.curModeSc.acts.Count-1) return;
SC.curModeSc.acts.Insert(curActionInd + 2, SC.curModeSc.acts[curActionInd].clone());
SC.curModeSc.acts.RemoveAt(curActionInd);
float scrollVal = GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value;
actionsView.UpdateItems(); actionsView.tap = 0;
GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value = scrollVal;
actionsView.onActionViewChange(curActionInd + 1);
scModifyed();
}
public void actionDelete()
{
int curActionInd = actionsView.curAction;
if (curActionInd < 0) return;
if (curActionInd >= SC.curModeSc.acts.Count) return;
SC.curModeSc.acts.RemoveAt(curActionInd);
float scrollVal = GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value;
actionsView.UpdateItems(); actionsView.tap = 0;
GameObject.Find("ActionsViewScrollbar").GetComponent<Scrollbar>().value = scrollVal;
if (curActionInd >= SC.curModeSc.acts.Count - 1)
curActionInd = SC.curModeSc.acts.Count - 1;
actionsView.onActionViewChange(curActionInd);
scModifyed();
}
public void ReloadButtonClicked()
{
man.objects.Load();
GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>().interactable = false;
}
public void SaveObjectsButtonClicked()
{
man.objects.Save();
GameObject.Find("SaveObjectsXMLBtn").GetComponent<Button>().interactable = false;
}
public void CopyDemoToLearn()
{
SC.train.acts.Clear();
foreach (ScAction act in SC.demo.acts)
SC.train.acts.Add(act.clone());
if (SC.curModeSc == SC.train)
actionsView.UpdateItems();
scModifyed();
}
public void CopyLearnToExam()
{
SC.exam.acts.Clear();
foreach (ScAction act in SC.train.acts)
SC.exam.acts.Add(act.clone());
if (SC.curModeSc == SC.exam)
actionsView.UpdateItems();
scModifyed();
}
public List<ScAction> MakeCurObjectActionsList()
{
// setState, setStateInRange, openPanel, setTextField, setIntField, switchTo3D, highlightOn, highlightOff,
// highlightTime, waitForClick, waitForTime, setCurCameraPos, showText, hideText, execScenario, playAudio
List<ScAction> actList = new List<ScAction>();
if (curObject == null)
return actList;
ScAction newAct;
// setStateInRange
bool isStates = true;
if (curObject.states == null || curObject.states.Count == 0) isStates = false;
if (curObject.stateInRange != null && !isStates)
if(curObject.name != "Panel0801_3D" && curObject.name != "Panel0802_3D")
{
newAct = new ScAction(); newAct.type = "setStateInRange";
newAct.objName = curObject.name;
newAct.title = "[" + curObject.name + "] " + "Установить значение состояния \"___\" за время ____ сек";
newAct.setStateInRange = new actSetStateInRange();
newAct.setStateInRange.val = 0;
newAct.setStateInRange.sec = 0;
newAct.setStateInRange.rangeStr = "(" + curObject.stateInRange.min + ".." + curObject.stateInRange.max + ")";
actList.Add(newAct);
}
// setState
if (isStates)
for(int i=0;i< curObject.states.Count;i++)
{
newAct = new ScAction(); newAct.type = "setState";
newAct.objName = curObject.name;
newAct.title = "[" + curObject.name + "] " + "Установить состояние \"" + curObject.states[i].name + "\"";
newAct.setState = new actSetState();
newAct.setState.val = i;
newAct.setState.name = curObject.states[i].name;
actList.Add(newAct);
}
// setTextField // setIntField
if (curObject.type.EndsWith("textField"))
{
newAct = new ScAction(); newAct.type = "setTextField";
newAct.objName = curObject.name;
newAct.title = "[" + curObject.name + "] " + "Установить текстовое поле в \"______________\"";
newAct.setTextField = new actSetTextField();
newAct.setTextField.text = "";
actList.Add(newAct);
newAct = new ScAction(); newAct.type = "setIntField";
newAct.objName = curObject.name;
newAct.title = "[" + curObject.name + "] " + "Изменить числовое текстовое поле c \"___\" до \"___\" за время ____ сек";
newAct.setIntField = new actSetIntField();
newAct.setIntField.valFrom = 0; newAct.setIntField.valTo = 0; newAct.setIntField.sec = 0;
actList.Add(newAct);
newAct = new ScAction(); newAct.type = "setFloatField";
newAct.objName = curObject.name;
newAct.title = "[" + curObject.name + "] " + "Изменить дробное числовое текстовое поле c \"___\" до \"___\" за время ____ сек";
newAct.setIntField = new actSetIntField();
newAct.setIntField.valFrom = 0; newAct.setIntField.valTo = 0; newAct.setIntField.sec = 0;
actList.Add(newAct);
}
// openPanel
if (curObject.type == "panel3D" && man.objects.Find(curObject.name.Replace("_3D", "")) != null || curObject.name == "Panel0801_3D" || curObject.name == "Panel0802_3D")
{
newAct = new ScAction(); newAct.type = "openPanel";
newAct.objName = curObject.name; //.Replace("_3D", "")
newAct.title = "[" + curObject.name + "] " + "Открыть 2D-панель";
actList.Add(newAct);
}
// switchTo3D
if (curObject.type == "panel3D" && man.objects.Find(curObject.name.Replace("_3D", "")) != null || curObject.name == "Panel0801_3D" || curObject.name == "Panel0802_3D")
{
newAct = new ScAction(); newAct.type = "switchTo3D";
newAct.objName = "";
newAct.title = "Закрыть 2D-панель";
actList.Add(newAct);
}
return actList;
}
public void InsertAction(ScAction act)
{
SC.curModeSc.acts.Insert(actionsView.curAction + 1, act);
int c = actionsView.curAction + 1;
if (c >= SC.curModeSc.acts.Count)
c = SC.curModeSc.acts.Count - 1;
actionsView.UpdateItems(); actionsView.tap = 0;
actionsView.onActionViewChange(c);
scModifyed();
}
public void Serialize(object item, string path)
{
if (Application.platform == RuntimePlatform.WebGLPlayer) return;
path = path.Replace("file:///", "");
if (path.Contains("http"))
{
Debug.Log("Cannot serialize to web resource.");
return;
}
XmlSerializer serializer = new XmlSerializer(item.GetType());
StreamWriter writer = new StreamWriter(path);
serializer.Serialize(writer.BaseStream, item);
writer.Close();
}
public T Deserialize<T>(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
StreamReader reader = new StreamReader(path);
T deserialized = (T)serializer.Deserialize(reader.BaseStream);
reader.Close();
return deserialized;
}
public bool CanDeserialize<T>(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
Stream fs = new FileStream(path, FileMode.Open);
XmlReader reader = new XmlTextReader(fs);
bool res = serializer.CanDeserialize(reader);
reader.Close();
fs.Close();
return res;
}
}