Exemplo n.º 1
0
    public void CreateNetwork(string name)
    {
        int i = 0;

        string copy = name.Clone().ToString();

        if (currentAssetLibrary == null)
        {
            return;
        }

        if (this.currentAssetLibrary.Get(name) != null)
        {
            while (this.currentAssetLibrary.Get(name + i) != null)
            {
                ++i;
            }

            copy += i;
        }

        ActionNetwork newNetwork = this.currentAssetLibrary.Add(new ActionNetwork(copy));

        if (ActionNetworkEditor.instance != null)
        {
            ActionNetworkEditor.instance.selectedConnection = null;
            ActionNetworkEditor.instance.selectedSkills.Clear();
        }

        currentLibraryNetwork = newNetwork;

        this.SaveLibrary();
    }
Exemplo n.º 2
0
    public static void CreateNetworkClass(ActionNetwork actionNetwork)
    {
        string path = Application.dataPath + @"/coAdjoint/Action/ActionTest.cs";

        //string path = @"C:/temp/ActionTest.cs";

        try
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            string text = ClassString(actionNetwork);

            // Create the file.
            using (FileStream fs = File.Create(path))
            {
                Byte[] info = new UTF8Encoding(true).GetBytes(text);
                // Add some information to the file.
                fs.Write(info, 0, info.Length);
            }
        }

        catch (Exception Ex)
        {
            Debug.Log(Ex.ToString());
        }
    }
Exemplo n.º 3
0
 public ActionNetwork Add(ActionNetwork actionNetwork)
 {
     ActionNetwork[] array = new ActionNetwork[this.networks.Length + 1];
     Array.Copy(this.networks, 0, array, 0, this.networks.Length);
     array[this.networks.Length] = actionNetwork;
     this.networks = array;
     this.IsDirty  = true;
     return(actionNetwork);
 }
Exemplo n.º 4
0
    public ActionNetwork Get(string name)
    {
        ActionNetwork[] networks = this.networks;

        for (int i = 0; i < networks.Length; i++)
        {
            ActionNetwork network = networks[i];
            if (network.name == name)
            {
                return(network);
            }
        }
        return(null);
    }
Exemplo n.º 5
0
    public void Delete(ActionNetwork actionNetworkToDelete)
    {
        int num = Array.IndexOf <ActionNetwork>(networks, actionNetworkToDelete);

        if (num == -1)
        {
            return;
        }

        ActionNetwork[] array = new ActionNetwork[networks.Length - 1];
        Array.Copy(networks, 0, array, 0, num);
        Array.Copy(networks, num + 1, array, num, networks.Length - num - 1);
        this.networks = array;

        ActionEditor.instance.currentLibraryNetwork = null;

        IsDirty = true;
    }
Exemplo n.º 6
0
    public ActionNetwork(string name, ActionNetwork original)
    {
        this.name = name;

        skills = new List <ActionSkill>();

        foreach (ActionSkill val in original.skills)
        {
            skills.Add(new ActionSkill(val.Name, this));
            skills.Last().Q = val.Q;
            skills.Last().B = val.B;
            skills.Last().v = val.v;

            skills.Last().Position = val.Position;
        }

        foreach (ActionConnection actC in original.connections)
        {
            AddConnection(Get(actC.To.Name), Get(actC.From.Name), actC.toValue, actC.fromValue);
        }
    }
Exemplo n.º 7
0
    public void CentreNetwork(ActionNetwork actionNetwork)
    {
        _zoom = 1.0f;

        Vector2 centreOfMass = new Vector2();

        float width  = _networkRect.width;
        float height = _networkRect.height;

        foreach (ActionSkill actS in actionNetwork.skills)
        {
            //actS.Draw(false,false);
            centreOfMass += actS.drawPos.center;
        }

        centreOfMass /= actionNetwork.skills.Count;

        Vector2 distToMove = centreOfMass - ConvertScreenCoordsToZoomCoords(new Vector2(width / 2, height / 2))
                             + new Vector2(offset.X, offset.Y);

        offset.X -= distToMove.x;
        offset.Y -= distToMove.y;
    }
