add particle systems

add vfx graph
This commit is contained in:
2025-06-06 12:48:53 +02:00
parent 9180b3c835
commit ddee61efc5
1624 changed files with 1725676 additions and 4 deletions
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
[ExecuteInEditMode]
public class AlignSceneView : MonoBehaviour
{
// Start is called before the first frame update
void Awake()
{
AlignCamera(transform);
}
private static void AlignCamera(Transform target)
{
#if UNITY_EDITOR
SceneView view = SceneView.lastActiveSceneView;
if (view == null) return;
Camera sceneCam = view.camera;
if(sceneCam == null) return;
sceneCam.transform.position = target.position;
sceneCam.transform.rotation = target.rotation;
view.AlignViewToObject(sceneCam.transform);
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6dac9292e94438546aa9801a7d4cbfd1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eda1e2b3d6595ed43b120dd269f7c3a7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,372 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;
using System.Text.RegularExpressions;
using System.Text;
using System;
using System.Collections;
using System.Reflection;
using UnityEngine.Rendering;
using UnityEditor.Inspector.GraphicsSettingsInspectors;
[InitializeOnLoad]
[CustomEditor(typeof(SamplesShowcase))]
public class SamplesShowcaseEditor : Editor
{
private static readonly string UXMLPath = "SamplesSelectionUXML";
public static readonly string[] supportedExtensions = {".shadergraph", ".vfx", ".cs", ".hlsl", ".shader", ".asset",".mat",".fbx",".prefab", ".png"};
SerializedProperty currentIndex;
Color headlineColor;
Color openColor;
Color highlightColor;
Color codeColor;
DropdownField dropdownField;
List<string> choices;
int indexSelected;
private VisualElement requiredSettingsBox;
private Dictionary<RequiredSettingBase, VisualElement> requiredSettingsVE = new Dictionary<RequiredSettingBase, VisualElement>();
private void OnEnable()
{
SamplesShowcase.OnUpdateSamplesInspector += UpdateSamplesInspector;
currentIndex = serializedObject.FindProperty("currentIndex");
RenderPipelineManager.activeRenderPipelineCreated += UpdateRequiredSettingsDisplay;
}
private void OnDisable()
{
RenderPipelineManager.activeRenderPipelineCreated -= UpdateRequiredSettingsDisplay;
SamplesShowcase.OnUpdateSamplesInspector -= UpdateSamplesInspector;
}
public void UpdateSamplesInspector()
{
SamplesShowcase self;
try
{
self = (SamplesShowcase)target;
}
catch
{
return;
}
if (dropdownField !=null && self != null)
{
dropdownField.value = choices[self.currentIndex]; //make sure samples description is updated from what the scene is showing, even during runtime input or inspector duplication
}
}
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
var visualTree = Resources.Load<VisualTreeAsset>(UXMLPath);
VisualElement inspectorUI = visualTree.CloneTree();
root.Add(inspectorUI);
var self = (SamplesShowcase)target;
//colors
headlineColor = EditorGUIUtility.isProSkin ? self.headlineDarkColor : self.headlineLightColor;
openColor = EditorGUIUtility.isProSkin ? self.openDarkColor : self.openLightColor;
highlightColor = EditorGUIUtility.isProSkin ? self.highlightDarkColor : self.highlightLightColor;
codeColor = EditorGUIUtility.isProSkin ? self.codeDarkColor : self.codeLightColor;
root.Q<Label>("headline").style.color = headlineColor;
bool isTextOnly = self.PresentationMode == SamplesShowcase.Mode.TextOnly ? true : false;
root.Q<VisualElement>("SamplesSelection").style.display = isTextOnly ? UnityEngine.UIElements.DisplayStyle.None : UnityEngine.UIElements.DisplayStyle.Flex;
// JSon data of the samples
if (self.SamplesDescriptionsJson != null)
{
string jsonText = SamplesShowcase.CleanupJson(self.SamplesDescriptionsJson.text);
Samples sampleJsonObject = Samples.CreateFromJSON(jsonText, self.samplesPrefabs);
//Introduction, it's the first part of the Samples Description text asset
var introElement = root.Q<VisualElement>("intro");
string introText = sampleJsonObject.introduction;
SamplesShowcase.SanitizedIntroduction = SamplesShowcase.SanitizeText(introText);
CreateMarkdown(introElement, introText);
SamplesShowcase.SanitizedDescriptions = new Dictionary<string, string>();
SamplesShowcase.SanitizedTitles = new Dictionary<string, string>();
foreach(GameObject prefab in self.samplesPrefabs)
{
Sample currentSample = sampleJsonObject.FindSampleWithPrefab(prefab);
if (currentSample == null)
continue;
string description = SamplesShowcase.SanitizeText(currentSample.description);
SamplesShowcase.SanitizedDescriptions.Add(prefab.name, description);
SamplesShowcase.SanitizedTitles.Add(prefab.name, currentSample.title);
}
//Create Samples Dropdown
dropdownField = root.Q<DropdownField>("SampleDropDown");
if (!isTextOnly && self.samplesPrefabs.Length > 0)
{
dropdownField = root.Q<DropdownField>("SampleDropDown");
choices = new List<string>();
foreach (GameObject prefab in self.samplesPrefabs)
{
Sample sample = sampleJsonObject.FindSampleWithPrefab(prefab);
if (sample != null)
{
choices.Add(sample.title);
}
}
if (currentIndex.intValue >= choices.Count)
currentIndex.intValue = choices.Count - 1;
dropdownField.value = choices[currentIndex.intValue];
dropdownField.choices = choices;
GoToSample(self, root, currentIndex.intValue, sampleJsonObject);
dropdownField.RegisterValueChangedCallback(v => GoToSample(self, root, choices.IndexOf(dropdownField.value), sampleJsonObject)); //Dropdown function call
root.Q<Button>("SelectSampleBtn").style.display = self.enableSelectButton ? UnityEngine.UIElements.DisplayStyle.Flex : UnityEngine.UIElements.DisplayStyle.None;
root.Q<Button>("SelectSampleBtn").clicked += () => { Selection.activeGameObject = self.currentPrefab; };
//Arrow Button Switch
root.Q<Button>("switchBack").clicked += () =>
{
currentIndex.intValue = currentIndex.intValue == 0 ? self.samplesPrefabs.Length - 1 : currentIndex.intValue - 1;
dropdownField.value = choices[currentIndex.intValue];
};
root.Q<Button>("switchForward").clicked += () =>
{
currentIndex.intValue = currentIndex.intValue == self.samplesPrefabs.Length - 1 ? 0 : currentIndex.intValue + 1;
dropdownField.value = choices[currentIndex.intValue];
};
}
}
requiredSettingsBox = root.Q(name = "RequiredSettingsBox");
var requiredSettingsList = root.Q(name = "RequiredSettingsList");
// Hide reference button
requiredSettingsList.Q(name = null, "requiredSettingButton").style.display = DisplayStyle.None;
var requiredSettingsSO = (target as SamplesShowcase).requiredSettingsSO;
if (requiredSettingsSO != null && requiredSettingsSO.requiredSettings != null && requiredSettingsSO.requiredSettings.Count > 0)
{
foreach (var setting in requiredSettingsSO.requiredSettings)
{
var settingButton = new Button(
() =>
{
if (RequiredSettingBase.showSettingCallback != null)
{
RequiredSettingBase.showSettingCallback(setting);
}
else if (!string.IsNullOrEmpty(setting.globalSettingsType))
{
var type = Type.GetType(setting.globalSettingsType);
GraphicsSettingsInspectorUtility.OpenAndScrollTo(type);
}
else
{
SettingsService.OpenProjectSettings(setting.projectSettingsPath);
CoreEditorUtils.Highlight("Project Settings", setting.propertyPath, HighlightSearchMode.Identifier);
}
})
{
text = setting.name
};
string description = setting.description;
if (string.IsNullOrEmpty(description))
description = setting.property.tooltip;
settingButton.tooltip = description;
settingButton.AddToClassList("requiredSettingButton");
if (!requiredSettingsVE.ContainsKey(setting))
requiredSettingsVE.Add(setting, settingButton);
requiredSettingsList.Add(settingButton);
}
}
UpdateRequiredSettingsDisplay();
// Add open window behaviour
root.Q<Button>(name = "OpenInWindowButton").clicked += () => {EditorWindow.GetWindow<SamplesWindow>("Samples Showcase", true, System.Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll"));};
return root;
}
void LinkOnPointerUp(PointerUpLinkTagEvent evt)
{
if (IsLinkFile(evt.linkID))
{
string finalPath = GetAssetFinalPath(evt.linkID);
var assetpath = AssetDatabase.LoadMainAssetAtPath(finalPath);
AssetDatabase.OpenAsset(assetpath);
}
else
{
Ping(evt.linkID);
}
}
void LinkOnPointerOver(PointerOverLinkTagEvent evt)
{
var targetVE = (VisualElement)evt.currentTarget;
targetVE.AddToClassList("link-cursor");
}
void LinkOnPointerOut(PointerOutLinkTagEvent evt)
{
var targetVE = (VisualElement)evt.currentTarget;
targetVE.RemoveFromClassList("link-cursor");
}
private void UpdateRequiredSettingsDisplay()
{
var samplesShowcase = target as SamplesShowcase;
if (samplesShowcase == null)
return;
if (samplesShowcase.requiredSettingsSO == null || samplesShowcase.requiredSettingsSO.requiredSettings == null || samplesShowcase.requiredSettingsSO.requiredSettings.Count == 0)
{
requiredSettingsBox.style.display = DisplayStyle.None;
}
bool displayBox = false;
foreach(var settingVEPair in requiredSettingsVE)
{
var state = settingVEPair.Key.state;
displayBox |= !state;
settingVEPair.Value.style.display = (state)? DisplayStyle.None : DisplayStyle.Flex;
}
requiredSettingsBox.style.display = (displayBox) ? DisplayStyle.Flex : DisplayStyle.None;
}
private void GoToSample(SamplesShowcase self, VisualElement root, int index, Samples sampleJsonObject)
{
serializedObject.Update();
currentIndex.intValue = index; //Send the new index value to the monobehaviour
var sampleInfosElement = root.Q<VisualElement>("sampleInfosContainer");
// Finding the sample in question
Sample currentSample = sampleJsonObject.FindSampleWithPrefab(self.samplesPrefabs[index]);
string currentSampleText = currentSample.description;
if (self.gameobjectSamplesName != null)
{
self.gameobjectSamplesName.text = currentSample.title;
}
if (self.gameobjectSamplesDescription != null)
{
self.gameobjectSamplesDescription.text = currentSampleText;
}
CreateMarkdown(sampleInfosElement, currentSampleText);
serializedObject.ApplyModifiedProperties();
}
private string CreateMarkdown(VisualElement element, string text)
{
if (element != null)
element.Clear();
var label = new Label();
var parsedText = text;
// Format tags
// Links
parsedText = Regex.Replace(parsedText, @"<(link=\""([\s\S]+?)\""[\s\S]*?)>", m =>
{
return $"<{m.Groups[1].Value}><color=#{ColorUtility.ToHtmlStringRGBA( IsLinkFile(m.Groups[2].Value)? openColor : highlightColor)}>";
});
parsedText = parsedText.Replace("</link>", "</color></link>");
// Titles
parsedText = parsedText.Replace("<h1>", "<b><size=16>");
parsedText = parsedText.Replace("</h1>", "</b></size>");
// Code
parsedText = parsedText.Replace("<code>", $"<color=#{ColorUtility.ToHtmlStringRGBA(codeColor)}><i>");
parsedText = parsedText.Replace("</code>", "</i></color>");
// Add tab spacing to lists
parsedText = Regex.Replace(parsedText, "•.*?(?:<br>|$)", "<margin=1em>$0</margin>");
// Remove ingore tags
parsedText = Regex.Replace(parsedText, @"<\/?ignore>", "");
// Register link callbacks
label.RegisterCallback<PointerUpLinkTagEvent>(LinkOnPointerUp);
label.RegisterCallback<PointerOverLinkTagEvent>(LinkOnPointerOver);
label.RegisterCallback<PointerOutLinkTagEvent>(LinkOnPointerOut);
label.enableRichText = true;
label.style.whiteSpace = WhiteSpace.Normal;
label.text = parsedText;
if (element != null)
element.Add(label);
return parsedText;
}
public static bool IsLinkFile( string linkID )
{
foreach (string extension in supportedExtensions)
{
if (linkID.EndsWith(extension))
return true;
}
return false;
}
private static string GetAssetFinalPath(string filename)
{
// Splitting the name
string filenameOnly = System.IO.Path.GetFileNameWithoutExtension(filename);
// Searching for asset with the filename
string[] results = AssetDatabase.FindAssets($"{filenameOnly}", null);
foreach (string result in results)
{
string path = AssetDatabase.GUIDToAssetPath(result);
// Making sure everything matches.
// /!\ will return the first if there's duplicate
if(path.EndsWith(filename)){
return path;
}
}
// If the asset hasn't been found display error on opening inspector (easy to spot mistakes all at once)
Debug.LogError($"Asset {filename} could not be found.");
return null;
}
private static void Ping(string gameObjectName)
{
GameObject go = GameObject.Find(gameObjectName);
UnityEditor.EditorGUIUtility.PingObject(go);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c991aba32574914193f4ed4bd96f43f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
using System.Reflection;
public class SamplesWindow : EditorWindow
{
[InitializeOnLoadMethod]
static void Init()
{
EditorSceneManager.sceneOpened += SceneOpened;
}
static void SceneOpened(Scene scene, OpenSceneMode openSceneMode)
{
var currentShowcase = (SamplesShowcase)FindFirstObjectByType(typeof(SamplesShowcase));
if(currentShowcase != null)
Selection.activeGameObject = currentShowcase.gameObject;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 928fe22384fe050469e4447de6b4c160
@@ -0,0 +1,28 @@
{
"name": "Unity.RenderPipelines.Core.Samples.Editor",
"rootNamespace": "",
"references": [
"Unity.RenderPipelines.Core.Runtime",
"Unity.RenderPipelines.Core.Editor",
"Unity.RenderPipelines.Core.Samples.Runtime",
"Unity.TextMeshPro",
"Unity.InputSystem"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.inputsystem",
"expression": "1.0.0",
"define": "INPUT_SYSTEM_INSTALLED"
}
],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b192f5b58f404a041b61eacc6c7c5483
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[ExecuteInEditMode]
public class GetSampleInfos : MonoBehaviour
{
public enum Type
{
Introduction,
Title,
Description
}
public Type type;
public GameObject prefab;
private TextMeshPro TextMeshProComponent = null;
// Start is called before the first frame update
IEnumerator Start()
{
yield return new WaitForSeconds(0);
UpdateText();
}
void UpdateTextMeshProReference()
{
TextMeshProComponent = this.GetComponent<TextMeshPro>();
if(TextMeshProComponent == null)
Debug.LogError($"TextMeshPro Component cannot be found on this GameObject: {this.gameObject.name}");
}
// Called when something has changed in the script
void OnValidate()
{
UpdateText();
}
void UpdateText()
{
if(TextMeshProComponent == null)
UpdateTextMeshProReference();
switch(type)
{
case Type.Introduction:
TextMeshProComponent.text = SamplesShowcase.GetSanitizedIntroduction();
break;
case Type.Title:
TextMeshProComponent.text = SamplesShowcase.GetSanitizedTitle(prefab.name);
break;
case Type.Description:
TextMeshProComponent.text = SamplesShowcase.GetSanitizedDescription(prefab.name);
break;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 47a805720b4974f4e8c8e1094a89d656
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ea5dfa3ed1d2e084aa5a954108236721
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
#if UNITY_EDITOR
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Rendering
{
public interface IRequiredSetting
{
public bool state { get; }
public string name { get; }
public string description { get; }
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5af45c846d3a5ef408a1a329e49c5aab
@@ -0,0 +1,146 @@
#if UNITY_EDITOR
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Rendering;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
using System.Reflection;
namespace UnityEngine.Rendering
{
[System.Serializable]
public class RequiredSettingBase : IRequiredSetting
{
[SerializeField]
private string m_name = "Property Name";
[SerializeField]
private string m_description = "";
[SerializeField]
public string propertyPath;
public string name => m_name;
public string description => m_description;
public string globalSettingsType;
public ValueType valueType = ValueType.Bool;
public float targetValue = 1f;
public ValidationType validationType = ValidationType.Equal;
private string m_propertyPath;
private string[] m_propertyPathHierarchyCache;
private string[] m_propertyPathHierarchy
{
get
{
if (m_propertyPath != null || m_propertyPath != propertyPath)
{
m_propertyPath = propertyPath;
m_propertyPathHierarchyCache = new string[2];
var temp = propertyPath.Split("."[0]);
m_propertyPathHierarchyCache[0] = temp[0];
m_propertyPathHierarchyCache[1] = propertyPath.Remove(0, m_propertyPathHierarchyCache[0].Length + 1);
}
return m_propertyPathHierarchyCache;
}
}
public virtual string projectSettingsPath { get; }
public static Action<RequiredSettingBase> showSettingCallback { get; set; } = null;
public virtual SerializedProperty property
{
get
{
var rpAsset = QualitySettings.renderPipeline;
if (rpAsset == null)
rpAsset = GraphicsSettings.defaultRenderPipeline;
if (rpAsset == null)
return null;
var serializedRPAsset = new SerializedObject(rpAsset);
var rootProperty = serializedRPAsset.FindProperty(m_propertyPathHierarchy[0]);
return rootProperty.FindPropertyRelative(m_propertyPathHierarchy[1]);
}
}
public virtual bool state
{
get
{
if (!string.IsNullOrEmpty(globalSettingsType))
{
var type = Type.GetType(globalSettingsType);
var field = type.GetField(propertyPath, BindingFlags.NonPublic | BindingFlags.Instance);
var getSettings = typeof(GraphicsSettings).GetMethod("GetRenderPipelineSettings").MakeGenericMethod(type);
object settings = getSettings.Invoke(null, null);
return (bool)field.GetValue(settings);
}
if (property == null)
return false;
float floatValue;
float comparedValue = targetValue;
switch(valueType)
{
case ValueType.Float:
floatValue = property.floatValue;
break;
case ValueType.Int:
floatValue = property.intValue;
comparedValue = (int)targetValue;
break;
default:
return property.boolValue == (targetValue > 0f);
}
switch (validationType)
{
case ValidationType.Greater:
return floatValue > comparedValue;
case ValidationType.Lower:
return floatValue < comparedValue;
case ValidationType.GreaterEqual:
return floatValue >= comparedValue;
case ValidationType.LowerEqual:
return floatValue <= comparedValue;
case ValidationType.Different:
return floatValue != comparedValue;
case ValidationType.LayermaskContains:
var intValue = property.intValue;
var intCompared = (int)targetValue;
return (intValue & intCompared) == intCompared;
default:
return floatValue == comparedValue;
}
}
}
}
public enum ValueType
{
Bool,
Int,
Float
};
public enum ValidationType
{
Equal,
Greater,
Lower,
GreaterEqual,
LowerEqual,
Different,
LayermaskContains
};
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1aebe677b50378d448d5406479ce8141
@@ -0,0 +1,44 @@
# if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Rendering;
using UnityEngine;
namespace UnityEngine.Rendering
{
public class RequiredSettingsSOT<T> : RequiredSettingsSO where T : RequiredSettingBase
{
[SerializeField]
public List<T> m_requiredSettings;
public override List<RequiredSettingBase> requiredSettings => new List<RequiredSettingBase>(m_requiredSettings);
public bool allGood
{
get
{
if (requiredSettings == null || requiredSettings.Count == 0)
return true;
foreach(var setting in requiredSettings)
{
if (!setting.state)
return false;
}
return true;
}
}
}
public abstract class RequiredSettingsSO : ScriptableObject, RequiredSettingsSOI
{
public abstract List<RequiredSettingBase> requiredSettings { get; }
}
public interface RequiredSettingsSOI
{
public List<RequiredSettingBase> requiredSettings { get; }
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c399b223e66c73344add0b780031ede6
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c48cade7f0de5e74b98d55addc85f9e0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
.warningIcon {
background-image: var(--unity-icons-console_entry_warn);
margin-right: 5px;
width: 32px;
height: 32px;
min-width: 32px;
min-height: 32px;
}
.link-cursor {
cursor: link;
}
.link {
}
Label {
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dace8ee3f59c99149ad4c1db64b635fe
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,27 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<Style src="project://database/Assets/Samples/Core%20RP%20Library/Common/Scripts/Resources/SamplesSelectionUSS.uss?fileID=7433441132597879392&amp;guid=dace8ee3f59c99149ad4c1db64b635fe&amp;type=3#SamplesSelectionUSS" />
<ui:ScrollView horizontal-scroller-visibility="Hidden">
<ui:Button text="Open in Window" name="OpenInWindowButton" enabled="true" style="margin-top: 15px; margin-bottom: 0; width: 100%; align-self: center; display: none;" />
<ui:VisualElement name="RequiredSettingsBox" style="flex-grow: 1; top: auto; left: auto; bottom: auto; right: auto; margin-left: 0; margin-right: 0; margin-top: 15px; margin-bottom: 15px; padding-left: 5px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; align-self: flex-start; border-left-color: rgba(0, 0, 0, 0.25); border-right-color: rgba(0, 0, 0, 0.25); border-top-color: rgba(0, 0, 0, 0.25); border-bottom-color: rgba(0, 0, 0, 0.25); flex-direction: column; flex-wrap: nowrap; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-top-left-radius: 5px; border-bottom-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; background-color: rgba(255, 255, 255, 0.1); justify-content: space-around; width: 100%;">
<ui:VisualElement style="flex-grow: 1; flex-direction: row; margin-bottom: 5px;">
<ui:VisualElement class="warningIcon" />
<ui:Label text="The following settings are required for the samples to display properly:" style="white-space: normal; justify-content: center; align-self: center; width: auto; margin-right: 39px;" />
</ui:VisualElement>
<ui:VisualElement name="RequiredSettingsList" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<ui:Button text="Button" name="PreviewButton" class="requiredSettingButton" style="border-left-color: rgba(0, 0, 0, 0.25); border-right-color: rgba(0, 0, 0, 0.25); border-top-color: rgba(0, 0, 0, 0.25); border-bottom-color: rgba(0, 0, 0, 0.25); margin-left: 0; padding-left: 12px;" />
</ui:VisualElement>
</ui:VisualElement>
<ui:Label tabindex="-1" text="Samples Selection" display-tooltip-when-elided="true" view-data-key="Headline" binding-path="headline" name="headline" style="-unity-font-style: bold; color: rgb(184, 226, 229); -unity-text-align: middle-center; font-size: 22px; white-space: normal; height: auto; width: auto; margin-bottom: 15px; margin-top: 15px; justify-content: center; align-self: center; flex-wrap: wrap; flex-direction: column; align-items: auto; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0;" />
<ui:VisualElement name="intro" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: column; flex-wrap: nowrap; padding-top: 0; padding-bottom: 0; padding-left: 0; padding-right: 0; height: auto; align-self: stretch; justify-content: center; align-items: stretch; width: 100%; margin-left: 0; margin-right: 0; margin-top: 15px; margin-bottom: 15px;" />
<ui:VisualElement name="SamplesSelection" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0.16); margin-right: 0; -unity-background-scale-mode: scale-to-fit; width: 100%; margin-left: 0; align-self: flex-start; align-items: stretch; justify-content: space-around; padding-right: 10px; padding-left: 10px; padding-top: 10px; padding-bottom: 9px; -unity-text-align: upper-left; white-space: normal; margin-top: 15px; margin-bottom: 15px; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; border-left-color: rgba(0, 0, 0, 0.25); border-right-color: rgba(0, 0, 0, 0.25); border-top-color: rgba(0, 0, 0, 0.25); border-bottom-color: rgba(0, 0, 0, 0.25); border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px;">
<ui:VisualElement name="selectionButtons" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: flex-start; margin-left: 0; margin-right: 0; margin-top: 0; align-self: auto; width: 100%; align-items: auto;">
<ui:Label text="Samples" style="-unity-font-style: bold; align-self: center; margin-left: 0; margin-right: 0; padding-right: 0; padding-left: 0; align-items: stretch; justify-content: flex-start;" />
<ui:DropdownField index="-1" choices="System.Collections.Generic.List`1[System.String]" name="SampleDropDown" tooltip="Select the Sample to Instantiate" style="opacity: 1; display: flex; visibility: visible; overflow: hidden; height: 18px; width: 50%; justify-content: space-evenly; align-items: flex-end; flex-direction: row; align-self: center; -unity-text-align: middle-center; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; margin-left: 5px; margin-right: 8px; margin-top: 0; margin-bottom: 0; text-overflow: ellipsis; min-height: auto; max-width: none; min-width: auto;" />
<ui:Button text="&lt;&lt;" name="switchBack" style="height: 18px; margin-left: 0; margin-right: 5px; margin-bottom: 0; padding-left: 0; padding-bottom: 0; padding-right: 0; padding-top: 0; min-height: auto; width: auto; justify-content: flex-start; align-self: center; align-items: stretch; margin-top: 0; border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0; -unity-text-align: middle-center; white-space: nowrap; max-width: none; max-height: none; min-width: 20px; font-size: 10px; -unity-font-style: bold;" />
<ui:Button text="&gt;&gt;" name="switchForward" style="height: 18px; margin-left: 0; margin-right: 0; margin-bottom: 0; padding-left: 0; padding-bottom: 0; padding-right: 0; padding-top: 0; min-height: auto; width: auto; justify-content: flex-start; align-self: center; align-items: stretch; margin-top: 0; border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0; -unity-text-align: middle-center; white-space: nowrap; font-size: 10px; -unity-font-style: bold; min-width: 20px;" />
</ui:VisualElement>
<ui:VisualElement name="sampleInfosContainer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); min-width: auto; min-height: auto; height: auto; padding-left: 0; padding-bottom: 0; padding-top: 0; padding-right: 0; justify-content: flex-start; width: 100%; margin-left: 0; margin-right: 0; margin-top: 20px; margin-bottom: 20px; max-height: none; align-self: center;" />
<ui:Button text="Select Object" display-tooltip-when-elided="true" name="SelectSampleBtn" style="width: 100%; align-self: center; padding-left: 0; margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; height: 18px; white-space: nowrap; justify-content: flex-start;" />
</ui:VisualElement>
</ui:ScrollView>
</ui:UXML>
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f6ae585466f660442ad348457c09c791
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Samples
{
public string introduction;
public Sample[] samples;
private Dictionary<GameObject, int> prefabToSample;
public static Samples CreateFromJSON(string jsonString, GameObject[] prefabs = null)
{
var newSamples = JsonUtility.FromJson<Samples>(jsonString);
if (prefabs != null)
{
newSamples.prefabToSample = new Dictionary<GameObject, int>();
foreach (var go in prefabs)
{
int index = System.Array.FindIndex(newSamples.samples, s => s.prefabName == jsonString);
if (index >= 0)
newSamples.prefabToSample.Add(go, index);
}
}
return newSamples;
}
public Sample FindSampleWithPrefab(GameObject prefab)
{
if ( prefabToSample.ContainsKey(prefab) )
return samples[prefabToSample[prefab]];
foreach(Sample sample in samples)
if (sample.prefabName == prefab.name)
return sample;
Debug.LogWarning($"Sample not found with prefabName: {prefab.name}");
return null;
}
}
[System.Serializable]
public class Sample
{
public string title;
public string prefabName;
public string description;
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7963d6d8a1e49574dbbe641be8d19c31
@@ -0,0 +1,207 @@
#if (ENABLE_INPUT_SYSTEM && INPUT_SYSTEM_INSTALLED)
#define USE_INPUT_SYSTEM
#endif
#if USE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Rendering
{
/// <summary>
/// Utility Free Camera component.
/// </summary>
[CoreRPHelpURLAttribute("Free-Camera")]
public class SamplesFreeCamera : MonoBehaviour
{
const float k_MouseSensitivityMultiplier = 0.01f;
/// <summary>
/// Rotation speed when using a controller.
/// </summary>
public float m_LookSpeedController = 120f;
/// <summary>
/// Rotation speed when using the mouse.
/// </summary>
public float m_LookSpeedMouse = 4.0f;
/// <summary>
/// Movement speed.
/// </summary>
public float m_MoveSpeed = 10.0f;
/// <summary>
/// Value added to the speed when incrementing.
/// </summary>
public float m_MoveSpeedIncrement = 2.5f;
/// <summary>
/// Scale factor of the turbo mode.
/// </summary>
public float m_Turbo = 10.0f;
#if USE_INPUT_SYSTEM
InputAction lookAction;
InputAction moveAction;
InputAction speedAction;
InputAction yMoveAction;
#elif ENABLE_LEGACY_INPUT_MANAGER
private static string kMouseX = "Mouse X";
private static string kMouseY = "Mouse Y";
private static string kRightStickX = "Controller Right Stick X";
private static string kRightStickY = "Controller Right Stick Y";
//private static string kVertical = "Vertical"; //Arrows used to switch Samples in the SamplesShowcase script
//private static string kHorizontal = "Horizontal"; //Arrows used to switch Samples in the SamplesShowcase script
private static string kYAxis = "YAxis";
private static string kSpeedAxis = "Speed Axis";
#endif
void OnEnable()
{
RegisterInputs();
}
void RegisterInputs()
{
#if USE_INPUT_SYSTEM
var map = new InputActionMap("Free Camera");
lookAction = map.AddAction("look", binding: "<Mouse>/delta");
moveAction = map.AddAction("move", binding: "<Gamepad>/leftStick");
speedAction = map.AddAction("speed", binding: "<Gamepad>/dpad");
yMoveAction = map.AddAction("yMove");
lookAction.AddBinding("<Gamepad>/rightStick").WithProcessor("scaleVector2(x=15, y=15)");
moveAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/w")
//.With("Up", "<Keyboard>/upArrow") //Used to switch Samples in the SamplesShowcase script
.With("Down", "<Keyboard>/s")
//.With("Down", "<Keyboard>/downArrow") //Used to switch Samples in the SamplesShowcase script
.With("Left", "<Keyboard>/a")
//.With("Left", "<Keyboard>/leftArrow") //Used to switch Samples in the SamplesShowcase script
.With("Right", "<Keyboard>/d");
//.With("Right", "<Keyboard>/rightArrow"); //Used to switch Samples in the SamplesShowcase script
speedAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/home")
.With("Down", "<Keyboard>/end");
yMoveAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/pageUp")
.With("Down", "<Keyboard>/pageDown")
.With("Up", "<Keyboard>/e")
.With("Down", "<Keyboard>/q")
.With("Up", "<Gamepad>/rightshoulder")
.With("Down", "<Gamepad>/leftshoulder");
moveAction.Enable();
lookAction.Enable();
speedAction.Enable();
yMoveAction.Enable();
#elif UNITY_EDITOR && ENABLE_LEGACY_INPUT_MANAGER
List<InputManagerEntry> inputEntries = new List<InputManagerEntry>();
// Add new bindings
inputEntries.Add(new InputManagerEntry { name = kRightStickX, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fourth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f });
inputEntries.Add(new InputManagerEntry { name = kRightStickY, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fifth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f, invert = true });
inputEntries.Add(new InputManagerEntry { name = kYAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page up", altBtnPositive = "joystick button 5", btnNegative = "page down", altBtnNegative = "joystick button 4", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kYAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "q", btnNegative = "e", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "home", btnNegative = "end", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
InputRegistering.RegisterInputs(inputEntries);
#endif
}
float inputRotateAxisX, inputRotateAxisY;
float inputChangeSpeed;
float inputVertical, inputHorizontal, inputYAxis;
bool leftShiftBoost, leftShift, fire1;
void UpdateInputs()
{
inputRotateAxisX = 0.0f;
inputRotateAxisY = 0.0f;
leftShiftBoost = false;
fire1 = false;
#if USE_INPUT_SYSTEM
var lookDelta = lookAction.ReadValue<Vector2>();
inputRotateAxisX = lookDelta.x * m_LookSpeedMouse * k_MouseSensitivityMultiplier;
inputRotateAxisY = lookDelta.y * m_LookSpeedMouse * k_MouseSensitivityMultiplier;
leftShift = Keyboard.current?.leftShiftKey?.isPressed ?? false;
fire1 = Mouse.current?.leftButton?.isPressed == true || Gamepad.current?.xButton?.isPressed == true;
inputChangeSpeed = speedAction.ReadValue<Vector2>().y;
var moveDelta = moveAction.ReadValue<Vector2>();
inputVertical = moveDelta.y;
inputHorizontal = moveDelta.x;
inputYAxis = yMoveAction.ReadValue<Vector2>().y;
#elif ENABLE_LEGACY_INPUT_MANAGER
if (Input.GetMouseButton(1))
{
leftShiftBoost = true;
inputRotateAxisX = Input.GetAxis(kMouseX) * m_LookSpeedMouse;
inputRotateAxisY = Input.GetAxis(kMouseY) * m_LookSpeedMouse;
}
inputRotateAxisX += (Input.GetAxis(kRightStickX) * m_LookSpeedController * k_MouseSensitivityMultiplier);
inputRotateAxisY += (Input.GetAxis(kRightStickY) * m_LookSpeedController * k_MouseSensitivityMultiplier);
leftShift = Input.GetKey(KeyCode.LeftShift);
fire1 = Input.GetAxis("Fire1") > 0.0f;
inputChangeSpeed = Input.GetAxis(kSpeedAxis);
//Because arrows from the axis controls are taken to switch samples
inputVertical = Input.GetKey(KeyCode.S) ? - 1 : 0;
inputVertical = Input.GetKey(KeyCode.W) ? 1 : inputVertical;
inputHorizontal = Input.GetKey(KeyCode.A) ? - 1 : 0;
inputHorizontal = Input.GetKey(KeyCode.D) ? 1 : inputHorizontal;
inputYAxis = Input.GetAxis(kYAxis);
#endif
}
void Update()
{
// If the debug menu is running, we don't want to conflict with its inputs.
if (DebugManager.instance.displayRuntimeUI)
return;
UpdateInputs();
if (inputChangeSpeed != 0.0f)
{
m_MoveSpeed += inputChangeSpeed * m_MoveSpeedIncrement;
if (m_MoveSpeed < m_MoveSpeedIncrement) m_MoveSpeed = m_MoveSpeedIncrement;
}
bool moved = inputRotateAxisX != 0.0f || inputRotateAxisY != 0.0f || inputVertical != 0.0f || inputHorizontal != 0.0f || inputYAxis != 0.0f;
if (moved)
{
float rotationX = transform.localEulerAngles.x;
float newRotationY = transform.localEulerAngles.y + inputRotateAxisX;
// Weird clamping code due to weird Euler angle mapping...
float newRotationX = (rotationX - inputRotateAxisY);
if (rotationX <= 90.0f && newRotationX >= 0.0f)
newRotationX = Mathf.Clamp(newRotationX, 0.0f, 90.0f);
if (rotationX >= 270.0f)
newRotationX = Mathf.Clamp(newRotationX, 270.0f, 360.0f);
transform.localRotation = Quaternion.Euler(newRotationX, newRotationY, transform.localEulerAngles.z);
float moveSpeed = Time.deltaTime * m_MoveSpeed;
if (fire1 || leftShiftBoost && leftShift)
moveSpeed *= m_Turbo;
transform.position += transform.forward * moveSpeed * inputVertical;
transform.position += transform.right * moveSpeed * inputHorizontal;
transform.position += Vector3.up * moveSpeed * inputYAxis;
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1fe00788be8798d4b88e0c4d7ef81378
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class SamplesLinkLightToEmissive : MonoBehaviour
{
public GameObject emissiveObject;
public Light lightToLink;
public string emissionColorProperty = "_Emission_Color";
public string emissionIntensityProperty ="_Intensity";
void Update()
{
if (lightToLink != null && emissiveObject !=null )
{
var renderer = emissiveObject.GetComponent<MeshRenderer>();
var propertyBlock = new MaterialPropertyBlock();
renderer.GetPropertyBlock(propertyBlock);
propertyBlock.SetColor(emissionColorProperty, lightToLink.color * Mathf.CorrelatedColorTemperatureToRGB(lightToLink.colorTemperature));
propertyBlock.SetFloat(emissionIntensityProperty,lightToLink.intensity);
renderer.SetPropertyBlock(propertyBlock);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c34d8416c6401f5479591edbb322a985
@@ -0,0 +1,327 @@
#if (ENABLE_INPUT_SYSTEM && INPUT_SYSTEM_INSTALLED)
#define USE_INPUT_SYSTEM
#endif
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEditor.SceneManagement;
#endif
using UnityEngine;
using TMPro;
using System.Collections;
using UnityEngine.Rendering;
using System.Text.RegularExpressions;
#if USE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
[ExecuteInEditMode]
public class SamplesShowcase : MonoBehaviour
{
public string headline = "Headline Goes Here";
// Color of the headline. light and dark theme variant.
public Color headlineLightColor = new Color(0.066f,0.066f,0.066f,1f);
public Color headlineDarkColor = new Color(0.82f,0.82f,0.82f,1f);
// Color of the text when a link is used to open an asset. light and dark theme variant.
public Color openLightColor = new Color(0.086f,0.427f,0.792f,1f);
public Color openDarkColor = new Color(0.478f,0.658f,0.933f,1f);
// Color of the text when a link is used to highlight an asset in the scene. light and dark theme variant.
public Color highlightLightColor = new Color(0.6f,0.4f,0f,1f);
public Color highlightDarkColor = new Color(1f,0.89f,0.45f,1f);
// Color for code markdown. light and dark theme variant.
public Color codeLightColor = new Color(0.76f,0.41f,0f,1f);
public Color codeDarkColor = new Color(0.91f,0.57f,0.17f,1f);
public TextAsset SamplesDescriptionsJson;
public enum Mode {Instantiation, Focus, TextOnly};
public GameObject[] samplesPrefabs;
public Mode PresentationMode = Mode.TextOnly;
public bool enableSelectButton = true;
public int currentIndex;
public GameObject currentPrefab;
int prefabIndex;
private Coroutine cameraCoroutine;
#if UNITY_EDITOR
[SerializeField]
public RequiredSettingsSO requiredSettingsSO;
#endif
//Variable containing TMPPro compatible sanitized text
public static string SanitizedIntroduction;
public static Dictionary<string, string> SanitizedDescriptions; //Key should be the prefabName, value is the description;
public static Dictionary<string, string> SanitizedTitles; //Key should be the prefabName, value is the title;
public TMP_Text gameobjectSamplesName; //if we want to have the samples name on a text mesh pro asset.
public TMP_Text gameobjectSamplesDescription; //if we want to have the samples name on a text mesh pro asset.
//Camera used to update view of samples focus in gameview
public Camera gameViewCamera;
private bool needUpdate;
private Vector3 savedPrefabPosition;
//Delegate to update every instance of samples showcase inspector UI
#if UNITY_EDITOR
public delegate void UpdateSamplesInspectorDelegate();
public static UpdateSamplesInspectorDelegate OnUpdateSamplesInspector;
void UpdateSamplesInspector()
{
if (OnUpdateSamplesInspector != null)
{
OnUpdateSamplesInspector();
}
}
#endif
void OnEnable()
{
// JSon data of the samples
if (SamplesDescriptionsJson != null)
{
string jsonText = CleanupJson(SamplesDescriptionsJson.text);
Samples sampleJsonObject = Samples.CreateFromJSON(jsonText, samplesPrefabs);
//Introduction, it's the first part of the Samples Description text asset
string introText = sampleJsonObject.introduction;
SamplesShowcase.SanitizedIntroduction = SanitizeText(introText);
SamplesShowcase.SanitizedDescriptions = new Dictionary<string, string>();
SamplesShowcase.SanitizedTitles = new Dictionary<string, string>();
foreach(GameObject prefab in samplesPrefabs)
{
Sample currentSample = sampleJsonObject.FindSampleWithPrefab(prefab);
if (currentSample == null)
continue;
string description = SanitizeText(currentSample.description);
SamplesShowcase.SanitizedDescriptions.Add(prefab.name, description);
SamplesShowcase.SanitizedTitles.Add(prefab.name, currentSample.title);
}
}
}
void OnValidate()
{
needUpdate = true;
}
void Update()
{
if (PresentationMode != Mode.TextOnly)
{
//Controls in GameMode
if (Application.isFocused && Application.isPlaying)
{
#if ENABLE_LEGACY_INPUT_MANAGER
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.UpArrow) )
{
SwitchEffect(currentIndex+1);
}
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.DownArrow) )
{
SwitchEffect(currentIndex-1);
}
#endif
#if USE_INPUT_SYSTEM
if (Keyboard.current.rightArrowKey.wasPressedThisFrame || Keyboard.current.upArrowKey.wasPressedThisFrame)
{
SwitchEffect(currentIndex+1);
}
if(Keyboard.current.leftArrowKey.wasPressedThisFrame ||Keyboard.current.downArrowKey.wasPressedThisFrame)
{
SwitchEffect(currentIndex-1);
}
#endif
}
if (needUpdate)
{
PresentSample(currentIndex);
needUpdate = false;
}
}
}
void SwitchEffect(int value)
{
currentIndex = value;
currentIndex = currentIndex > samplesPrefabs.Length - 1 ? 0 : currentIndex;
currentIndex = currentIndex < 0 ? samplesPrefabs.Length - 1 : currentIndex;
needUpdate = true;
}
void PresentSample(int index)
{
switch (PresentationMode)
{
case Mode.Instantiation:
if (index != prefabIndex)
{
CleanChildren();
if (index <= samplesPrefabs.Length && samplesPrefabs.Length > 0)
{
currentPrefab = samplesPrefabs[index];
}
// Instantiate the prefab as child
if (currentPrefab != null)
{
GameObject instantiatedPrefab = Instantiate(currentPrefab, transform.position, Quaternion.identity) as GameObject;
instantiatedPrefab.transform.parent = gameObject.transform;
instantiatedPrefab.transform.localRotation = Quaternion.identity;
currentPrefab = instantiatedPrefab;
prefabIndex = index;
// This is for keeping the prefab at the same position as before
instantiatedPrefab.transform.position = savedPrefabPosition;
}
}
break;
case Mode.Focus:
if (index <= samplesPrefabs.Length && samplesPrefabs.Length > 0)
{
currentPrefab = samplesPrefabs[index];
}
if (currentPrefab != null)
{
Transform viewPoint = currentPrefab.transform.Find("ViewPoint");
if (viewPoint != null)
{
// Align Scene View Camera
#if UNITY_EDITOR
SceneView view = SceneView.lastActiveSceneView;
if (view != null)
{
view.AlignViewToObject(viewPoint.transform);
}
#endif
// Align game view if a gameViewCamera is set
if (gameViewCamera != null)
{
if(cameraCoroutine !=null)
{
StopCoroutine(cameraCoroutine);
}
cameraCoroutine = StartCoroutine(lerpTransform(gameViewCamera.transform, viewPoint));
}
}
}
break;
}
#if UNITY_EDITOR
UpdateSamplesInspector();
#endif
}
private IEnumerator lerpTransform(Transform transformA, Transform transformB)
{
float startTime=Time.time;
while(Time.time-startTime<=1)//one second
{
transformA.position=Vector3.Lerp(transformA.position,transformB.position,Time.time-startTime);
transformA.rotation = Quaternion.Lerp(transformA.rotation,transformB.rotation, Time.time-startTime);
yield return 1; // wait for next frame
}
}
void CleanChildren()
{
//We just remove anything that has been spawn as child
if (transform.childCount > 0)
{
// This is for keeping the prefab at the same position as before
savedPrefabPosition = transform.GetChild(0).position;
foreach (Transform child in transform)
{
GameObject.DestroyImmediate(child.gameObject);
}
}
}
public static string GetSanitizedDescription(string prefabName)
{
if(SanitizedDescriptions == null) return "";
if(SanitizedDescriptions.ContainsKey(prefabName))
return SanitizedDescriptions[prefabName];
return "";
}
public static string GetSanitizedTitle(string prefabName)
{
if(SanitizedTitles == null) return "";
if(SanitizedTitles.ContainsKey(prefabName))
return SanitizedTitles[prefabName];
return "";
}
public static string GetSanitizedIntroduction()
{
return SanitizedIntroduction;
}
public static string SanitizeText(string text)
{
// Convert <br> to line break characters
text = text.Replace("<br>", "\n");
// Format <link> and <a>
text = Regex.Replace(text, @"<a[\s\S]*?>([\s\S]*?)<\/a>", $"$1");
text = Regex.Replace(text, @"<link[\s\S]*?>([\s\S]*?)<\/link>", $"$1");
// Add some offset to lists
text = text.Replace("�", " �");
// Remove text between <ignore> tags
text = Regex.Replace(text, @"<ignore>[\s\S]*?</ignore>", "");
return text;
}
public static string CleanupJson(string jsonString)
{
// Reformat json
// For text between triple quotes, remove \r \n \t characters
// Select text between triple quotes
string pattern = @"(\""\""\"")([\s\S]*?)(\""\""\"")";
// Clean it
jsonString = Regex.Replace(jsonString, pattern, m =>
{
string tripleQuotedText = m.Groups[2].Value;
// Replace newline by <br>
tripleQuotedText = tripleQuotedText.Replace("\n", "<br>");
// Escape quotes
tripleQuotedText = tripleQuotedText.Replace("\"", "\\\"");
// Remove carriage return and tabs
tripleQuotedText = Regex.Replace(tripleQuotedText, "[\r\t]", "");
return $"\"{tripleQuotedText}\"";
});
return jsonString;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43f37cacaa9726942b97c38d03b617ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
{
"name": "Unity.RenderPipelines.Core.Samples.Runtime",
"rootNamespace": "",
"references": [
"Unity.TextMeshPro",
"Unity.RenderPipelines.Core.Runtime",
"Unity.InputSystem"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.inputsystem",
"expression": "1.0.0",
"define": "INPUT_SYSTEM_INSTALLED"
}
],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 835b943161f7b5d42861f1a6b4d9d88b
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: