-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneLayout.cs
99 lines (92 loc) · 3.56 KB
/
SceneLayout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Dynamic;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using VNENGINE;
using System.Linq;
using Unity.VisualScripting;
namespace PointClick
{
public class SceneLayout
{
public string name = string.Empty;
public string description = string.Empty;
private string label = string.Empty;
private string image = string.Empty;
private bool hasBack = false, hasLeft = false, hasRight = false, hasForward = false;
private List<List<int>> hotSpots;
private List<string> places;
private List<string> items;
public SceneLayout(string name, string description = "", string image = "", List<string> places = null, float[][] hotSpots = null)
{
this.name = name;
this.description = description;
this.image = image;
this.hasBack = false;
this.hasLeft = false;
this.hasRight = false;
this.hasForward = false;
if (places != null && hotSpots != null)
{
if (places.Count != hotSpots.Length)
throw new System.ArgumentException($"Error! places list length '{places.Count}' != hotspots array length '{hotSpots.Length}'");
}
for (var i = 0;i < places.Count; i++)
{
var place = places[i];
var hotspot = hotSpots[i];
//this.hotSpots.Add(place, hotspot);
}
}
public SceneLayout(Dictionary<string, object> data)
{
foreach (var item in data.Keys)
{
var prop = this.GetType().GetField(item, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (prop == null)
{
Debug.LogWarning($"Cannot find field {item}");
}
else
{
Type type = prop.FieldType;
//prop = new type();
/*if (type.IsGenericType)
{
object genProp = Activator.CreateInstance(type);
prop.SetValue(this, genProp);
Debug.Log($"Generic {prop.GetValue(this)}");
}
else*/
if (item == "places" || item == "items")
{
List<object> tmpobj = (List<object>)data[item];
List<string> tmpstr = tmpobj.Select(i => i.ToString()).ToList();
prop.SetValue(this, tmpstr);
}
else if (item == "hotSpots")
{
List<List<object>> tmpobj = (List<List<object>>)data[item];
List<List<int>> tmpspots = new();
foreach (var tmpspot in tmpobj)
{
List<int> tmp = tmpspot.Select(i => (int)i).ToList();
tmpspots.Add(tmp);
}
prop.SetValue(this, tmpspots);
}
else
prop.SetValue(this, data[item]);
}
}
if (name == string.Empty)
throw new System.ArgumentException($"Error! Place {data["label"]} does not contain 'name' field!");
}
public T GetInstance<T>(Type type)
{
return (T)Activator.CreateInstance(type);
}
}
}