Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
This change addresses two issues.
Browse files Browse the repository at this point in the history
1) moves the project's files forward to Unity 5.4.0f3

2) when using Galaxy Explorer from play/preview mode in the Unity editor, Unity will persist any changes GE's scripts make to the materials they control. This is OK when running on device because those changes aren't persisted. When used in the editor, however, the changes are persisted to disk which makes making changes to other areas of the application difficult to isolate, especially when GIT is the source code control mechanism. The previous mechanism was to just assign a copy of the material to the renderer (wrapped in a #if UNITY_EDITOR block). Using this approach, the editor's play mode was visually different from the in-device experience (POI line ends always visible, cursor always visible, etc.)

Update to Unity 5.4.0.f3
* .gitignore
* Assets/Models/HighlightReticle/Reticle.fbx.meta
* ProjectSettings/GraphicsSettings.asset
* ProjectSettings/ProjectSettings.asset
* ProjectSettings/ProjectVersion.txt
* UWP/UnityOverwrite.txt
* UWP/GalaxyExplorer/Assets/StoreLogo.scale-100.png

Unity's Material format changed.
* Assets\SolarSystem\Planets\*.mat

Better fix to restore materials that Unity's editor thinks it needs to modify in play mode:
* Assets/Galaxy/DrawStars.cs
* Assets/Scripts/Input/Button.cs
* Assets/Scripts/Input/PointOfInterest.cs
* Assets/Scripts/Input/Tool.cs
* Assets/Scripts/MaterialsFader.cs
* Assets/Scripts/Utilities/ScrollMaterialTexture.cs
* Assets/SolarSystem/Asteroids/AsteroidRing.cs
* Assets/SolarSystem/OrbitalTrails/OrbitalTrail.cs
* Assets/SolarSystem/Planets/LODs/LODInstanceSunReceiver.cs
* Assets/SolarSystem/Planets/LODs/LODSunReceiver.cs
* Assets/SolarSystem/Planets/SaturnVisual.cs
* Assets/SolarSystem/Sun/LensFlare.shader
* Assets/SolarSystem/Sun/SunLensFlareSetter.cs
* Assets/SolarSystem/SunLightReceiver.cs
* Assets/SolarSystem/TrueScaleSetting.cs
* Assets/UI/Cursor/Cursor.cs
  • Loading branch information
Tim Gerken committed Aug 10, 2016
1 parent c93f132 commit a6bd70d
Show file tree
Hide file tree
Showing 42 changed files with 5,106 additions and 6,392 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ UWP/**
!UWP/GalaxyExplorer/Assets/Square44x44Logo.targetsize-256_altform-unplated.png
!UWP/GalaxyExplorer/Assets/StoreLogo.png
!UWP/GalaxyExplorer/Assets/StoreLogo.scale-400.png
!UWP/GalaxyExplorer/Assets/StoreLogo.scale-100.png
!UWP/GalaxyExplorer/Assets/Wide310x150Logo.scale-200.png
!UWP/GalaxyExplorer/Properties/AssemblyInfo.cs

11 changes: 7 additions & 4 deletions Assets/Galaxy/DrawStars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class DrawStars : MonoBehaviour

public bool renderIntoDownscaledTarget;
public MeshRenderer referenceQuad;
private float originalTransitionAlpha;

private HoloCube holoCube;

Expand All @@ -117,13 +118,10 @@ private IEnumerator Start()
holoCube = TransitionManager.Instance.ViewVolume.GetComponentInChildren<HoloCube>(includeInactive: true);
}

#if UNITY_EDITOR
if (referenceQuad && referenceQuad.sharedMaterial)
{
// We don't want to change the material in the Editor, but a copy of it.
referenceQuad.sharedMaterial = new Material(referenceQuad.sharedMaterial);
originalTransitionAlpha = referenceQuad.sharedMaterial.GetFloat("_TransitionAlpha");
}
#endif
}

public void CreateBuffers(StarVertDescriptor[] stars)
Expand Down Expand Up @@ -165,6 +163,11 @@ private void OnDisable()

private void OnDestroy()
{
if (referenceQuad && referenceQuad.sharedMaterial)
{
referenceQuad.sharedMaterial.SetFloat("_TransitionAlpha", originalTransitionAlpha);
}

DisposeBuffer(ref starsData);

if (holoCube)
Expand Down
4 changes: 3 additions & 1 deletion Assets/Models/HighlightReticle/Reticle.fbx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions Assets/Scripts/Input/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEngine.VR.WSA.Input;
using System;
using System.Collections.Generic;

public enum ButtonType
{
Expand All @@ -18,7 +19,9 @@ public class Button : GazeSelectionTarget, IFadeTarget
{
public GameObject TooltipObject;
public Material DefaultMaterial;
public Dictionary<string, float> defaultMaterialDefaults = new Dictionary<string, float>();
public Material HightlightMaterial;
public Dictionary<string, float> highlightMaterialDefaults = new Dictionary<string, float>();
public ButtonType type;
public bool IsDisabled;

Expand Down Expand Up @@ -68,31 +71,41 @@ private void ApplyOpacity(Material material, float value)
}
}

private void CacheMaterialDefaultAttributes(ref Dictionary<string, float>dict, Material mat)
{
dict.Add("_TransitionAlpha", mat.GetFloat("_TransitionAlpha"));
dict.Add("_SRCBLEND", (float)mat.GetInt("_SRCBLEND"));
dict.Add("_DSTBLEND", (float)mat.GetInt("_DSTBLEND"));
dict.Add("_ZWRITE", (float)mat.GetInt("_ZWRITE"));
}

private void RestoreMaterialDefaultAttributes(ref Dictionary<string, float>dict, Material mat)
{
mat.SetFloat("_TransitionAlpha", dict["_TransitionAlpha"]);
mat.SetInt("_SRCBLEND", (int)dict["_SRCBLEND"]);
mat.SetInt("_DSTBLEND", (int)dict["_DSTBLEND"]);
mat.SetInt("_ZWRITE", (int)dict["_ZWRITE"]);
}

private void Awake()
{
if (DefaultMaterial == null)
{
Debug.LogWarning(gameObject.name + " Button has no default material.");
}
#if UNITY_EDITOR
else
{
// We don't want to change the material in the Editor, but a copy of it.
DefaultMaterial = new Material(DefaultMaterial);
CacheMaterialDefaultAttributes(ref defaultMaterialDefaults, DefaultMaterial);
}
#endif

if (HightlightMaterial == null)
{
Debug.LogWarning(gameObject.name + " Button has no highlight material.");
}
#if UNITY_EDITOR
else
{
// We don't want to change the material in the Editor, but a copy of it.
HightlightMaterial = new Material(HightlightMaterial);
CacheMaterialDefaultAttributes(ref highlightMaterialDefaults, HightlightMaterial);
}
#endif

meshRenderer = GetComponentInChildren<MeshRenderer>();

Expand Down Expand Up @@ -228,4 +241,10 @@ public void ButtonAction()
break;
}
}

private void OnDestroy()
{
RestoreMaterialDefaultAttributes(ref defaultMaterialDefaults, DefaultMaterial);
RestoreMaterialDefaultAttributes(ref highlightMaterialDefaults, HightlightMaterial);
}
}
13 changes: 10 additions & 3 deletions Assets/Scripts/Input/PointOfInterest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public override bool SetAlpha(float alphaValue)
public AudioClip AirtapSound;

public Material MaterialToFade;
private float originalTransitionAlpha;

protected AudioSource audioSource;

Expand All @@ -75,16 +76,14 @@ public override bool SetAlpha(float alphaValue)
private Vector3 targetOffset;
protected bool initialized = false;

#if UNITY_EDITOR
private void Awake()
{
if (MaterialToFade)
{
// We don't want to change the material in the Editor, but a copy of it.
MaterialToFade = new Material(MaterialToFade);
originalTransitionAlpha = MaterialToFade.GetFloat("_TransitionAlpha");
}
}
#endif

protected virtual void OnEnable()
{
Expand Down Expand Up @@ -247,4 +246,12 @@ public void GoToScene()
TransitionManager.Instance.LoadNextScene(TransitionScene, gameObject);
}
}

private void OnDestroy()
{
if (MaterialToFade)
{
MaterialToFade.SetFloat("_TransitionAlpha", originalTransitionAlpha);
}
}
}
39 changes: 27 additions & 12 deletions Assets/Scripts/Input/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.
using UnityEngine;
using UnityEngine.VR.WSA.Input;
using System.Collections.Generic;

public enum ToolType
{
Expand All @@ -18,8 +19,11 @@ public class Tool : GazeSelectionTarget, IFadeTarget

public GameObject TooltipObject;
public Material DefaultMaterial;
private Dictionary<string, float> defaultMaterialDefaults = new Dictionary<string, float>();
public Material HighlightMaterial;
private Dictionary<string, float> highlightMaterialDefaults = new Dictionary<string, float>();
public Material SelectedMaterial;
private Dictionary<string, float> selectedMaterialDefaults = new Dictionary<string, float>();
public ToolType type;
public float PanSpeed = 0.25f;
public float RotationSpeed = 30.0f;
Expand Down Expand Up @@ -67,43 +71,50 @@ private void ApplyOpacity(Material material, float value)
}
}

private void CacheMaterialDefaultAttributes(ref Dictionary<string, float> dict, Material mat)
{
dict.Add("_TransitionAlpha", mat.GetFloat("_TransitionAlpha"));
dict.Add("_SRCBLEND", (float)mat.GetInt("_SRCBLEND"));
dict.Add("_DSTBLEND", (float)mat.GetInt("_DSTBLEND"));
dict.Add("_ZWRITE", (float)mat.GetInt("_ZWRITE"));
}

private void RestoreMaterialDefaultAttributes(ref Dictionary<string, float> dict, Material mat)
{
mat.SetFloat("_TransitionAlpha", dict["_TransitionAlpha"]);
mat.SetInt("_SRCBLEND", (int)dict["_SRCBLEND"]);
mat.SetInt("_DSTBLEND", (int)dict["_DSTBLEND"]);
mat.SetInt("_ZWRITE", (int)dict["_ZWRITE"]);
}

private void Awake()
{
if (DefaultMaterial == null)
{
Debug.LogWarning(gameObject.name + " Tool has no active material.");
}
#if UNITY_EDITOR
else
{
// We don't want to change the material in the Editor, but a copy of it.
DefaultMaterial = new Material(DefaultMaterial);
CacheMaterialDefaultAttributes(ref defaultMaterialDefaults, DefaultMaterial);
}
#endif

if (HighlightMaterial == null)
{
Debug.LogWarning(gameObject.name + " Tool has no highlight material.");
}
#if UNITY_EDITOR
else
{
// We don't want to change the material in the Editor, but a copy of it.
HighlightMaterial = new Material(HighlightMaterial);
CacheMaterialDefaultAttributes(ref highlightMaterialDefaults, HighlightMaterial);
}
#endif

if (SelectedMaterial == null)
{
Debug.LogWarning(gameObject.name + " Tool has no selected material.");
}
#if UNITY_EDITOR
else
{
// We don't want to change the material in the Editor, but a copy of it.
SelectedMaterial = new Material(SelectedMaterial);
CacheMaterialDefaultAttributes(ref selectedMaterialDefaults, SelectedMaterial);
}
#endif

meshRenderer = GetComponentInChildren<MeshRenderer>();

Expand Down Expand Up @@ -134,6 +145,10 @@ private void OnDestroy()
PlayerInputManager.Instance.TapPressAction -= PlayEngagedSound;
PlayerInputManager.Instance.TapReleaseAction -= PlayDisengagedSound;
}

RestoreMaterialDefaultAttributes(ref defaultMaterialDefaults, DefaultMaterial);
RestoreMaterialDefaultAttributes(ref highlightMaterialDefaults, HighlightMaterial);
RestoreMaterialDefaultAttributes(ref selectedMaterialDefaults, SelectedMaterial);
}

public void Highlight()
Expand Down
29 changes: 16 additions & 13 deletions Assets/Scripts/MaterialsFader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ public class MaterialsFader : Fader

private MaterialSettings[] settings;

#if UNITY_EDITOR
private void Awake()
{
for (int i = 0; i < materials.Length; i++)
{
// We don't want to change the material in the Editor, but a copy of it.
materials[i] = new Material(materials[i]);
}
}
#endif

private void Start()
{
settings = new MaterialSettings[materials.Length];
Expand All @@ -45,9 +34,23 @@ private void OnDestroy()
// since the material is shared our settings will persist; loaded scenes should have full transition alpha
for (int materialIndex = 0; materialIndex < materials.Length; ++materialIndex)
{
if (materials[materialIndex] != null)
if (materials[materialIndex] != null && settings != null)
{
materials[materialIndex].SetFloat("_TransitionAlpha", 1.0f);
MaterialSettings matset = settings[materialIndex];
if (matset.material != null)
{
matset.material.SetFloat("_TransitionAlpha", 1.0f);

if (matset.originalSourceBlend != -1)
{
matset.material.SetInt("_SRCBLEND", matset.originalSourceBlend);
}

if (matset.originalDestinationBlend != -1)
{
matset.material.SetInt("_DSTBLEND", matset.originalDestinationBlend);
}
}
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions Assets/Scripts/Utilities/ScrollMaterialTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ public class ScrollMaterialTexture : MonoBehaviour
public string textureName;

private float currentOffset;
private Vector2 originalTextureOffset;

#if UNITY_EDITOR
private void Awake()
{
if (material)
{
// We don't want to change the material in the Editor, but a copy of it.
material = new Material(material);
originalTextureOffset = material.GetTextureOffset(textureName);
}
}
#endif

private void Update()
{
Expand All @@ -32,4 +30,12 @@ private void Update()
material.SetTextureOffset(textureName, new Vector2((currentOffset * direction.x) % 1.0f, (currentOffset * direction.y) % 1.0f));
}
}

private void OnDestroy()
{
if (material)
{
material.SetTextureOffset(textureName, originalTextureOffset);
}
}
}
17 changes: 13 additions & 4 deletions Assets/SolarSystem/Asteroids/AsteroidRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private struct InstanceData
}

public Material instancingMaterial;
private Vector3 originalLightPosition;

private MeshFilter meshFilter;

Expand Down Expand Up @@ -47,13 +48,13 @@ private struct InstanceData
// the size of the asteroid belt to fit appropriately in the solar system
public Vector3 defaultLocalScale = new Vector3(0.833f, 0.833f, 0.833f);

#if UNITY_EDITOR
private void Awake()
{
// We don't want to change the material in the Editor, but a copy of it.
instancingMaterial = TrueScaleSetting.Instance.AsteroidMaterial;
if (instancingMaterial != null)
{
originalLightPosition = instancingMaterial.GetVector("_LightPosition");
}
}
#endif

private void Start()
{
Expand Down Expand Up @@ -219,4 +220,12 @@ private void Update()
generated.transform.localRotation = Quaternion.AngleAxis(age * Mathf.Rad2Deg, Vector3.up);
}
}

private void OnDestroy()
{
if (instancingMaterial != null)
{
instancingMaterial.SetVector("_LightPosition", originalLightPosition);
}
}
}
Loading

0 comments on commit a6bd70d

Please sign in to comment.