Exemplo n.º 8
0
    public static void GenerateRTLibrary(ActionAsset asset)
    {
        ActionLibrary library = ActionLibrary.LoadData(asset.libraryData);

        ActionNetwork illegalNetwork = AreSkillNamesUnique(library);

        StringBuilder text = new StringBuilder();

        if (illegalNetwork != null)
        {
            EditorUtility.DisplayDialog("Error", "At least two skills in the network " + illegalNetwork.name + " contained in the currently " +
                                        "selected asset have the same name after special characters have been removed from their names. Please change their names to ensure " +
                                        "they will be unique when special characters are removed.", "Ok");

            return;
        }
        else
        {
            for (int i = 0; i < library.networks.Length; ++i)
            {
                if (library.networks[i].skills.Count > 0)
                {
                    text.Append(ActionClassGenerator.ClassString(library.networks[i]) + "\n\n");
                }
            }

            string TEMPADDRESS = string.Empty;

            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                TEMPADDRESS = Path.Combine(Path.Combine(Path.Combine(EditorApplication.applicationContentsPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar), "Frameworks"), "Managed")
                                           , "UnityEngine.dll");
            }
            else
            {
                TEMPADDRESS = Path.Combine(Path.Combine(EditorApplication.applicationContentsPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar), "Managed")
                                           , "UnityEngine.dll");
            }

            using (StreamWriter writer = new StreamWriter("output.txt", false))
            {
                writer.WriteLine(text);
            }

            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.ReferencedAssemblies.Add(TEMPADDRESS);
            compilerParameters.ReferencedAssemblies.Add("system.dll");
            compilerParameters.ReferencedAssemblies.Add(Application.dataPath + @"/coAdjoint/Action/ACE.dll");
            compilerParameters.OutputAssembly = Application.dataPath + "/coAdjoint/Action/Builds/" + asset.name + "Build.dll";

            CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp");

            CompilerResults cr = codeDomProvider.CompileAssemblyFromSource(compilerParameters, new string[]
            {
                text.ToString()
            });

            if (cr.Errors.Count > 0)
            {
                foreach (CompilerError ce in cr.Errors)
                {
                    throw new ApplicationException(ce.ToString());
                }
            }

            AssetDatabase.Refresh();
        }
    }
Exemplo n.º 9
0
    public static void ImportActionLibrary()
    {
        string file = EditorUtility.OpenFilePanel("Select Action Library to import", "", "xml");

        if (file == null || file.Length == 0)
        {
            return;
        }

        XDocument doc = XDocument.Load(file);

        try
        {
            ActionLibrary importedLibrary = new ActionLibrary();

            foreach (var network in doc.Root.Elements("Network"))
            {
                ActionNetwork actN = new ActionNetwork(network.Attribute("Name").Value);

                importedLibrary.Add(actN);

                foreach (var skill in network.Elements("Skills").Elements("Skill"))
                {
                    string[] position = skill.Element("Position").Value.Replace("(", "").Replace(")", "").Split(',');

                    EditorTwoVector pos = new EditorTwoVector(float.Parse(position[0]), float.Parse(position[1]));

                    actN.AddSkill(skill.Attribute("Name").Value, double.Parse(skill.Element("Q").Value), double.Parse(skill.Element("B").Value),
                                  double.Parse(skill.Element("v").Value), pos);
                }

                foreach (var connection in network.Elements("Connections").Elements("Connection"))
                {
                    actN.AddConnection(actN.Get(connection.Element("ToSkill").Value), actN.Get(connection.Element("FromSkill").Value),
                                       double.Parse(connection.Element("ToValue").Value), double.Parse(connection.Element("FromValue").Value));
                }
            }

            string fileName = Path.GetFileNameWithoutExtension(file);

            string nameCopy = fileName.Clone().ToString();

            int index = 0;

            if (System.IO.File.Exists(Application.dataPath + "/coAdjoint/Action/Libraries/" + fileName + ".asset"))
            {
                ++index;

                while (System.IO.File.Exists(Application.dataPath + "/coAdjoint/Action/Libraries/" + fileName + index + ".asset"))
                {
                    ++index;
                }

                nameCopy += index.ToString();
            }

            var asset = ScriptableObject.CreateInstance <ActionAsset>();

            asset.libraryData = importedLibrary.GetData();

            AssetDatabase.CreateAsset(asset, "Assets/coAdjoint/Action/Libraries/" + nameCopy + ".asset");

            Selection.activeObject = asset;

            ActionMenu.EditLibraryAsset();
        }
        catch (Exception e)
        {
            Debug.LogError("Failed to deserialize. Reason: " + e.Message);
            throw;
        }
    }
