Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class DotGridProperties : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private MaterialPropertyBlockEditor _materialPropertyBlockEditor;
|
||||
|
||||
[SerializeField]
|
||||
private int _columns;
|
||||
|
||||
[SerializeField]
|
||||
private int _rows;
|
||||
|
||||
[SerializeField]
|
||||
private float _radius;
|
||||
|
||||
[SerializeField]
|
||||
private Color _color;
|
||||
|
||||
public int Columns
|
||||
{
|
||||
get
|
||||
{
|
||||
return _columns;
|
||||
}
|
||||
set
|
||||
{
|
||||
_columns = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Rows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _rows;
|
||||
}
|
||||
set
|
||||
{
|
||||
_rows = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Radius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radius;
|
||||
}
|
||||
set
|
||||
{
|
||||
_radius = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
set
|
||||
{
|
||||
_color = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _change = false;
|
||||
private readonly int _colorShaderID = Shader.PropertyToID("_Color");
|
||||
private readonly int _dimensionsShaderID = Shader.PropertyToID("_Dimensions");
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.AssertField(_materialPropertyBlockEditor, nameof(_materialPropertyBlockEditor));
|
||||
_change = true;
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (!_change || _materialPropertyBlockEditor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MaterialPropertyBlock block = _materialPropertyBlockEditor.MaterialPropertyBlock;
|
||||
block.SetColor(_colorShaderID, _color);
|
||||
block.SetVector(_dimensionsShaderID, new Vector4((float)_columns, (float)_rows, _radius, 0));
|
||||
_materialPropertyBlockEditor.UpdateMaterialPropertyBlock();
|
||||
|
||||
_change = false;
|
||||
}
|
||||
|
||||
protected virtual void OnValidate()
|
||||
{
|
||||
_change = true;
|
||||
}
|
||||
|
||||
#region Inject
|
||||
|
||||
public void InjectAllDotGridProperties(MaterialPropertyBlockEditor editor)
|
||||
{
|
||||
InjectMaterialPropertyBlockEditor(editor);
|
||||
}
|
||||
|
||||
public void InjectMaterialPropertyBlockEditor(MaterialPropertyBlockEditor editor)
|
||||
{
|
||||
_materialPropertyBlockEditor = editor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e88dc9128cf44114596fb50087e9ee4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
[Serializable]
|
||||
public struct MaterialPropertyVector
|
||||
{
|
||||
public string name;
|
||||
public Vector4 value;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct MaterialPropertyColor
|
||||
{
|
||||
public string name;
|
||||
[ColorUsage(showAlpha: true, hdr: true)]
|
||||
public Color value;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct MaterialPropertyFloat
|
||||
{
|
||||
public string name;
|
||||
public float value;
|
||||
}
|
||||
|
||||
[ExecuteAlways]
|
||||
public class MaterialPropertyBlockEditor : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private List<Renderer> _renderers;
|
||||
|
||||
[SerializeField]
|
||||
private List<MaterialPropertyVector> _vectorProperties;
|
||||
|
||||
[SerializeField]
|
||||
private List<MaterialPropertyColor> _colorProperties;
|
||||
|
||||
[SerializeField]
|
||||
private List<MaterialPropertyFloat> _floatProperties;
|
||||
|
||||
[SerializeField]
|
||||
private bool _updateEveryFrame = true;
|
||||
|
||||
public List<Renderer> Renderers
|
||||
{
|
||||
get
|
||||
{
|
||||
return _renderers;
|
||||
}
|
||||
set
|
||||
{
|
||||
_renderers = value;
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaterialPropertyVector> VectorProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
return _vectorProperties;
|
||||
}
|
||||
set
|
||||
{
|
||||
_vectorProperties = value;
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaterialPropertyColor> ColorProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorProperties;
|
||||
}
|
||||
set
|
||||
{
|
||||
_colorProperties = value;
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaterialPropertyFloat> FloatProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
return _floatProperties;
|
||||
}
|
||||
set
|
||||
{
|
||||
_floatProperties = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialPropertyBlock MaterialPropertyBlock
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_materialPropertyBlock == null)
|
||||
{
|
||||
_materialPropertyBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
return _materialPropertyBlock;
|
||||
}
|
||||
}
|
||||
|
||||
private MaterialPropertyBlock _materialPropertyBlock = null;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (_renderers == null)
|
||||
{
|
||||
Renderer renderer = GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
_renderers = new List<Renderer>()
|
||||
{
|
||||
renderer
|
||||
};
|
||||
}
|
||||
}
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
public void UpdateMaterialPropertyBlock()
|
||||
{
|
||||
var materialPropertyBlock = MaterialPropertyBlock;
|
||||
|
||||
if (_vectorProperties != null)
|
||||
{
|
||||
foreach (var property in _vectorProperties)
|
||||
{
|
||||
_materialPropertyBlock.SetVector(property.name, property.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (_colorProperties != null)
|
||||
{
|
||||
foreach (var property in _colorProperties)
|
||||
{
|
||||
_materialPropertyBlock.SetColor(property.name, property.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (_floatProperties != null)
|
||||
{
|
||||
foreach (var property in _floatProperties)
|
||||
{
|
||||
_materialPropertyBlock.SetFloat(property.name, property.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (_renderers != null)
|
||||
{
|
||||
foreach (Renderer renderer in _renderers)
|
||||
{
|
||||
renderer.SetPropertyBlock(materialPropertyBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (_updateEveryFrame)
|
||||
{
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5e48d93b64a9ae4f9fd5a728c8f51af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the Oculus SDK License Agreement (the "License");
|
||||
* you may not use the Oculus SDK except in compliance with the License,
|
||||
* which is provided at the time of installation or download, or which
|
||||
* otherwise accompanies this software in either electronic or hard copy form.
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://developer.oculus.com/licenses/oculussdk/
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, the Oculus SDK
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Oculus.Interaction
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class RoundedBoxProperties : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private MaterialPropertyBlockEditor _editor;
|
||||
|
||||
[SerializeField]
|
||||
private float _width = 1.0f;
|
||||
|
||||
[SerializeField]
|
||||
private float _height = 1.0f;
|
||||
|
||||
[SerializeField]
|
||||
private Color _color = Color.white;
|
||||
|
||||
[SerializeField]
|
||||
private Color _borderColor = Color.black;
|
||||
|
||||
[SerializeField]
|
||||
private float _radiusTopLeft;
|
||||
|
||||
[SerializeField]
|
||||
private float _radiusTopRight;
|
||||
|
||||
[SerializeField]
|
||||
private float _radiusBottomLeft;
|
||||
|
||||
[SerializeField]
|
||||
private float _radiusBottomRight;
|
||||
|
||||
[SerializeField]
|
||||
private float _borderInnerRadius;
|
||||
|
||||
[SerializeField]
|
||||
private float _borderOuterRadius;
|
||||
|
||||
#region Properties
|
||||
|
||||
public float Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
set
|
||||
{
|
||||
_width = value;
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
|
||||
public float Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
set
|
||||
{
|
||||
_height = value;
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
set
|
||||
{
|
||||
_color = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Color BorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _borderColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
_borderColor = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float RadiusTopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radiusTopLeft;
|
||||
}
|
||||
set
|
||||
{
|
||||
_radiusTopLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float RadiusTopRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radiusTopRight;
|
||||
}
|
||||
set
|
||||
{
|
||||
_radiusTopRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float RadiusBottomLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radiusBottomLeft;
|
||||
}
|
||||
set
|
||||
{
|
||||
_radiusBottomLeft = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float RadiusBottomRight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _radiusBottomRight;
|
||||
}
|
||||
set
|
||||
{
|
||||
_radiusBottomRight = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderInnerRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _borderInnerRadius;
|
||||
}
|
||||
set
|
||||
{
|
||||
_borderInnerRadius = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float BorderOuterRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _borderOuterRadius;
|
||||
}
|
||||
set
|
||||
{
|
||||
_borderOuterRadius = value;
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly int _colorShaderID = Shader.PropertyToID("_Color");
|
||||
private readonly int _borderColorShaderID = Shader.PropertyToID("_BorderColor");
|
||||
private readonly int _radiiShaderID = Shader.PropertyToID("_Radii");
|
||||
private readonly int _dimensionsShaderID = Shader.PropertyToID("_Dimensions");
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
UpdateSize();
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
this.AssertField(_editor, nameof(_editor));
|
||||
UpdateSize();
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
private void UpdateSize()
|
||||
{
|
||||
transform.localScale = new Vector3(_width + _borderOuterRadius * 2,
|
||||
_height + _borderOuterRadius * 2,
|
||||
1.0f);
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
private void UpdateMaterialPropertyBlock()
|
||||
{
|
||||
if (_editor == null)
|
||||
{
|
||||
_editor = GetComponent<MaterialPropertyBlockEditor>();
|
||||
if (_editor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MaterialPropertyBlock block = _editor.MaterialPropertyBlock;
|
||||
|
||||
block.SetColor(_colorShaderID, _color);
|
||||
block.SetColor(_borderColorShaderID, _borderColor);
|
||||
block.SetVector(_radiiShaderID,
|
||||
new Vector4(
|
||||
_radiusTopRight,
|
||||
_radiusBottomRight,
|
||||
_radiusTopLeft,
|
||||
_radiusBottomLeft
|
||||
));
|
||||
block.SetVector(_dimensionsShaderID,
|
||||
new Vector4(
|
||||
transform.localScale.x,
|
||||
transform.localScale.y,
|
||||
_borderInnerRadius,
|
||||
_borderOuterRadius
|
||||
));
|
||||
|
||||
_editor.UpdateMaterialPropertyBlock();
|
||||
}
|
||||
|
||||
protected virtual void OnValidate()
|
||||
{
|
||||
UpdateSize();
|
||||
UpdateMaterialPropertyBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a0ad4ecf30771d44bf163058922924b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user