Example #1
0
        private PrefabField     FetchUnityObjectReferences(NGRemoteHierarchyWindow hierarchy, List <AssetImportParameters> globalRefs, PrefabConstruct prefab, string name, object value)
        {
            UnityObject uo = value as UnityObject;

            if (uo != null)
            {
                if (uo.instanceID == 0)
                {
                    return(null);
                }

                AssetImportParameters importParameters = null;

                // AssetImportParameters must be known in 3 places to be reused: global, prefab & fields.
                for (int i = 0; i < prefab.importParameters.Count; i++)
                {
                    if (prefab.importParameters[i].instanceID == uo.instanceID)
                    {
                        importParameters = prefab.importParameters[i];
                        break;
                    }
                }

                if (importParameters == null)
                {
                    for (int i = 0; i < globalRefs.Count; i++)
                    {
                        if (globalRefs[i].instanceID == uo.instanceID)
                        {
                            importParameters = globalRefs[i];
                            break;
                        }
                    }

                    if (importParameters != null)
                    {
                        prefab.importParameters.Add(importParameters);
                    }
                }

                if (importParameters == null)
                {
                    Debug.Log("C");
                    importParameters = new AssetImportParameters(hierarchy, name, uo.type, this.component.parent.instanceID, this.component.instanceID, uo.instanceID, RemoteUtility.GetImportAssetTypeSupported(uo.type) != null, null)
                    {
                        prefabPath = Path.GetDirectoryName(prefab.path)
                    };
                    prefab.importParameters.Add(importParameters);
                    globalRefs.Add(importParameters);
                }
                else
                {
                    importParameters.originPath.Add(new AssetImportParameters.MyClass()
                    {
                        gameObjectInstanceID = this.component.parent.instanceID, componentInstanceID = this.component.instanceID, path = name
                    });
                }

                return(new PrefabField(name, importParameters));
            }

            ClientClass gc = value as ClientClass;

            if (gc != null)
            {
                PrefabField field = null;

                for (int j = 0; j < gc.fields.Length; j++)
                {
                    PrefabField child = this.FetchUnityObjectReferences(hierarchy, globalRefs, prefab, gc.fields[j].name, gc.fields[j].value);

                    if (child != null)
                    {
                        if (field == null)
                        {
                            field = new PrefabField(name);
                        }
                        field.AddChild(child);
                    }
                }

                return(field);
            }

            ArrayData a = value as ArrayData;

            if (a != null && a.array != null)
            {
                PrefabField field = null;

                for (int j = 0; j < a.array.Length; j++)
                {
                    PrefabField child = this.FetchUnityObjectReferences(hierarchy, globalRefs, prefab, j.ToCachedString(), a.array.GetValue(j));

                    if (child != null)
                    {
                        if (field == null)
                        {
                            field = new PrefabField(name);
                        }
                        field.AddChild(child);
                    }
                }

                return(field);
            }

            return(null);
        }
Example #2
0
        public PrefabComponent(NGRemoteHierarchyWindow hierarchy, List <AssetImportParameters> existingRefs, PrefabConstruct prefab, ClientComponent component)
        {
            this.component = component;

            for (int i = 0; i < this.component.fields.Length; i++)
            {
                PrefabField field = this.FetchUnityObjectReferences(hierarchy, existingRefs, prefab, this.component.fields[i].name, this.component.fields[i].value);

                if (field != null)
                {
                    field.UpdateIsSupported();
                    if (field.isSupported == true)
                    {
                        this.hasImportableAssets = true;
                    }

                    PrefabComponent.pool.Add(field);
                }
            }

            if (PrefabComponent.pool.Count > 0)
            {
                this.fields = PrefabComponent.pool.ToArray();
                PrefabComponent.pool.Clear();
            }
        }
Example #3
0
        public bool     VerifyComponentsReady(NGRemoteHierarchyWindow hierarchy, List <AssetImportParameters> globalRefs, PrefabConstruct prefab, Client client)
        {
            bool verified = true;

            if (this.gameObject.components == null)
            {
                this.gameObject.RequestComponents(client, go =>
                {
                    this.ConstructComponents(hierarchy, globalRefs, prefab);
                    Utility.RepaintEditorWindow(typeof(NGRemoteWindow));
                });

                verified = false;
            }
            else if (this.components == null)
            {
                this.ConstructComponents(hierarchy, globalRefs, prefab);
            }

            for (int i = 0; i < this.children.Length; i++)
            {
                if (this.children[i].VerifyComponentsReady(hierarchy, globalRefs, prefab, client) == false)
                {
                    verified = false;
                }
            }

            return(verified);
        }
Example #4
0
        private void    ConstructComponents(NGRemoteHierarchyWindow hierarchy, List <AssetImportParameters> globalRefs, PrefabConstruct prefab)
        {
            for (int i = 0; i < this.gameObject.components.Count; i++)
            {
                PrefabComponent component = new PrefabComponent(hierarchy, globalRefs, prefab, this.gameObject.components[i]);

                if (component.fields != null)
                {
                    PrefabGameObject.pool.Add(component);
                }
            }

            this.components = PrefabGameObject.pool.ToArray();
            PrefabGameObject.pool.Clear();
        }