Exemplo n.º 10
0
    public bool OnNetworkListItemGUI(object item, bool selected, ICollection list)
    {
        ActionNetwork myItem = (ActionNetwork)item;

        GUIStyle style  = (!selected || highlightedItemType != ItemType.ActionNetwork) ? ActionResources.listItem : ((!this.HasFocus) ? ActionResources.unfocusedSelectedListItem : ActionResources.selectedListItem);
        GUIStyle style2 = (!selected || highlightedItemType != ItemType.ActionNetwork) ? ActionResources.list : ((!this.HasFocus) ? ActionResources.unfocusedSelectedList : ActionResources.selectedList);

        GUILayout.BeginHorizontal(style, new GUILayoutOption[0]);

        GUILayout.Space(20f);

        if (GUILayout.Button((myItem.explorerExpanded)?ActionResources.expanded:ActionResources.collapsed, style2, new GUILayoutOption[]
        {
            GUILayout.Width(14f),
            GUILayout.Height(14f)
        }))
        {
            myItem.explorerExpanded = !myItem.explorerExpanded;
        }

        if (editingNames && _highlightedItemType == ItemType.ActionNetwork && selected)
        {
            editingString = GUILayout.TextField(editingString, EditorStyles.textField, new GUILayoutOption[]
            {
                GUILayout.Height(14f)
            });
        }
        else if (GUILayout.Button(myItem.name, style2, new GUILayoutOption[]
        {
            GUILayout.Height(14f)
        }))
        {
            editingNames = false;

            if (highlightedItemType == ItemType.ActionNetwork)
            {
                ActionEditor.instance.currentLibraryNetwork.name = ActionEditor.instance.currentLibraryNetwork.name.Replace(" ", string.Empty);
            }
            else
            {
                highlightedSkill.Name = highlightedSkill.Name.Replace(" ", string.Empty);
            }

            selected = true;
            this.highlightedItemType = ItemType.ActionNetwork;

            ActionNetworkEditor.instance.selectedSkills.Clear();

            //ActionNetworkEditor.instance.CentreNetwork(ActionEditor.instance.currentLibraryNetwork);
        }
        GUILayout.EndHorizontal();

        if (myItem.explorerExpanded)
        {
            if (myItem.skills.Count > 0)
            {
                ActionSkill[] temp  = myItem.skills.ToArray();
                List <object> list2 = new List <object>(temp);
                list2.Sort((x, y) => string.Compare(x.ToString(), y.ToString()));

                highlightedSkill = (ActionSkill)ActionResources.SelectList(list2, highlightedSkill, new ActionResources.OnListItemGUI(OnSubCollectionListItemGUI));
            }
            else
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(40f);
                    GUILayout.Label(new GUIContent("Empty Network"), new GUILayoutOption[0]);
                } GUILayout.EndHorizontal();
            }
        }

        return(selected);
    }
Exemplo n.º 11
0
    public ActionConnection(ActionSkill toSkill, ActionSkill fromSkill, double toV, double fromV, ActionNetwork owner)
    {
        this.To   = toSkill;
        this.From = fromSkill;

        this.toValue   = toV;
        this.fromValue = fromV;
    }
Exemplo n.º 12
0
 public ActionSkill(string Name, ActionNetwork myOwner)
 {
     this.Name = Name;
 }
