Exemplo n.º 1
0
    // Use this for initialization
    void Awake()
    {
        //initialize objectmaker
        objectMaker = FindObjectOfType <ObjectMaker>();

        //mum get the camera
        mainCamera = Camera.main;

        //make the first room
        GenerateRoom(Vector3.zero, 0, 0, 0);

        //for testing only
        //objectMaker.MakeDetectorEnemy(new Vector3(20,0,0), 4);

        //set the current room to 1
        ReceivePlayerCurrentRoom(roomNumber - 1);

        //make the player
        //put him in the first room
        player      = (GameObject)Instantiate(playerPrefab, new Vector3(0, 1, 0), new Quaternion(0, 0, 0, 0));
        player.name = "Player";
        visited.Add(playerCurrentRoom);

        //i do not want to call this every frame, only every time a new room is entered
        PopulateGraph();
    }
Exemplo n.º 2
0
 void Start()
 {
     canvas_setting     = GameObject.Find("ModelSetting").GetComponent <Canvas> ();
     canvas_mode_change = GameObject.Find("ModeChange").GetComponent <Canvas> ();
     scroll_view        = GameObject.Find("ScrollView");
     obj_mkr            = GameObject.Find("ObjectMaker").GetComponent <ObjectMaker>();
 }
Exemplo n.º 3
0
    void VertexChoice()
    {
        Ray ray = cam.ScreenPointToRay(Input.mousePosition);

        if (Physics.SphereCast(ray, raySize, out hit))
        {
            Debug.Log(hit);
            string     objectName = hit.collider.gameObject.name;
            GameObject hitObj     = hit.collider.gameObject;
            objMaker = hitObj.GetComponent <ObjectMaker>();
            for (int i = 0; i < objMaker.vertextList.Count; i++)
            {
                if (Vector3.Distance(Input.mousePosition, cam.WorldToScreenPoint(objMaker.vertextList[i] + objMaker.transform.position)) < raySize * 100)
                {
                    //Debug.Log(cam.WorldToScreenPoint(objMaker.vertextList[i]));
                    choiceVertNum = i;
                    choiceVert    = true;
                }
            }
            if (choiceVert)
            {
                prePosVert = cam.WorldToScreenPoint(objMaker.vertextList[choiceVertNum]);
            }
        }
    }
Exemplo n.º 4
0
 void Start()
 {
     canvas_anchor_setting = GameObject.Find("AnchorSetting").GetComponent <Canvas> ();
     canvas_can_go_walk    = GameObject.Find("CanGoWalk").GetComponent <Canvas> ();
     obj_mkr         = GameObject.Find("ObjectMaker").GetComponent <ObjectMaker>();
     obj_mkr.obj_num = 1;
     obj_mkr.CreateObj(new Vector3(0f, 3f, 0f));
 }
Exemplo n.º 5
0
 public ObjectMakerCreationEventArgs(Type objectType, ObjectMaker maker)
 {
     ObjectType = objectType;
     Maker      = maker;
 }
Exemplo n.º 6
0
        private ObjectMaker MakeObjectMaker(Type objectType)
        {
            // Specific custom deserialization
            ObjectMaker customMaker = _TranslatorExtensions?.MakeObjectMaker(objectType);

            if (customMaker != null)
            {
                return(customMaker);
            }

            // String
            if (objectType == typeof(string))
            {
                return(json =>
                {
                    if (json.ObjectType == JsonObject.Type.Null)
                    {
                        return null;
                    }
                    else
                    {
                        return json.String;
                    }
                });
            }

            // Nullable types
            if (objectType.IsGenericType && objectType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                ObjectMaker subObjectMaker = MakeObjectMaker(objectType.GetGenericArguments()[0]);
                return(json =>
                {
                    if (json.ObjectType == JsonObject.Type.Null)
                    {
                        return null;
                    }
                    else
                    {
                        return subObjectMaker(json);
                    }
                });
            }

            // Enums
            if (objectType.IsEnum)
            {
                return(json =>
                {
                    if (json.ObjectType != JsonObject.Type.String)
                    {
                        throw new FormatException("Invalid JSON: Expected JSON String for .NET Enum type " + objectType.FullName + " but found instead " + json.ObjectType);
                    }
                    return Enum.Parse(objectType, json.String);
                });
            }

            // Simple types
            if (SIMPLE_TYPES.ContainsKey(objectType))
            {
                JsonObject.Type[] allowableTypes = SIMPLE_TYPES[objectType];
                return(json =>
                {
                    if (allowableTypes.Contains(json.ObjectType))
                    {
                        return JsonReflection.Cast(json.Value, objectType);
                    }
                    else
                    {
                        throw new FormatException("Invalid JSON: Expected JSON " + allowableTypes.Select(t => t.ToString()).Aggregate((a, b) => a + " or " + b) + " for .NET " + objectType.Name + "; instead found JSON " + json.ObjectType);
                    }
                });
            }

            // Explicit Dictionary
            JsonReflection.DictionaryInfo dinfo = JsonReflection.IsDictionary(objectType);
            if (dinfo != null)
            {
                Func <object>         dictConstructor = JsonReflection.GetDefaultMaker(objectType);
                Func <string, object> keyParser       = JsonReflection.GetParser(dinfo.KeyType);
                if (keyParser == null)
                {
                    throw new InvalidOperationException("Cannot create JsonMaker for type " + objectType.FullName + " because key type " + dinfo.KeyType.FullName + " cannot be parsed from a string");
                }
                ObjectMaker valueMaker = GetObjectMaker(dinfo.ValueType);
                MethodInfo  add        = objectType.GetMethod("Add", new Type[] { dinfo.KeyType, dinfo.ValueType });

                return(json =>
                {
                    if (json.ObjectType == JsonObject.Type.Null)
                    {
                        return null;
                    }
                    var result = dictConstructor();
                    foreach (var kvp in json.Dictionary)
                    {
                        add.Invoke(result, new object[] { keyParser(kvp.Key), valueMaker(kvp.Value) });
                    }
                    return result;
                });
            }

            // Enumerable types
            if (typeof(IEnumerable).IsAssignableFrom(objectType))
            {
                // Arrays
                if (typeof(Array).IsAssignableFrom(objectType))
                {
                    Type itemType = objectType.GetElementType();
                    return(json =>
                    {
                        if (json.ObjectType == JsonObject.Type.Null)
                        {
                            return null;
                        }
                        if (json.ObjectType != JsonObject.Type.Array)
                        {
                            throw new FormatException("Invalid JSON: Expected JSON Array for .NET type " + objectType.FullName + " but found instead " + json.ObjectType);
                        }
                        JsonObject[] jitems = json.Array;
                        Array result = (Array)Activator.CreateInstance(objectType, new object[] { jitems.Length });
                        ObjectMaker itemMaker = GetObjectMaker(itemType);
                        int i = 0;
                        foreach (JsonObject jitem in jitems)
                        {
                            result.SetValue(itemMaker(jitem), i);
                            i++;
                        }
                        return result;
                    });
                }

                // Other enumerable classes
                Func <object> enumConstructor = JsonReflection.GetDefaultMaker(objectType);
                if (enumConstructor == null)
                {
                    throw new InvalidOperationException("Cannot create JSON Array ObjectMaker for type " + objectType.FullName + " because it does not have a default constructor");
                }
                Type       contentType = JsonReflection.GetEnumerableType(objectType);
                MethodInfo addMethod   = objectType.GetMethod("Add", new Type[] { contentType });
                if (enumConstructor == null)
                {
                    throw new InvalidOperationException("Cannot create JSON Array ObjectMaker for type " + objectType.FullName + " because it does not have an Add method");
                }

                return(json =>
                {
                    if (json.ObjectType == JsonObject.Type.Null)
                    {
                        return null;
                    }
                    ObjectMaker itemMaker = GetObjectMaker(contentType);
                    object result = enumConstructor();
                    foreach (JsonObject jitem in json.Array)
                    {
                        addMethod.Invoke(result, new object[] { itemMaker(jitem) });
                    }
                    return result;
                });
            }

            // Parseable from string
            Func <string, object> parser = JsonReflection.GetParser(objectType);

            if (parser != null)
            {
                return(json =>
                {
                    if (json.ObjectType == JsonObject.Type.String || json.ObjectType == JsonObject.Type.Null)
                    {
                        return parser(json.String);
                    }
                    else
                    {
                        throw new FormatException("Invalid JSON: Expected parseable JSON String for .NET type " + objectType.FullName + "; instead found JSON " + json.ObjectType);
                    }
                });
            }

            // Object-as-Dictionary (choice of last resort)
            Func <object> ci = JsonReflection.GetDefaultMaker(objectType);

            if (ci == null)
            {
                throw new InvalidOperationException("Cannot create JSON Dictionary ObjectMaker for type " + objectType.FullName + " because a default object cannot be created");
            }

            var setters = new Dictionary <string, MemberSetter>();
            var types   = new Dictionary <string, Type>();

            FieldInfo[] fields = objectType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo fi in fields)
            {
                if (fi.GetCustomAttribute <JsonIgnoreAttribute>() != null)
                {
                    continue;
                }

                string name = AdjustedFieldName(fi.Name);

                types[name]   = fi.FieldType;
                setters[name] = (obj, value) => fi.SetValue(obj, value);
            }

            //PropertyInfo[] properties = objectType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            //foreach (PropertyInfo pi in properties)
            //{
            //    if (pi.GetCustomAttribute<JsonIgnoreAttribute>() != null)
            //        continue;

            //    throw new NotImplementedException("Property serialization not yet supported");
            //}

            return(json =>
            {
                if (json.ObjectType != JsonObject.Type.Dictionary)
                {
                    throw new FormatException("Invalid JSON: Expected JSON Dictionary for .NET type " + objectType.FullName + "; instead found JSON " + json.ObjectType);
                }
                object result = ci();
                Dictionary <string, JsonObject> jfields = json.Dictionary;
                foreach (var kvp in jfields)
                {
                    if (!setters.ContainsKey(kvp.Key))
                    {
                        throw new FormatException("No field named '" + kvp.Key + "' found in .NET type " + objectType.FullName);
                    }
                    ObjectMaker maker = GetObjectMaker(types[kvp.Key]);
                    setters[kvp.Key](result, maker(kvp.Value));
                }
                return result;
            });
        }
Exemplo n.º 7
0
 void Start()
 {
     obj_mkr  = GameObject.Find("ObjectMaker").GetComponent <ObjectMaker>();
     animator = GetComponent <Animator> ();
 }
Exemplo n.º 8
0
 void Start()
 {
     obj_mkr = GameObject.Find("ObjectMaker").GetComponent <ObjectMaker> ();
     select  = GameObject.Find("ObjectMaker").GetComponent <ObjectSelector> ();
 }