Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

9 changes: 0 additions & 9 deletions AssemblyInfo.cs

This file was deleted.

File renamed without changes.
114 changes: 92 additions & 22 deletions Scripts/Editor/AutoLOD.cs → Editor/AutoLOD.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#if UNITY_2018_1_OR_NEWER
#if UNITY_2018_4_OR_NEWER
#define HAS_MINIMUM_REQUIRED_VERSION
#endif

#if UNITY_2018_3_OR_NEWER
#pragma warning disable 0618 // TODO: Remove this when minimum version is 2018.3
#endif

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Unity.AutoLOD.Utilities;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine;
using UnityObject = UnityEngine.Object;

Expand All @@ -21,13 +19,14 @@ namespace Unity.AutoLOD
[InitializeOnLoad]
class AutoLOD
{
const string k_MinimumRequiredVersion = "AutoLOD requires Unity 2018.1 or a later version";
const string k_MinimumRequiredVersion = "AutoLOD requires Unity 2018.4 or a later version";

const HideFlags k_DefaultHideFlags = HideFlags.None;
const string k_MaxExecutionTime = "AutoLOD.MaxExecutionTime";
const int k_DefaultMaxExecutionTime = 8;
const string k_DefaultMeshSimplifier = "AutoLOD.DefaultMeshSimplifier";
const string k_DefaultMeshSimplifierDefault = "QuadricMeshSimplifier";
const string k_DefaultMeshSimplifierDefine = "ENABLE_UNITYMESHSIMPLIFIER";
const string k_DefaultBatcher = "AutoLOD.DefaultBatcher";
const string k_MaxLOD = "AutoLOD.MaxLOD";
const int k_DefaultMaxLOD = 2;
Expand Down Expand Up @@ -175,12 +174,91 @@ static List<Type> batchers
static List<Type> s_Batchers;
static IPreferences s_SimplifierPreferences;

#if HAS_MINIMUM_REQUIRED_VERSION
static IEnumerator GetDefaultSimplifier()
{
var list = Client.List(true);
while (!list.IsCompleted)
yield return null;

PackageStatus status = PackageStatus.Unknown;
if (list.Status == StatusCode.Success)
{
foreach (var package in list.Result)
{
if (package.name == "com.whinarn.unitymeshsimplifier")
{
status = package.status;
break;
}
}
}

if (status != PackageStatus.Available
&& EditorUtility.DisplayDialog("Install Default Mesh Simplifier?",
"You are missing a default mesh simplifier. Would you like to install one?",
"Yes", "No"))
{
var request = Client.Add("https://github.com/Unity-Technologies/UnityMeshSimplifier.git");
while (!request.IsCompleted)
yield return null;

switch (request.Status)
{
case StatusCode.Success:
status = PackageStatus.Available;
break;
case StatusCode.InProgress:
status = PackageStatus.InProgress;
break;
case StatusCode.Failure:
Debug.LogError($"AutoLOD: {request.Error.message}");
break;
}
}

if (status == PackageStatus.Available)
{
// Cribbed from ConditionalCompilationUtility
// TODO: Remove when minimum version is 2019 LTS and use define constraints instead
var buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
if (buildTargetGroup == BuildTargetGroup.Unknown)
{
var propertyInfo = typeof(EditorUserBuildSettings).GetProperty("activeBuildTargetGroup",
BindingFlags.Static | BindingFlags.NonPublic);
if (propertyInfo != null)
buildTargetGroup = (BuildTargetGroup)propertyInfo.GetValue(null, null);
}

var previousProjectDefines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup);
var projectDefines = previousProjectDefines.Split(';').ToList();
if (!projectDefines.Contains(k_DefaultMeshSimplifierDefine, StringComparer.OrdinalIgnoreCase))
{
EditorApplication.LockReloadAssemblies();

projectDefines.Add(k_DefaultMeshSimplifierDefine);

// This will trigger another re-compile, which needs to happen, so all the custom attributes will be visible
PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Join(";", projectDefines.ToArray()));

// Let other systems execute before reloading assemblies
yield return null;
EditorApplication.UnlockReloadAssemblies();
}
}
else if (status != PackageStatus.InProgress)
{
Debug.LogError("AutoLOD: You must set a valid Default Mesh Simplifier under Edit -> Preferences");
}
}
#endif