Exemplo n.º 13
0
    public static string ClassString(ActionNetwork actionNetwork)
    {
        string text =
            "\n\tpublic sealed class " + actionNetwork.name.RemoveSpecialCharacters() + " : ACE.Runtime.Network \n" +
            "\t{\n" +
            "\t\tpublic enum Skill \n" +
            "\t\t{ \n";

        string[] skillNames = new string[actionNetwork.skills.Count];

        for (int i = 0; i < actionNetwork.skills.Count; ++i)
        {
            skillNames[i] = actionNetwork.skills[i].Name;

            text += "\t\t\t" + skillNames[i].RemoveSpecialCharacters().Replace(" ", string.Empty) + "=" + i + ",\n";
        }

        text += "\t\t}\n\n";

        text += "\t\tprivate void Init()\n" +
                "\t\t{\n" +
                "\t\t\tmodelNo = " + actionNetwork.skills.Count.ToString() + "; \n\n" +
                "\t\t\t_stren = new double[][]" +
                "\t{";

        double[,] connectionMatrix = new double[actionNetwork.skills.Count, actionNetwork.skills.Count];

        List <ActionConnection> alreadyCoveredConnections = new List <ActionConnection>();

        for (int j = 0; j < actionNetwork.skills.Count; ++j)
        {
            foreach (ActionConnection actC in actionNetwork.connections)
            {
                if (!alreadyCoveredConnections.Contains(actC))
                {
                    ActionSkill actS = actionNetwork.skills[j];

                    if (actC.Contains(actS))
                    {
                        alreadyCoveredConnections.Add(actC);

                        if (actC.isTo(actS))
                        {
                            int index = actionNetwork.skills.IndexOf(actC.From);

                            if (index != -1)
                            {
                                connectionMatrix[j, index] = actC.toValue;
                                connectionMatrix[index, j] = actC.fromValue;
                            }
                        }
                        else
                        {
                            int index = actionNetwork.skills.IndexOf(actC.To);

                            if (index != -1)
                            {
                                connectionMatrix[index, j] = actC.toValue;
                                connectionMatrix[j, index] = actC.fromValue;
                            }
                        }
                    }
                }
            }
        }

        for (int j = 0; j < actionNetwork.skills.Count; ++j)
        {
            text += "\t\n\t\t\t new double[] {";

            for (int k = 0; k < actionNetwork.skills.Count - 1; ++k)
            {
                text += connectionMatrix[j, k].ToString() + ", ";
            }

            text += connectionMatrix[j, actionNetwork.skills.Count - 1].ToString();

            text += " },";
        }

        text += "\t};";

        text += "\t\n\n";

        text += "\t\t\t_l = new double[" + actionNetwork.skills.Count + "];\n";
        text += "\t\t\t_exp = new double[" + actionNetwork.skills.Count + "];\n";
        text += "\t\t\t_skills = new ACE.Runtime.Skill[" + actionNetwork.skills.Count + "]{\n";

        for (int i = 0; i < actionNetwork.skills.Count; ++i)
        {
            if (i != 0)
            {
                text += "\t\n";
            }

            text += "\t\t\t\tnew ACE.Runtime.Skill( \"" + skillNames[i] + "\", this, " + i.ToString() + ", " + actionNetwork.skills[i].Q.ToString() +
                    ", " + actionNetwork.skills[i].B.ToString() + ", " + actionNetwork.skills[i].v.ToString() + "),";
        }

        text = text.Remove(text.Length - 1);

        text += "\t};\n";

        text += "\t\t}\n\n";

        text += "\t\tpublic " + actionNetwork.name + "()\n" +
                "\t\t{\n" +
                "\t\t\tInit();\n" +
                "\t\t\tSetAllLevels(1);\n" +
                "\t\t}\n\n";

        text += "\t\tpublic " + actionNetwork.name + "(double level)\n" +
                "\t\t{\n" +
                "\t\t\tInit();\n" +
                "\t\t\tSetAllLevels(level);\n" +
                "\t\t}\n\n";

        text += "\t\tpublic " + actionNetwork.name + "(double[] levels)\n" +
                "\t\t{\n" +
                "\t\t\tif(levels.Length != " + actionNetwork.skills.Count + ")\n" +
                "\t\t\t{\n" +
                "\t\t\t\tUnityEngine.Debug.LogError(\"Double array input length does not equal \" + " + actionNetwork.skills.Count + " + \". Calling default constructor\");\n" +
                "\t\t\t\tInit();\n" +
                "\t\t\t\tSetAllLevels(1);\n\n" +
                "\t\t\t\treturn;\n" +
                "\t\t\t}\n" +
                "\t\t\telse\n" +
                "\t\t\t{\n" +
                "\t\t\t\tInit();\n\n" +
                "\t\t\t\tfor(int i = 0; i < " + actionNetwork.skills.Count + "; ++i)\n" +
                "\t\t\t\t{\n" +
                "\t\t\t\t\tSetLevel((Skill)i, levels[i]);\n" +
                "\t\t\t\t}\n" +
                "\t\t\t}\n" +
                "\t\t}\n\n" +
                "\t\tpublic void SetAllLevels(double level)\n" +
                "\t\t{\n" +
                "\t\t\tfor(int i = 0; i < " + actionNetwork.skills.Count + "; ++i)\n" +
                "\t\t\t{\n" +
                "\t\t\t\tSetLevel((Skill)i, level);\n" +
                "\t\t\t}\n" +
                "\t\t}\n\n" +
                "\t\tpublic void SetLevel(Skill skill, double val)\n" +
                "\t\t{\n" +
                "\t\t\tint model = (int)skill;\n\n" +
                "\t\t\tRemoveSkillFromQueue(model);\n\n" +
                "\t\t\t_exp[model] = ACE.Runtime.BrentSolver.Brent(new ACE.Runtime.BrentSolver.FunctionOfOneVariable(_skills[model].Level), 0, 1000, 1e-10, val);\n" +
                "\t\t\t_l[model] = _skills[model].Level(_exp[model]);\n" +
                "\t\t}\n\n" +
                "\t\tpublic double GetLevelAsDouble(Skill skill)\n \t\t{\n\t\t\tint model = (int)skill;\n\n\t\t\tlock(_skills[model].loc)\n\t\t\t{\n\t\t\t\treturn _l[model];\n" +
                "\t\t\t}\n\t\t}\n\n" +
                "\t\tpublic float GetLevelAsFloat(Skill skill)\n \t\t{\n \t\t\treturn (float)GetLevelAsDouble(skill);\n \t\t}\n\n" +
                "\t\tpublic double GetExperienceAsDouble(Skill skill)\n \t\t{\n \t\t\tint model = (int)skill;\n\n \t\t\tlock(_skills[model].loc)\n \t\t\t{\n \t\t\t\treturn _exp[model];\n \t\t\t}\n \t\t}\n\n" +
                "\t\tpublic float GetExperienceAsFloat(Skill skill)\n\t\t{\n\t\t\treturn (float)GetExperienceAsDouble(skill);\n\t\t}\n\n" +
                "\t\tpublic void LevelUp(Skill skill, double val)\n\t\t{\n\t\t\tint model = (int)skill;\n\n\t\t\tACE.Runtime.ThreadedActionScript.instance.Action(_skills[model],val);\n \t\t}\n\n" +
                "\t\tprivate void RemoveSkillFromQueue(Skill skill)\n \t\t{\n \t\t\tint model = (int)skill;\n\n  \t\t\tRemoveSkillFromQueue(model);\n \t\t}\n\n" +
                "\t\tprivate void RemoveSkillFromQueue(int i)\n\t\t{\n \t\t\tlock(_skills[i].loc)\n \t\t\t{\n \t\t\t\t_skills[i].isBlockedFromQueue = true;\n\n  \t\t\t\tif(_skills[i].isInQueue)\n \t\t\t\t{\n \t\t\t\t\tACE.Runtime.ThreadedActionScript.instance.RemoveFromQueue(_skills[i]);\n\t\t\t\t}\n\n\t\t\t\t_skills[i].isBlockedFromQueue = false;\n \t\t\t}\n \t\t}\n\n" +
                "\t\tpublic void Remove()\n\t\t{\n \t\t\tACE.Runtime.ThreadedActionScript.instance.ClearQueue();\n \t\t}\n";

        return(text + "\t}");
    }