• @dragoonleaph -- Good catch. The "using ORKFramework.Editor;" statement should actually have been placed inside the "#if UNITY_EDITOR" directive. As with placing the script inside a folder named Editor, this will exclude the contained code from any non-Editor platform builds.

    I edited the original post to fix this. The improvements that @Shurijo made are definitely worthwhile, and one day I will probably update the original code with them. Today is not that day. ;-)
  • @Keldryn
    Isn't the generation code editor-only anyway?
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • @Keldryn -- Again, super appreciate the clarification. I got the script working with GiL's suggestion but I'll move the "#if UNITY_EDITOR" directive just to have that practice.

    Now my issue is trying to get my health, stamina, etc. bars to transition correctly using these constants. But that's for another thread at another time. Like you said, "Today is not that day."
  • gamingislove said: Isn't the generation code editor-only anyway?
    Yes, it is. Just fixing what is technically an error in the code. If the one Editor using statement is inside #if UNITY_EDITOR then the other one should be too. ;-)

    I had originally copied some code from the Unity Toolbag and just modified it to do the ORK constants, so those directives were in the original file. But really it's far simpler to just put the whole code listing inside a single #if UNITY_EDITOR, so I went back and did that.

    @dragoonleaph - If you put the script inside a folder named Editor then you don't need to worry about the #if UNITY_EDITOR at all. That directive allows you to place editor mode code in the same assembly as your runtime code. For a utility script like this, there's generally no reason not to put it in an Editor folder. However, now the script will work if you don't have it in such a folder and it won't generate any compiler errors when you build.
  • edited January 2022
    These no longer work in ORK3.
    GetNames are all gone.
    For example
    Writer.WriteLine(BuildClass("CombatantStatusEffect", ORK.StatusEffects.GetNames(false).ToList()));

    In ORK3, what is the alternative to this?
    In my project, I need at least the following, but GetNames is required for all items.
    writer.WriteLine(BuildClass("CombatantStatusValue", ORK.StatusValues.Get( .GetNames(false).ToList()));
    writer.WriteLine(BuildClass("CombatantStatusEffect", ORK.StatusEffects.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("CombatantAbility", ORK.Abilities.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("CombatantEquipmentPart", ORK.EquipmentParts.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("ORKInput", ORK.InputKeys.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("GlobalEvent", ORK.GlobalEvents.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("Weapons", ORK.Weapons.GetNames(false).ToList()));
    writer.WriteLine(BuildClass("ItemTypes", ORK.ItemTypes.GetNames(false).ToList()));

    What is the alternative to GetNames, or what do I need to use it in CustomScript?
    This is required to reduce bugs caused by MagicNumber and MagicString.
    Alternatively, could you add it to the standard ORK3 functionality?
    Post edited by joeee19 on
  • Due to the new data structure this will no longer be possible.
    Individual things are now assets and not all of them are referenced by the central project asset - so accessing them like this is no longer supported.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Update on ORK 3 - the just released RC 1 adds a GetNames() function back in, but it's only available in those parts that also reference their assets in the main project asset (e.g. items, equipment and other things that need to be accessible there for save games).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thank you for bringing back GetNames.
    I haven't tried it in the beta version, so I don't know, but perhaps it might be useful.
    Could you consider implementing GetNames, or rather exporting a Static Class of the form [public const int XXX = X;] as a standard feature of ORK?
    In short, I don't want to use String as much as possible.
    The problem is that if I specify IDs or Strings directly in a C# custom script, and later change the IDs or Strings on the ORK side, there is no compile error.
    In other words, you don't notice the bug until you play.

    1:Things that use IDs (items/equipment/combatants...)
    2:Variables used in ORK
    For example, it would be useful if the ORK editor came standard with the ability to generate such a SaticClass.
    Is it practically difficult to implement this?

    Namespace MyGame
    public static class CombatantStatusValue
    {
    public const int MaxHP = 0;
    public const int HP = 1;
    public const int Atk = 2;
    public const int Def = 3;
    public const int Exp = 4;
    public const int ItemExp = 5;


    public static class ORKVariables
    public const string ORKVariableA = "ORKVariableA";
    public const string ORKVariableB = "ORKVariableB";
    public const string ORKVariableC = "ORKVariableC";
    }
  • Well, with ORK 3's new data system it's actually not really needed to do something like this anymore.

    Since all of these things are now separate assets (e.g. an equipment or ability are each an asset), you can use them like any other Unity asset (like audio clip, sprite, etc.). So your component can just reference the assets and use them to access functionality (or their settings).

    Each of the ORK (or Makinom) assets has a Settings property that gives you access to all it's settings, and you can use it's settings class also to access individual things (e.g. getting an ability from a combatant for that ability settings).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited July 2022
    I think this script is still relevant, so I have updated it to be ORK3 Makinom compatible, feel free to rename the namespaces

    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using UnityEngine;
    using System.IO;
    using System.Linq;
    using System.Text;
    using GamingIsLove.Makinom;
    using GamingIsLove.ORKFramework;

    #if UNITY_EDITOR
    using UnityEditor;
    #endif

    // Thanks to Keldryn
    // http://forum.orkframework.com/discussion/3336/resource-generating-ork-constants-for-scripting#latest

    namespace RustedGames
    {
    #if UNITY_EDITOR
    public static class MakinORKConstantsGenerator
    {
    [MenuItem("Edit/Generate MakinORKConstants.cs")]
    public static void Generate()
    {
    // Try to find an existing file in the project called "ORKConstants.cs"
    string filePath = string.Empty;
    foreach (var file in Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories))
    {
    if (Path.GetFileNameWithoutExtension(file) == "MakinORKConstants")
    {
    filePath = file;
    break;
    }
    }

    // If no such file exists already, use the save panel to get a folder in which the file will be placed.
    if (string.IsNullOrEmpty(filePath))
    {
    string directory = EditorUtility.OpenFolderPanel("Choose location for MakinORKConstants.cs", Application.dataPath, "");

    // Canceled choose? Do nothing.
    if (string.IsNullOrEmpty(directory))
    {
    return;
    }

    filePath = Path.Combine(directory, "MakinORKConstants.cs");
    }


    // Ensure that ORK is instantiated
    if (!Maki.Initialized)
    {
    Maki.Initialize(GamingIsLove.Makinom.Editor.MakinomAssetHelper.LoadProjectAsset());
    }

    Debug.Log("Generating MakinORKConstants.cs...");
    // Write out our file
    using (var writer = new StreamWriter(filePath))
    {
    writer.WriteLine("// This file is auto-generated. Modifications are not saved.");
    writer.WriteLine();
    writer.WriteLine("namespace RustedGames");
    writer.WriteLine("{");

    // Write out the tags

    writer.WriteLine(BuildClass("ORKStatusValue", ORK.StatusValues.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKStatusEffect", ORK.StatusEffects.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKAbility", ORK.Abilities.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKEquipmentSlots", ORK.EquipmentSlots.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKEquipment", ORK.Equipment.GetNames().ToList()));

    // Custom
    writer.WriteLine(BuildClass("ORKCombatants", ORK.Combatants.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKItemTypes", ORK.ItemTypes.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKItems", ORK.Items.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKCurrencies", ORK.Currencies.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKInputKeys", Maki.InputKeys.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKControlMaps", ORK.ControlMaps.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKAbilityTypes", ORK.AbilityTypes.GetNames().ToList()));

    writer.WriteLine(BuildClass("ORKAreaTypes", ORK.AreaTypes.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKAreas", ORK.Areas.GetNames().ToList()));
    writer.WriteLine(BuildClass("ORKDifficulties", ORK.Difficulties.GetNames().ToList()));


    // End of namespace RustedGames
    writer.WriteLine("}");
    writer.WriteLine();

    }

    Debug.Log("Completed");

    // Refresh
    AssetDatabase.Refresh();
    }
    private static string BuildClass(string className, List<string> constantNames)
    {
    StringBuilder sb = new StringBuilder(" public static class ");
    sb.AppendLine(className);
    sb.AppendLine(" {");

    try
    {
    for (int i = 0; i < constantNames.Count; i++)
    {
    sb.AppendLine(string.Format(" public const int {0} = {1};", MakeSafeForCode(constantNames[i].ToUpper()),
    i));
    }
    }
    catch (Exception ex)
    {
    Debug.LogError(string.Format("Could not generate class {0}: {1}", className, ex.Message));
    }
    finally
    {
    sb.AppendLine(" }");
    sb.AppendLine();
    }


    return sb.ToString();
    }

    private static string MakeSafeForCode(string str)
    {
    str = Regex.Replace(str, "[^a-zA-Z0-9_]", "_", RegexOptions.Compiled);
    if (char.IsDigit(str[0]))
    {
    str = "_" + str;
    }
    return str;
    }
    }
    #endif //UNITY_EDITOR
    }

    Post edited by RustedGames on
Sign In or Register to comment.