177 lines
6.8 KiB
C#
177 lines
6.8 KiB
C#
//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
|
|
//
|
|
// Purpose: Part of the My Behaviour Tree Controller Code
|
|
//
|
|
//=============================================================================
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using MyBT;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
[CustomEditor(typeof(NamedSkybox2TexStereo))]
|
|
public class NamedSkybox2TexStereoInspector : ComponentHandlerInspector {
|
|
}
|
|
#endif
|
|
|
|
[System.Serializable]
|
|
public class SkyboxItem2TexStereo {
|
|
public string skyboxLabel;
|
|
public Texture2D skyboxTexture_L0;
|
|
public Texture2D skyboxTexture_L1;
|
|
public Texture2D skyboxTexture_R0;
|
|
public Texture2D skyboxTexture_R1;
|
|
public float rotation;
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class NamedSkybox2TexStereo : ComponentHandler {
|
|
public override string TypeLabel () {
|
|
return "Skybox";
|
|
}
|
|
|
|
public override string ContentLabel() {
|
|
UpdateComponent();
|
|
return "";
|
|
}
|
|
|
|
public override void UpdateComponent() {
|
|
base.UpdateComponent();
|
|
}
|
|
|
|
public List<SkyboxItem2TexStereo> skyboxes;
|
|
public Material skyboxInterpolationMaterialPrefab;
|
|
private Material skyboxInterpolationMaterialInstance;
|
|
public Material skyboxStaticMaterialPrefab;
|
|
private Material skyboxStaticMaterialInstanceA;
|
|
private Material skyboxStaticMaterialInstanceB;
|
|
// public float rotation;
|
|
// public float exposure = 1.0f;
|
|
|
|
public override string titleText {
|
|
get {
|
|
return "Set \"TexName1\" \"TexName2\" , FadeIn/FadeOut between";
|
|
}
|
|
}
|
|
|
|
public override string[][] helpText {
|
|
get {
|
|
return new string[][] {
|
|
new string[] {"Set", "Set Panoramic Image", $"BTC.Set(\"{roomId}\", \"{gameObject.name}\", \"TextureName1\", \"TextureName2\")"},
|
|
new string[] {"Show", "Show Texture 1", $"BTC.Show(\"{roomId}\", \"{gameObject.name}\")"},
|
|
new string[] {"Hide", "Show Texture 2", $"BTC.Hide(\"{roomId}\", \"{gameObject.name}\")"},
|
|
new string[] {"FadeIn", "Fade From Texture 1 to 2", $"BTC.FadeIn(\"{roomId}\", \"{gameObject.name}\")"},
|
|
new string[] {"FadeOut", "Fade From Texture 2 to 1", $"BTC.FadeOut(\"{roomId}\", \"{gameObject.name}\")"},
|
|
};
|
|
}
|
|
}
|
|
|
|
public override void Start() {
|
|
skyboxInterpolationMaterialInstance = new Material(skyboxInterpolationMaterialPrefab);
|
|
skyboxStaticMaterialInstanceA = new Material(skyboxStaticMaterialPrefab);
|
|
skyboxStaticMaterialInstanceB = new Material(skyboxStaticMaterialPrefab);
|
|
}
|
|
|
|
public override void Set(NodeState nodeState, string texName1, string texName2) {
|
|
if ((nodeState == NodeState.FirstRun) || (nodeState == NodeState.Running)) {
|
|
Texture2D texL0_A = null;
|
|
Texture2D texL1_A = null;
|
|
Texture2D texR0_A = null;
|
|
Texture2D texR1_A = null;
|
|
float rotation_A = 0;
|
|
|
|
foreach (SkyboxItem2TexStereo skyboxItem in skyboxes) {
|
|
if (skyboxItem.skyboxLabel == texName1) {
|
|
texL0_A = skyboxItem.skyboxTexture_L0;
|
|
texL1_A = skyboxItem.skyboxTexture_L1;
|
|
texR0_A = skyboxItem.skyboxTexture_R0;
|
|
texR1_A = skyboxItem.skyboxTexture_R0;
|
|
rotation_A = skyboxItem.rotation;
|
|
}
|
|
}
|
|
|
|
Texture2D texL0_B = null;
|
|
Texture2D texL1_B = null;
|
|
Texture2D texR0_B = null;
|
|
Texture2D texR1_B = null;
|
|
float rotation_B = 0;
|
|
|
|
foreach (SkyboxItem2TexStereo skyboxItem in skyboxes) {
|
|
if (skyboxItem.skyboxLabel == texName2) {
|
|
texL0_B = skyboxItem.skyboxTexture_L0;
|
|
texL1_B = skyboxItem.skyboxTexture_L1;
|
|
texR0_B = skyboxItem.skyboxTexture_R0;
|
|
texR1_B = skyboxItem.skyboxTexture_R1;
|
|
rotation_B = skyboxItem.rotation;
|
|
}
|
|
}
|
|
if ((texL0_A != null) && (texL0_B != null)) {
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexL1_A", texL0_A);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexL2_A", texL1_A);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexR1_A", texR0_A);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexR2_A", texR1_A);
|
|
skyboxInterpolationMaterialInstance.SetFloat("_x_offset_A", rotation_A);
|
|
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexL1_B", texL0_B);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexL2_B", texL1_B);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexR1_B", texR0_B);
|
|
skyboxInterpolationMaterialInstance.SetTexture("_MainTexR2_B", texR1_B);
|
|
skyboxInterpolationMaterialInstance.SetFloat("_x_offset_B", rotation_B);
|
|
|
|
skyboxStaticMaterialInstanceA.SetTexture("_MainTexL1", texL0_A);
|
|
skyboxStaticMaterialInstanceA.SetTexture("_MainTexL2", texL1_A);
|
|
skyboxStaticMaterialInstanceA.SetTexture("_MainTexR1", texR0_A);
|
|
skyboxStaticMaterialInstanceA.SetTexture("_MainTexR2", texR1_A);
|
|
skyboxStaticMaterialInstanceA.SetFloat("_x_offset", rotation_A);
|
|
|
|
skyboxStaticMaterialInstanceB.SetTexture("_MainTexL1", texL0_B);
|
|
skyboxStaticMaterialInstanceB.SetTexture("_MainTexL2", texL1_B);
|
|
skyboxStaticMaterialInstanceB.SetTexture("_MainTexR1", texR0_B);
|
|
skyboxStaticMaterialInstanceB.SetTexture("_MainTexR2", texR1_B);
|
|
skyboxStaticMaterialInstanceB.SetFloat("_x_offset", rotation_B);
|
|
|
|
SetAlpha(0);
|
|
|
|
Task.SetSucceeded();
|
|
return;
|
|
}
|
|
|
|
else {
|
|
Debug.LogError($"NamedSkybox.Set: skybox with name {texName1} or {texName2} not available");
|
|
Task.SetFailed();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Update() {
|
|
base.Update();
|
|
}
|
|
|
|
#region both values setting
|
|
public override void SetAlpha(float alpha) {
|
|
Task.log = $"{alpha}";
|
|
skyboxInterpolationMaterialInstance.SetFloat("_Blend", alpha);
|
|
|
|
if (alpha <= 0) {
|
|
RenderSettings.skybox = skyboxStaticMaterialInstanceA;
|
|
}
|
|
else if (alpha >= 1) {
|
|
RenderSettings.skybox = skyboxStaticMaterialInstanceB;
|
|
}
|
|
else {
|
|
RenderSettings.skybox = skyboxInterpolationMaterialInstance;
|
|
}
|
|
|
|
DynamicGI.UpdateEnvironment();
|
|
}
|
|
|
|
public override float GetAlpha() {
|
|
return skyboxInterpolationMaterialInstance.GetFloat("_Blend");
|
|
}
|
|
#endregion
|
|
}
|