Esempio n. 1
0
 private static void OnHierarchyObjectButtonGUI(Object sceneObject)
 {
     if (GUILayout.Button(sceneObject.FullName(FullName.Parts.FullScenePath), CustomEditorStyles.ButtonLeft))
     {
         Selection.activeObject = sceneObject;
         EditorGUIUtility.PingObject(sceneObject);
     }
 }
            private void MoveRelativeReference(string sourceRootPath, string targetRootPath, SerializedProperty sp)
            {
                if (sp.propertyType != SerializedPropertyType.ObjectReference)
                {
                    return;
                }

                Object reference = sp.objectReferenceValue;

                if (!reference || !AssetDatabase.GetAssetPath(reference).IsNullOrEmpty())
                {
                    return;
                }

                sourceRootPath += "/";
                targetRootPath += "/";

                string sourcePath = reference.FullName(FullName.Parts.FullScenePath) + "/";

                if (!sourcePath.StartsWith(sourceRootPath, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                string targetPath = sourcePath.Replace(sourceRootPath, targetRootPath).TrimEnd('/');

                Debug.Log(m_TargetComponent.GetType().Name + " has a " + reference.GetType().Name + " reference on " + m_TargetComponent.name + ": " + sourcePath + " --> " + targetPath, m_TargetComponent);
                GameObject targetObject = GameObject.Find(targetPath);

                if (!targetObject)
                {
                    Debug.LogWarning("Couldn't find " + targetPath);
                    return;
                }

                if (reference is GameObject)
                {
                    sp.objectReferenceValue = targetObject;
                }
                else
                {
                    sp.objectReferenceValue = targetObject.GetComponent(reference.GetType());

                    if (!sp.objectReferenceValue)
                    {
                        Debug.LogWarning("Couldn't find a component that matches type " + reference.GetType().Name, reference);
                    }
                }
            }
        private static void RepopulateSelection(bool forceRepopulate)
        {
            List <Object> objects = new List <Object>();
            ErrorReport   report  = new ErrorReport();

            try {
                if (EditorUtility.DisplayCancelableProgressBar("Repopulating", "Searching...", 0))
                {
                    report.Error("User canceled");
                }
                else
                {
                    foreach (Object o in Selection.objects)
                    {
                        GameObject go = o as GameObject;
                        if (go != null)
                        {
                            if (!objects.Contains(go))
                            {
                                objects.Add(go);
                                List <GameObject> children = new List <GameObject>();
                                GetChildrenRecursive(go, children);
                                foreach (GameObject child in children)
                                {
                                    if (!objects.Contains(child))
                                    {
                                        objects.Add(child);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Component component = o as Component;
                            if (component != null)
                            {
                                objects.Add(component);
                                AutoPopulate(component, forceRepopulate, report);
                            }
                        }
                    }

                    for (int i = 0; i < objects.Count; i++)
                    {
                        Object o = objects[i];
                        if (EditorUtility.DisplayCancelableProgressBar(
                                "Repopulating",
                                o.FullName(Extensions.FullNameFlags.FullSceneOrAssetPath),
                                (float)i / objects.Count))
                        {
                            report.Error("User canceled");
                            break;
                        }
                        GameObject go = o as GameObject;
                        if (go != null)
                        {
                            // use non-recursive, because we already unrolled all the child objects when we were searching above
                            AutoPopulate(go, false, forceRepopulate, report);
                        }
                        else
                        {
                            Component component = o as Component;
                            if (component != null)
                            {
                                AutoPopulate(component, forceRepopulate, report);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                report.HandleException(e);
            } finally {
                if (objects.Count == 0)
                {
                    report.Warning("Nothing selected was Auto-populatable");
                }
                report.Done();
                EditorUtility.ClearProgressBar();
            }
        }