-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from ToniMacaroni/development
Fix SettingsSetter error after soft reload
- Loading branch information
Showing
6 changed files
with
157 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Linq; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace SaberFactory.Helpers | ||
{ | ||
internal class ImmediateDrawer | ||
{ | ||
public bool IsInitialized { get; private set; } | ||
|
||
public ImmediateDrawer() | ||
{ | ||
var prim = GameObject.CreatePrimitive(PrimitiveType.Sphere); | ||
_ballmesh = prim.GetComponent<MeshFilter>().mesh; | ||
Object.Destroy(prim); | ||
|
||
var shader = FindShader(); | ||
if (!shader) | ||
{ | ||
return; | ||
} | ||
|
||
_mat = new Material(shader); | ||
IsInitialized = true; | ||
} | ||
|
||
public void DrawBall(Vector3 pos, float size, Color color) | ||
{ | ||
_mat.color = color; | ||
_mat.SetPass(0); | ||
Graphics.DrawMesh(_ballmesh, Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one * size), _mat, 0); | ||
} | ||
|
||
public void DrawSmallBall(Vector3 pos, Color? color = null) | ||
{ | ||
if(color == null) | ||
color = Color.red; | ||
DrawBall(pos, 0.05f, color.Value); | ||
} | ||
|
||
private Shader FindShader() | ||
{ | ||
var possibleShaders = new string[] | ||
{ | ||
"BeatSaber/Unlit Glow", | ||
"Standard", | ||
}; | ||
|
||
return Resources.FindObjectsOfTypeAll<Shader>().FirstOrDefault(x=> possibleShaders.Contains(x.name)); | ||
} | ||
|
||
private Mesh _ballmesh; | ||
private Material _mat; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.