Ejemplo n.º 1
0
        internal static void ApplyPrefabAddedGameObjects(object userData)
        {
            ObjectInstanceAndSourcePathInfo[] infos = (ObjectInstanceAndSourcePathInfo[])userData;

            GameObject[] gameObjects = new GameObject[infos.Length];
            for (int i = 0; i < infos.Length; i++)
            {
                ObjectInstanceAndSourcePathInfo info = infos[i];
                gameObjects[i] = info.instanceObject as GameObject;
            }

            if (!PrefabUtility.HasSameParent(gameObjects))
            {
                throw new ArgumentException(nameof(gameObjects), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent.");
            }

            if (!HasSameAssetPath(infos))
            {
                throw new ArgumentException(nameof(infos), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.");
            }

            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(infos[0].assetPath, PrefabUtility.SaveVerb.Apply))
            {
                return;
            }

            PrefabUtility.ApplyAddedGameObjects(gameObjects, infos[0].assetPath, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }