Skip to content

Commit

Permalink
Merge pull request #33 from UniToolsTeam/fix/defines-editor
Browse files Browse the repository at this point in the history
Fix/defines editor
  • Loading branch information
Rinal authored Mar 15, 2023
2 parents 9148b32 + ebb914c commit 5cd15c8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Editor/Core/Parameters/Int/IntBuildParameterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void Draw(IntBuildParameter target, SerializedObject serializedObj

EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField($"CLI: {target.CliKey} {value.intValue}");
EditorGUILayout.LabelField($"CLI: {target.CliCommand}");
copyToClipboard = GUILayout.Button("Copy");
}
EditorGUILayout.EndHorizontal();
Expand All @@ -58,7 +58,7 @@ public static void Draw(IntBuildParameter target, SerializedObject serializedObj

if (copyToClipboard)
{
EditorGUIUtility.systemCopyBuffer = $"{target.CliKey} {value.intValue}";
EditorGUIUtility.systemCopyBuffer = $"{target.CliCommand}";
}
}
}
Expand Down
22 changes: 16 additions & 6 deletions Editor/Core/Parameters/ScriptableBuildParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@

namespace UniTools.Build
{
/// <summary>
/// Any value that can used inside a build pipeline and can be overriden from the command line
/// </summary>
public abstract class ScriptableBuildParameter<TValue> : ScriptableObject
public abstract class ScriptableBuildParameter : ScriptableObject
{
[SerializeField] private TValue m_value = default;

/// <summary>
/// The name of the parameter that can be used inside a command line
/// </summary>
public string CliKey => $"--{name.Replace(" ", string.Empty).ToLower()}";

/// <summary>
/// The command for the CLI with a current value
/// </summary>
public abstract string CliCommand { get; }
}

/// <summary>
/// Any value that can used inside a build pipeline and can be overriden from the command line
/// </summary>
public abstract class ScriptableBuildParameter<TValue> : ScriptableBuildParameter
{
[SerializeField] private TValue m_value = default;

/// <summary>
/// Is this collection if not empty the values can be selected as enum
/// </summary>
Expand All @@ -36,6 +44,8 @@ public TValue Value
}
}

public override string CliCommand => $"{CliKey} {Value.ToString()}";