Example #5
0
        private void    DrawPrefabs()
        {
            EditorGUILayout.BeginHorizontal();
            {
                for (int i = 0; i < this.Hierarchy.PendingPrefabs.Count; i++)
                {
                    EditorGUI.BeginChangeCheck();
                    NGEditorGUILayout.OutlineToggle(this.Hierarchy.PendingPrefabs[i].rootGameObject.gameObject.name, this.selectedPrefab == i);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.selectedPrefab = i;
                    }
                }

                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndHorizontal();

            if (this.selectedPrefab < this.Hierarchy.PendingPrefabs.Count)
            {
                PrefabConstruct prefab = this.Hierarchy.PendingPrefabs[this.selectedPrefab];

                GUILayout.Space(10F + 32F);

                Rect r = GUILayoutUtility.GetLastRect();

                r.xMin += 20F;
                r.width = 150F;
                if (GUI.Button(r, prefab.rootGameObject.gameObject.name) == true)
                {
                    this.Hierarchy.PingObject(prefab.rootGameObject.gameObject.instanceID);
                }

                r.x += r.width + 10F;

                if (prefab.constructionError != null)
                {
                    EditorGUI.HelpBox(r, prefab.constructionError, MessageType.Error);
                }
                else if (prefab.outputPath != null)
                {
                    if (GUI.Button(r, "Local Prefab", GeneralStyles.ToolbarDropDown) == true)
                    {
                        EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(prefab.outputPath, typeof(Object)));
                    }
                }

                r.width = 20F;
                if (GUI.Button(r, GUIContent.none, GeneralStyles.ToolbarDropDown) == true)
                {
                }

                GUILayout.Space(11F);

                r = GUILayoutUtility.GetLastRect();

                r.y     += r.height - 1F;
                r.height = 1F;
                r.width  = this.position.width;
                EditorGUI.DrawRect(r, Color.cyan);
                r.y     += 1F;
                r.height = 20F;

                Rect rH = r;
                rH.width = Mathf.Round(rH.width * .33F);
                GUI.Label(rH, "Hierarchy");

                rH.y     += rH.height;
                rH.height = prefab.rootGameObject.GetHeight();

                Rect view = new Rect(0F, 0F, 0F, rH.height);

                this.hierarchyScrollPosition = GUI.BeginScrollView(rH, this.hierarchyScrollPosition, view);
                {
                    rH.y      = 0F;
                    rH.height = Constants.SingleLineHeight;
                    prefab.rootGameObject.DrawGameObject(rH, this);
                }
                GUI.EndScrollView();

                Rect rI = r;
                rI.x += rH.width;

                rI.width  = 1F;
                rI.height = this.position.height - rI.y;
                rI.y     += 1F;
                EditorGUI.DrawRect(rI, Color.cyan);
                rI.y -= 1F;
                rI.x += 1F;

                rI.width  = this.position.width - rH.xMax - 1F;
                rI.height = Constants.SingleLineHeight;
                GUI.Label(rI, "Inspector");

                rI.y     += rI.height;
                rI.height = this.position.height - rI.yMax;

                if (this.selectedGameObject != null)
                {
                    if (this.selectedGameObject.components != null)
                    {
                        if (this.selectedGameObject.components.Length > 0)
                        {
                            view.height = 0F;
                            for (int i = 0; i < this.selectedGameObject.components.Length; i++)
                            {
                                view.height += this.selectedGameObject.components[i].GetHeight(this, Hierarchy);
                            }
                        }
                        else
                        {
                            view.height = 32F;
                        }

                        this.inspectorScrollPosition = GUI.BeginScrollView(rI, this.inspectorScrollPosition, view);
                        {
                            rI.x = 0F;
                            rI.y = 0F;

                            if (this.selectedGameObject.components.Length > 0)
                            {
                                for (int i = 0; i < this.selectedGameObject.components.Length; i++)
                                {
                                    rI.height = this.selectedGameObject.components[i].GetHeight(this, Hierarchy);
                                    this.selectedGameObject.components[i].DrawComponent(rI, this, this.Hierarchy);
                                    rI.y += rI.height;
                                }
                            }
                            else
                            {
                                rI.height = 32F;
                                rI.xMin  += 5F;
                                rI.xMax  -= 5F;
                                EditorGUI.HelpBox(rI, "Does not contain a Component with importable assets.", MessageType.Info);
                            }
                        }
                        GUI.EndScrollView();
                    }
                    else
                    {
                        EditorGUI.HelpBox(rI, "Loading Components.", MessageType.Info);
                        GUI.Label(rI, GeneralStyles.StatusWheel);
                    }
                }
            }
        }