MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ScriptItem

Class ScriptItem

Source/Editor/Content/Items/ScriptItem.cs:11–96  ·  view source on GitHub ↗

Content item that contains script file with source code.

Source from the content-addressed store, hash-verified

9 /// </summary>
10 /// <seealso cref="FlaxEditor.Content.ContentItem" />
11 public abstract class ScriptItem : ContentItem
12 {
13 /// <summary>
14 /// Gets the name of the script (deducted from the asset name).
15 /// </summary>
16 public string ScriptName => FilterScriptName(ShortName);
17
18 /// <summary>
19 /// Checks if the script item references the valid use script type that can be used in a gameplay.
20 /// </summary>
21 public bool IsValid => ScriptsBuilder.FindScript(ScriptName) != null;
22
23 /// <summary>
24 /// Initializes a new instance of the <see cref="ScriptItem"/> class.
25 /// </summary>
26 /// <param name="path">The path to the item.</param>
27 protected ScriptItem(string path)
28 : base(path)
29 {
30 ShowFileExtension = true;
31 }
32
33 internal static string FilterScriptName(string input)
34 {
35 var length = input.Length;
36 var sb = new StringBuilder(length);
37
38 // Skip leading '0-9' characters
39 for (int i = 0; i < length; i++)
40 {
41 var c = input[i];
42
43 if (char.IsLetterOrDigit(c) && !char.IsDigit(c))
44 break;
45 }
46
47 // Remove all characters that are not '_' or 'a-z' or 'A-Z' or '0-9'
48 for (int i = 0; i < length; i++)
49 {
50 var c = input[i];
51
52 if (c == '_' || char.IsLetterOrDigit(c))
53 sb.Append(c);
54 }
55
56 return sb.ToString();
57 }
58
59 /// <summary>
60 /// Creates the name of the script for the given file.
61 /// </summary>
62 /// <param name="path">The path.</param>
63 /// <returns>Script name</returns>
64 public static string CreateScriptName(string path)
65 {
66 return FilterScriptName(System.IO.Path.GetFileNameWithoutExtension(path));
67 }
68

Callers

nothing calls this directly

Calls 1

FindScriptMethod · 0.45

Tested by

no test coverage detected