public void     Aggregate(IncompleteGameObjectException ex)
 {
     if (ex.paths != null)
     {
         this.paths.AddRange(ex.paths);
         this.types.AddRange(ex.types);
         this.instanceIDs.AddRange(ex.instanceIDs);
         this.gameObjectInstanceIDs.AddRange(ex.gameObjectInstanceIDs);
         this.componentInstanceIDs.AddRange(ex.componentInstanceIDs);
         this.needGenerate.AddRange(ex.needGenerate);
     }
 }
Beispiel #2
0
        private object  ConvertValue(string path, Type type, object value)
        {
            ClientClass gc = value as ClientClass;

            if (gc != null)
            {
                IncompleteGameObjectException incompleteEx = null;
                object result = Activator.CreateInstance(type);

                for (int j = 0; j < gc.fields.Length; j++)
                {
                    FieldInfo subField = type.GetField(gc.fields[j].name);
                    InternalNGDebug.Assert(subField != null, "Field \"" + gc.fields[j].name + "\" was not found in type \"" + type + "\".");

                    if (subField.IsLiteral == true)
                    {
                        continue;
                    }

                    try
                    {
                        result = this.SetValue(path + "." + gc.fields[j].name, result, gc.fields[j].name, gc.fields[j].value);
                    }
                    catch (IncompleteGameObjectException ex)
                    {
                        if (incompleteEx == null)
                        {
                            incompleteEx = ex;
                        }
                        else
                        {
                            incompleteEx.Aggregate(ex);
                        }
                    }
                }

                if (incompleteEx != null)
                {
                    throw incompleteEx;
                }

                return(result);
            }

            ArrayData a = value as ArrayData;

            if (a != null)
            {
                if (a.array != null)
                {
                    if (type.IsArray == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        Type  subType = Utility.GetArraySubType(type);
                        Array result  = Array.CreateInstance(type, a.array.Length);

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                result.SetValue(this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j)), j);
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }

                        return(result);
                    }
                    else if (typeof(IList).IsAssignableFrom(type) == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        IList result  = Activator.CreateInstance(type) as IList;
                        Type  subType = Utility.GetArraySubType(type);

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                result.Add(this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j)));
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }

                        return(result);
                    }
                    else
                    {
                        throw new InvalidCastException("Type \"" + type + "\" is not supported as an array.");
                    }
                }

                return(null);
            }

            UnityObject uo = value as UnityObject;

            if (uo != null)
            {
                return(this.TryFetchFromProject(path, uo));
            }

            return(null);
        }
Beispiel #3
0
        public bool             CopyComponentToGameObjectAndClipboard(GameObject go)
        {
            GameObject newGO = null;

            if (go == null)
            {
                go = newGO = new GameObject();
            }

            try
            {
                IncompleteGameObjectException incompleteEx = null;
                Component c;

                go.GetComponents(this.type, ClientComponent.reuseComponents);

                int componentIndex = 0;

                if (newGO != null)
                {
                    c = go.AddComponent(this.type);
                }
                else
                {
                    for (int i = 0; i < this.parent.components.Count; i++)
                    {
                        if (this.parent.components[i].type == this.type)
                        {
                            if (this.parent.components[i] == this)
                            {
                                break;
                            }

                            ++componentIndex;
                        }
                    }

                    if (ClientComponent.reuseComponents.Count <= componentIndex)
                    {
                        c = go.AddComponent(this.type);
                    }
                    else
                    {
                        c = ClientComponent.reuseComponents[componentIndex];
                    }
                }

                for (int i = 0; i < this.fields.Length; i++)
                {
                    try
                    {
                        this.SetValue(c.GetType().FullName + "#" + componentIndex + "." + this.fields[i].name, c, this.fields[i].name, this.fields[i].value);
                    }
                    catch (IncompleteGameObjectException ex)
                    {
                        if (incompleteEx == null)
                        {
                            incompleteEx = ex;
                        }
                        else
                        {
                            incompleteEx.Aggregate(ex);
                        }
                    }
                }

                if (incompleteEx != null)
                {
                    throw incompleteEx;
                }

                if (ComponentUtility.CopyComponent(c) == false)
                {
                    Debug.LogError("Copy component failed.");
                }
                else
                {
                    return(true);
                }
            }
            catch (IncompleteGameObjectException)
            {
                throw;
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException("Copy component failed.", ex);
            }
            finally
            {
                if (newGO != null)
                {
                    GameObject.DestroyImmediate(newGO);
                }
            }

            return(false);
        }