Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 public void Clone(UnitKnowledge unitKnowledge)
 {
     path       = unitKnowledge.path;
     unitIDPool = unitKnowledge.unitIDPool;
     unitTypes.Clear();
     for (int i = 0; i < unitKnowledge.unitTypes.Count; ++i)
     {
         UnitType unitType = new UnitType();
         unitType.Clone(unitKnowledge.unitTypes [i]);
         unitTypes.Add(unitType);
     }
 }
Ejemplo n.º 3
0
    private void OnGUI()
    {
        if (box == null)
        {
            box = new GUIStyle("box");
        }

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

        if (unitKnowledge != null)
        {
            EditorGUILayout.BeginHorizontal();
            {
                type = (UnitTypes)EditorGUILayout.EnumPopup("Type", type);
                if (GUILayout.Button("Add Unit Type"))
                {
                    //Tile tileBase = null;
                    //if ( Selection.activeObject != null && Selection.activeObject.GetType () == typeof ( Tile ) )
                    //	tileBase = Selection.activeObject as Tile;

                    UnitType unit = new UnitType();
                    //newTileType.tileBase = tileBase;
                    unit.type = (int)type;

                    //if ( tileBase != null )
                    //	newTileType.tilePath = AssetDatabase.GetAssetPath ( Selection.activeObject );

                    unitKnowledge.AddUnit(unit);
                }
            }
            EditorGUILayout.EndHorizontal();

            if (unitType != null)
            {
                EditorGUILayout.BeginVertical(box);
                {
                    unitType.name       = EditorGUILayout.TextField("Name", unitType.name);
                    unitType.type       = (int)(UnitTypes)EditorGUILayout.EnumPopup("Type", (UnitTypes)unitType.type);
                    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 : "";

                    unitType.sprite2     = EditorGUILayout.ObjectField("Color", unitType.sprite2, typeof(Sprite), false) as Sprite;
                    unitType.spritePath2 = unitType.sprite2 != null?AssetDatabase.GetAssetPath(unitType.sprite2) : "";

                    unitType.spriteName2 = unitType.sprite2 != null ? unitType.sprite2.name : "";

                    unitType.sprite3     = EditorGUILayout.ObjectField("Body", unitType.sprite3, typeof(Sprite), false) as Sprite;
                    unitType.spritePath3 = unitType.sprite3 != null?AssetDatabase.GetAssetPath(unitType.sprite3) : "";

                    unitType.spriteName3 = unitType.sprite3 != null ? unitType.sprite3.name : "";

                    if (GUILayout.Button("Apply"))
                    {
                        unitKnowledge.unitTypes.Find(m => m.id == unitType.id).Clone(unitType);
                    }
                }
                EditorGUILayout.EndVertical();
            }

            folding = !EditorGUILayout.Foldout(!folding, "Fold");
            if (!folding)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                {
                    for (int a = 0; a < unitKnowledge.unitTypes.Count; ++a)
                    {
                        UnitType unit = unitKnowledge.unitTypes [a];

                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(unit.name);
                            unit.type = (int)(UnitTypes)EditorGUILayout.EnumPopup((UnitTypes)unit.type);

                            if (GUILayout.Button("Select"))
                            {
                                CloneUnitType(unit);
                            }
                            else if (GUILayout.Button("Remove"))
                            {
                                if (unitType != null && unit.id == unitType.id)
                                {
                                    unitType = null;
                                }

                                unitKnowledge.unitTypes.RemoveAt(a);
                                --a;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }
    }