Example #1
0
        public static object InstantiateObject(PfObject pfobj, Type context_type = null)
        {
            var type = pfobj.Type.Resolve(context_type);
            var obj  = Activator.CreateInstance(type);

            FillInFields(obj, pfobj.Data, type);
            return(obj);
        }
Example #2
0
        public static void VerifyTransform(PfObject obj)
        {
            var type = obj.Type.Resolve();

            if (type != TransformType)
            {
                throw new Exception("The transform field must be a UnityEngine.Transform object");
            }
        }
Example #3
0
        public object TryMakeObject()
        {
            var a = ArrayType != null;
            var b = CollectionType != null;
            var c = ObjectType != null;
            var d = InsertID != null;

            if (a && b || a && c || a && d || b && c || b && d || c && d)
            {
                throw new InvalidOperationException("Inconsistent object type");
            }

            object obj = null;

            if (ArrayType != null)
            {
                obj = new PfArray(ArrayType, ArrayEntries);
            }
            else if (CollectionType != null)
            {
                obj = new PfCollection(CollectionType, CollectionElements);
            }
            else if (ObjectType != null)
            {
                obj = new PfObject(ObjectType, Data);
            }
            else if (InsertID != null)
            {
                obj = new PfInsert(InsertID, Data);
            }

            if (obj == null)
            {
                throw new InvalidOperationException("Unknown object type");
            }

            return(obj);
        }