Exemple #1
0
 void Awake()
 {
     Instance      = this;
     unitKnowledge = ExtensionMethods.LoadXML(unitKnowledgeAsset.text, typeof(UnitKnowledge)) as UnitKnowledge;
     unitKnowledge.Initialize();
     buildingKnowledge = ExtensionMethods.LoadXML(buildingKnowledgeAsset.text, typeof(BuildingKnowledge)) as BuildingKnowledge;
     buildingKnowledge.Initialize();
     ColorKingdomUnits();
     Random.InitState(0);
 }
Exemple #2
0
 public void Clone(BuildingKnowledge buildingKnowledge)
 {
     path           = buildingKnowledge.path;
     buildingIDPool = buildingKnowledge.buildingIDPool;
     buildings.Clear();
     for (int i = 0; i < buildingKnowledge.buildings.Count; ++i)
     {
         BuildingType buildingType = new BuildingType();
         buildingType.Clone(buildingKnowledge.buildings [i]);
         buildings.Add(buildingType);
     }
 }
Exemple #3
0
    private void OnGUI()
    {
        if (box == null)
        {
            box = new GUIStyle("box");
        }

        EditorGUILayout.TextField(errorMessage);
        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Load Building Knowledge"))
            {
                if (Selection.activeObject != null && Selection.activeObject.GetType() == typeof(TextAsset))
                {
                    BuildingKnowledge tempBuildingKnowledge = (BuildingKnowledge)ExtensionMethods.LoadXML((Selection.activeObject as TextAsset).text, typeof(BuildingKnowledge));
                    if (tempBuildingKnowledge == null)
                    {
                        errorMessage = "Failed to load Building Knowledge.";
                    }
                    else
                    {
                        tempBuildingKnowledge.path = AssetDatabase.GetAssetPath(Selection.activeObject);
                        buildingKnowledge          = new BuildingKnowledge();
                        buildingKnowledge.Clone(tempBuildingKnowledge);
                        errorMessage = "Building Knowledge loaded. " + tempBuildingKnowledge.path;
                    }
                }
                else
                {
                    errorMessage = "Failed to load Building Knowledge.";
                }
            }
            else if (GUILayout.Button("New Building Knowledge"))
            {
                string path = EditorUtility.SaveFilePanelInProject("Create Building Knowledge", "BuildingKnowledge", "xml", "Create Building Knowledge");
                if (path.Length > 0)
                {
                    buildingKnowledge      = new BuildingKnowledge();
                    buildingKnowledge.path = path;
                    ExtensionMethods.CreateXML(buildingKnowledge, typeof(BuildingKnowledge), path);
                    AssetDatabase.Refresh();
                    errorMessage = "Building Knowledge created. " + buildingKnowledge.path;
                }
                else
                {
                    errorMessage = "Failed to create Building Knowledge.";
                }
            }
            EditorGUI.BeginDisabledGroup(buildingKnowledge == null);
            {
                if (GUILayout.Button("Save Building Knowledge"))
                {
                    if (buildingKnowledge.path.Length > 0)
                    {
                        ExtensionMethods.CreateXML(buildingKnowledge, typeof(BuildingKnowledge), buildingKnowledge.path);
                        AssetDatabase.Refresh();
                        errorMessage = "Building Knowledge saved. " + buildingKnowledge.path;
                    }
                    else
                    {
                        errorMessage = "Failed to save Building Knowledge.";
                    }
                }
            }
            EditorGUI.EndDisabledGroup();
        }
        EditorGUILayout.EndHorizontal();

        if (buildingKnowledge != null)
        {
            EditorGUILayout.BeginHorizontal();
            {
                type = (BuildingTypes)EditorGUILayout.EnumPopup("Type", type);
                if (GUILayout.Button("Add Building Type"))
                {
                    BuildingType building = new BuildingType();
                    building.type = (int)type;
                    buildingKnowledge.AddBuilding(building);
                }
            }
            EditorGUILayout.EndHorizontal();

            if (buildingType != null)
            {
                EditorGUILayout.BeginVertical(box);
                {
                    buildingType.name     = EditorGUILayout.TextField("Name", buildingType.name);
                    buildingType.type     = (int)(BuildingTypes)EditorGUILayout.EnumPopup("Type", (BuildingTypes)buildingType.type);
                    buildingType.tileBase = EditorGUILayout.ObjectField("Tile", buildingType.tileBase, typeof(Tile), false) as Tile;
                    buildingType.tilePath = buildingType.tileBase != null?AssetDatabase.GetAssetPath(buildingType.tileBase) : "";

                    //unitType.sprite = EditorGUILayout.ObjectField ( "Sprite", unitType.sprite, typeof ( Sprite ), false ) as Sprite;
                    //unitType.spritePath = unitType.sprite != null ? AssetDatabase.GetAssetPath ( unitType.sprite ) : "";
                    //unitType.spriteName = unitType.sprite != null ? unitType.sprite.name : "";

                    if (GUILayout.Button("Apply"))
                    {
                        buildingKnowledge.buildings.Find(m => m.id == buildingType.id).Clone(buildingType);
                    }
                }
                EditorGUILayout.EndVertical();
            }

            folding = !EditorGUILayout.Foldout(!folding, "Fold");
            if (!folding)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                {
                    for (int a = 0; a < buildingKnowledge.buildings.Count; ++a)
                    {
                        BuildingType building = buildingKnowledge.buildings [a];

                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(building.name);
                            building.type = (int)(BuildingTypes)EditorGUILayout.EnumPopup((BuildingTypes)building.type);

                            if (GUILayout.Button("Select"))
                            {
                                CloneBuildingType(building);
                            }
                            else if (GUILayout.Button("Remove"))
                            {
                                if (buildingType != null && building.id == buildingType.id)
                                {
                                    buildingType = null;
                                }

                                buildingKnowledge.buildings.RemoveAt(a);
                                --a;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }
    }