Skip to content

Commit d05de90

Browse files
committed
fix: base of the viewcreator finished
1 parent e29dab2 commit d05de90

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

Editor/ViewCreatorEditor.cs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
using System.Collections.Generic;
33
using UnityEditor;
44
using UnityEngine;
5-
5+
using UnityEngine.UI;
6+
using BigasTools.UI;
67

78
namespace BigasTools.Editor{
89
public class CreateViewEditor : EditorWindow
@@ -29,16 +30,43 @@ void OnGUI()
2930
OnComponentAdd();
3031
}
3132
foreach (var item in components)
32-
{
33-
string name = "";
34-
bool isModal = false;
35-
Object sprite = null;
36-
37-
name = EditorGUILayout.TextField("Child Name", name);
38-
isModal = EditorGUILayout.Toggle("Is Modal Object", isModal);
39-
sprite = EditorGUILayout.ObjectField("Sprite", sprite, typeof(Sprite), true);
33+
{
34+
item.name = EditorGUILayout.TextField("Child Name", item.name);
35+
item.isModal = EditorGUILayout.Toggle("Is Modal Object", item.isModal);
36+
item.sprite = EditorGUILayout.ObjectField("Sprite", item.sprite, typeof(Sprite), true);
4037
if(GUILayout.Button("Remove component")){
41-
components.Remove(item);
38+
try
39+
{
40+
components.Remove(item);
41+
}
42+
catch (System.Exception)
43+
{
44+
45+
}
46+
}
47+
}
48+
if(GUILayout.Button("Create View")){
49+
var obj = new GameObject();
50+
51+
obj.AddComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
52+
obj.AddComponent<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
53+
obj.GetComponent<CanvasScaler>().referenceResolution = new Vector2(1920,1080);
54+
obj.GetComponent<CanvasScaler>().screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
55+
obj.AddComponent<GraphicRaycaster>();
56+
obj.name = viewName;
57+
58+
if(hasModal)obj.AddComponent<ModalHandler>();
59+
60+
foreach (var item in components)
61+
{
62+
var o = new GameObject();
63+
64+
o.name = item.name;
65+
if(item.isModal)o.AddComponent<ModalObject>();
66+
if(item.sprite!=null){
67+
o.AddComponent<Image>().sprite = item.sprite as Sprite;
68+
}
69+
o.transform.SetParent(obj.transform);
4270
}
4371
}
4472
}
@@ -49,6 +77,8 @@ void OnComponentAdd(){
4977
}
5078
[System.Serializable]
5179
public class CreateViewObject{
52-
80+
public string name;
81+
public bool isModal;
82+
public Object sprite;
5383
}
5484
}

Runtime/UI/ModalHandler.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ public void InteractAny(int index){
8383
modals[index].OnInteract();
8484
}
8585
public void DeselectAll(){
86-
foreach(var m in modals){
87-
m.OnDeselect();
86+
try
87+
{
88+
foreach(var m in modals){
89+
m.OnDeselect();
90+
}
91+
}
92+
catch (System.Exception)
93+
{
94+
8895
}
8996
}
9097
}

0 commit comments

Comments
 (0)