bookmate game
en
Книжки
Angelo Tadres

Extending Unity with Editor Scripting

  • Timur Ahmetovцитує7 років тому
    Publishing in the Asset Store
  • Timur Ahmetovцитує7 років тому
    Sharing code using Git submodules

    Using packages to share code across different projects has a few problems. These are hard to maintain because any change means a new package must be generated and distributed manually across the team.
    Collaboration is not easy because fixes to bugs in the implementation are not necessarily shared across the team, unless you invest time to manually share the packages with updates. This is not good, as it requires extra management.
    The good news is that we can address this situation using Git submodules as we started using Git in the previous chapter.
    With submodules, you can maintain a Git repository as a subdirectory of another Git repository. This lets you clone another repository with a specific tool into your project and keep your commits separate.
    In this section, we will make the AppBuilder tool a submodule used by Run & Jump.
    Creating a submodule
  • Timur Ahmetovцитує7 років тому
    Distributing your video game using AppBlade

    In this section, you will learn how to integrate with AppBlade to our pipeline to distribute Android builds.
    AppBlade is a platform for mobile application distribution, simplifying how you share your mobile applications or video games with your team and testers. Using the application available on Google Play and the AppStore, you can install and run your builds directly in your phone.
  • Timur Ahmetovцитує7 років тому
    Using the bash script in our pipeline

    Unity doesn't allow us to create text files that are not meant to be used as C# or JavaScript scripts, so access the folder Assets/Tools/Bash from outside and create a new text file called mac_githash.sh and add the following code to the file:
    #! /usr/bin/env sh
    SHORT_HASH="$( git log --pretty=format:'%h' -n 1 )"
    echo $SHORT_HASH
    This script grabs the current commit hash and returns a short version of it. So, instead of 40 characters, this will return something like 4cd9c3a.
    Note
    You must give execution permission to this script in order to make it work.
    To use and call these kinds of scripts from Unity, we will create a utility method that receives the path from the script and parameters, if necessary.
    Inside the Builder class, add the following method:
    private static string ExecuteCommand (
    string command, string arguments = "") {
    System.Diagnostics.Process pProcess = new
    System.Diagnostics.Process ();
    pProcess.StartInfo.FileName = command;
    pProcess.StartInfo.Arguments = arguments;
    pProcess.StartInfo.UseShellExecute = false;
    pProcess.StartInfo.RedirectStandardOutput = true;
    pProcess.Start ();
    string strOutput = pProcess.StandardOutput.ReadToEnd ();
    pProcess.WaitForExit ();
    return strOutput;
    }
    )
    In this method we use the Process class, which is part of the .Net API. This provides access to local and remote processes and enables you to start and stop local system processes.
    Basically, we are creating a Process instance here, setting its properties, and finally executing it. If there is any kind of output, that will be returned by the method as a string.
    For each bash script we want to use, we must use this method to integrate it with our editor scripting code.
    Still in the Builder class, we now create a new method to wrap the scripts we created in the folder Bash:
    private static string batchPath = Application.dataPath + "/Tools/AppBuilder/Bash";
    private static string GitHash () {
    string command = batchPath + "/mac-githash.sh";
    string output = ExecuteCommand (command);
    // We trim the output to remove new lines at the end.
    return output.Trim();
    }
  • Timur Ahmetovцитує7 років тому
    Interacting with external scripts

    In this section, you will learn how to call bash scripts from Unity and how to integrate this to our pipeline.
  • Timur Ahmetovцитує7 років тому
    On MacOS, the EditorPrefs values are stored in ~/Library/Preferences/com.unity3d.UnityEditor.plist. On Windows, the EditorPrefs values are stored in the registry under the HKCU\Software\Unity Technologies\UnityEditor key.
    An EditorPref value requires the creation of a key (just a unique string name to identify the variable we want to set or get) and then you can use that key to set or save the following types:
    Int
    Float
    Bool
    Strings
    In our case, we use this with a Bool to represent the state of the toggle, using the methods GetBool() and SetBool() (you can expect the same kind of naming convention for the rest of the types).
  • Timur Ahmetovцитує7 років тому
    In this chapter, you learned how to use the AssetPostprocessor in your projects, allowing you to control what is happening every time you drop an asset into your project.
    The main idea behind using these classes is to deal with asset settings, which are very important to keep your project up and running without problems.
    We did a very basic example in this chapter but the main idea remains, and it is up to you to make simple or complex things using the AssetPostprocessor to satisfy the requirements of your team and your project.
    In the next chapter we are going to continue automating things now in the build pipeline.
  • Timur Ahmetovцитує7 років тому
    When you create a new project and select the option 2D or 3D, it tells Unity how to deal with the assets imported, in this case, for example, the project uses 2D so all the images are imported as Sprites instead of textures.
  • Timur Ahmetovцитує7 років тому
    The AssetPostprocessor is a class meant to help us to automate the process of applying specific configurations to the assets imported.
    Is up to you how you define the criteria for applying or not a specific configuration, for example you can use a system based on the location of the imported asset or detecting keywords in the asset name to do several things such as adding scripts to objects, adding colliders to objects, or changing settings to textures.
    In order to guarantee the availability of the AssetPostprocessor scripts you are going to implement, it is good practice to use a DLL to group them and use the DLL inside the Editor folder in your target video game project. If you don't use a DLL and something in the project fails to compile, your assets are not going to be configured as you was planned.
  • Timur Ahmetovцитує7 років тому
    If you have a growing video game project and your artists or other team members constantly drop assets in Unity, there is no doubt you have experienced the problem of having to manage the import settings on all of those assets.
    Most of the time, importing assets is subject to errors, as somebody in the team often forgets to set the right parameters for them. Due to these kind of situations, automating the import pipeline of our video game project is important.
    Fortunately, Unity has a feature called AssetPostprocessor, which allows us to hook actions prior to or after importing an asset.
fb2epub
Перетягніть файли сюди, не більш ніж 5 за один раз