Пример #1
0
 public void Clear()
 {
     SceneCleaning.Instance.Clean();
     InteractionModule.GetInit().TargetObjectClean();
     ChangeModule.Instance.ResetChange();
     structureM.NewStructure();
     LoadSaveDialog.GetInstance().Clear();
 }
Пример #2
0
        public GameObject InitGraph(Vector3 position, Vector3 _scale, Color32 _color, string _name, string _nameModel, float _scaleSelectMarker, Transform parent = null)
        {
            Transform parentUse = parent ?? parentStandart;
            //string namePrefabObject = (Style3D) ? "GraphPrefab" : "2DVertexPrefab";
            GameObject objectVar = Instantiate(resourceM.GetPrefab("GraphPrefab"), position, Quaternion.identity, parentUse).gameObject;

            objectVar.transform.localScale = _scale;
            objectVar.GetComponent <Renderer>().material.color = _color;
            objectVar.name = _name;

            TooltipText tT = objectVar.GetComponent <TooltipText>();

            tT.text = _name;
            tT.selectedContainer = Instantiate(prefabSelectedContainer, objectVar.transform);
            tT.sizeSelectMarker  = _scaleSelectMarker;

            if (_nameModel != null)
            {
                string _path;
                if (LoadSaveDialog.GetInstance().fileName != "")
                {
                    _path = Path.GetDirectoryName(LoadSaveDialog.GetInstance().fileName);
                }
                else
                {
                    _path = Application.dataPath + "/MetagraphEditorTemp";
                }
                objectVar.GetComponent <DemoLoadObj>().LoadModel(_path, _nameModel);
            }

            objectVar.GetComponentInChildren <TextMesh>().text = _name;
            // Расчёт степени контрастности и соответствующего цвета.
            objectVar.GetComponentInChildren <TextMesh>().color = (_color.r * 0.299 + _color.g * 0.587 + _color.b * 0.114 <= 140) ? Color.white : Color.black;

            return(objectVar);
        }
Пример #3
0
        // Загрузка из JSON.
        public void LoadingJson(string path)
        {
            // СТАДИЯ 1. ЗАГРУЗКА ИЗ JSON В СТРУКТУРУ.

            // Очищаем выделение, если оно и было.
            changeM.ResetChange();
            // Очищаем объекты unity сцены.
            SceneCleaning.Instance.Clean();
            // Очищаем систему имён.
            PredicateModule.NameSystem.Clear();
            // Создаём новую структуру.
            NewStructure();

            using (StreamReader sr = new StreamReader(path))
            {
                string json = sr.ReadToEnd();
                json = json.Replace("\t", string.Empty);
                json = json.Replace("\n", string.Empty);
                json = json.Replace("\r", string.Empty);
                Structure[] structureArr = JsonHelper.FromJson <Structure>(json);
                foreach (var part in structureArr)
                {
                    structure[part.Name] = part;
                }
            }

            // TO DO Возможно после билда не заработает.
            string pathTemp     = Application.dataPath + "/MetagraphEditorTemp";
            string homeLocation = Path.GetDirectoryName(LoadSaveDialog.GetInstance().fileName);

            if (!Directory.Exists(pathTemp))
            {
                Directory.CreateDirectory(pathTemp);
            }

            foreach (var part in structure)
            {
                foreach (var parent in part.Value.ParentStructuresKeys)
                {
                    part.Value.ParentStructures.Add(parent, structure[parent]);
                }
                foreach (var child in part.Value.ChildStructuresKeys)
                {
                    part.Value.ChildStructures.Add(child, structure[child]);
                }
                // Поправить как-нибудь. TO DO
                // При десериализации null становится empty.
                if (part.Value.Description == string.Empty)
                {
                    part.Value.Description = null;
                }
                if (part.Value.Start == string.Empty)
                {
                    part.Value.Start = null;
                }
                if (part.Value.End == string.Empty)
                {
                    part.Value.End = null;
                }
                if (part.Value.NameModel != null && part.Value.NameModel != string.Empty)
                {
                    File.Copy(homeLocation + "/" + part.Value.NameModel, pathTemp + "/" + part.Value.NameModel, true);
                }
                else
                {
                    part.Value.NameModel = null;
                }
            }

            // Загружаем новые имена в менеджер имён.
            PredicateModule.NameSystem.LoadNameDict(ref structure);

            // СТАДИЯ 2. ПОСТРОЕНИЕ ГРАФА ПО СТРУКТУРЕ.
            predicateM.BuildGraphs();
        }