static void UpdateDependencies()
{
#if HAS_MINIMUM_REQUIRED_VERSION
if (meshSimplifierType == null)
{
Debug.LogError("AutoLOD: You must set a valid Default Mesh Simplifier under Edit -> Preferences");
MonoBehaviourHelper.StartCoroutine(GetDefaultSimplifier());
ModelImporterLODGenerator.enabled = false;
return;
}
Expand Down Expand Up @@ -343,8 +421,8 @@ static void ForceGenerateLOD()
var selection = Selection.activeGameObject;
if (selection)
{
var prefabType = PrefabUtility.GetPrefabType(selection);
if (prefabType == PrefabType.ModelPrefab)
var prefabType = PrefabUtility.GetPrefabAssetType(selection);
if (prefabType == PrefabAssetType.Model)
{
var assetPath = AssetDatabase.GetAssetPath(selection);

Expand All @@ -361,7 +439,7 @@ static void ForceGenerateLOD()

AssetDatabase.ImportAsset(assetPath);
}
else if (prefabType == PrefabType.Prefab)
else if (prefabType == PrefabAssetType.Regular)
{
GenerateLODs(new MenuCommand(null));
}
Expand All @@ -372,8 +450,8 @@ static void ForceGenerateLOD()
static bool CanForceGenerateLOD()
{
var selection = Selection.activeGameObject;
var prefabType = selection ? PrefabUtility.GetPrefabType(selection) : PrefabType.None;
return selection && prefabType == PrefabType.ModelPrefab || prefabType == PrefabType.Prefab;
var prefabType = selection ? PrefabUtility.GetPrefabAssetType(selection) : PrefabAssetType.NotAPrefab;
return selection && prefabType == PrefabAssetType.Model || prefabType == PrefabAssetType.Regular;
}


Expand Down Expand Up @@ -449,11 +527,11 @@ static void IterateOverSelectedGameObjects(Action<GameObject> callback)
if (EditorUtility.DisplayCancelableProgressBar("Prefabs", selection.name, i / (float)count))
break;

if (selection && PrefabUtility.GetPrefabType(selection) == PrefabType.Prefab)
if (selection && PrefabUtility.GetPrefabAssetType(selection) == PrefabAssetType.Regular)
{
var go = (GameObject)PrefabUtility.InstantiatePrefab(selection);
callback(go);
PrefabUtility.ReplacePrefab(go, selection);
PrefabUtility.SaveAsPrefabAsset(go, AssetDatabase.GetAssetPath(selection));
UnityObject.DestroyImmediate(go);
}
else
Expand Down Expand Up @@ -550,11 +628,7 @@ static void GenerateLODs(GameObject go)
lodGroup.RecalculateBounds();
lodGroup.ForceLOD(-1);

#if UNITY_2018_2_OR_NEWER
var prefab = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
var prefab = PrefabUtility.GetPrefabParent(go);
#endif
if (prefab)
{
var lodsAssetPath = GetLODAssetPath(prefab);
Expand Down Expand Up @@ -601,11 +675,7 @@ static void RemoveLODs(GameObject go)
UnityObject.DestroyImmediate(mf.gameObject);
}

#if UNITY_2018_2_OR_NEWER
var prefab = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
var prefab = PrefabUtility.GetPrefabParent(go);
#endif
if (prefab)
{
var lodAssetPath = GetLODAssetPath(prefab);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ public IEnumerator Batch(GameObject go)
}

var combinedMesh = new Mesh();
#if UNITY_2017_3_OR_NEWER
combinedMesh.indexFormat = IndexFormat.UInt32;
#endif
combinedMesh.CombineMeshes(combine.ToArray(), true, true);
combinedMesh.RecalculateBounds();
var meshFilter = go.AddComponent<MeshFilter>();
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ IEnumerator Start()
ProfilerDriver.ClearAllFrames();

// Skip first frame stutter
#if UNITY_2017_3_OR_NEWER
ProfilerDriver.enabled = false;
#endif
yield return null;
#if UNITY_2017_3_OR_NEWER
ProfilerDriver.enabled = true;
#endif

if (showProfilerWindow)
{
Expand All @@ -35,9 +31,7 @@ IEnumerator Start()
while (playableDirector.playableGraph.IsValid() && playableDirector.playableGraph.IsPlaying())
yield return null;

#if UNITY_2017_3_OR_NEWER
ProfilerDriver.enabled = false;
#endif
EditorApplication.isPlaying = false;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
using UnityObject = UnityEngine.Object;
#endif

#if UNITY_2017_3_OR_NEWER
[assembly: Unity.AutoLOD.OptionalDependency("InstaLOD.InstaLODNative", "ENABLE_INSTALOD")]
#endif

#if ENABLE_INSTALOD
namespace Unity.AutoLOD
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
using WMesh = Unity.AutoLOD.WorkingMesh;
#endif

#if UNITY_2017_3_OR_NEWER
[assembly: Unity.AutoLOD.OptionalDependency("MeshDecimator.MeshDecimation", "ENABLE_MESHDECIMATOR")]
#endif

#if ENABLE_MESHDECIMATOR
namespace Unity.AutoLOD
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
using Mesh = Unity.AutoLOD.WorkingMesh;
#endif

#if UNITY_2017_3_OR_NEWER
[assembly: Unity.AutoLOD.OptionalDependency("UnityMeshSimplifier.MeshSimplifier", "ENABLE_UNITYMESHSIMPLIFIER")]
#endif

#if ENABLE_UNITYMESHSIMPLIFIER
namespace Unity.AutoLOD
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
using UnityObject = UnityEngine.Object;
#endif

#if UNITY_2017_3_OR_NEWER
[assembly: Unity.AutoLOD.OptionalDependency("Simplygon.Unity.EditorPlugin.Window", "ENABLE_SIMPLYGON")]
#endif

#if ENABLE_SIMPLYGON
namespace Unity.AutoLOD
{
Expand Down
10 changes: 0 additions & 10 deletions Scripts/Editor/SceneLOD.cs → Editor/SceneLOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ static void SaveUniqueHLODAsset(UnityObject asset, string scenePath)

void OnEnable()
{
#if UNITY_2017_3_OR_NEWER
if (LayerMask.NameToLayer(LODVolume.HLODLayer) == -1)
{
var layers = TagManager.GetRequiredLayers();
Expand All @@ -128,7 +127,6 @@ void OnEnable()
AddCallbacks();

ResetServiceCoroutineQueue();
#endif
}

void OnDisable()
Expand All @@ -140,11 +138,7 @@ void OnDisable()
void AddCallbacks()
{
EditorApplication.update += EditorUpdate;
#if UNITY_2018_1_OR_NEWER
EditorApplication.hierarchyChanged += OnHierarchyChanged;
#else
EditorApplication.hierarchyWindowChanged += OnHierarchyChanged;
#endif
Selection.selectionChanged += OnSelectionChanged;
Camera.onPreCull += PreCull;
#if UNITY_2019_1_OR_NEWER
Expand All @@ -157,11 +151,7 @@ void AddCallbacks()
void RemoveCallbacks()
{
EditorApplication.update -= EditorUpdate;
#if UNITY_2018_1_OR_NEWER
EditorApplication.hierarchyChanged -= OnHierarchyChanged;
#else
EditorApplication.hierarchyWindowChanged -= OnHierarchyChanged;
#endif
Selection.selectionChanged -= OnSelectionChanged;
Camera.onPreCull -= PreCull;
#if UNITY_2019_1_OR_NEWER
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "AutoLOD-Editor",
"name": "Unity.AutoLOD.Editor",
"references": [
"AutoLOD",
"Unity.AutoLOD",
"Whinarn.UnityMeshSimplifier.Runtime"
],
"optionalUnityReferences": [],
Expand All @@ -13,6 +13,5 @@
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"defineConstraints": []
}
10 changes: 0 additions & 10 deletions Packages.meta

This file was deleted.

1 change: 0 additions & 1 deletion Packages/CCU
Submodule CCU deleted from f36409
1 change: 0 additions & 1 deletion Packages/UnityMeshSimplifier
Submodule UnityMeshSimplifier deleted from d856c3
10 changes: 0 additions & 10 deletions Packages/UnityMeshSimplifier.meta

This file was deleted.

Loading