protected abstract bool TryParseFromCommandLine(string commandLine, out TValue v);
}
}
4 changes: 2 additions & 2 deletions Editor/Core/Parameters/String/StringBuildParameterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void Draw(StringBuildParameter target, SerializedObject serialized

EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField($"CLI: {target.CliKey} {value.stringValue}");
EditorGUILayout.LabelField($"CLI: {target.CliCommand}");
copyToClipboard = GUILayout.Button("Copy");
}
EditorGUILayout.EndHorizontal();
Expand All @@ -58,7 +58,7 @@ public static void Draw(StringBuildParameter target, SerializedObject serialized

if (copyToClipboard)
{
EditorGUIUtility.systemCopyBuffer = $"{target.CliKey} {value.stringValue}";
EditorGUIUtility.systemCopyBuffer = $"{target.CliCommand}";
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions Editor/Core/Pipelines/CustomEditors/BuildPipelinePresenter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

Expand All @@ -6,21 +7,29 @@ namespace UniTools.Build
public sealed class BuildPipelinePresenter
{
private readonly BuildPipeline m_buildPipeline = default;
private readonly List<ScriptableBuildParameter> m_parameters = default;
private bool m_foldout = false;

public BuildPipelinePresenter(BuildPipeline buildPipeline)
public BuildPipelinePresenter(BuildPipeline buildPipeline, IEnumerable<ScriptableBuildParameter> parameters)
{
m_buildPipeline = buildPipeline;
m_parameters = new List<ScriptableBuildParameter>(parameters);
}

public void Draw()
{
bool run = false;
bool select = false;
string command = string.Empty;
foreach (ScriptableBuildParameter p in m_parameters)
{
command += $" {p.CliCommand} ";
}

if (m_foldout)
{
string sh = $"./build.sh --pipeline {m_buildPipeline.name}";
string ps = $".\\build.ps1 --pipeline {m_buildPipeline.name}";
string sh = $"./build.sh --pipeline {m_buildPipeline.name} {command}";
string ps = $".\\build.ps1 --pipeline {m_buildPipeline.name} {command}";
bool copySh = false;
bool copyPs = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private BuildPipelinesProjectSettingsProvider(string path)
public override void OnActivate(string searchContext, VisualElement rootElement)
{
//Find parameters
List<ScriptableBuildParameter> parameters = new List<ScriptableBuildParameter>();
m_parameterPresenters.Clear();
m_allParameterKeys.Clear();
string[] guids = AssetDatabase.FindAssets($"t:{nameof(StringBuildParameter)}");
Expand All @@ -32,6 +33,7 @@ public override void OnActivate(string searchContext, VisualElement rootElement)
string path = AssetDatabase.GUIDToAssetPath(guid);
StringBuildParameter parameter = AssetDatabase.LoadAssetAtPath<StringBuildParameter>(path);
m_parameterPresenters.Add(new StringBuildParameterPresenter(parameter));
parameters.Add(parameter);
}

guids = AssetDatabase.FindAssets($"t:{nameof(IntBuildParameter)}");
Expand All @@ -40,17 +42,20 @@ public override void OnActivate(string searchContext, VisualElement rootElement)
string path = AssetDatabase.GUIDToAssetPath(guid);
IntBuildParameter parameter = AssetDatabase.LoadAssetAtPath<IntBuildParameter>(path);
m_parameterPresenters.Add(new IntBuildParameterPresenter(parameter));
parameters.Add(parameter);
}

m_allParameterKeys.AddRange(m_parameterPresenters.Select(k => k.CliKey));

//Find defines
m_defineSymbolsPresenters.Clear();
guids = AssetDatabase.FindAssets($"t:{nameof(ScriptingDefineSymbols)}");
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
ScriptingDefineSymbols define = AssetDatabase.LoadAssetAtPath<ScriptingDefineSymbols>(path);
m_defineSymbolsPresenters.Add(new ScriptingDefineSymbolsPresenter(define));
parameters.Add(define);
}

//Find pipelines
Expand All @@ -60,7 +65,7 @@ public override void OnActivate(string searchContext, VisualElement rootElement)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
BuildPipeline pipline = AssetDatabase.LoadAssetAtPath<BuildPipeline>(path);
m_pipelinePresenters.Add(new BuildPipelinePresenter(pipline));
m_pipelinePresenters.Add(new BuildPipelinePresenter(pipline, parameters));
}
}

Expand Down
8 changes: 2 additions & 6 deletions Editor/Defines/ScriptingDefineSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace UniTools.Build
fileName = nameof(ScriptingDefineSymbols),
menuName = MenuPaths.Defines + "DefineSymbols"
)]
public sealed class ScriptingDefineSymbols : ScriptableObject
public sealed class ScriptingDefineSymbols : ScriptableBuildParameter
{
[Serializable]
public sealed class DefineSymbol
Expand All @@ -19,11 +19,7 @@ public sealed class DefineSymbol
}

[SerializeField] private List<DefineSymbol> m_defines = new List<DefineSymbol>();

/// <summary>
/// The name of the parameter that can be used inside a command line
/// </summary>
public string CliKey => $"--{name.ToLower()}";
public override string CliCommand => $"{CliKey} \"{ToString()}\"";

public override string ToString()
{
Expand Down
4 changes: 2 additions & 2 deletions Editor/Defines/ScriptingDefineSymbolsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Draw(ScriptingDefineSymbols target, SerializedObject serializ

EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField($"CLI: {target.CliKey} \"{target.ToString()}\"");
EditorGUILayout.LabelField($"CLI: {target.CliCommand}");
copyToClipboard = GUILayout.Button("Copy");
}
EditorGUILayout.EndHorizontal();
Expand All @@ -36,7 +36,7 @@ public static void Draw(ScriptingDefineSymbols target, SerializedObject serializ

if (copyToClipboard)
{
EditorGUIUtility.systemCopyBuffer = $"{target.CliKey} \"{target.ToString()}\"";
EditorGUIUtility.systemCopyBuffer = $"{target.CliCommand}";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "UniTools.Build",
"name": "com.unitools.build",
"version": "0.1.5-preview",
"version": "0.1.6-preview",
"unity": "2019.1",
"description": "Customizable Build Pipeline for Unity3D",
"keywords": [
Expand Down

0 comments on commit 5cd15c8

Please sign in to comment.