Skip to content

Commit

Permalink
Default values for SavedAttributes of various components
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzchen committed Jul 27, 2023
1 parent a44beac commit e482f46
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions pyunity/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ class AudioSource(Component):

playOnStart = ShowInInspector(bool, False)
loop = ShowInInspector(bool, False)
clip = ShowInInspector(AudioClip)
clip = ShowInInspector(AudioClip, None)

def __init__(self):
super(AudioSource, self).__init__()
global channels
self.clip = None
self.channel = channels
channels += 1
if config.audio:
Expand Down
5 changes: 2 additions & 3 deletions pyunity/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ class SingleComponent(Component):
localPosition=ShowInInspector(Vector3, name="position"),
localRotation=ShowInInspector(Quaternion, name="rotation"),
localScale=ShowInInspector(Vector3, name="scale"),
parent=HideInInspector(addFields.selfref))
parent=HideInInspector(addFields.selfref, None))
class Transform(SingleComponent):
"""
Class to hold data about a GameObject's transformation.
Expand All @@ -677,7 +677,7 @@ class Transform(SingleComponent):
Scale of the Transform in local space.
parent : Transform or None
Parent of the Transform. The hierarchical tree is
actually formed by the Transform, not the GameObject.
formed by the Transform, not the GameObject.
Do not modify this attribute.
children : list
List of children
Expand All @@ -690,7 +690,6 @@ def __init__(self):
self._localRotation = Quaternion.identity()
self._localScale = Vector3.one()
self.hasChanged = False
self.parent = None
self.children = []
self.modelMatrix = None

Expand Down
12 changes: 5 additions & 7 deletions pyunity/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,12 @@ class RectTransform(SingleComponent):

anchors = ShowInInspector(RectAnchors)
offset = ShowInInspector(RectOffset)
pivot = ShowInInspector(Vector2)
pivot = ShowInInspector(Vector2, Vector2(0.5, 0.5))
rotation = ShowInInspector(float, 0)
def __init__(self):
super(RectTransform, self).__init__()
self.anchors = RectAnchors()
self.offset = RectOffset()
self.pivot = Vector2(0.5, 0.5)

@property
def parent(self):
Expand Down Expand Up @@ -338,14 +337,14 @@ class Image2D(GuiRenderComponent):
"""

texture = ShowInInspector(Texture2D)
texture = ShowInInspector(Texture2D, None)
depth = ShowInInspector(float, 0.0)
def __init__(self):
super(Image2D, self).__init__()
self.rectTransform = self.GetComponent(RectTransform)

class RenderTarget(GuiRenderComponent):
source = ShowInInspector(Camera)
source = ShowInInspector(Camera, None)
depth = ShowInInspector(float, 0.0)
canvas = ShowInInspector(bool, True, "Render Canvas")
flipY = 1
Expand Down Expand Up @@ -473,7 +472,7 @@ class Button(GuiComponent):
"""

callback = ShowInInspector(Event)
callback = ShowInInspector(Event, None)
state = ShowInInspector(KeyState, KeyState.UP)
mouseButton = ShowInInspector(MouseCode, MouseCode.Left)
pressed = ShowInInspector(bool, False)
Expand Down Expand Up @@ -766,15 +765,14 @@ class Text(GuiRenderComponent):

font = ShowInInspector(Font, FontLoader.LoadFont("Arial", 24))
text = ShowInInspector(str, "Text")
color = ShowInInspector(Color)
color = ShowInInspector(Color, RGB(255, 255, 255))
depth = ShowInInspector(float, 0.1)
centeredX = ShowInInspector(TextAlign, TextAlign.Left)
centeredY = ShowInInspector(TextAlign, TextAlign.Center)
def __init__(self):
super(Text, self).__init__()
self.rect = None
self.texture = None
self.color = RGB(255, 255, 255)

def PreRender(self):
if self.texture is None:
Expand Down
2 changes: 1 addition & 1 deletion pyunity/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class MeshRenderer(SingleComponent):

DefaultMaterial = Material(RGB(200, 200, 200))
DefaultMaterial.default = True
mesh = ShowInInspector(Mesh)
mesh = ShowInInspector(Mesh, None)
mat = ShowInInspector(Material, DefaultMaterial, "material")

def Render(self):
Expand Down
3 changes: 1 addition & 2 deletions pyunity/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class Camera(SingleComponent):

near = ShowInInspector(float, 0.05)
far = ShowInInspector(float, 200)
clearColor = ShowInInspector(Color)
clearColor = ShowInInspector(Color, RGB(0, 0, 0))
shader = ShowInInspector(Shader, shaders["Standard"])
skyboxEnabled = ShowInInspector(bool, True)
skybox = ShowInInspector(Skybox, skyboxes["Water"])
Expand All @@ -434,7 +434,6 @@ def __init__(self):
self.guiShader = shaders["GUI"]
self.skyboxShader = shaders["Skybox"]
self.depthShader = shaders["Depth"]
self.clearColor = RGB(0, 0, 0)
self.customProjMat = None

self.fov = 90
Expand Down

0 comments on commit e482f46

Please sign in to comment.