Example #1
0
 public void Clear()
 {
     SceneCleaning.Instance.Clean();
     InteractionModule.GetInit().TargetObjectClean();
     ChangeModule.Instance.ResetChange();
     structureM.NewStructure();
     LoadSaveDialog.GetInstance().Clear();
 }
Example #2
0
        // Awake()
        //{
        //engineM = Engine.GetInit();

        //lDialog = new System.Windows.Forms.OpenFileDialog();
        //lcDialog = new System.Windows.Forms.OpenFileDialog();
        //sDialog = new System.Windows.Forms.SaveFileDialog();

        //    lDialog.RestoreDirectory = true;
        //    lDialog.InitialDirectory = @"C:\\";
        //    lDialog.Title = "Please select the Metafile file. ";
        //    lDialog.Filter = "MGPL Files (*.mgpl) | *.mgpl |All Files | *.* ";

        //    lcDialog.RestoreDirectory = true;
        //    lcDialog.InitialDirectory = @"C:\\";
        //    lcDialog.Title = "Please select the Metagraph json file. ";
        //    lcDialog.Filter = "JSON Files (*.json) | *.json |All Files | *.* ";

        //    sDialog.AddExtension = true;
        //    sDialog.OverwritePrompt = true;
        //    sDialog.RestoreDirectory = true;
        //    sDialog.InitialDirectory = @"C:\\";
        //    sDialog.Title = "Save the Metagraph json file. ";
        //    sDialog.Filter = "JSON Files (*.json) | *.json |All Files | *.* ";
        //}

        //public void ReloadFile()
        //{
        //    if (engineM.lastLoadType == "MGPL")
        //    {
        //        string content = File.ReadAllText(fileName);
        //        readerM.ReadCode(content);
        //        logicM.LogicAdd();
        //        predicateM.BuildGraphs();
        //    }
        //    else if (engineM.lastLoadType == "JSON")
        //    {
        //        structureM.LoadingJson(fileName);
        //    }
        //}

        private void Start()
        {
            Instance = this;
            //readerM = Reader.GetInit();
            //logicM = LogicModule.GetInit();
            //predicateM = PredicateModule.GetInit();
            changeM = ChangeModule.GetInit();

            structureM = StructureModule.GetInit();
        }
Example #3
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);
        }
Example #4
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();
        }